Commit Graph

29376 Commits

Author SHA1 Message Date
David Spickett
a8af51dfa5 [lldb][test] Skip global module cache on Arm/AArch64 Linux (again)
This reverts commit 01c4ecb7ae,
d14d52158b and
a756dc4724.

This removes the logging and workaround I added earlier,
and puts back the skip for Arm/AArch64 Linux.

I've not seen it fail on AArch64 since, but let's not create
more noise if it does.

I've written up the issue as https://github.com/llvm/llvm-project/issues/76057.
It's something to do with trying to destroy a process while
a thread is doing a single sep. So my workaround wouldn't have
worked in any case. It needs a more involved fix.
2023-12-20 13:56:40 +00:00
David Spickett
83f8caeab4 [lldb][test] Skip runlocker test on AArch64 Linux
This has been flaky for a while, for example
https://lab.llvm.org/buildbot/#/builders/96/builds/50350

```
Command Output (stdout):
--
lldb version 18.0.0git (https://github.com/llvm/llvm-project.git revision 3974d89bde)
  clang revision 3974d89bde
  llvm revision 3974d89bde
"can't evaluate expressions when the process is running."
```

```
  PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
   #0 0x0000ffffa46191a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x529a1a0)
   #1 0x0000ffffa4617144 llvm::sys::RunSignalHandlers() (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x5298144)
   #2 0x0000ffffa46198d0 SignalHandler(int) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x529a8d0)
   #3 0x0000ffffab25b7dc (linux-vdso.so.1+0x7dc)
   #4 0x0000ffffab13d050 /build/glibc-Q8DG8B/glibc-2.31/string/../sysdeps/aarch64/multiarch/memcpy_advsimd.S:92:0
   #5 0x0000ffffa446f420 lldb_private::process_gdb_remote::GDBRemoteRegisterContext::PrivateSetRegisterValue(unsigned int, llvm::ArrayRef<unsigned char>) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x50f0420)
   #6 0x0000ffffa446f7b8 lldb_private::process_gdb_remote::GDBRemoteRegisterContext::GetPrimordialRegister(lldb_private::RegisterInfo const*, lldb_private::process_gdb_remote::GDBRemoteCommunicationClient&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x50f07b8)
   #7 0x0000ffffa446f308 lldb_private::process_gdb_remote::GDBRemoteRegisterContext::ReadRegisterBytes(lldb_private::RegisterInfo const*) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x50f0308)
   #8 0x0000ffffa446ec1c lldb_private::process_gdb_remote::GDBRemoteRegisterContext::ReadRegister(lldb_private::RegisterInfo const*, lldb_private::RegisterValue&) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x50efc1c)
   #9 0x0000ffffa412eaa4 lldb_private::RegisterContext::ReadRegisterAsUnsigned(lldb_private::RegisterInfo const*, unsigned long) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x4dafaa4)
  #10 0x0000ffffa420861c ReadLinuxProcessAddressMask(std::shared_ptr<lldb_private::Process>, llvm::StringRef) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x4e8961c)
  #11 0x0000ffffa4208430 ABISysV_arm64::FixCodeAddress(unsigned long) (/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lib/python3.8/site-packages/lldb/_lldb.cpython-38-aarch64-linux-gnu.so+0x4e89430)
```

Judging by the backtrace something is trying to read the pointer authentication address/code mask
registers. This explains why I've not seen this issue locally, as the buildbot runs on Graviton
3 with has the pointer authentication extension.

I will try to reproduce, fix and re-enable the test.
2023-12-20 11:05:52 +00:00
David Spickett
01c4ecb7ae [lldb][test] Remove Arm/AArch64 Linux skip for global modules test
So we can see it failing and get the extra logged information.
2023-12-20 09:42:07 +00:00
David Spickett
d14d52158b [lldb][test] Add extra logging for module cache test
And remove the workaround I was trying, as this logging may prove what
the actual issue is.

Which I think is that the thread plan map in Process is cleared before
the threads are destroyed. So Thread::ShouldStop could be getting
the current plan, then the plan map is cleared, then Thread::ShouldStop
is deciding based on that plan to pop a plan from the now empty stack.
2023-12-20 09:41:33 +00:00
David Spickett
a756dc4724 [lldb][test] Try a workaround for module cache test on Arm/AArch64 Linux
If this works it'll give me a clue for the underlying issue.
2023-12-20 08:46:10 +00:00
Pete Lawrence
8ddf98ad4b
[lldb] Remove unused GetChildAtIndexPath(...) methods from ValueObject.cpp (#75870)
This a follow-up PR from this other one:
https://github.com/llvm/llvm-project/pull/74413

Nothing calls into these two methods, so we (@DavidSpickett,
@adrian-prantl, and I) agreed to remove them once we merged the previous
PR.
2023-12-19 15:00:56 -08:00
Adrian Prantl
45657e81a1
Remove unused FileSPec::IsResolved() functionality. (#75840)
This API seems to be completely unused. Should we just remove it?
2023-12-19 08:49:12 -08:00
David Spickett
970152bec1 [lldb] Add issue link for TestUniqueTypes4.py Windows skip
The changes to this test uncovered a pre-existing issue that I've
documented in the linked issue.
2023-12-19 14:25:23 +00:00
Pavel Labath
3068d277fd
[lldb] Fix TestSBValueSynthetic on windows (#75908)
We don't have a std::vector formatter on windows, so use a custom
formatter in this test to avoid relying on std::vector.
2023-12-19 09:58:25 +01:00
David Spickett
87bf1afbbf
[lldb][PDB] Update max matches test for type queries (#75813)
NestedClass will be found via Class::NestedClass and
ClassTypedef::NestedClass. So the first part of the test gets 2 results
as the default is to find all matching types.

In the next part, we ask for only the first match and expect to get only
1 of those two possible results.
2023-12-19 08:54:03 +00:00
Pavel Labath
927926b8af
[lldb] Fix a quirk in SBValue::GetDescription (#75793)
The function was using the default version of ValueObject::Dump, which
has a default of using the synthetic-ness of the top-level value for
determining whether to print _all_ values as synthetic. This resulted in
some unusual behavior, where e.g. a std::vector is stringified as
synthetic if its dumped as the top level object, but in its raw form if
it is a member of a struct without a pretty printer.

The SBValue class already has properties which determine whether one
should be looking at the synthetic view of the object (and also whether
to use dynamic types), so it seems more natural to use that.
2023-12-18 21:23:03 +01:00
Kazu Hirata
364d7e775f [lldb] Use StringRef::starts_with (NFC)
This patch replaces uses of StringRef::startswith with
StringRef::starts_with for consistency with
std::{string,string_view}::starts_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-17 15:51:48 -08:00
Kazu Hirata
ee667db4b8 [lldb] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-16 15:02:15 -08:00
Kazu Hirata
744f38913f [lldb] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-16 14:39:37 -08:00
Alex Langford
7113c80289
[lldb][NFCI] Remove unused parameter from BreakpointResolver*::CreateFromStructuredData (#75374)
These appear to be unused.
2023-12-15 10:26:01 -08:00
Greg Clayton
8959cef135
[lldb] Trying to fix windows buildbots after #74786 (#75566)
This patch fixes the SymbolFilePDBTests::TestMaxMatches(...) by making
it test what it was testing before, see comments in the test case for
details.

It also disables TestUniqueTypes4.py for now until we can debug or fix
why it isn't working.
2023-12-15 11:55:40 +00:00
Michael Christensen
4051942575
Add option to pass thread ID to thread select command (#73596)
We'd like a way to select the current thread by its thread ID (rather
than its internal LLDB thread index).

This PR adds a `-t` option (`--thread_id` long option) that tells the
`thread select` command to interpret the `<thread-index>` argument as a
thread ID.

Here's an example of it working:
```
michristensen@devbig356 llvm/llvm-project (thread-select-tid) » ../Debug/bin/lldb ~/scratch/cpp/threading/a.out
(lldb) target create "/home/michristensen/scratch/cpp/threading/a.out"
Current executable set to '/home/michristensen/scratch/cpp/threading/a.out' (x86_64).
(lldb) b 18
Breakpoint 1: where = a.out`main + 80 at main.cpp:18:12, address = 0x0000000000000850
(lldb) run
Process 215715 launched: '/home/michristensen/scratch/cpp/threading/a.out' (x86_64)
This is a thread, i=1
This is a thread, i=2
This is a thread, i=3
This is a thread, i=4
This is a thread, i=5
Process 215715 stopped
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555400850 a.out`main at main.cpp:18:12
   15     for (int i = 0; i < 5; i++) {
   16       pthread_create(&thread_ids[i], NULL, foo, NULL);
   17     }
-> 18     for (int i = 0; i < 5; i++) {
   19       pthread_join(thread_ids[i], NULL);
   20     }
   21     return 0;
(lldb) thread select 2
* thread #2, name = 'a.out'
    frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
->  0x7ffff68f9918 <+72>: cmpq   $-0x1000, %rax ; imm = 0xF000
    0x7ffff68f991e <+78>: ja     0x7ffff68f9952 ; <+130>
    0x7ffff68f9920 <+80>: movl   %edx, %edi
    0x7ffff68f9922 <+82>: movl   %eax, 0xc(%rsp)
(lldb) thread info
thread #2: tid = 216047, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'

(lldb) thread list
Process 215715 stopped
  thread #1: tid = 215715, 0x0000555555400850 a.out`main at main.cpp:18:12, name = 'a.out', stop reason = breakpoint 1.1
* thread #2: tid = 216047, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
  thread #3: tid = 216048, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
  thread #4: tid = 216049, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
  thread #5: tid = 216050, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
  thread #6: tid = 216051, 0x00007ffff68f9918 libc.so.6`__nanosleep + 72, name = 'a.out'
(lldb) thread select 215715
error: invalid thread #215715.
(lldb) thread select -t 215715
* thread #1, name = 'a.out', stop reason = breakpoint 1.1
    frame #0: 0x0000555555400850 a.out`main at main.cpp:18:12
   15     for (int i = 0; i < 5; i++) {
   16       pthread_create(&thread_ids[i], NULL, foo, NULL);
   17     }
-> 18     for (int i = 0; i < 5; i++) {
   19       pthread_join(thread_ids[i], NULL);
   20     }
   21     return 0;
(lldb) thread select -t 216051
* thread #6, name = 'a.out'
    frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
->  0x7ffff68f9918 <+72>: cmpq   $-0x1000, %rax ; imm = 0xF000
    0x7ffff68f991e <+78>: ja     0x7ffff68f9952 ; <+130>
    0x7ffff68f9920 <+80>: movl   %edx, %edi
    0x7ffff68f9922 <+82>: movl   %eax, 0xc(%rsp)
(lldb) thread select 3
* thread #3, name = 'a.out'
    frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
->  0x7ffff68f9918 <+72>: cmpq   $-0x1000, %rax ; imm = 0xF000
    0x7ffff68f991e <+78>: ja     0x7ffff68f9952 ; <+130>
    0x7ffff68f9920 <+80>: movl   %edx, %edi
    0x7ffff68f9922 <+82>: movl   %eax, 0xc(%rsp)
(lldb) thread select -t 216048
* thread #3, name = 'a.out'
    frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
->  0x7ffff68f9918 <+72>: cmpq   $-0x1000, %rax ; imm = 0xF000
    0x7ffff68f991e <+78>: ja     0x7ffff68f9952 ; <+130>
    0x7ffff68f9920 <+80>: movl   %edx, %edi
    0x7ffff68f9922 <+82>: movl   %eax, 0xc(%rsp)
(lldb) thread select --thread_id 216048
* thread #3, name = 'a.out'
    frame #0: 0x00007ffff68f9918 libc.so.6`__nanosleep + 72
libc.so.6`__nanosleep:
->  0x7ffff68f9918 <+72>: cmpq   $-0x1000, %rax ; imm = 0xF000
    0x7ffff68f991e <+78>: ja     0x7ffff68f9952 ; <+130>
    0x7ffff68f9920 <+80>: movl   %edx, %edi
    0x7ffff68f9922 <+82>: movl   %eax, 0xc(%rsp)
(lldb) help thread select
Change the currently selected thread.

Syntax: thread select <cmd-options> <thread-index>

Command Options Usage:
  thread select [-t] <thread-index>

       -t ( --thread_id )
            Provide a thread ID instead of a thread index.

     This command takes options and free-form arguments.  If your arguments
     resemble option specifiers (i.e., they start with a - or --), you must use
     ' -- ' between the end of the command options and the beginning of the
     arguments.
(lldb) c
Process 215715 resuming
Process 215715 exited with status = 0 (0x00000000)
```
2023-12-14 15:19:38 -08:00
cmtice
e692d08360
[LLDB] Add more helper functions to CompilerType class (second try). (#73472)
This adds 23 new helper functions to LLDB's CompilerType class, things
like IsSmartPtrType, IsPromotableIntegerType,
GetNumberofNonEmptyBaseClasses, and GetTemplateArgumentType (to name a
few).

It also has run clang-format on the files CompilerType.{h,cpp}.

These helper functions are needed as part of the implementation for the
Data Inspection Language, (see
https://discourse.llvm.org/t/rfc-data-inspection-language/69893).
2023-12-14 14:10:19 -08:00
Walter Erquinigo
aa207674f9
[lldb-dap] Implement command directives (#74808)
This adds support for optionally prefixing any command with `?` and/or
`!`.
- `?` prevents the output of a commands to be printed to the console
unless it fails.
- `!` aborts the dap if the command fails.

They come in handy when programmatically running commands on behalf of
the user without wanting them to know unless they fail, or when a
critical setup is required as part of launchCommands and it's better to
abort on failures than to silently skip.
2023-12-14 15:04:35 -05:00
David Spickett
1bce61e6b0 [lldb] Remove PopPlan asserts and skip test on Arm/AArch64 Linux
This reverts commit 481bb62e50 and
71b4d7498f, along with the logging
and assert I had added to the test previously.

Now that I've caught it failing on Arm:
https://lab.llvm.org/buildbot/#/builders/17/builds/46598

Now I have enough to investigate, skip the test on the effected
platforms while I do that.
2023-12-14 19:17:49 +00:00
Kevin Frei
0544c78172
Fix a crash from character type confusion interaction with libedit (#75388)
If you type `settings show <tab>` LLDB might crash, depending on the
version of libedit you're compiled with, and whether you're compiled
with `-DLLDB_EDITLINE_USE_WCHAR=0` (and depending on how the optimizer
lays out the stack...)

The issue has to do with trying to figure out whether the libedit
`getchar` callback is supposed to read a wide or 8 bit character. In
order to maintain backward compatibility, there's really no 'clean' way
to do it. We just have to make sure that we're invoking el_[w]getc with
a buffer that is as wide as the getchar callback (registered by the
`SetGetCharacterFunction` function further down in `Editline.cpp`.

So, it's 'fixed' with a comment, and a wider version of the 'reply'
variable.

Co-authored-by: Kevin Frei <freik@meta.com>
2023-12-14 11:10:51 -08:00
David Blaikie
5bc1adff69 Revert "lldb: Cache string hash during ConstString pool queries/insertions"
Underlying StringMap API for providing a hash has caused some problems
(observed a crash in lld) - so reverting this until I can figure out/fix
what's going on there.

This reverts commit 52ba075571.
This reverts commit 2e19760230.
2023-12-14 17:44:18 +00:00
David Spickett
71b4d7498f [lldb] Fixup PopPlan assert
Fixes 481bb62e50.
2023-12-14 16:55:07 +00:00
David Spickett
481bb62e50 [lldb] Assert immediately prior to calling PopPlan
This is part of ongoing attempts to catch the test from
2684281d20 failing on Arm and AArch64.

I did get logs for the failure but only on Arm, where the backtrace is
truncated. So, let's do the assert that PopPlan was going to do,
before we call it.

Then I should know exactly which PopPlan is asserting.

Technically I should take a mutex here, but technically I shouldn't
be debugging via buildbot, so I'm going to take the risk temporarily.
2023-12-14 16:51:12 +00:00
David Spickett
d0f5039e5d Reland "Add a test for evicting unreachable modules from the global module cache (#74894)"
This reverts commit 35dacf2f51.

And relands the original change with two additions so I can debug the failure on Arm/AArch64:
* Enable lldb step logging in the tests.
* Assert that the current plan is not the base plan at the spot I believe is calling PopPlan.

These will be removed and replaced with a proper fix once I see some failures on the bots,
I couldn't reproduce it locally.

(also, no sign of it on the x86_64 bot)
2023-12-14 10:54:03 +00:00
Augusto Noronha
b047c91164
[lldb] Skip 2 newly introduced tests from running on DWARF2 and clang 11 (#75406) 2023-12-13 16:30:39 -08:00
Pete Lawrence
c1552695ae
[lldb] Return index of element in ValueObject path instead of the element's value (#74413)
It's more meaningful and actionable to indicate which element in the
array has an issue by returning that element's index instead of its
value. The value can be ambiguous if at least one other element has the
same value.

The first parameter for these methods is `idxs`, an array of indices
that represent a path from a (root) parent to on of its descendants,
typically though intermediate descendants. When the path leads to a
descendant that doesn't exist, the method is supposed to indicate where
things went wrong by setting an index to `&index_of_error`, the second
parameter.

The problem is the method sets `*index_of_error` to the index of the
most recent parent's child in the hierarchy, which isn't very useful if
there's more one index with the same value in the path.

In this example, each element in the path has a value that's the same as
another element.

```cpp
GetChildAtIndexPath({1, 2, 3, 3, 1, 1, 2}, &index_of_error);
```

Say the the second `1` in the path (the 5th element at `[4]`) doesn't
exist and the code returns a `nullptr`. In that situation, the code sets
`*index_of_error` to `1`, but that's an ambiguous hint can implicate the
1st, 5th, or 6th element (at `[0]`, `[4]`, or `[5]`).

It’s more helpful to set `*index_of_error` to `4` to clearly indicate
which element in `idxs` has the issue.
2023-12-13 15:26:05 -08:00
David Spickett
f59fed261e [lldb][PDB] TypeQuery parameter should be ConstString 2023-12-13 12:46:16 +00:00
David Spickett
e34c35a21c [lldb][PDB] Fix more issues with PDB tests 2023-12-13 11:49:24 +00:00
David Spickett
35dacf2f51 Revert "Add a test for evicting unreachable modules from the global module cache (#74894)"
This reverts commit 2684281d20.

Due to being flaky on Arm and AArch64 buildbots.
2023-12-13 11:34:43 +00:00
David Spickett
887f211028 [lldb][PDB] Attempt to fix tests on Windows 2023-12-13 11:15:46 +00:00
Greg Clayton
dcbf1e4e49
[lldb] Fix buildbots after PR 74786 (#75272)
Fix unexpected pass after
https://github.com/llvm/llvm-project/pull/74786.
2023-12-13 09:12:30 +00:00
Greg Clayton
dd95877958
[lldb] Make only one function that needs to be implemented when searching for types (#74786)
This patch revives the effort to get this Phabricator patch into
upstream:

https://reviews.llvm.org/D137900

This patch was accepted before in Phabricator but I found some
-gsimple-template-names issues that are fixed in this patch.

A fixed up version of the description from the original patch starts
now.

This patch started off trying to fix Module::FindFirstType() as it
sometimes didn't work. The issue was the SymbolFile plug-ins didn't do
any filtering of the matching types they produced, and they only looked
up types using the type basename. This means if you have two types with
the same basename, your type lookup can fail when only looking up a
single type. We would ask the Module::FindFirstType to lookup "Foo::Bar"
and it would ask the symbol file to find only 1 type matching the
basename "Bar", and then we would filter out any matches that didn't
match "Foo::Bar". So if the SymbolFile found "Foo::Bar" first, then it
would work, but if it found "Baz::Bar" first, it would return only that
type and it would be filtered out.

Discovering this issue lead me to think of the patch Alex Langford did a
few months ago that was done for finding functions, where he allowed
SymbolFile objects to make sure something fully matched before parsing
the debug information into an AST type and other LLDB types. So this
patch aimed to allow type lookups to also be much more efficient.

As LLDB has been developed over the years, we added more ways to to type
lookups. These functions have lots of arguments. This patch aims to make
one API that needs to be implemented that serves all previous lookups:

- Find a single type
- Find all types
- Find types in a namespace

This patch introduces a `TypeQuery` class that contains all of the state
needed to perform the lookup which is powerful enough to perform all of
the type searches that used to be in our API. It contain a vector of
CompilerContext objects that can fully or partially specify the lookup
that needs to take place.

If you just want to lookup all types with a matching basename,
regardless of the containing context, you can specify just a single
CompilerContext entry that has a name and a CompilerContextKind mask of
CompilerContextKind::AnyType.

Or you can fully specify the exact context to use when doing lookups
like: CompilerContextKind::Namespace "std"
CompilerContextKind::Class "foo"
CompilerContextKind::Typedef "size_type"

This change expands on the clang modules code that already used a
vector<CompilerContext> items, but it modifies it to work with
expression type lookups which have contexts, or user lookups where users
query for types. The clang modules type lookup is still an option that
can be enabled on the `TypeQuery` objects.

This mirrors the most recent addition of type lookups that took a
vector<CompilerContext> that allowed lookups to happen for the
expression parser in certain places.

Prior to this we had the following APIs in Module:

```
void
Module::FindTypes(ConstString type_name, bool exact_match, size_t max_matches,
                  llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
                  TypeList &types);

void
Module::FindTypes(llvm::ArrayRef<CompilerContext> pattern, LanguageSet languages,
                  llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files,
                  TypeMap &types);

void Module::FindTypesInNamespace(ConstString type_name,
                                  const CompilerDeclContext &parent_decl_ctx,
                                  size_t max_matches, TypeList &type_list);
```

The new Module API is much simpler. It gets rid of all three above
functions and replaces them with:

```
void FindTypes(const TypeQuery &query, TypeResults &results);
```
The `TypeQuery` class contains all of the needed settings:

- The vector<CompilerContext> that allow efficient lookups in the symbol
file classes since they can look at basename matches only realize fully
matching types. Before this any basename that matched was fully realized
only to be removed later by code outside of the SymbolFile layer which
could cause many types to be realized when they didn't need to.
- If the lookup is exact or not. If not exact, then the compiler context
must match the bottom most items that match the compiler context,
otherwise it must match exactly
- If the compiler context match is for clang modules or not. Clang
modules matches include a Module compiler context kind that allows types
to be matched only from certain modules and these matches are not needed
when d oing user type lookups.
- An optional list of languages to use to limit the search to only
certain languages

The `TypeResults` object contains all state required to do the lookup
and store the results:
- The max number of matches
- The set of SymbolFile objects that have already been searched
- The matching type list for any matches that are found

The benefits of this approach are:
- Simpler API, and only one API to implement in SymbolFile classes
- Replaces the FindTypesInNamespace that used a CompilerDeclContext as a
way to limit the search, but this only worked if the TypeSystem matched
the current symbol file's type system, so you couldn't use it to lookup
a type in another module
- Fixes a serious bug in our FindFirstType functions where if we were
searching for "foo::bar", and we found a "baz::bar" first, the basename
would match and we would only fetch 1 type using the basename, only to
drop it from the matching list and returning no results
2023-12-12 16:51:49 -08:00
jimingham
2684281d20
Add a test for evicting unreachable modules from the global module cache (#74894)
When you debug a binary and the change & rebuild and then rerun in lldb
w/o quitting lldb, the Modules in the Global Module Cache for the old
binary & .o files if used are now "unreachable". Nothing in lldb is
holding them alive, and they've already been unlinked. lldb will
properly discard them if there's not another Target referencing them.

However, this only works in simple cases at present. If you have several
Targets that reference the same modules, it's pretty easy to end up
stranding Modules that are no longer reachable, and if you use a
sequence of SBDebuggers unreachable modules can also get stranded. If
you run a long-lived lldb process and are iteratively developing on a
large code base, lldb's memory gets filled with useless Modules.

This patch adds a test for the mode that currently works:

(lldb) target create foo
(lldb) run
<rebuild foo outside lldb>
(lldb) run

In that case, we do delete the unreachable Modules.

The next step will be to add tests for the cases where we fail to do
this, then see how to safely/efficiently evict unreachable modules in
those cases as well.
2023-12-12 11:28:06 -08:00
Pete Lawrence
0e9879ed97
[lldb] Correctly check and report error states in StackFrame.cpp (#74414)
This commits fixes a few subtle bugs where the method:
1. Declares a local `Status error` which eclipses the method's parameter
`Status &error`.
- The method then sets the error state to the local `error` and returns
without ever touching the parameter `&error`.
- This effectively traps the error state and its message from ever
reaching the caller.
- I also threw in a null pointer check in case the callee doesn't set
its `Status` parameter but returns `0`/`nullptr`.

2. Declares a local `Status deref_error` (good), passes it to the
`Dereference` method (also good), but then checks the status of the
method's `Status &error` parameter (not good).
- The fix checks `deref_error` instead and also checks for a `nullptr`
return value.
- There's a good opportunity here for a future PR that changes the
`Dereference` method to fold an error state into the `ValueObject`
return value's `m_error` instead of using a parameter.

3. Declares another local `Status error`, which it doesn't pass to a
method (because there isn't a parameter for it), and then checks for an
error condition that never happens.
- The fix just checks the callee's return value, because that's all it
has to go on.
	- This likely comes from a copy/paste from issue 1 above.


rdar://119155810
2023-12-12 09:50:18 -03:00
David Blaikie
2e19760230 lldb: Cache string hash during ConstString pool queries/insertions
lldb was rehashing the string 3 times (once to determine which StringMap
to use, once to query the StringMap, once to insert) on insertion (twice
on successful lookup).

This patch allows the lldb to benefit from hash improvements in LLVM
(from djbHash to xxh3).

Though further changes would be needed to cache this value to disk - we
shouldn't rely on the StringMap::hash remaining the same in the
future/this value should not be serialized to disk. If we want cache
this value StringMap should take a hashing template parameter to allow
for a fixed hash to be requested.
2023-12-12 00:07:08 +00:00
Augusto Noronha
a37fa2a8e1
[lldb] Disable new TestLocationListLookup when clang version is <= 11 (#75102)
The newly introduced LocationListLookupTestCase.test_loclist_expr test
fails with older clangs.
2023-12-11 14:40:43 -08:00
Walter Erquinigo
0ea19bd333
[lldb-dap] Emit declarations along with variables (#74865)
This is an extension to the protocol that emits the declaration
information along with the metadata of each variable. This can be used
by vscode extensions to implement, for example, a "goToDefinition"
action in the debug tab, or for showing the value of a variable right
next to where it's declared during a debug session.
As this is cheap, I'm not gating this information under any setting.
2023-12-11 15:20:06 -05:00
Walter Erquinigo
07ed3258d0
[lldb-dap] Include [opt] in the frame name only if a custom frame format is not specified. (#74861)
Currently there's an include in which `[opt]` might be emitted twice if
the frame format also asks for it. As a trivial fix, we should manually
emit `[opt]` only if a custom frame format is not specified.
2023-12-11 14:46:25 -05:00
Felipe de Azevedo Piovezan
06d6af72fb
[lldb][NFC] Simplify DWARRFDeclContext::GetQualifiedName (#74788)
This commit factors out the logic building each component of a qualified
name into its own function so that it may be reused by a future commit,
while also simplifying the logic of assembling these pieces together by
using llvm::interleave.
2023-12-11 11:16:36 -03:00
Felipe de Azevedo Piovezan
162248c22d
[SymbolFileDWARF][NFC] Remove duplicated code checking for type tags (#74773)
There was duplicated (and complex) code querying whether tags were
type-like tags (i.e. class or struct); this has been factored out into a
helper function.

There was also a comment about not comparing identical DIEs without ever
performing that check; this comment has been removed. It was likely a
result of copy paste from another function in this same file which
actually does that check.
2023-12-11 08:01:04 -03:00
Kazu Hirata
cc4ecfd68b
[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)
This patch renames {starts,ends}with to {starts,ends}_with for
consistency with std::{string,string_view}::{starts,ends}_with in
C++20.  Since there are only a handful of occurrences, this patch
skips the deprecation phase and simply renames them.
2023-12-09 14:28:45 -08:00
David Spickett
61f18255fa [lldb][test] Disable image lookup colour test on Mac OS
I think it can work there but we need to correct the CHECK lines.

```
command-image-lookup-color.test:34:11: error: CHECK7: expected string not found in input
          ^
```
https://green.lab.llvm.org/green/view/LLDB/job/as-lldb-cmake/10880/testReport/

I don't have a way to see the full output.
2023-12-08 13:44:06 +00:00
David Spickett
810d09faf8 [lldb][test] Disable image lookup colour test on Windows
On Linux `main.c` shows up in the symbol search but this is not the
case on Windows according to:
https://lab.llvm.org/buildbot/#/builders/219/builds/7422/steps/6/logs/stdio

It's possible we could make this test work there once function
search highlighting is implemented.
2023-12-08 13:36:41 +00:00
David Spickett
ce3c7c0910 [lldb][test] Don't check line number in image lookup colour test
We can assume the correct symbol is found, so putting the line
number here is just going to confuse anyone extending these tests.
2023-12-08 13:34:07 +00:00
David Spickett
ffd61c1e96 [lldb] Add missing nullptr checks when colouring symbol output
This adds some checks missed by c90cb6eee8,
probably because some tests only run on certain platforms.
2023-12-08 11:24:07 +00:00
taalhaataahir0102
c90cb6eee8
[lldb] colorize symbols in image lookup with a regex pattern (#69422)
Fixes https://github.com/llvm/llvm-project/issues/57372

Previously some work has already been done on this. A PR was generated
but it remained in review:
https://reviews.llvm.org/D136462

In short previous approach was following:
Changing the symbol names (making the searched part colorized) ->
printing them -> restoring the symbol names back in their original form.

The reviewers suggested that instead of changing the symbol table, this
colorization should be done in the dump functions itself. Our strategy
involves passing the searched regex pattern to the existing dump
functions responsible for printing information about the searched
symbol. This pattern is propagated until it reaches the line in the dump
functions responsible for displaying symbol information on screen.

At this point, we've introduced a new function called
"PutCStringColorHighlighted," which takes the searched pattern, a prefix and suffix,
and the text and applies colorization to highlight the pattern in the
output. This approach aims to streamline the symbol search process to
improve readability of search results.

Co-authored-by: José L. Junior <josejunior@10xengineers.ai>
2023-12-08 11:09:04 +00:00
Mikhail Goncharov
b43ab18204 Reapply "[lldb][test] TestLocationListLookup.py: skip expr check on unsupported platforms (#74818)"
This reverts commit e33302fa12.

there is a fix already, sorry for the noise
2023-12-08 11:43:14 +01:00
Mikhail Goncharov
e33302fa12 Revert "[lldb][test] TestLocationListLookup.py: skip expr check on unsupported platforms (#74818)"
This reverts commit 11a7e5781c.

Test fails: https://lab.llvm.org/buildbot/#/builders/219/builds/7416 and
others.
2023-12-08 11:39:10 +01:00
Michael Buch
11a7e5781c
[lldb][test] TestLocationListLookup.py: skip expr check on unsupported platforms (#74818)
The `expect_expr` check was introduced in
https://github.com/llvm/llvm-project/pull/74772. It is failing on Linux
and Windows, so skip this test to unblock the bots
2023-12-08 10:09:38 +00:00
Michael Buch
58bdef2be7
[lldb][Symbol] Make sure we decrement PC before checking location list (#74772) 2023-12-08 07:32:23 +00:00
jimingham
9d3aec5535
Fix a stall in running quit while a live process is running (#74687)
We need to generate events when finalizing, or we won't know that we
succeeded in stopping the process to detach/kill. Instead, we stall and
then after our 20 interrupt timeout, we kill the process (even if we
were supposed to detach) and exit.

OTOH, we have to not generate events when the Process is being
destructed because shared_from_this has already been torn down, and
using it will cause crashes.
2023-12-07 14:36:27 -08:00
Michael Buch
7de53a8cfe [lldb][test] TestConstStaticIntegralMember.py: un-XFAIL tests for DWARFv5 2023-12-07 11:38:26 +00:00
Felipe de Azevedo Piovezan
71be8f3c23 [lldb] Un-xfail test after commit revert
These tests started passing after this PR landed:
https://github.com/llvm/llvm-project/pull/74580
2023-12-06 14:35:34 -08:00
Michael Buch
4db54e6597
[clang][DebugInfo] Revert "emit definitions for constant-initialized static data-members" (#74580)
This commit reverts the changes in
https://github.com/llvm/llvm-project/pull/71780 and all of its follow-up
patches.

We got reports of the `.debug_names/.debug_gnu_pubnames/gdb_index/etc.`
sections growing by a non-trivial amount for some large projects. While
GCC emits definitions for static data member constants into the Names
index, they do so *only* for explicitly `constexpr` members. We were
indexing *all* constant-initialized const-static members, which is
likely where the significant size difference comes from. However, only
emitting explicitly `constexpr` variables into the index doesn't seem
like a good way forward, since from clang's perspective `const`-static
integrals are `constexpr` too, and that shouldn't be any different in
the debug-info component. Also, as new code moves to `constexpr` instead
of `const` static for constants, such solution would just delay the
growth of the Names index.

To prevent the size regression we revert to not emitting definitions for
static data-members that have no location.

To support access to such constants from LLDB we'll most likely have to
have to make LLDB find the constants by looking at the containing class
first.
2023-12-06 22:13:54 +00:00
Felipe de Azevedo Piovezan
9982f8ee02
[lldb][SymbolFileDWARF][NFC] Remove unnecessary calls to GetDWARFDeclContext (#74523)
The function FindDefinitionTypeForDWARFDeclContext loops over all DIEs
corresponding to types with a certain name and compares the context of
each found DIE with the context of a target DIE. However, the target DIE
never changes throughout this search, and yet we recompute its
DeclContext on every iteration of the search. This is wasteful because
the method is not exactly free (see
DWARFDebugInfoEntry::GetDWARFDeclContextStatic).
2023-12-06 10:42:42 -08:00
Augusto Noronha
901bc5129d
[NFC][lldb] Implement DiagnosticManager::Consume (#74011)
In some situations it may be useful to have a separate DiagnosticManager
instance, and then later of move the contents of that instance back to
the "main" DiagnosticManager. For example, when silently retrying some
operation with different parameters, depending on whether the retry
succeeded or failed, LLDB may want to present a different set of
diagnostics to the user (the ones generated on the first try vs the
retry). Implement DiagnosticManager::Consume to allow for this use case.
2023-12-05 12:26:10 -08:00
Brad Smith
5c70c181a3
[lldb] Sync OpenBSD GetOSVersion() closer to NetBSD function (#74396)
Also eliminate an unused variable while here.
2023-12-05 02:50:21 -05:00
Brad Smith
98b4c1ee21 [lldb][NFC] Minor formatting nits with some of the NetBSD code 2023-12-04 23:21:45 -05:00
Brad Smith
961d943e39 [lldb] Remove unused variable
lldb/source/Host/netbsd/HostInfoNetBSD.cpp:48:8: warning: unused variable 'osrev_str' [-Wunused-variable]
  char osrev_str[12];
       ^
1 warning generated.
2023-12-04 19:51:31 -05:00
Brad Smith
a2e61bc2f3
[lldb] Additional pieces towards OpenBSD support (#74198) 2023-12-04 15:14:49 -05:00
Kevin Frei
c43c86c285
DEBUGINFOD based DWP acquisition for LLDB (#70996)
I've plumbed the LLVM DebugInfoD client into LLDB, and added automatic
downloading of DWP files to the SymbolFileDWARF.cpp plugin. If you have
DEBUGINFOD_URLS set to a space delimited set of web servers, LLDB will
try to use them as a last resort when searching for DWP files. If you do
*not* have that environment variable set, nothing should be changed.
There's also a setting, per @clayborg 's suggestion, that will override
the environment variable, or can be used instead of the environment
variable. The setting is why I also needed to add an API to the
llvm-debuginfod library

### Test Plan:

Suggestions are welcome here. I should probably have some positive and
negative tests, but I wanted to get the diff up for people who have a
clue what they're doing to rip it to pieces before spending too much
time validating the initial implementation.

---------

Co-authored-by: Kevin Frei <freik@meta.com>
Co-authored-by: Alex Langford <nirvashtzero@gmail.com>
2023-12-04 11:45:40 -08:00
Felipe de Azevedo Piovezan
d24d7edaef [lldb][NFC] Delete unreachable code and dead variable in OptionArgParser
With the combination of an early return and removing an else-after-return, it
becomes evident that there is unreachable code in the function being changed.
2023-12-04 10:23:05 -08:00
Felipe de Azevedo Piovezan
3e98a28513 [lldb][NFC] Remove else after return in OptionArgParse
This will enable us to prove that there is unreachable code in this function in
a subsequent commit.
2023-12-04 10:23:05 -08:00
Felipe de Azevedo Piovezan
7a86cc6c4c [lldb][NFC] Remove unnecessary std::string temporaries
The existing code was taking three substrings from a regex match and converting
to std::strings prior to using them. This may have been done to address
null-termination concerns, but this is not the case:

1. `name` was being used to call `c_str()` and then implicitly converted back to
a `StringRef` on the call to `ToAddress`. While the path `const char *` ->
`StringRef` requires null-termination, we can simply use the original StringRef.
2. `str_offset` was being converted back to a StringRef in order to call a
member method. Member methods can't handle non-null termination.
3. `sign` simply had it's 0-th element accessed.
2023-12-04 10:23:04 -08:00
Brad Smith
b96bae2887
[lldb] Fix building on NetBSD 8.x (#74191)
PT_STOP was introduced with NetBSD 9.0.
2023-12-04 03:02:13 -05:00
Brad Smith
c1e2457a14
[lldb] Fix build on NetBSD (#74190)
lldb/source/Host/netbsd/HostNetBSD.cpp:112:32: error: reinterpret_cast from 'const uint8_t *' (aka 'const unsigned char *') to 'char *' casts away qualifiers
                              {reinterpret_cast<char *>(buffer_sp->GetBytes()),
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
2023-12-04 03:01:38 -05:00
Brad Smith
25ea0e9d9a
[lldb] Make use of LD_LIBRARY_PATH on OpenBSD (#74017) 2023-12-01 16:06:22 -05:00
Brad Smith
c3f0932c18
[lldb] Simplify pipe2(2) handling on FreeBSD (#74019)
FreeBSD 10.x and 11.x support has been dropped leaving 12.x as the
minimum version. This FreeBSD check can be simplified.


812dad536e
2023-12-01 16:05:38 -05:00
Brad Smith
81cd283f06
[lldb/test] Add OpenBSD to _get_platform_os (#74036) 2023-12-01 16:04:19 -05:00
Brad Smith
a37c69ec31
[lldb] Remove pre GCC 4.8 workaround (#73981)
The minimum GCC version was bumped up from 4.8 to 5.1 and then even newer
awhile ago so garbage collect the pre 4.8 workaround.

https://reviews.llvm.org/D66188
2023-11-30 23:14:46 -05:00
Brad Smith
668a4a2380
[lldb] pipe2(2) is also supported by OpenBSD (#74012) 2023-11-30 20:19:36 -05:00
Jason Molenda
9e77d666d8 Correctly disable hardware watchpoints after a fork event
Fix a failure on Linux system where follow-fork-mode
exists, which caused the large watchpoint NFC patch
to be reverted earlier this week.
2023-11-30 14:59:10 -08:00
Nico Weber
22f72642fe [lldb] try to fix build on linux after fc6b72523f
Tries to fix:

    ../../lldb/source/Breakpoint/WatchpointResource.cpp:59:12:
    error: no member named 'find' in namespace 'std'; did you mean 'fill'?
          std::find(m_constituents.begin(), m_constituents.end(), wp_sp);
          ~~~~~^~~~
               fill

(cherry picked from commit a6c62bf1a4)
2023-11-30 14:59:10 -08:00
Jason Molenda
162e4b8c49 Include <vector> in WatchpointResource.h
On macOS <vector> was already included via another
header file, but this failed on the CI bots.  I'd
tested on linux earlier in this patch's life when
the headers were differently arranged.

(cherry picked from commit a0a1ff3ab4)
2023-11-30 14:59:10 -08:00
Jason Molenda
c73a3f16f8 [lldb] [mostly NFC] Large WP foundation: WatchpointResources (#68845)
This patch is rearranging code a bit to add WatchpointResources to
Process. A WatchpointResource is meant to represent a hardware
watchpoint register in the inferior process. It has an address, a size,
a type, and a list of Watchpoints that are using this
WatchpointResource.

This current patch doesn't add any of the features of
WatchpointResources that make them interesting -- a user asking to watch
a 24 byte object could watch this with three 8 byte WatchpointResources.
Or a Watchpoint on 1 byte at 0x1002 and a second watchpoint on 1 byte at
0x1003, these must both be served by a single WatchpointResource on that
doubleword at 0x1000 on a 64-bit target, if two hardware watchpoint
registers were used to track these separately, one of them may not be
hit. Or if you have one Watchpoint on a variable with a condition set,
and another Watchpoint on that same variable with a command defined or
different condition, or ignorecount, both of those Watchpoints need to
evaluate their criteria/commands when their WatchpointResource has been
hit.

There's a bit of code movement to rearrange things in the direction I'll
need for implementing this feature, so I want to start with reviewing &
landing this mostly NFC patch and we can focus on the algorithmic
choices about how WatchpointResources are shared and handled as they're
triggeed, separately.

This patch also stops printing "Watchpoint <n> hit: old value: <x>, new
vlaue: <y>" for Read watchpoints. I could make an argument for print
"Watchpoint <n> hit: current value <x>" but the current output doesn't
make any sense, and the user can print the value if they are
particularly interested. Read watchpoints are used primarily to
understand what code is reading a variable.

This patch adds more fallbacks for how to print the objects being
watched if we have types, instead of assuming they are all integral
values, so a struct will print its elements. As large watchpoints are
added, we'll be doing a lot more of those.

To track the WatchpointSP in the WatchpointResources, I changed the
internal API which took a WatchpointSP and devolved it to a Watchpoint*,
which meant touching several different Process files. I removed the
watchpoint code in ProcessKDP which only reported that watchpoints
aren't supported, the base class does that already.

I haven't yet changed how we receive a watchpoint to identify the
WatchpointResource responsible for the trigger, and identify all
Watchpoints that are using this Resource to evaluate their conditions
etc. This is the same work that a BreakpointSite needs to do when it has
been tiggered, where multiple Breakpoints may be at the same address.

There is not yet any printing of the Resources that a Watchpoint is
implemented in terms of ("watchpoint list", or
SBWatchpoint::GetDescription).

"watchpoint set var" and "watchpoint set expression" take a size
argument which was previously 1, 2, 4, or 8 (an enum). I've changed this
to an unsigned int. Most hardware implementations can only watch 1, 2,
4, 8 byte ranges, but with Resources we'll allow a user to ask for
different sized watchpoints and set them in hardware-expressble terms
soon.

I've annotated areas where I know there is work still needed with
LWP_TODO that I'll be working on once this is landed.

I've tested this on aarch64 macOS, aarch64 Linux, and Intel macOS.

https://discourse.llvm.org/t/rfc-large-watchpoint-support-in-lldb/72116
(cherry picked from commit fc6b72523f)
2023-11-30 14:59:10 -08:00
John Harrison
c8f72856db
[lldb-dap] Fixing a type encoding issue with dap Stopped events. (#72292)
Previously the type of the breakpoint id in the Stopped event was a
uint64_t, however thats the wrong type for a breakpoint id, which can
cause encoding issues when internal breakpoints are hit.
2023-11-30 15:17:12 -05:00
jimingham
d1bf1947e4
Send an explicit interrupt to cancel an attach waitfor. (#72565)
Currently when you interrupt a:

(lldb) process attach -w -n some_process

lldb just closes the connection to the stub and kills the
lldb_private::Process it made for the attach. The stub at the other end
notices the connection go down and exits because of that. But when
communication to a device is handled through some kind of proxy server
which isn't as well behaved as one would wish, that signal might not be
reliable, causing debugserver to persist on the machine, waiting to
steal the next instance of that process.

We can work around those failures by sending an explicit interrupt
before closing down the connection. The stub will also have to be
waiting for the interrupt for this to make any difference. I changed
debugserver to do that.

I didn't make the equivalent change in lldb-server. So long as you
aren't faced with a flakey connection, this should not be necessary.
2023-11-30 09:48:04 -08:00
Michael Buch
effaf41d20
[lldb][DWARFASTParserClang][NFCI] Make ParsedDWARFTypeAttributes parameter const (#73833) 2023-11-30 05:16:23 +00:00
Michael Buch
bcb621f0a1
[lldb][DWARFASTParserClang][NFC] Remove redundant parameter to AddMethodToObjCObjectType (#73832) 2023-11-30 05:15:57 +00:00
Greg Clayton
ce00133e5f
Allow lldb to load .dwp files with large .debug_info or .debug_types. (#73736)
A previous patch to llvm allowed the DWARFUnitIndex class to handle
.debug_info.dwo and .debug_types.dwo sections to go over 4GB by checking
for this case and fixing up the DWARFUnitIndex. LLDB's DWARF parser
tries to use the llvm's DWARF parser when it can, and LLDB's DWARF
parser uses the llvm::DWARFUnitIndex which should allow us to load large
.dwp files, but there were a few things missing on the LLDB front:
- support for parsing DWARFUnit objects when the offset exceeds 4GB due
to a 32 bit truncation issue
- not populating the required DWARF sections when we call
DWARFContext::GetAsLLVM() which didn't allow the fixups to happen as the
data was missing.

This patch fixes these issues and now allows LLDB to parse large .dwp
files without issues. The issue was discovered when running the "target
modules dump separate-debug-info" command on one of these binaries that
used a large .dwp file.

This is unfortunately hard to test without creating a huge .dwp file, so
there are currently no tests for this that I can think of adding that
wouldn't cause disk space constraints or making testing times longer by
producing a huge .dwp file.
2023-11-29 11:19:50 -08:00
Jordan Rupprecht
3d7e6db120
[lldb][test] Remove reason from unittest2.expectedFailure usage (#73028) 2023-11-28 23:36:05 -06:00
Michael Buch
4eb4211924
[lldb][test] TestConstStaticIntegralMember: relax assertion on number of global variables (#73707)
In https://github.com/llvm/llvm-project/pull/73626 we started attaching
`DW_AT_const_value`s on a static data-member's declaration again. In
DWARFv5, those static members are represented with a `DW_TAG_variable`.
When LLDB builds the `ManualDWARFIndex`, it simply iterates over all
DIEs in a CU and puts *any* `DW_TAG_variable` with a constant or
location into the index. So when using the manual index, we can end up
having 2 entries for a static data member in the index, one for the
declaration and one for the definition.

This caused a test failure on Linux (where DWARFv5 is the default and
the tests use the manual index).

This patch loosens the restriction that we find exactly 1 variable.
2023-11-28 17:04:19 -08:00
Greg Clayton
3661eb150e
Add support for parsing type unit entries in .debug_names. (#72952)
This is a follow up patch after .debug_names can now emit local type
unit entries when we compile with type units + DWARF5 + .debug_names.
The pull request that added this functionality was:

https://github.com/llvm/llvm-project/pull/70515

This patch makes sure that the DebugNamesDWARFIndex in LLDB will not
manually need to parse type units if they have a valid index. It also
fixes the index to be able to correctly extract name entries that
reference type unit DIEs. Added a test to verify things work as
expected.
2023-11-28 13:56:45 -08:00
Chelsea Cassanova
c846f8ba10
[lldb][progress] Always report progress upon Progress object destruction (#73605)
This commit allows a final progress report upon the destruction of the
`Progress` object to happen at all times as opposed to when the progress
was not completed.
2023-11-28 10:45:02 -08:00
Haojian Wu
439b16e2b3
[LLDB] Respect the DW_AT_alignment attribute. (#73307)
Part of fixes for #72913.

clang emits `DW_AT_alignment` attribute, however LLDB didn't respect it,
resulting in incorrect RecordDecls built by lldb.

This only fixes non-inheritance cases. The inheritance case will be
handled in a follow-up patch.
2023-11-28 12:27:55 +01:00
David Spickett
b0af8a1ede Revert "[lldb] [mostly NFC] Large WP foundation: WatchpointResources (#68845)"
...and follow ups.

As it has caused test failures on Linux Arm and AArch64:
https://lab.llvm.org/buildbot/#/builders/96/builds/49126
https://lab.llvm.org/buildbot/#/builders/17/builds/45824

```
  lldb-shell :: Subprocess/clone-follow-child-wp.test
  lldb-shell :: Subprocess/fork-follow-child-wp.test
  lldb-shell :: Subprocess/vfork-follow-child-wp.test
```

This reverts commit a6c62bf1a4,
commit a0a1ff3ab4 and commit
fc6b72523f.
2023-11-28 09:39:37 +00:00
David Spickett
1459c627f0 [lldb][PDB] Fix message order in test case
Launch/stopped ordering was fixed by bd8f1068ca
but the Windows on Arm bot wasn't running at the time it landed.
2023-11-28 09:15:51 +00:00
Nico Weber
a6c62bf1a4 [lldb] try to fix build on linux after fc6b72523f
Tries to fix:

    ../../lldb/source/Breakpoint/WatchpointResource.cpp:59:12:
    error: no member named 'find' in namespace 'std'; did you mean 'fill'?
          std::find(m_constituents.begin(), m_constituents.end(), wp_sp);
          ~~~~~^~~~
               fill
2023-11-28 08:53:05 +09:00
Jason Molenda
a0a1ff3ab4 Include <vector> in WatchpointResource.h
On macOS <vector> was already included via another
header file, but this failed on the CI bots.  I'd
tested on linux earlier in this patch's life when
the headers were differently arranged.
2023-11-27 13:39:24 -08:00
Jason Molenda
fc6b72523f
[lldb] [mostly NFC] Large WP foundation: WatchpointResources (#68845)
This patch is rearranging code a bit to add WatchpointResources to
Process. A WatchpointResource is meant to represent a hardware
watchpoint register in the inferior process. It has an address, a size,
a type, and a list of Watchpoints that are using this
WatchpointResource.

This current patch doesn't add any of the features of
WatchpointResources that make them interesting -- a user asking to watch
a 24 byte object could watch this with three 8 byte WatchpointResources.
Or a Watchpoint on 1 byte at 0x1002 and a second watchpoint on 1 byte at
0x1003, these must both be served by a single WatchpointResource on that
doubleword at 0x1000 on a 64-bit target, if two hardware watchpoint
registers were used to track these separately, one of them may not be
hit. Or if you have one Watchpoint on a variable with a condition set,
and another Watchpoint on that same variable with a command defined or
different condition, or ignorecount, both of those Watchpoints need to
evaluate their criteria/commands when their WatchpointResource has been
hit.

There's a bit of code movement to rearrange things in the direction I'll
need for implementing this feature, so I want to start with reviewing &
landing this mostly NFC patch and we can focus on the algorithmic
choices about how WatchpointResources are shared and handled as they're
triggeed, separately.

This patch also stops printing "Watchpoint <n> hit: old value: <x>, new
vlaue: <y>" for Read watchpoints. I could make an argument for print
"Watchpoint <n> hit: current value <x>" but the current output doesn't
make any sense, and the user can print the value if they are
particularly interested. Read watchpoints are used primarily to
understand what code is reading a variable.

This patch adds more fallbacks for how to print the objects being
watched if we have types, instead of assuming they are all integral
values, so a struct will print its elements. As large watchpoints are
added, we'll be doing a lot more of those.

To track the WatchpointSP in the WatchpointResources, I changed the
internal API which took a WatchpointSP and devolved it to a Watchpoint*,
which meant touching several different Process files. I removed the
watchpoint code in ProcessKDP which only reported that watchpoints
aren't supported, the base class does that already.

I haven't yet changed how we receive a watchpoint to identify the
WatchpointResource responsible for the trigger, and identify all
Watchpoints that are using this Resource to evaluate their conditions
etc. This is the same work that a BreakpointSite needs to do when it has
been tiggered, where multiple Breakpoints may be at the same address.

There is not yet any printing of the Resources that a Watchpoint is
implemented in terms of ("watchpoint list", or
SBWatchpoint::GetDescription).

"watchpoint set var" and "watchpoint set expression" take a size
argument which was previously 1, 2, 4, or 8 (an enum). I've changed this
to an unsigned int. Most hardware implementations can only watch 1, 2,
4, 8 byte ranges, but with Resources we'll allow a user to ask for
different sized watchpoints and set them in hardware-expressble terms
soon.

I've annotated areas where I know there is work still needed with
LWP_TODO that I'll be working on once this is landed.

I've tested this on aarch64 macOS, aarch64 Linux, and Intel macOS.

https://discourse.llvm.org/t/rfc-large-watchpoint-support-in-lldb/72116
2023-11-27 13:28:59 -08:00
David Spickett
772f296214 [lldb][AArch64][Linux] Correct name of FPCR field
It should be "RMode" as in "rounding mode" not "RMMode".
2023-11-27 09:10:56 +00:00
David Spickett
8167934480
[lldb] Improve error message for script commands when there's no interpreter (#73321)
It was:
```
error: there is no embedded script interpreter in this mode.
```

1. What does "mode" mean?
2. It implies there might be an embedded script interpreter for some
other "mode", whatever that would be.

So I'm simplifying it and noting the most common reason for this which
is that lldb wasn't built with a scripting language enabled in the first
place.

There are other tips for dealing with this, but I'm not sure this
message is the best place for them.
2023-11-27 09:10:39 +00:00
Caroline Tice
af3c5a7cf1 Revert "[LLDB] Add more helper functions to CompilerType class."
PR 73467 was committed by accident. This undoes the premature commit.
2023-11-26 17:03:35 -08:00
cmtice
42d669f82c
[LLDB] Add more helper functions to CompilerType class. (#73467)
This adds 23 new helper functions to LLDB's CompilerType class, things
like IsSmartPtrType, IsPromotableIntegerType,
GetNumberofNonEmptyBaseClasses, and GetTemplateArgumentType (to name a
few).

These helper functions are needed as part of the implementation for the
Data Inspection Language, (see
https://discourse.llvm.org/t/rfc-data-inspection-language/69893).
2023-11-26 16:37:39 -08:00
José Lira Junior
bd8f1068ca
[lldb] correct inconsistent order of messages on process launch (#73173)
Fixes [#68035](https://github.com/llvm/llvm-project/issues/68035), where
an inconsistency in the order of "Process launched" and "Process
stopped" messages occurs during `process launch`.

The fix involves adjusting the message output sequence in
`CommandObjectProcessLaunch::DoExecute` within
`source/Commands/CommandObjectProcess.cpp`. This ensures "Process
launched" consistently precedes "Process stopped" when executing
commands with the '-o' flag, i.e., non-interactive mode.

Upon implementing this change, two tests failed:
`lldb/test/Shell/Breakpoint/jit-loader_jitlink_elf.test` and
`lldb/test/Shell/Breakpoint/jit-loader_rtdyld_elf.test`. These failures
were expected as they relied on the previous, now-corrected message
order. Updating these tests to align with the new message sequence is
part of this PR's scope.
2023-11-24 15:48:16 +00:00
jeffreytan81
85ee3fc7ec
Fix command escape bug in lldb-dap (#72902)
https://github.com/llvm/llvm-project/pull/69238 caused breakage in
VSCode debug console usage -- the user's input is always treated as
commands instead of expressions (the same behavior as if empty command
escape prefix is specified).

The bug is in one overload of `GetString()` which did not respect the
default value of "\`". But more important, I am puzzled to find out why
the regression is not caught by lldb test (testdap_evaluate). Turns out
https://github.com/llvm/llvm-project/pull/69238 specifies
commandEscapePrefix default value in test framework to be "\`" while
VSCode will default not specify any commandEscapePrefix at all. Changing
it to None will fail `testdap_evaluate`. We should align the default
behavior between DAP client and testcase.

This patches fixes the bug in `GetString()` and changed the default
value of commandEscapePrefix in testcases to be None (be consistent with
IDE).

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2023-11-20 15:57:14 -08:00
Tom Yang
69a5869da4
[lldb][split-dwarf] implement GetSeparateDebugInfo for SymbolFileOnDemand (#71230)
Small change to get `image dump separate-debug-info` working when using
`symbols.load-on-demand`.

Added tests to `TestDumpDwo`, and enabled the test for all platforms. If we fail to build, we skip the test, so this shouldn't cause the test to fail on unsupported platforms.
```
bin/lldb-dotest -p TestDumpDwo
```

It's easy to verify this manually by running 
```
lldb --one-line-before-file "settings set symbols.load-on-demand true" <some_target>
(lldb) image dump separate-debug-info
...
```

---------

Co-authored-by: Tom Yang <toyang@fb.com>
2023-11-20 12:17:15 -08:00
Muhammad Omair Javaid
c1fe190049 Revert "Add new API in SBTarget for loading core from SBFile (#71769)"
This reverts commit e2fb816c4f.
It breaks TestLinuxCore.py on lldb-*-windows. See buildbot below:
https://lab.llvm.org/buildbot/#/builders/219/builds/7014
2023-11-20 11:12:34 +05:00
Jonas Devlieghere
94ce378ec0
[lldb] Remove unused Status::SetMachError (NFC) (#72668)
This function is never used, neither here nor downstream in the Swift
fork. As far as I can tell, the same is true for the corresponding
eErrorTypeMachKernel but as that's part of the SB API we cannot remove
that.
2023-11-17 10:17:48 -08:00
GeorgeHuyubo
e2fb816c4f
Add new API in SBTarget for loading core from SBFile (#71769)
Add a new API in SBTarget to Load Core from a SBFile.
This will enable a target to load core from a file descriptor.
So that in coredumper, we don't need to write core file to disk, instead
we can pass the input file descriptor to lldb directly.


Test:
```
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> file_object = open("/home/hyubo/210hda79ms32sr0h", "r")
>>> fd=file_object.fileno()
>>> file = lldb.SBFile(fd,'r', True)
>>> error = lldb.SBError()
>>> target = lldb.debugger.CreateTarget(None)
>>> target.LoadCore(file,error)
SBProcess: pid = 56415, state = stopped, threads = 1
```
2023-11-17 09:53:12 -08:00
Jonas Devlieghere
ec6a34e2a7
[lldb] Pass important options to dsymForUUID (#72669)
On macOS, we usually use the DebugSymbols framework to find dSYMs, but
we have a few places (including crashlog.py) that calls out directly to
dsymForUUID. Currently, this invocation is missing two important
options:

* `--ignoreNegativeCache`: Poor network connectivity or lack of VPN can
lead to a negative cache hit. Avoiding those issues is worth the penalty
of skipping these caches.
* `--copyExecutable`: Ensure we copy the executable as it might not be
available at its original location.

rdar://118480731
2023-11-17 08:00:07 -08:00
santhoshe447
06effaf43e
[lldb][test] Add the ability to extract the variable value out of the summary. (#72631)
Fix for https://github.com/llvm/llvm-project/issues/71897
When it comes to test infrastructure the test (TestDAP_variables.py:
test_scopes_variables_setVariable_evaluate_with_descriptive_summaries)
will fail if the variable has a summary along with value.

I just tried to add a summary to a variable before we set a value to the
variable using below expression from “request_setVariable” function.
RunLLDBCommands(llvm::StringRef(), {std::string("type summary add
--summary-string "{sample summary}" (const char **) argv")});

As value has nonnumeric characters where we are trying to convert into
integer, python is throwing an error. We did not see this issue in
upstream as we are not adding summary explicitly, by default we are
getting empty summary & value for all children’s of argv parameter (even
after auto summary).

The test is failing with below error:
ERROR:
test_scopes_variables_setVariable_evaluate_with_descriptive_summaries
(TestDAP_variables.TestDAP_variables)
Traceback (most recent call last):
File
"/llvm/llvm-project/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py",
line 372, in
test_scopes_variables_setVariable_evaluate_with_descriptive_summaries
enableAutoVariableSummaries=True
File
"/llvm/llvm-project/lldb/test/API/tools/lldb-dap/variables/TestDAP_variables.py",
line 266, in do_test_scopes_variables_setVariable_evaluate
argv = self.get_local_as_int("argv")
File
"//llvm/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py",
line 199, in get_local_as_int
return int(value, 16)
ValueError: invalid literal for int() with base 16: '0x0000000000001234
sample summary'
Config=x86_64-//llvm/llvm-build/bin/clang

Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com>
2023-11-17 10:15:23 -05:00
Augusto Noronha
46396108de
[lldb] Add interface to check if UserExpression::Parse() is cacheable (#66826)
When setting conditional breakpoints, we currently assume that a call to
UserExpression::Parse() can be cached and resued multiple times. This
may not be true for every user expression. Add a new method so
subclasses of UserExpression can customize if they are parseable or not.
2023-11-16 14:20:14 -08:00
Jason Molenda
5f64b94076
Clarify error messages on corefiles that no plugin handles (#72559)
These error messages are written in a way that makes sense to an lldb
developer, but not to an end user who asks lldb to run on a compressed
corefile or whatever. Simplfy the messages.
2023-11-16 13:58:07 -08:00
Alex Langford
a322d50804 [lldb] Add forward declaration for SBWatchpointOptions in SBDefines.h 2023-11-16 12:13:44 -08:00
Michael Buch
70900ec799
[lldb][DWARFASTParserClang][NFC] Clarify comment around static member variable handling (#72495) 2023-11-16 16:09:47 +00:00
Jordan Rupprecht
212a60ec37
[lldb][test] Remove self references from decorators (#72416)
This is partial step toward removing the vendored `unittest2` dep in
favor of the `unittest` library in standard python. One of the large
differences is when xfail decorators are evaluated. With the `unittest2`
vendored dep, this can happen at the moment of calling the test case,
and with LLDB's decorator wrappers, we are passed the test class in the
decorator arg. With the `unittest` framework, this is determined much
earlier; we cannot decide when the test is about to start that we need
to xfail.

Fortunately, almost none of these checks require any state that can't be
determined statically. For this patch, I moved the impl for all the
checks to `lldbplatformutil` and pointed the decorators to that,
removing as many `self` (i.e. test class object) references as possible.
I left wrappers within `TestBase` that forward to `lldbplatformutil` for
convenience, but we should probably remove those later.

The remaining check that can't be moved statically is the check for the
debug info type (e.g. to xfail only for dwarf). Fixing that requires a
different approach, so I will postpone that to the next patch.
2023-11-15 17:51:25 -08:00
Jason Molenda
a3fe9221ab
Remove hardware index from watchpoints and breakpoints (#72012)
The Watchpoint and Breakpoint objects try to track the hardware index
that was used for them, if they are hardware wp/bp's. The majority of
our debugging goes over the gdb remote serial protocol, and when we set
the watchpoint/breakpoint, there is no (standard) way for the remote
stub to communicate to lldb which hardware index was used. We have an
lldb-extension packet to query the total number of watchpoint registers.

When a watchpoint is hit, there is an lldb extension to the stop reply
packet (documented in lldb-gdb-remote.txt) to describe the watchpoint
including its actual hardware index,

<addr within wp range> <wp hw index> <actual accessed address>

(the third field is specifically needed for MIPS). At this point, if the
stub reported these three fields (the stub is only required to provide
the first), we can know the actual hardware index for this watchpoint.

Breakpoints are worse; there's never any way for us to be notified about
which hardware index was used. Breakpoints got this as a side effect of
inherting from StoppointSite with Watchpoints.

We expose the watchpoint hardware index through "watchpoint list -v" and
through SBWatchpoint::GetHardwareIndex.

With my large watchpoint support, there is no *single* hardware index
that may be used for a watchpoint, it may need multiple resources. Also
I don't see what a user is supposed to do with this information, or an
IDE. Knowing the total number of watchpoint registers on the target, and
knowing how many Watchpoint Resources are currently in use, is helpful.
Knowing how many Watchpoint Resources
a single user-specified watchpoint needed to be implemented is useful.
But knowing which registers were used is an implementation detail and
not available until we hit the watchpoint when using gdb remote serial
protocol.

So given all that, I'm removing watchpoint hardware index numbers. I'm
changing the SB API to always return -1.
2023-11-15 13:32:42 -08:00
Michael Buch
35b10acf20
[lldb][DWARFASTParserClang] DWARFv5: support DW_TAG_variable static data members declarations (#72236)
The accepted DWARFv5 issue 161118.1: "DW_TAG for C++ static data
members" specifies that static data member declaration be described by
DW_TAG_variable. Make sure we recognize such members.

Depends on:
* https://github.com/llvm/llvm-project/pull/72234
* https://github.com/llvm/llvm-project/pull/72235
2023-11-15 11:01:52 +00:00
Greg Clayton
beb702c0ad
Add support for arm64 registers in minidump core file saving. (#72315)
This patch adds support for saving minidumps with the arm64
architecture. It also will cause unsupported architectures to emit an
error where before this patch it would emit a minidump with partial
information. This new code is tested by the arm64 windows buildbot that
was failing:

https://lab.llvm.org/buildbot/#/builders/219/builds/6868

This is needed following this PR:
https://github.com/llvm/llvm-project/pull/71772
2023-11-14 16:49:44 -08:00
Walter Erquinigo
1654d7dc38
[lldb-dap] Add an option to provide a format for threads (#72196)
When this option gets enabled, descriptions of threads will be generated
using the format provided in the launch configuration instead of
generating it manually in the dap code. This allows lldb-dap to show an
output similar to the one in the CLI.
This is very similar to https://github.com/llvm/llvm-project/pull/71843
2023-11-14 13:23:55 -05:00
Michael Buch
27c5a9bbb0 [lldb][test] TestConstStaticIntegralMember.py: fix on older clang versions
`638a8393615e911b729d5662096f60ef49f1c65e` removed the `dsym`
condition for older compiler versions which caused the `dwarf`
variants tests to XPASS. This patch reverts to only XFAIL-ing
the `dsym` variant.

`15c80852028ff4020b3f85ee13ad3a2ed4bce3be` added
`test_shadowed_static_inline_members` which isn't supported
on older compiler versions.
2023-11-14 10:31:07 +00:00
Haojian Wu
b837361b80
[LLDB] Display artificial __promise and __coro_frame variables. (#71928)
See the discussion in #69309.
2023-11-14 09:06:40 +01:00
Walter Erquinigo
d9ec4b24a8
[lldb-dap] Add an option to provide a format for stack frames (#71843)
When this option gets enabled, descriptions of stack frames will be
generated using the format provided in the launch configuration instead
of simply calling `SBFrame::GetDisplayFunctionName`. This allows
lldb-dap to show an output similar to the one in the CLI.
2023-11-13 21:10:16 -05:00
Michael Buch
743c4fe43c
[lldb][DWARFASTParserClang][NFC] Extract static data member decl creation into helper (#72109)
This patch extracts the logic to create a static variable member decl
into a helper. We will use this in an upcoming patch which will need to
call exactly the same logic from a separate part of the DWARF parser.
2023-11-13 19:30:28 +00:00
Alex Langford
ad20a9e1a1
[lldb] Remove StructuredData::Array::GetItemAtIndexAsArray (#71994)
This method is completely unused.
2023-11-13 10:12:36 -08:00
Haojian Wu
0515ccc0c4 [lldb] Fix a typo in the comment, NFC 2023-11-13 10:12:55 +01:00
Michael Buch
f86770aa07 Reland "[lldb][DWARFASTParserClang] Make MemberAttributes const when parsing member DIEs (#71921)"
Changed the recently added `FindConstantOnVariableDefinition` to
not rely on MemberAttributes being non-const.

Original commit message:
"""
This patch removes the Objective-C accessibility workaround added in
5a477cfd90
(rdar://8492646). This allows us to make the local `MemberAttributes`
variable immutable, which is useful for some other work around this
function I was planning on doing.

We don't need the workaround anymore since compiler-support for giving
debuggers access to private ivars was done couple of years later in
d6cb4a858d
(rdar://10997647).

**Testing**

* Test-suite runs cleanly
"""
2023-11-13 06:38:57 +00:00
Michael Buch
c501bf4334 Revert "[lldb][DWARFASTParserClang] Make MemberAttributes const when parsing member DIEs (#71921)"
This reverts commit 576f7ccfa4.

Causes build bot failure because new code started depending
on the non-constness of the MemberAttributes.
2023-11-13 06:16:32 +00:00
Michael Buch
9d587480dc [lldb][DWARFASTParserClang][NFC] Fix build failure
Caused by a badly resolved merge conflict
2023-11-13 06:14:23 +00:00
Michael Buch
576f7ccfa4
[lldb][DWARFASTParserClang] Make MemberAttributes const when parsing member DIEs (#71921)
This patch removes the Objective-C accessibility workaround added in
5a477cfd90
(rdar://8492646). This allows us to make the local `MemberAttributes`
variable immutable, which is useful for some other work around this
function I was planning on doing.

We don't need the workaround anymore since compiler-support for giving
debuggers access to private ivars was done couple of years later in
d6cb4a858d
(rdar://10997647).

**Testing**

* Test-suite runs cleanly
2023-11-13 06:11:05 +00:00
Michael Buch
15c8085202
Reland "[lldb][DWARFASTParserClang] Fetch constant value from variable defintion if available" (#71800)
This patch relands https://github.com/llvm/llvm-project/pull/71004 which
was reverted because the clang change it depends on was reverted.

In addition to the original patch, this PR includes a change to
`SymbolFileDWARF::ParseVariableDIE` to support CU-level variable
definitions that don't have locations, but represent a constant value.
Previously, when debug-maps were available, we would assume that a
variable with "static lifetime" (which in this case means "has a linkage
name") has a valid address, which isn't the case for non-locationed
constants. We could omit this additional change if we stopped attaching
linkage names to global non-locationed constants.

Original commit message:
"""
https://github.com/llvm/llvm-project/pull/71780 proposes moving the
`DW_AT_const_value` on inline static members from the declaration DIE to
the definition DIE. This patch makes sure the LLDB's expression
evaluator can continue to support static initialisers even if the
declaration doesn't have a `DW_AT_const_value` anymore.

Previously the expression evaluator would find the constant for a
VarDecl from its declaration `DW_TAG_member` DIE. In cases where the
initialiser was specified out-of-class, LLDB could find it during symbol
resolution.

However, neither of those will work for constants, since we don't have a
constant attribute on the declaration anymore and we don't have
constants in the symbol table.
"""

Depends on:
* https://github.com/llvm/llvm-project/pull/71780
2023-11-13 06:09:58 +00:00
Michael Buch
638a839361
Reland "[clang][DebugInfo] Emit global variable definitions for static data members with constant initializers" (#71780)
This patch relands https://github.com/llvm/llvm-project/pull/70639

It was reverted because under certain conditions we triggered an
assertion
in `DIBuilder`. Specifically, in the original patch we called
`EmitGlobalVariable`
at the end of `CGDebugInfo::finalize`, after all the temporary `DIType`s
have
been uniqued. With limited debug-info such temporary nodes would be
created
more frequently, leaving us with non-uniqued nodes by the time we got to
`DIBuilder::finalize`; this violated its pre-condition and caused
assertions to trigger.

To fix this, the latest iteration of the patch moves
`EmitGlobalVariable` to the
beginning of `CGDebugInfo::finalize`. Now, when we create a temporary
`DIType` node as a result of emitting a variable definition, it will get
uniqued
in time. A test-case was added for this scenario.

We also now don't emit a linkage name for non-locationed constants since
LLDB doesn't make use of it anyway.

Original commit message:
"""
When an LLDB user asks for the value of a static data member, LLDB
starts
by searching the Names accelerator table for the corresponding variable
definition DIE. For static data members with out-of-class definitions
that
works fine, because those get represented as global variables with a
location
and making them eligible to be added to the Names table. However,
in-class
definitions won’t get indexed because we usually don't emit global
variables
for them. So in DWARF we end up with a single `DW_TAG_member` that
usually holds the constant initializer. But we don't get a corresponding
CU-level `DW_TAG_variable` like we do for out-of-class definitions.

To make it more convenient for debuggers to get to the value of inline
static data
members, this patch makes sure we emit definitions for static variables
with
constant initializers the same way we do for other static variables.
This also aligns
Clang closer to GCC, which produces CU-level definitions for inline
statics and also
emits these into `.debug_pubnames`.

The implementation keeps track of newly created static data members.
Then in `CGDebugInfo::finalize`, we emit a global `DW_TAG_variable` with
a
`DW_AT_const_value` for any of those declarations that didn't end up
with a
definition in the `DeclCache`.

The newly emitted `DW_TAG_variable` will look as follows:
```
0x0000007b:   DW_TAG_structure_type
                DW_AT_calling_convention        (DW_CC_pass_by_value)
                DW_AT_name      ("Foo")
                ...

0x0000008d:     DW_TAG_member
                  DW_AT_name    ("i")
                  DW_AT_type    (0x00000062 "const int")
                  DW_AT_external        (true)
                  DW_AT_declaration     (true)
                  DW_AT_const_value     (4)

Newly added
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

0x0000009a:   DW_TAG_variable
                DW_AT_specification     (0x0000008d "i")
                DW_AT_const_value       (4)
                DW_AT_linkage_name      ("_ZN2t2IiE1iIfEE")
```

This patch also drops the `DW_AT_const_value` off of the declaration
since we
now always have it on the definition. This ensures that the
`DWARFParallelLinker`
can type-merge class with static members where we couldn't attach the
constant
on the declaration in some CUs.
"""

Dependent changes:
* https://github.com/llvm/llvm-project/pull/71800
2023-11-13 06:04:27 +00:00
Brad Smith
9ba5b52c13
[lldb][test] Implement getting thread ID on OpenBSD (#71129) 2023-11-12 14:38:09 -05:00
Greg Clayton
215bacb5dc
Centralize the code that figures out which memory ranges to save into core files (#71772)
Prior to this patch, each core file plugin (ObjectFileMachO.cpp and
ObjectFileMinindump.cpp) would calculate the address ranges to save in
different ways. This patch adds a new function to Process.h/.cpp:

```
Status Process::CalculateCoreFileSaveRanges(lldb::SaveCoreStyle core_style, CoreFileMemoryRanges &ranges);
```

The patch updates the ObjectFileMachO::SaveCore(...) and
ObjectFileMinindump::SaveCore(...) to use same code. This will allow
core files to be consistent with the lldb::SaveCoreStyle across
different core file creators and will allow us to add new core file
saving features that do more complex things in future patches.
2023-11-11 11:21:32 -08:00
Walter Erquinigo
309596f249
[LLDB] Ensure the data of apple accelerator tables is kept around (#71828)
lldb's AppleDWARFIndex is created with a few
`llvm::AppleAcceleratorTable` variables, but they only hold pointers to
the underlying data, which doesn't prevent the data owner (lldb's
DataBufferHeap) from being disposed.

Because of this, an asan build of lldb was showing an error in which a
jitted accelerator table was being fred before read, which made my lldb
fall in an infinite loop trying to parse corrupted accel table data.
This issue only happens when I'm using a jitted execution and not when
debugging a precompiled binary, probably because in the jit case the
underlying data has to necessarily be copied via gdb-remote instead of
mmaping a debug info file.

The correct fix seems to also store the underlying storage along with
the accelerator tables in AppleDWARFIndex.
2023-11-10 21:53:58 -05:00
jimingham
0f8d3e62d3
Fix a little thinko in sending events to secondary listeners. (#71997)
If `unique` is true, I was redoing the uniqueness check for the
secondary listeners, which is racy since a "duplicate" event could come
in between deciding to send the event to the main listener and checking
for the shadow listener, and then the two streams would get out of sync.

There's not a good way to write a direct test for this, but the
test_shadow_listeners test has been flakey and this is the only racy
part of that system I can find. So the test would be that that
test_shadow_listeners becomes not flakey.
2023-11-10 16:12:51 -08:00
Jonas Devlieghere
64f62de966
[lldb] Read Checksum from DWARF line tables (#71458)
Read the MD5 checksum from DWARF line tables and store it in the
corresponding support files.

This is a re-land after fixing an off-by-one error in LLDB's
ParseSupportFilesFromPrologue (fixed in #71984).
2023-11-10 14:43:47 -08:00
Jonas Devlieghere
fa7e07ed99
[lldb] Fix a off-by-one error in ParseSupportFilesFromPrologue (#71984)
This fixes a subtle and previously harmless off-by-one bug in
ParseSupportFilesFromPrologue. The function accounts for the start index
being one-based for DWARF v4 and earlier and zero-based for DWARF v5 and
later. However, the same care wasn't taken for the end index.

This bug existed unnoticed because GetFileByIndex gracefully handles an
invalid index. However, the bug manifested itself after #71458, which
added a call to getFileNameEntry which requires the index to be valid.

No test as the bug cannot be observed without the changes from #71458.
Once that PR is merged, this will be covered by all the DWARF v5 tests.
2023-11-10 14:03:29 -08:00
Alex Langford
133bcacecf
[lldb] Change interface of StructuredData::Array::GetItemAtIndexAsDictionary (#71961)
Similar to my previous patch (#71613) where I changed
`GetItemAtIndexAsString`, this patch makes the same change to
`GetItemAtIndexAsDictionary`.

`GetItemAtIndexAsDictionary` now returns a std::optional that is either
`std::nullopt` or is a valid pointer. Therefore, if the optional is
populated, we consider the pointer to always be valid (i.e. no need to
check pointer validity).
2023-11-10 12:47:43 -08:00
Haojian Wu
81a76902ae [lldb] Only run ignored_artificial_fields.test when gcc is available. 2023-11-10 20:56:27 +01:00
David Spickett
d96ea27973 Revert "[lldb] Remove the newly-added test in 66acd1e4dc1080015fe6b234226f1d30d6577f04"
This reverts commit 343eb4b425.

This test should work now that the build script doesn't add -m(32|64) on Arm/AArch64
builders.
2023-11-10 13:47:41 +00:00
David Spickett
6b4ac76504 Reland "[lldb][test] Only add -m(64|32) for GCC on non Arm/AArch64 platforms"
This reverts commit fd5206cc55.

Fixing the test case would require some awkard %if use that I'm not
sure would even work, or splitting it into 2 copies that are almost
identical.

Instead, always add -m for clang, which allows it for all targets,
but not for gcc which does not.
2023-11-10 13:36:23 +00:00
David Spickett
fd5206cc55 Revert "[lldb][test] Only add -m(64|32) for GCC on non Arm/AArch64 platforms"
This reverts commit 7c3603e1c1.

Turns out when you ask for "clang" it also uses the GCC Builder class,
so I need to update some tests.
2023-11-10 13:17:01 +00:00
David Spickett
7c3603e1c1 [lldb][test] Only add -m(64|32) for GCC on non Arm/AArch64 platforms
This option is definitely needed for x86_64, and is valid for PowerPC
and s390x too.

I'm using "in" because on Armv8 Linux the uname is actually "armv8l"
not just "arm".
2023-11-10 12:52:36 +00:00
Haojian Wu
343eb4b425 [lldb] Remove the newly-added test in 66acd1e4dc
The test added causes some buildbot failures:
- https://lab.llvm.org/buildbot/#/builders/17/builds/45077
https://lab.llvm.org/buildbot/#/builders/96/builds/48277

Remove the test for now to make the builtbots happy, and will re-add it after
investigation.
2023-11-10 13:46:36 +01:00
David Spickett
bd61126499 [lldb][docs] Update Discord invite link
The previous one must have been an expiring one, this new
one is a non-expiring one that Chandler generated some time ago.
2023-11-10 11:18:30 +00:00
Haojian Wu
66acd1e4dc
[LLDB] Ignore actual-needed artificial members in DWARFASTParserClang::ParseSingleMember (#70779)
Address the FIXME, this will allow lldb to print all fields of the
generated coroutine frame structure.

Fixes #69309.
2023-11-10 10:53:03 +01:00
David Spickett
9ad25f2352
[lldb][AArch64][Linux] Add register field information for SME's SVCR register (#71809)
This register is a pseudo register but mirrors the architectural
register's contents. See:
https://developer.arm.com/documentation/ddi0616/latest/

For the full details. Example output:
```
(lldb) register read svcr
    svcr = 0x0000000000000002
         = (ZA = 1, SM = 0)
```
2023-11-10 09:30:11 +00:00
David Spickett
2f8e3d55da
[lldb][AArch64][Linux] Add field information for the mte_ctrl register (#71808)
This is a Linux pseudo register provided by the NT_ARM_TAGGED_ADDR_CTRL
register set. It reflects the value passed to prctl
PR_SET_TAGGED_ADDR_CTRL.

https://docs.kernel.org/arch/arm64/memory-tagging-extension.html

The fields are made from the #defines the kernel provides for setting
the value. Its contents are constant so no runtime detection is needed
(once we've decided we have this register in the first place).

The permitted generated tags is technically a bitfield but at this time
we don't have a way to mark a field as preferring hex formatting.

```
(lldb) register read mte_ctrl
mte_ctrl = 0x000000000007fffb
         = (TAGS = 65535, TCF_ASYNC = 0, TCF_SYNC = 1, TAGGED_ADDR_ENABLE = 1)
```

(4 bit tags mean 16 possible tags, 16 bit bitfield)

Testing has been added to TestMTECtrlRegister.py, which needed a more
granular way to check for XML support, so I've added hasXMLSupport that
can be used within a test case instead of skipping whole tests if XML
isn't supported.

Same for the core file tests.
2023-11-10 09:01:22 +00:00
Alex Langford
1486264d5f
[lldb] Change interface of StructuredData::Array::GetItemAtIndexAsString (#71613)
This patch changes the interface of
StructuredData::Array::GetItemAtIndexAsString to return a
`std::optional<llvm::StringRef>` instead of taking an out parameter.
More generally, this commit serves as proposal that we change all of the
sibling APIs (`GetItemAtIndexAs`) to do the same thing. The reason this
isn't one giant patch is because it is rather unwieldy changing just one
of these, so if this is approved, I will do all of the other ones as
individual follow-ups.
2023-11-09 13:35:35 -08:00
Alex Langford
fe98cce6a9
[lldb] Change Breakpoint::AddName return value (#71236)
The return value is completely unused. Let's just return nothing.
2023-11-09 13:34:59 -08:00
Jonas Devlieghere
73519ba27a
Revert "[lldb] Read Checksum from DWARF line tables" (#71864)
Reverts llvm/llvm-project#71458 as it might have caused
cross-project-test failures.
2023-11-09 12:43:53 -08:00
Jonas Devlieghere
5da98dec7a
[lldb] Read Checksum from DWARF line tables (#71458)
Read the MD5 checksum from DWARF line tables and store it in the
corresponding support files.
2023-11-09 08:59:03 -08:00
David Spickett
220abb02cb [lldb][Utility] Fix GCC suggest braces warning for checksum value
[4314/5686] Building CXX object tools/lldb/sou...lity/CMakeFiles/lldbUtility.dir/Checksum.cpp.o
<...>/Checksum.cpp:43:46: warning: suggest braces around initialization of subobject [-Wmissing-braces]
llvm::MD5::MD5Result Checksum::g_sentinel = {0, 0, 0, 0, 0, 0, 0, 0,
                                             ^~~~~~~~~~~~~~~~~~~~~~~
                                             {
2023-11-09 12:38:01 +00:00
David Spickett
c51a8968a4 [lldb][AArch64][Linux] Fix HWCAP constant sizes when built on 32 bit
One of them is << 32 which means it must be a 64 bit value.

Fixes e3d750cc40.
2023-11-09 10:55:43 +00:00
David Spickett
e3d750cc40
[lldb][AArch64][Linux] Add fields for FPCR register (#71694)
Follows the format laid out in the Arm manual, AArch32 only fields are
ignored.

```
(lldb) register read fpcr
    fpcr = 0x00000000
         = (AHP = 0, DN = 0, FZ = 0, RMMode = 0, FZ16 = 0, IDE = 0, IXE = 0, UFE = 0, OFE = 0, DZE = 0, IOE = 0)
```

Tests use the first 4 fields that we know are always present.

Converted all the HCWAP defines to `UL` because I'm bound to
forget one if I don't do it now.
2023-11-09 09:32:24 +00:00
David Spickett
14b5abbfe2
[lldb][AArch64][Linux] Add field information for the fpsr register (#71651)
This one is easy because none of the fields depend on extensions. Only
thing to note is that I've ignored some AArch32 only fields.

```
(lldb) register read fpsr
    fpsr = 0x00000000
         = (QC = 0, IDC = 0, IXC = 0, UFC = 0, OFC = 0, DZC = 0, IOC = 0)
```
2023-11-09 08:18:44 +00:00
Jonas Devlieghere
919f5ef462
[lldb] Add Checksum to FileSpec (#71457)
Store a Checksum in FileSpec. Its purpose is to store the MD5 hash that
was added to the DWARF 5 line table.

This increases the size of a FileSpec from 24 to 40 bytes. The
alternative is to introduce a new SupportFile abstraction for a FileSpec
+ Checksum but that would require a corresponding SupportFileList class.
During review we decided that wasn't worth it, but that's something we
can revisit in the future.
2023-11-08 20:11:48 -08:00