Commit Graph

30796 Commits

Author SHA1 Message Date
Zequan Wu
8193832fb9 [lldb] Search main function with lldb::eFunctionNameTypeFull when getting default file and line. (#113980)
This is to work around the fact that
`SymbolFileNativePDB::FindFunctions` only support
`lldb::eFunctionNameTypeFull` and `lldb::eFunctionNameTypeMethod` now.
Since `main`'s full name is the same as base name (`main`), it's okay to
search with `lldb::eFunctionNameTypeFull` when trying to get the default
file and line. With this, `lldb/test/Shell/Driver/TestSingleQuote.test`
passes on Windows with NativePDB plugin.
2024-10-29 16:23:33 -04:00
Michael Buch
b4e1af0096 [lldb-dap] Always pass disableASLR to the DAP executable (#113891)
More context can be found in
https://github.com/llvm/llvm-project/pull/110303

For DAP tests running in constrained environments (e.g., Docker
containers), disabling ASLR isn't allowed. So we set `disableASLR=False`
(since https://github.com/llvm/llvm-project/pull/113593).

However, the `dap_server.py` will currently only forward the value
of `disableASLR` to the DAP executable if it's set to `True`. If the
DAP executable wasn't provided a `disableASLR` field it defaults to
`true` too:
f147437945/lldb/tools/lldb-dap/lldb-dap.cpp (L2103-L2104)

This means that passing `disableASLR=False` from the tests is currently
not possible.

This is also true for many of the other boolean arguments of
`request_launch`. But this patch only addresses `disableASLR` for now
since it's blocking a libc++ patch.
2024-10-29 18:40:06 +00:00
Wanyi
efc6d33be9 [lldb] Fix write only file action to truncate the file (#112657)
When `FileAction` opens file with write access, it doesn't clear the
file nor append to the end of the file if it already exists. Instead, it
writes from cursor index 0.

For example, by using the settings `target.output-path` and
`target.error-path`, lldb will redirect process stdout/stderr to files.
It then calls this function to write to the files which the above
symptoms appear.

## Test
- Added unit test checking the file flags
- Added 2 api tests checking
  - File content overwritten if the file path already exists
- Stdout and stderr redirection to the same file doesn't change its
behavior
2024-10-29 14:22:51 -04:00
Jonas Devlieghere
2ab98dfe19 [lldb] Update link to GreenDragon in the docs 2024-10-29 09:45:29 -07:00
Felipe de Azevedo Piovezan
474234a096 [debugserver] Mark ASAN memory regions as "heap" (#113968)
This memory type is currently not handled, but it makes sense to mark it
as a heap allocation in requests asking for memory region info.
2024-10-28 15:02:07 -07:00
jimingham
b54bc104ea Revert "Add the ability to break on call-site locations, improve inli… (#113947)
…ne stepping (#112939)"

This was breaking some gdb-remote packet counting tests on the bots. I
can't see how this patch could cause that breakage, but I'm reverting to
figure that out.

This reverts commit f147437945.
2024-10-28 11:52:32 -07:00
Zequan Wu
19c0a74ad6 [lldb] Fix lldb windows build breakage from https://github.com/llvm/llvm-project/pull/113839. 2024-10-28 11:13:00 -07:00
jimingham
f147437945 Add the ability to break on call-site locations, improve inline stepping (#112939)
Previously lldb didn't support setting breakpoints on call site
locations. This patch adds that ability.

It would be very slow if we did this by searching all the debug
information for every inlined subroutine record looking for a call-site
match, so I added one restriction to the call-site support. This change
will find all call sites for functions that also supply at least one
line to the regular line table. That way we can use the fact that the
line table search will move the location to that subsequent line (but
only within the same function). When we find an actually moved source
line match, we can search in the function that contained that line table
entry for the call-site, and set the breakpoint location back to that.

When I started writing tests for this new ability, it quickly became
obvious that our support for virtual inline stepping was pretty buggy.
We didn't print the right file & line number for the breakpoint, and we
didn't set the position in the "virtual inlined stack" correctly when we
hit the breakpoint. We also didn't step through the inlined frames
correctly. There was code to try to detect the right inlined stack
position, but it had been refactored a while back with the comment that
it was super confusing and the refactor was supposed to make it clearer,
but the refactor didn't work either.

That code was made much clearer by abstracting the job of "handling the
stack readjustment" to the various StopInfo's. Previously, there was a
big (and buggy) switch over stop info's. Moving the responsibility to
the stop info made this code much easier to reason about.

We also had no tests for virtual inlined stepping (our inlined stepping
test was actually written specifically to avoid the formation of a
virtual inlined stack... So I also added tests for that along with the
tests for setting the call-site breakpoints.
2024-10-28 10:01:57 -07:00
Adrian Vogelsgesang
09c258ef6a [NFC][lldb-dap] Clean-up includes (#113839)
This commit cleans up the includes in the `lldb-dap` subfolder. The main
motivation was that I got annoyed by `clangd` always complaining about
unused includes while working on lldb-dap.
2024-10-28 11:01:57 +01:00
Kazu Hirata
ccc15cd6f5 [lldb] Avoid repeated hash lookups (NFC) (#113412) 2024-10-25 15:35:01 -07:00
Michael Buch
2d26ef09fc [lldb-dap][test] Set disableASLR to False for tests (#113593)
When running in constrained environments like docker, disabling ASLR
might fail with errors like:
```
AssertionError: False is not true : launch failed (Cannot launch
'/__w/.../lldb-dap/stackTrace/subtleFrames/TestDAP_subtleFrames.test_subtleFrames/a.out':
personality set failed: Operation not permitted)
```
E.g., https://github.com/llvm/llvm-project/pull/110303

Hence we already run `settings set target.disable-aslr false` as part of
the init-commands for the non-DAP tests (see
https://github.com/llvm/llvm-project/pull/88312 and
https://discourse.llvm.org/t/running-lldb-in-a-container/76801).

But we never adjusted it for the DAP tests. As a result we get
conflicting test logs like:
```
 {
    "arguments": {
      "commandEscapePrefix": null,
      "disableASLR": true,
     ....
      "initCommands": [
        ...
        "settings set target.disable-aslr false",
```

Disabling ASLR by default in tests isn't useulf (it's only really a
debugging aid for users). So this patch sets `disableASLR=False` by
default.
2024-10-25 12:06:57 +01:00
Jonas Devlieghere
b852fb1ec5 [lldb] Move ValueObject into its own library (NFC) (#113393)
ValueObject is part of lldbCore for historical reasons, but conceptually
it deserves to be its own library. This does introduce a (link-time) circular
dependency between lldbCore and lldbValueObject, which is unfortunate
but probably unavoidable because so many things in LLDB rely on
ValueObject. We already have cycles and these libraries are never built
as dylibs so while this doesn't improve the situation, it also doesn't
make things worse.

The header includes were updated with the following command:

```
find . -type f -exec sed -i.bak "s%include \"lldb/Core/ValueObject%include \"lldb/ValueObject/ValueObject%" '{}' \;
```
2024-10-24 20:20:48 -07:00
jeffreytan81
25909b811a Fix pointer to reference type (#113596)
We have got customer reporting "v &obj" and "p &obj" reporting different
results.
Turns out it only happens for obj that is itself a reference type which
"v &obj" reports the address of the reference itself instead of the
target object the reference points to. This diverged from C++ semantics.

This PR fixes this issue by returning the address of the dereferenced
object if it is reference type.

A new test is added which fails before.

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2024-10-24 17:13:32 -07:00
Stefan Gränitz
76edf72501 Reland: [lldb] Fix crash missing MSInheritanceAttr with DWARF on Windows (#112928)
Member pointers refer to data or function members of a `CXXRecordDecl`,
which require a `MSInheritanceAttr` in order to be complete. Without that
we cannot calculate the size of a member pointer in memory. The attempt
has been causing a crash further down in the clang AST context. In order
to implement the feature, DWARF will need a new attribtue to convey the
information. For the moment, this patch teaches LLDB to handle to
situation and avoid the crash.
2024-10-24 13:47:15 +02:00
David Spickett
f52b89561f [lldb][AArch64] Read fpmr register from core files (#110104)
https://developer.arm.com/documentation/ddi0601/2024-06/AArch64-Registers/FPMR--Floating-point-Mode-Register
for details of the register.
2024-10-24 10:27:56 +01:00
Shubham Sandeep Rastogi
c9199700b8 Revert "[lldb] Fix crash missing MSInheritanceAttr on CXXRecordDecl with DWARF on Windows" (#113498)
Reverts llvm/llvm-project#112928

This is because it broke greendragon:
SymbolFile/DWARF/x86/member-pointers.cpp
2024-10-23 14:31:15 -07:00
Spencer Abson
3309061b2d [lldb] Cover all of SVE_TYPE in encoding switch 2024-10-23 17:05:28 +00:00
Stefan Gränitz
ba19e98ca5 [lldb][CMake] If make isn't found, print a warning but don't error out (#111531)
Bot maintainers should be aware and it became too much of a burden
for developers. In particular on Windows, where make.exe won't be
found in Path typically.
2024-10-23 14:32:58 +02:00
Stefan Gränitz
699ce16b62 [lldb] Fix crash missing MSInheritanceAttr with DWARF on Windows (#112928)
Member pointers refer to data or function members of a `CXXRecordDecl` and
require a `MSInheritanceAttr` in order to be complete. Without that we
cannot calculate their size in memory. The attempt has been causing a crash
further down in the clang AST context. In order to implement the feature,
DWARF will need a new attribtue to convey the information. For the moment,
this patch teaches LLDB to handle to situation and avoid the crash.
2024-10-23 13:21:22 +02:00
Jonas Devlieghere
cd4b33c9a9 [lldb] Log errors to the system log if they would otherwise get dropped (#111911)
Log errors to the (always-on) system log if they would otherwise get
dropped by LLDB_LOG_ERROR.
2024-10-22 09:00:08 -07:00
Jordan Rupprecht
5942be03ea [lldb][test] Fix TestUseSourceCache for readonly source trees (#113251)
TestUseSourceCache attempts to write to a build artifact copied from the
source tree, and asserts the write succeeded. If the source tree is read
only, the copy will also be read only, causing it to fail. When
producing the build artifact, ensure that it is writable.
2024-10-22 10:34:15 -05:00
Kazu Hirata
5dbfb49490 [lldb] Avoid repeated hash lookups (NFC) (#113248) 2024-10-22 07:59:41 -07:00
Michael Buch
7b703bd3e7 [lldb][docs] Fix "Developing LLDB" table of contents (#113166)
Currently all the headings marked as `#` show up
as a top-level entry in the `Developing LLDB`
toctree. This patch marks these as `##` so only
`Adding Programming Language Support` is displayed
in the table of contents.
2024-10-21 22:19:26 +01:00
Adrian Prantl
74e1554d7b [lldb] Fix the sorting function for diagnostics (#113220) 2024-10-21 14:03:49 -07:00
Jonas Devlieghere
40ea92c859 [lldb] Update ScriptInterpreterTests for CommandReturnObject API change 2024-10-21 11:37:26 -07:00
Jonas Devlieghere
4de708e32e [lldb] Remove stack_logging.h (#112987)
This file is covered under the Apple open source license rather than the
LLVM license. Presumably this was an oversight, but it doesn't really
matter as this file is unused. Remove it altogether.
2024-10-21 10:45:55 -07:00
Augusto Noronha
30a402833f [lldb][NFC] Fix doxygen comment on top of GetMangledTypeName 2024-10-21 10:37:46 -07:00
Kazu Hirata
1bf1e92c72 [lldb] Avoid repeated map lookups (NFC) (#113121) 2024-10-21 06:51:25 -07:00
David Spickett
c47df3e8c8 [lldb][test] Make vector operator[] return T& to workaround Arm codegen issue
Since https://github.com/llvm/llvm-project/pull/109628 landed, this test
has been failing on 32-bit Arm.

This is due to a codegen problem (whether added or uncovered by the change,
not known) where the trap instruction is placed after the frame pointer
and link register are restored.

https://github.com/llvm/llvm-project/issues/113154

So the code was:
```
std::__1::vector<int>::operator[](unsigned int):
  sub sp, sp, #8
  str r0, [sp, #4]
  str r1, [sp]
  add sp, sp, #8
  .inst 0xe7ffdefe
  bx lr
```
When lldb saw the trap, the PC was inside operator[] but the frame
information actually pointed to g.

This bug only happens for leaf functions so adding a return type
works around it:
```
std::__1::vector<int>::operator[](unsigned int):
  push {r11, lr}
  mov r11, sp
  sub sp, sp, #8
  str r0, [sp, #4]
  str r1, [sp]
  mov sp, r11
  pop {r11, lr}
  .inst 0xe7ffdefe
  bx lr
```
(and operator[] should return T& anyway)

Now the PC location and frame information should match and the
test passes.
2024-10-21 11:54:54 +00:00
Liu An
911a6f2fcc [lldb][LoongArch64] Add support for LoongArch64 in elf-core for lldb (#112296)
When using the lldb command 'target create --core' on the LoongArch64
architecture, this part of the code is required.
2024-10-21 10:04:55 +01:00
Kazu Hirata
8673d0e067 [lldb] Avoid repeated map lookups (NFC) (#113073) 2024-10-20 09:07:10 -07:00
Felipe de Azevedo Piovezan
cd938bf327 [lldb] Introduce Language::AreEquivalentFunctions (#112720)
This allows languages to provide an opinion on whether two symbol
contexts are equivalent (i.e. belong to the same function).

It is useful to drive the comparisons done by stepping plans that need
to ensure symbol contexts obtained from different points in time are
actually the same.
2024-10-19 16:53:29 -07:00
Kazu Hirata
ca9f396cac [lldb] Avoid repeated hash lookups (NFC) (#113024) 2024-10-19 14:39:25 -07:00
Adrian Prantl
697a455e6f More aggressively deduplicate global warnings based on contents. (#112801)
I've been getting complaints from users being spammed by -gmodules
missing file warnings going out of control because each object file
depends on an entire DAG of PCM files that usually are all missing at
once. To reduce this problem, this patch does two things:

1. Module now maintains a DenseMap<hash, once> that is used to display
each warning only once, based on its actual text.

2. The PCM warning itself is reworded to include less details, such as
the DIE offset, which is only useful to LLDB developers, who can get
this from the dwarf log if they need it. Because the detail is omitted
the hashing from (1) deduplicates the warnings.

rdar://138144624
2024-10-19 09:38:25 -07:00
Michael Buch
aa320600e2 [lldb][ClangASTImporter][NFC] Emit a log message when we break MapImported invariant (#112748)
This patch emits a warning into the expression log when we call
`MapImported` on a decl which has already been imported, but with a new
`to` destination decl. In asserts builds this would lead to triggering
this [ASTImporter::MapImported
assertion](6d7712a70c/clang/lib/AST/ASTImporter.cpp (L10493-L10494)).
In no-asserts builds we will likely crash, in potentially non-obvious
ways. The hope is that the log message will help in diagnosing this type
of issue in the field.

The underlying issue is discussed in more detail in:
https://github.com/llvm/llvm-project/pull/112566.

In a non-asserts build, the last few expression log entries would look
as follows:
```
     CompleteTagDecl on (ASTContext*)scratch ASTContext Completing (TagDecl*)0x00000001132d31d0 named Foo
       CTD Before:
CXXRecordDecl 0x1132d31d0 <<invalid sloc>> <invalid sloc> <undeserialized declarations> struct Foo

 [ClangASTImporter] WARNING: overwriting an already imported decl '0x000000014378fd80' ('Foo') from '0x0000000143790c00' with 0x00000001132d31d0. Likely due to a name conflict when importing 'Foo'.
     [ClangASTImporter] Imported (FieldDecl*)0x0000000143790220, named service (from (Decl*)0x0000000143791270), metadata 271
     [ClangASTImporter] Decl has no origin information in (ASTContext*)0x00000001132c8c00
 FindExternalLexicalDecls on (ASTContext*)0x0000000143c1f600 'scratch ASTContext' in 'Foo' (CXXRecordDecl*)0x000000014378FD80
   FELD Original decl (ASTContext*)0x00000001132c8c00 (Decl*)0x0000000143790c00:
CXXRecordDecl 0x143790c00 <<invalid sloc>> <invalid sloc> struct Foo definition
|-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal
| |-DefaultConstructor exists trivial needs_implicit
| |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-FieldDecl 0x143791270 <<invalid sloc>> <invalid sloc> service 'Service *'
`-FieldDecl 0x1437912c8 <<invalid sloc>> <invalid sloc> mach_endpoint 'int'

   FELD Adding [to CXXRecordDecl Foo] lexical FieldDecl FieldDecl 0x143791270 <<invalid sloc>> <invalid sloc> service 'Service *'

   FELD Adding [to CXXRecordDecl Foo] lexical FieldDecl FieldDecl 0x1437912c8 <<invalid sloc>> <invalid sloc> mach_endpoint 'int'

     [ClangASTImporter] Imported (FieldDecl*)0x0000000143790278, named mach_endpoint (from (Decl*)0x00000001437912c8), metadata 280
     [ClangASTImporter] Decl has no origin information in (ASTContext*)0x00000001132c8c00
```
Note how we start "completing" `Foo`. Then emit our new `WARNING`.
Shortly after, we crash, and the log abruptly ends.

rdar://135551810
2024-10-19 10:08:29 +01:00
Michael Buch
faed85b8e4 [lldb][test][NFC] Document DYLIB_NAME Makefile variable (#112735)
Got caught out by this because simply specifying `DYLIB_CXX_SOURCES`
(without specifying `DYLIB_NAME`) resulted in linker errors because the
dylib was never built (and linked). We should probably make that a
Makefile error (though I haven't audited when exactly not specifying
`DYLIB_NAME` is valid; looked like that can happen when we specify
`FRAMEWORK`).
2024-10-19 10:07:57 +01:00
Augusto Noronha
3d84b74cb3 [lldb] Add GetMangledTypeName to TypeSystem/CompilerType (#113006)
Swift types have mangled names, so there should be a way to read those
from the compiler type.

This patch upstreams these two changes from swiftlang/llvm-project
(which were added there since at least 2016).
2024-10-18 22:57:45 -07:00
Adrian Prantl
2b7e9d2781 [lldb] Add missing whitespace in help text 2024-10-18 16:55:21 -07:00
Jonas Devlieghere
6e02e19cd3 [lldb][docs] Add JSON symbol file docs to the ToC 2024-10-18 14:22:54 -07:00
Igor Kudrin
b88d94caba [lldb] Speed up FindInMemory tests (#111951)
A memory region can be relatively large. Searching for a value in the
entire region is time-consuming, especially when running tests against a
remote target, because the memory data is transferred in small chunks
over a relatively slow GDB Remote Protocol. The patch limits the address
range to be searched to 2K, which seems sufficient for these tests. In
my setup, for local runs, these tests now take half the time they did
before the patch. For a remote target, the improvement is even more
significant.
2024-10-18 14:13:27 -07:00
Igor Kudrin
47d9ca87b0 [lldb] Fix and re-enable TestUseSourceCache.py (#111237)
The decorators caused the `test_set_use_source_cache_true()` test to be
skipped in most scenarios. It was only run on a Windows host targeting a
non-Windows remote platform. The source file is opened with the
`FILE_SHARE_DELETE` sharing mode, which allows the file to be removed
even though it is also memory-mapped; at least, this behavior is
observed on Windows 11.

The patch replaces the operation with an attempt to overwrite the file,
which still fails for such files on Windows 11.
2024-10-18 14:11:23 -07:00
Jonas Devlieghere
7437f3ef7e [lldb] Document SymbolFileJSON (#112938)
I've had multiple request for documentation about the JSON symbol file
format that LLDB supports. This patch documents the structure and
fields, shows a handful of examples and explains how to use it in LLDB.
2024-10-18 13:24:15 -07:00
Luke Drummond
b55c52c047 Revert "Renormalize line endings whitespace only after dccebddb3b80"
This reverts commit 9d98acb196.
2024-10-18 21:16:50 +01:00
Kazu Hirata
a01d7df090 [lldb] Avoid repeated map lookups (NFC) (#112823) 2024-10-18 10:40:13 -07:00
Jay Foad
922992a22f Fix typo "instrinsic" (#112899) 2024-10-18 15:58:33 +01:00
Michael Buch
3bc765dbbf [lldb][test] Add test for ASTImporter's name conflict resolution (#112566)
This is a reduced test case from a crash we've observed in the past. The
assertion that this test triggers is:
```
Assertion failed: ((Pos == ImportedDecls.end() || Pos->second == To) && "Try to import an already imported Decl"), function MapImported, file ASTImporter.cpp, line 10494.
```

In a non-asserts build we crash later on in the ASTImporter. The root
cause is, as the assertion above points out, that we erroneously replace
an existing `From->To` decl mapping with a `To` decl that isn't
complete. Then we try to complete it but it has no definition and we
dereference a nullptr.

The reason this happens is basically what's been described in
https://reviews.llvm.org/D67803?id=220956#1676588

The dylib contains a definition of `Service` which is different to the
one in the main executable. When we start dumping the children of the
variable we're printing, we start completing it's members,
`ASTImport`ing fields in the process. When the ASTImporter realizes
there's been a name conflict (i.e., a structural mismatch on the
`Service` type) it would usually report back an error. However, LLDB
uses `ODRHandlingType::Liberal`, which means we create a new decl for
the ODR'd type instead of re-using the previously mapped decl.
Eventually this leads us to crash.

Ideally we'd be using `ODRHandlingType::Conservative` and warn/error,
though LLDB relies on this in some cases (particularly for
distinguishing template specializations, though maybe there's better a
way to deal with those).

We should really warn the user when this happens and not crash. To avoid
the crash we'd need to know to not create a decl for the ODR violation,
and instead re-use the definition we've previously seen. Though I'm not
yet sure that's viable for all of LLDB's use-cases (where ODR violations
might legimiately occur in a program, e.g., with opaque definitions,
etc.).
2024-10-18 14:19:42 +01:00
Benjamin Kramer
8e6abf526e Fix -Wswitch after 508fd966fb 2024-10-18 12:30:16 +02:00
Jason Molenda
9c6f85f57a [lldb][NFC] fix two small typeos in aarch64-linxu.md 2024-10-17 19:46:08 -07:00
Jacob Lalonde
5033ea73bb [LLDB][Minidump] Add breakpoint stop reasons to the minidump. (#108448)
Recently my coworker @jeffreytan81 pointed out that Minidumps don't show
breakpoints when collected. This was prior blocked because Minidumps
could only contain 1 exception, now that we support N signals/sections
we can save all the threads stopped on breakpoints.
2024-10-17 15:26:05 -07:00
Pavel Labath
98b419ca76 [lldb] Don't exit the main loop when in runs out of things to listen on (#112565)
This behavior made sense in the beginning as the class was completely
single threaded, so if the source count ever reached zero, there was no
way to add new ones. In https://reviews.llvm.org/D131160, the class
gained the ability to add events (callbacks) from other threads, which
means that is no longer the case (and indeed, one possible use case for
this class -- acting as a sort of arbiter for multiple threads wanting
to run code while making sure it runs serially -- has this class sit in
an empty Run call most of the time). I'm not aware of us having a use
for such a thing right now, but one of my tests in another patch turned
into something similar by accident.

Another problem with the current approach is that, in a
distributed/dynamic setup (multiple things using the main loop without a
clear coordinator), one can never be sure whether unregistering a
specific event will terminate the loop (it depends on whether there are
other listeners). We had this problem in lldb-platform.cpp, where we had
to add an additional layer of synchronization to avoid premature
termination. We can remove this if we can rely on the loop terminating
only when we tell it to.
2024-10-17 17:29:38 +02:00