Commit Graph

29350 Commits

Author SHA1 Message Date
Alex Langford
a451c3b9e2
[lldb] Support changes to TLS on macOS (#77988)
The TLS implementation on apple platforms has changed. Instead of
invoking pthread_getspecific with a pthread_key_t, we instead perform a
virtual function call.

Note: Some versions of Apple's new linker do not emit debug symbols for
TLS symbols. This causes the TLS tests to fail because LLDB and dsymutil
expects there to be debug symbols to resolve the relevant TLS block. You
may work around this by switching to the older linker (ld-classic) or by
disabling the TLS tests until you have a newer version of the new
linker.

rdar://120676969
2024-01-17 11:20:26 -08:00
Jonas Devlieghere
3b6a8f823b
[lldb] Upstream xros support in lldb (#78389)
Upstream support for debugging xros applications through LLDB.
2024-01-17 09:47:08 -08:00
John Harrison
4ea1994a03
[lldb-dap] Adjusting how repl-mode auto determines commands vs variable expressions. (#78005)
The previous logic for determining if an expression was a command or
variable expression in the repl would incorrectly identify the context
in many common cases where a local variable name partially overlaps with
the repl input.

For example:
```
int foo() {
  int var = 1; // break point, evaluating "p var", previously emitted a warning
}
```

Instead of checking potentially multiple conflicting values against the
expression input, I updated the heuristic to only consider the first
term. This is much more reliable at eliminating false positives when the
input does not actually hide a local variable.

Additionally, I updated the warning on conflicts to occur anytime the
conflict is detected since the specific conflict can change based on the
current input. This also includes additional details on how users can
change the behavior.

Example Debug Console output from
lldb/test/API/tools/lldb-dap/evaluate/main.cpp:11 breakpoint 3.

```
lldb-dap> var + 3
Warning: Expression 'var' is both an LLDB command and variable. It will be evaluated as a variable. To evaluate the expression as an LLDB command, use '`' as a prefix.
45

lldb-dap> var + 1
Warning: Expression 'var' is both an LLDB command and variable. It will be evaluated as a variable. To evaluate the expression as an LLDB command, use '`' as a prefix.
43
```
2024-01-17 09:00:22 -08:00
Alexandre Ganea
9110c2b402 [lldb] On Windows, silence warning with latest MSVC
This fixes:
```
[6083/7449] Building CXX object tools\lldb\source\Commands\CMakeFiles\lldbCommands.dir\CommandObjectFrame.cpp.obj
C:\git\llvm-project\lldb\source\Commands\CommandObjectFrame.cpp(497) : warning C4715: 'CommandObjectFrameVariable::ScopeRequested': not all control paths return a value
```
2024-01-17 07:23:58 -05:00
Alexandre Ganea
8ef7aaa637 [lldb] Silence warning with Clang ToT
This fixes `-Wcovered-switch-default` warnings. This is a reminiscent of an old refactoring, see ce03a86237.
2024-01-17 07:23:58 -05:00
Alexandre Ganea
994e478601 [lldb] Use LLVM_FALLTHROUGH to avoid a compiler error when building with MSVC. 2024-01-17 07:23:57 -05:00
Alexandre Ganea
47bd76d80f [lldb] Replace deprecated std::unique_ptr::unique() to silence a warning with MS-STL. NFC.
MS-STL warns about this with `warning STL4016: std::shared_ptr::unique() is deprecated in C++17`.
2024-01-17 07:23:57 -05:00
Alexandre Ganea
935c652d07 [lldb] Silence warning when building with Clang ToT
Fixes:
```
C:\git\llvm-project\lldb\source\Plugins\Process\Windows\Common\x64\RegisterContextWindows_x64.cpp(195,5): warning: missing field 'flags_type' initializer [-Wmissing-field-initializers]
```
2024-01-17 07:23:56 -05:00
Pavel Labath
15311d5822 [lldb] Skip TestExecutableFirst.test_executable_is_first_before_run on ELF
ELF does not have a hard distinction between shared libraries (and
position-independent) executables. It is possible to create a shared
library that will also be executable.
2024-01-17 10:36:44 +00:00
Jason Molenda
54d8193639
Return high address masks correctly in Process (#78379)
In https://reviews.llvm.org/D151292 I added the ability to track address
masks separately for high and low memory addresses, a capability of
AArch64. I did my testing with manual address mask settings (via
target.process.highmem-virtual-addressable-bits) but didn't have a real
corefile that included this metadata and required it.

My intention is that when the high address mask isn't specified, by the
user (via the setting) or the Process plugin, we fall back to using the
low address mask. The low and high address mask is the same for almost
all environments.

But the patch I wrote never uses the Process plugin high address mask if
it was set, e.g. from corefile metadata. This patch corrects that.

I also have an old patch in Phabractor that was approved to add
FixAddress methods to SBProcess; I need to pick that patch up and finish
it (I wanted to add an enum to specify which mask is being requested
iirc), so I can do address masks tests in API tests.

rdar://120926000
2024-01-16 23:59:05 -08:00
Jonas Devlieghere
5aea6ba8f5
[lldb] Fix trailing whitespace & formatting in Core/Module.cpp (NFC)
I have my editor configured to remove trailing whitespace and every time
I touch this file I end up with a bunch of clang-format changes to lines
that were modified because of it. Nobody likes trailing whitespace so
this cleans up the file.
2024-01-16 21:30:02 -08:00
Jonas Devlieghere
ff9fcc74a3
[lldb] Store SupportFile in CompileUnit (NFC)
Store a SupportFile, rather than a FileSpec, in CompileUnit. This commit
works towards having the SourceManager operate on SupportFiles so that
it can (1) validate the Checksum and (2) materialize the content of
inline source information.
2024-01-16 21:27:20 -08:00
Jonas Devlieghere
933c25e558
[lldb] Store SupportFile in LineEntry (NFC) (#77999)
Store a SupportFile, rather than a FileSpec, in LineEntry. This commit
works towards having the SourceManageroperate on SupportFiles so that it
can (1) validate the Checksum and (2) materialize the content of inline
source information.
2024-01-16 21:09:23 -08:00
jimingham
705c5b80ac
Add the Linux "you can use this binary" bits to run_to_source_breakpoint (#78377)
Follow-on to a4cd99ea87 - I forgot you
have to add ANY shared library you want to use to extra_images...
2024-01-16 17:54:12 -08:00
jimingham
a4cd99ea87
Ensure that the executable module is ModuleList[0] (#78360)
We claim in a couple places that the zeroth element of the module list
for a target is the main executable, but we don't actually enforce that
in the ModuleList class. As we saw, for instance, in

32dd5b2097

it's not all that hard to get this to be off. This patch ensures that
the first object file of type Executable added to it is moved to the
front of the ModuleList. I also added a test for this.

In the normal course of operation, where the executable is added first,
this only adds a check for whether the first element in the module list
is an executable. If that's true, we just append as normal.

Note, the code in Target::GetExecutableModule doesn't actually agree
that the zeroth element must be the executable, it instead returns the
first Module of type Executable. But I can't tell whether that was a
change in intention or just working around the bug that we don't always
maintain this ordering. But given we've said this in scripting as well
as internally, I think we shouldn't change our minds about this.
2024-01-16 17:12:32 -08:00
Jonas Devlieghere
32382bb832
[lldb] Remove unused LineEntry ctor (NFC) 2024-01-16 16:37:27 -08:00
Alex Langford
a43a4a5329
[lldb] Build the TestRosetta.py executable with system stdlib (#78370)
This is a speculative fix for TestRosetta.py which is currently failing
on Green Dragon.

TestRosetta just makes sure we can debug an x86_64 process on Apple
Silicon. However, we're failing to build the x86_64 test binary. The
linker is failing with some warnings about libc++ and libunwind being
build for arm64 while the target binary is x86_64. I'm going to try
building with the system standard libraries instead of the just-built
ones to workaround it.
2024-01-16 16:29:31 -08:00
Jonas Devlieghere
854aa9112d
[lldb] Store SupportFile as shared_ptr (NFC) 2024-01-16 15:40:15 -08:00
Chelsea Cassanova
8947469ec1
[lldb][Progress] Fix test for trimmed progress reports (#78357)
The test TestTrimmedProgressReporting tests that progress reports are
being sent by listening for events with the titles of specific progress
reports. Commit f1ef910b removed the report for Apple DWARF indices
which was one of the reports being listened for in this test, so that
report is removed here as well.

That commit also now creates all progress reports with details so
reports string are prepended with the details count. This changes the
length of the trimmed progress report title string that's checked for
here so this commit changes the string to match as well.

This test was skipped on non-Apple platforms, but since the progress
report for Apple DWARF indices has been removed this commit removes that
decorator.
2024-01-16 14:35:39 -08:00
Jonas Devlieghere
1b5f72c5ec
[lldb] Hoist SupportFile out of FileSpecList (NFC)
This hoists SupportFile out of FileSpecList. SupportFileList is still
implemented there as it's very similar to FileSpecList.
2024-01-16 14:20:22 -08:00
Craig Topper
142f270c27 Recommit "[AST] Use APIntStorage to fix memory leak in EnumConstantDecl. (#78311)"
With lldb build fix.

Original message:

EnumConstantDecl is allocated by the ASTContext allocator so the
destructor is never called.

This patch takes a similar approach to IntegerLiteral by using
APIntStorage to allocate large APSInts using the ASTContext allocator as
well.

The downside is that an additional heap allocation and copy of the data
needs to be made when calling getInitValue if the APSInt is large.

Fixes #78160.
2024-01-16 13:52:17 -08:00
jimingham
32dd5b2097
Work around a bug in the interaction between newer dyld's and older simulator dyld's (#78004)
There's a bad interaction between the macOS 14 dyld and the "dyld_sim"
shim that comes from older (iOS 15) simulator downloads that results in
dyld reporting some modules twice in the return from the dyld callback
to list modules. The records were identical, but lldb wasn't happy with
seeing the duplicates...

Since it's not possible to load two different modules at the same
address, this change just picks the first instance of any entries that
have the same load address.

There really isn't a good way to test this patch.
2024-01-16 11:31:42 -08:00
Chelsea Cassanova
f1ef910b97
[lldb][Progress] Separate title and details (#77547)
Per this RFC:
https://discourse.llvm.org/t/rfc-improve-lldb-progress-reporting/75717
on improving progress reports, this commit separates the title field and
details field so that the title specifies the category that the progress
report falls under. The details field is added as a part of the
constructor for progress reports and by default is an empty string. In addition, changes the total amount of progress completed into a std::optional. Also
updates the test to check for details being correctly reported from the
event structured data dictionary.
2024-01-16 07:57:18 -08:00
Zequan Wu
1617c8d3b8
[lldb] Add LLDB_BUG_REPORT_URL macro to allow a different URL for lldb bug reporting. (#78210)
This allows release teams to customize the bug report url for lldb. It
also removes unnecessary constructions of
`llvm::PrettyStackTraceProgram` as it's already constructed inside
`llvm::InitLLVM`.
2024-01-16 10:50:48 -05:00
Michael Buch
2bb2a42fa2
[lldb][ValueObject][NFC] Further remove redundant parameters to ReadPointedString (#78029)
We only ever call this function once, without relying on the defaulted
`honor_array` parameter, so make it non-defaulted. Also `max_length` is
always set to `0`, so remove it entirely.

This simplifies some upcoming refactoring.
2024-01-15 21:04:05 +00:00
Pavel Labath
14268ad2a2 [lldb] Skip part of TestDataFormatterAdv (#72233)
libstdc++ data formatter simply forwards to the `const char *` formatter
-- which means it suffers from the same problem/bug as that one.
2024-01-15 12:49:24 +00:00
Mark de Wever
e3fde34851
[lldb][libc++] Adds missing C++20 calendar data formatters. (#77954)
This is a followup of #76983 and adds the libc++ data formatters for
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.
2024-01-13 13:21:33 +01:00
Michael Buch
f4461cf4f3
[lldb][test] Add tests for target.max-string-summary-length setting (#77920)
This adds API tests for the `target.max-string-summary-length`, which
was recently fixed in https://github.com/llvm/llvm-project/pull/72233
2024-01-12 22:26:31 +00:00
John Harrison
40a361acf5
[lldb-dap] Updating VariableDescription to use GetDescription() as a fallback. (#77026)
When generating a `display_value` for a variable the current approach
calls `SBValue::GetValue()` and `SBValue::GetSummary()` to generate a
`display_value` for the `SBValue`. However, there are cases where both
of these return an empty string and the fallback is to print a pointer
and type name instead (e.g. `FooBarType @ 0x00321`).

For swift types, lldb includes a langauge runtime plugin that can
generate a description of the object but this is only used with
`SBValue::GetDescription()`.

For example:
```
$ lldb swift-binary
... stop at breakpoint ...
lldb> script
>>> event = lldb.frame.GetValueForVariablePath("event")
>>> print("Value", event.GetValue())
Value None
>>> print("Summary", event.GetSummary())
Summary None
>>> print("Description", event) # __str__ calls SBValue::GetDescription()
Description (main.Event) event = (name = "Greetings", time = 2024-01-04 23:38:06 UTC)
```

With this change, if GetValue and GetSummary return empty then we try
`SBValue::GetDescription()` as a fallback before using the previous
logic of printing `<type> @ <addr>`.
2024-01-12 17:12:30 -05:00
Alex Langford
c8ef88c446
[lldb][NFCI] Remove CommandReturnObject from BreakpointIDList (#77858)
BreakpointIDList does not need to know about CommandReturnObject.
BreakpointIDList::FindAndReplaceIDRanges is the last place that uses it
in BreakpointIDList.

Instead of passing in a CommandReturnObject, it now returns an
llvm::Error. The callsite uses the Error to populate the
CommandReturnObject as needed.
2024-01-12 13:52:59 -08:00
Jonas Devlieghere
e27561fc7d
[lldb] Move MD5 Checksum from FileSpec to SupportFile
When I added the MD5 checksum I was on the fence between storing it in
FileSpec or creating a new SupportFile abstraction. The latter was
deemed overkill for just the MD5 hashes, but support for inline sources
in the DWARF 5 line table tipped the scales. This patch moves the MD5
checksum into the new SupportFile class.
2024-01-12 13:08:24 -08:00
Michael Buch
844a8dcaaf
[lldb][ValueObject][NFC] Remove unused parameter to ReadPointedString (#77919)
All its usages were removed in
`2206b48d6ddabad61979fa69ba09e6b6fb19b0b2`.
2024-01-12 16:11:59 +00:00
dancing-leaves
ee45710258
[lldb] Fix MaxSummaryLength target property type (#72233)
There seems to be a regression since
6f8b33f6df.
`Max String Summary Length` target property is not read properly and the
default value (1024) is being used instead.

16.0.6:
```
(lldb) settings set target.max-string-summary-length 16
(lldb) var
(std::string) longStdString = "0123456789101112131415161718192021222324252627282930313233343536"
(const char *) longCharPointer = 0x000055555556f310 "0123456789101112131415161718192021222324252627282930313233343536"
```

17.0.4:
```
(lldb) settings set target.max-string-summary-length 16
(lldb) var
(std::string) longStdString = "0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377"...
(const char *) longCharPointer = 0x000055555556f310 "*same as line above*"...
```

Comparison fails here:

9cb1673fa5/lldb/source/Interpreter/OptionValue.cpp (L256)

Due to the type difference:

9cb1673fa5/lldb/source/Target/Target.cpp (L4611)

9cb1673fa5/lldb/source/Target/TargetProperties.td (L98)
2024-01-11 17:57:30 +00:00
Pete Lawrence
cd7eaaa6db
[lldb] Add color support to StreamString (#77380)
This change just adds a `bool colors` parameter to the `StreamString`
class's constructor, which it passes up to its superclass’s constructor.

I'm working on another patch that prints out error messages using a
`StreamString` but I wasn't getting colorized text because of this
missing implementation detail.

rdar://120671168
2024-01-10 10:13:14 -08:00
Michael Buch
5c0b3a0cb7
[lldb][ClangASTImporter][NFC] Remove redundant do-while loop (#77596)
This seems to have always been a redundant do-while since its
introduction in `2e93a2ad2148d19337bf5f9885e46e3c00e8ab82`.
2024-01-10 13:08:11 +00:00
Jason Molenda
5f71aa9270
[lldb] [Mach-O] don't strip the end of the "kern ver str" LC_NOTE (#77538)
The "kern ver str" LC_NOTE gives lldb a kernel version string -- with a
UUID and/or a load address (stext) to load it at. The LC_NOTE specifies
a size of the identifier string in bytes. In
ObjectFileMachO::GetIdentifierString, I copy that number of bytes into a
std::string, and in case there were additional nul characters at the end
of the sting for padding reasons, I tried to shrink the std::string to
not include these extra nul's.

However, I did this resizing without handling the case of an empty
identifier string. I don't know why any corefile creator would do that,
but of course at least one does. This patch removes the resizing
altogether; I was solving something that hasn't ever shown to be a
problem. I also added a test case for this, to check that lldb doesn't
crash when given one of these corefiles.

rdar://120390199
2024-01-09 15:20:06 -08:00
Walter Erquinigo
b5d4332286
[lldb-dap] Create a typescript extension for lldb-dap (#75515)
The main motivations behind this are two:

- Allow different companies developing their own vscode extensions for
LLDB to have a single contribution point, thus sharing resources and
working as a virtual large team.
- Allow for visual ways to configure the debugger, which currently has
to be done through launch.json files.

In terms of implementation, this is very straightforward and these are
the most important details:

- All the cpp code has been moved to a subfolder for cleanness. There's
a specific commit in the list of commits of this PR that just does that,
in case that helps reviewing this.
- A new folder `src-ts` has been created for the typescript code
- The ts extension can be used in two ways: as a regular vscode
extension and as a library. There file `extension.ts` explains which
entry point to use.
- The README has been updated the mention how to install the extension,
which is simpler than before. There are two additional sections for
rebuilding and formatting.
- The ts code I added merely sets up the debug adapter using two
possible options: reading the lldb-dap path from vscode settings or from
a config object passed by users of the extension is used as a library. I
did this to show how we can support easily both worlds.
2024-01-09 17:10:15 -05:00
Kazu Hirata
47605ffec8 [lldb] Fix a warning
This patch fixes:

  lldb/source/Target/ProcessTrace.cpp:23:33: error: extra ';' outside
  of a function is incompatible with C++98
  [-Werror,-Wc++98-compat-extra-semi]
2024-01-09 12:04:20 -08:00
Nicholas Mosier
a50ea2f76f
[lldb] Fix Intel PT plugin compile errors (#77252)
Fix #77251.
2024-01-09 10:58:47 -08:00
Adrian Prantl
fa9284589f
[lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (#77157)
…ntext

Following the specification chain seems to be clearly the expected
behavior of GetDeclContext(). Otherwise C++ methods have an empty
CompilerContext instead of being nested in their struct/class.

Theprimary motivation for this functionality is the Swift plugin. In
order to test the change I added a proof-of-concept implementation of a
Module::FindFunction() variant that takes a CompilerContext, expesed via
lldb-test.

rdar://120553412
2024-01-09 10:45:30 -08:00
Mark de Wever
b5f2db9406
[lldb][libc++] Adds some C++20 calendar data formatters. (#76983)
This adds a subset of the C++20 calendar data formatters:
- day,
- month,
- year,
- month_day,
- month_day_last, and
- year_month_day.

A followup patch will add the missing calendar data formatters:
- weekday,
- weekday_indexed,
- weekday_last,
- month_weekday,
- month_weekday_last,
- year_month,
- year_month_day_last
- year_month_weekday, and
- year_month_weekday_last.
2024-01-09 17:19:10 +01:00
Michael Buch
4ea5c603b4
[lldb][Type] Add TypeQuery::SetLanguages API (#75926)
This is required for users of `TypeQuery` that limit the set of
languages of the query using APIs such as
`GetSupportedLanguagesForTypes` or
`GetSupportedLanguagesForExpressions`.

Example usage: https://github.com/apple/llvm-project/pull/7885
2024-01-09 16:02:56 +00:00
Alex Langford
16b8a0dc68
[lldb] Change interface of StructuredData::Array::GetItemAtIndexAsInteger (#71993)
This is a follow-up to (#71613) and (#71961).
2024-01-08 13:31:03 -08:00
Alex Langford
09e32ab750
[lldb] Deprecate SBBreakpoint::AddName in favor of AddNameWithErrorHandling (#71228)
AddName gives no feedback other than if it succeeded whereas
AddNameWithErrorHandling gives you back an SBError object. I would like
to mark AddName as deprecated and direct folks to use
AddNameWithErorrHandling instead.

---------

Co-authored-by: Med Ismail Bennani <ismail@bennani.ma>
2024-01-08 13:30:24 -08:00
Alex Langford
5cbf74b012
[lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (#77166)
There are 2 motivations here:
1.) There is no need to hand out constant references to BreakpointIDs,
they are only 8 bytes big. In addition, every use of this method already
  makes a copy anyway.
2.) Each BreakpointIDList held onto an invalid BreakpointID specifically
to
  prevent lifetime issues. Returning a value means you can return an
  invalid BreakpointID instead of needing to allocate storage for an
  invalid BreakpointID.
2024-01-08 10:52:00 -08:00
Alex Langford
07d6fbf8d8
[lldb][NFCI] Remove BreakpointIDList::InsertStringArray (#77161)
This abstraction is leaky and BreakpointIDList does not need to know
about CommandReturnObject.
Additionally, setting the CommandReturnObject inout param to a success
state does very little. The function returns immediately if the input
ArrayRef is empty, and reading
CommandObjectMultiwordBreakpoint::VerifyIDs more closely, the input is
always empty if the previous call to
BreakpointIDList::FindAndReplaceIDRanges failed. If the call was
successful, then the CommandReturnObject is already in a success state.

I have opted to remove the function altogether and inline the
functionality where it was used.
2024-01-08 10:51:00 -08:00
Felipe de Azevedo Piovezan
b4ee7d6119
[lldb][DWARFIndex][nfc] Factor out fully qualified name query (#76977)
This moves the functionally of finding a DIE based on a fully qualified
name from SymbolFileDWARF into DWARFIndex itself, so that
specializations of DWARFIndex can implement faster versions of this
query.
2024-01-08 11:16:22 -03:00
Michael Buch
2bf01d73f6
[lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (#77155)
With DWARFv5, C++ static data members are represented as
`DW_TAG_variable`s (see `faa3a5ea9ae481da757dab1c95c589e2d5645982`).

In GetClangDeclForDIE, when trying to parse the `DW_AT_specification`
that a static data member's CU-level `DW_TAG_variable` points to, we
would try to `CreateVariableDeclaration`. Whereas previously it was a
no-op (for `DW_TAG_member`s). However, adding `VarDecls` to RecordDecls
for static data members should always be done in
`CreateStaticMemberVariable`. The test-case is an exapmle where we would
crash if we tried to create a `VarDecl` from within `GetClangDeclForDIE`
for a static data member.

This patch simply checks whether the `DW_TAG_variable` being parsed is a
static data member, and if so, trivially returns from
`GetClangDeclForDIE` (as we previously did for `DW_TAG_member`s).
2024-01-08 14:10:02 +00:00
David Spickett
ba4cf31fac [lldb][test] Skip part of nested expressions test on Windows
This was added by e42edb5547 and
has been failing: https://lab.llvm.org/buildbot/#/builders/219/builds/8012
2024-01-08 12:17:16 +00:00
David Spickett
8b49ed8ba1 [lldb][test] Skip DWARF inline source file test on Windows
This was added by 917b404e2c
and fails for unknown reasons.
2024-01-08 12:11:52 +00:00