31630 Commits

Author SHA1 Message Date
Michael Buch
cbbf562d1c [lldb][Format][NFC] Remove unused FormatEntity::FormatCString
One can use `FormatStringRef` instead anyway
2025-04-14 13:42:35 +01:00
Dmitry Vasilyev
e4a672bc17
[LLDB] Reapply refactored CPlusPlusLanguage::MethodName to break lldb-server dependencies (#135033)
The original PR is #132274.

Co-authored-by: @bulbazord Alex Langford
2025-04-14 14:30:09 +04:00
Jonas Devlieghere
73b554d7a0
[lldb] Make sure the process is stopped when computing the symbol context (#135458)
Make sure the process is stopped when computing the symbol context. Both
Adrian and Felipe reported a handful of crashes in GetSymbolContext
called from Statusline::Redraw on the default event thread.

Given that we're handling a StackFrameSP, it's not clear to me how that
could have gotten invalidated, but Jim points out that it doesn't make
sense to compute the symbol context for the frame when the process isn't
stopped.

Depends on  #135455
2025-04-14 10:09:43 +02:00
Jonas Devlieghere
d792094c26
[lldb] Remove ProcessRunLock::TrySetRunning (#135455)
I traced the issue reported by Caroline and Pavel in #134757 back to the
call to ProcessRunLock::TrySetRunning. When that fails, we get a
somewhat misleading error message:

> process resume at entry point failed: Resume request failed - process
still running.

This is incorrect: the problem was not that the process was in a running
state, but rather that the RunLock was being held by another thread
(i.e. the Statusline). TrySetRunning would return false in both cases
and the call site only accounted for the former.

Besides the odd semantics, the current implementation is inherently
race-y and I believe incorrect. If someone is holding the RunLock, the
resume call should block, rather than give up, and with the lock held,
switch the running state and report the old running state.

This patch removes ProcessRunLock::TrySetRunning and updates all callers
to use ProcessRunLock::SetRunning instead. To support that,
ProcessRunLock::SetRunning (and ProcessRunLock::SetStopped, for
consistency) now report whether the process was stopped or running
respectively. Previously, both methods returned true unconditionally.

The old code has been around pretty much pretty much forever, there's
nothing in the git history to indicate that this was done purposely to
solve a particular issue. I've tested this on both Linux and macOS and
confirmed that this solves the statusline issue.

A big thank you to Jim for reviewing my proposed solution offline and
trying to poke holes in it.
2025-04-14 10:09:19 +02:00
Michael Buch
a3f8359410 [lldb][test] Fix NativePDB/inline_sites_live.cpp inlined frame format
Adjust after https://github.com/llvm/llvm-project/pull/135343
2025-04-14 06:31:50 +01:00
Michael Buch
af7a7ba4aa [lldb][Format][NFC] Factor FunctionNameWithArgs case out into helper function 2025-04-14 00:12:30 +01:00
Michael Buch
1e153b782e
[lldb][Format] Display only the inlined frame name in backtraces if available (#135343)
When a frame is inlined, LLDB will display its name in backtraces as
follows:
```
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.3
  * frame #0: 0x0000000100000398 a.out`func() [inlined] baz(x=10) at inline.cpp:1:42
    frame #1: 0x0000000100000398 a.out`func() [inlined] bar() at inline.cpp:2:37
    frame #2: 0x0000000100000398 a.out`func() at inline.cpp:4:15
    frame #3: 0x00000001000003c0 a.out`main at inline.cpp:7:5
    frame #4: 0x000000026eb29ab8 dyld`start + 6812
```
The longer the names get the more confusing this gets because the first
function name that appears is the parent frame. My assumption (which may
need some more surveying) is that for the majority of cases we only care
about the actual frame name (not the parent). So this patch removes all
the special logic that prints the parent frame.

Another quirk of the current format is that the inlined frame name does
not abide by the `${function.name-XXX}` format variables. We always just
print the raw demangled name. With this patch, we would format the
inlined frame name according to the `frame-format` setting (see the
test-cases).

If we really want to have the `parentFrame [inlined] inlinedFrame`
format, we could expose it through a new `frame-format` variable (e..g.,
`${function.inlined-at-name}` and let the user decide where to place
things.
2025-04-13 23:21:52 +01:00
Michael Buch
52e45a79ad
[lldb][Language] Change GetFunctionDisplayName to take SymbolContext by reference (#135536)
Both the `CPlusPlusLanguage` plugins and the Swift language plugin
already assume the `sc != nullptr`. And all `FormatEntity` callsites of
`GetFunctionDisplayName` already check for nullptr before passing `sc`.
This patch makes this pre-condition explicit by changing the parameter
to `const SymbolContext &`. This will help with some upcoming changes in
this area.
2025-04-13 23:19:26 +01:00
Adrian Prantl
99df442df1 Skip test on Darwin 2025-04-13 14:40:41 -07:00
Pavel Labath
1c5ce2d74f Reapply "[lldb] ProcessGdbRemote header gardning"
This reverts commit 68ab45f0533f3bbfc1c96bddd53de7e769180219, reapplying
2fd860c1f559c0b0be66cc000e38270a04d0a1a3. The only change is keeping
"lldb/Host/Config.h", which I believe was the cause of the failures.
2025-04-13 09:52:30 +02:00
Pavel Labath
f4fba20726
[lldb] Remove vestigial remnants of reproducers (#135361)
Not touching the SB API.
2025-04-13 08:55:24 +02:00
Alexandre Ganea
715c61e9a7 [lldb][lldbp-dap] On Windoows, silence warnings when building with MSVC
Fixes:
```
[6373/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\DAP.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\DAP.cpp(725) : warning C4715: '`lldb_dap::DAP::HandleObject'::`30'::<lambda_2>::operator()': not all control paths return a value
[6421/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Protocol\ProtocolTypes.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(203) : warning C4715: 'lldb_dap::protocol::ToString': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(98) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(72) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(111) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
[6426/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Protocol\ProtocolBase.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolBase.cpp(287) : warning C4715: 'lldb_dap::protocol::fromJSON': not all control paths return a value
```
2025-04-11 17:50:15 -04:00
Alexandre Ganea
e1d91ba06d [lldb] Fix erroneous return value
Found when building with MSVC on Windows, was seeing:
```
[2703/7138] Building CXX object tools\lldb\source\Plugins\Process\Utility\CMakeFiles\lldbPluginProcessUtility.dir\NativeRegisterContextDBReg.cpp.obj
C:\git\llvm-project\lldb\source\Plugins\Process\Utility\NativeRegisterContextDBReg.cpp(286): warning C4305: 'return': truncation from 'unsigned int' to 'bool'
```
2025-04-11 17:50:15 -04:00
Alexandre Ganea
84ed81bc8a [lldb] On Windows, silence warning when building with Clang ToT
Fixes:
```
[930/2017] Building CXX object tools\lldb\unittests\Thread\CMakeFiles\ThreadTests.dir\ThreadTest.cpp.obj
C:\git\llvm-project\lldb\unittests\Thread\ThreadTest.cpp(51,23): warning: cast from 'FARPROC' (aka 'long long (*)()') to 'SetThreadDescriptionFunctionPtr' (aka 'long (*)(void *, const wchar_t *)') converts to incompatible function type [-Wcast-function-type-mismatch]
   51 |       SetThreadName = reinterpret_cast<SetThreadDescriptionFunctionPtr>(
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   52 |           ::GetProcAddress(hModule, "SetThreadDescription"));
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
2025-04-11 17:49:26 -04:00
Jonas Devlieghere
179d30f8c3
Revert "[lldb] Make sure the process is stopped when computing the symbol context (#134757)" (#135408)
This reverts commit e84a80408523a48d6eaacd795f1615e821ffb233 because on
Linux there seems to be a race around GetRunLock. See #134757 for more
context.
2025-04-11 11:50:42 -07:00
Felipe de Azevedo Piovezan
c2939b9bf6
Reland "[lldb] Clear thread-creation breakpoints in ProcessGDBRemote::Clear (#134397)" (#135296)
This reapplies commit
232525f069.

The original commit triggered a sanitizer failure when `Target` was
destroyed. In `Target::Destroy`, `DeleteCurrentProcess` was called, but
it did not destroy the thread creation breakpoints for the underlying
`ProcessGDBRemote` because `ProcessGDBRemote::Clear` was not called in
that path.

`Target `then proceeded to destroy its breakpoints, which resulted in a
call to the destructor of a `std::vector` containing the breakpoints.
Through a sequence of complicated events, destroying breakpoints caused
the reference count of the underlying `ProcessGDBRemote` to finally
reach zero. This, in turn, called `ProcessGDBRemote::Clear`, which
attempted to destroy the breakpoints. To do that, it would go back into
the Target's vector of breakpoints, which we are in the middle of
destroying.

We solve this by moving the breakpoint deletion into
`Process:DoDestroy`, which is a virtual Process method that will be
called much earlier.
2025-04-11 11:46:22 -07:00
Jonas Devlieghere
68ab45f053
Revert "[lldb] ProcessGdbRemote header gardning"
This reverts commit 2fd860c1f559c0b0be66cc000e38270a04d0a1a3 as this is
causing a EXC_BAD_ACCESS on Darwin:

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/23807/
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/11255/
2025-04-11 10:44:43 -07:00
Jonas Devlieghere
70627af91f
[lldb] Synchronize access to m_statusline in the Debugger (#134759)
Eliminate the potential for a race between the main thread, the default
event handler thread and the signal handling thread, when accessing the
m_statusline member.
2025-04-11 08:53:49 -07:00
David Spickett
5b384c3015 [lldb][test] Adjust TestTargetReadInstructionsFlavor skipIfs
Original in https://github.com/llvm/llvm-project/pull/134626 was
written as if it was "this or this" but it's "this and this".

So the test ran on AArch64 Linux, because Linux is not Windows.

Split out the Windows check to fix that.
2025-04-11 13:14:16 +00:00
Ebuka Ezike
dda53bef35
[lldb] Fix SBTarget::ReadInstruction with flavor (#134626)
When you call the `SBTarget::ReadInstructions` with flavor from lldb
crashes. This is because the wrong order of the `DisassemblyBytes`
constructor this fixes that

---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
2025-04-11 13:45:19 +01:00
Pavel Labath
2fd860c1f5 [lldb] ProcessGdbRemote header gardning
Remove unused headers, add used headers, remove declared-but-not-defined
entities.
2025-04-11 14:36:08 +02:00
Michael Buch
b656915d5a
[lldb][Format][NFCI] Refactor CPlusPlusLanguage::GetFunctionDisplayName into helpers and use LLVM style (#135331)
Same cleanup as in https://github.com/llvm/llvm-project/pull/135031. It
pretty much is the same code that we had to duplicate in the language
plugin. Maybe eventually we'll find a way of getting rid of the
duplication.
2025-04-11 11:01:27 +01:00
Pavel Labath
23c9cfcb74
[lldb] Small refactor of eh_frame parsing (#134806)
.. which prepares us for handling of discontinuous functions. The main
change there is that we can have multiple FDEs contributing towards an
unwind plan of a single function. This patch separates the logic for
parsing of a single FDE from the construction of an UnwindPlan (so that
another patch can change the latter to combine several unwind plans).

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-04-11 09:27:56 +02:00
Jonas Devlieghere
a62b9b387f
[lldb] Calling Debugger::SetStatuslineFormat should redraw the statusline 2025-04-10 16:55:59 -07:00
Jonas Devlieghere
2b984fd0e3
[lldb] Support programmatically setting the statusline format (NFC) (#135250)
Support programmatically setting the statusline format. I want to use
this API downstream, to change the statusline format for the Swift REPL.
2025-04-10 15:36:28 -07:00
Jonas Devlieghere
6493345c5a
[lldb] Handle signals in a separate thread in the driver (#134956)
Handle signals in a separate thread in the driver so that we can stop
worrying about signal safety of functions in libLLDB that may get called
from a signal handler.
2025-04-10 11:04:05 -07:00
Pavel Labath
cdb9c6190f
[lldb] Support negative function offsets in UnwindPlans (#134662)
These are needed for functions whose entry point is not their lowest
address.
2025-04-10 11:31:44 +02:00
Michael Buch
f030f6f3c5
[lldb][FormatEntity][NFCI] Refactor FunctionNameWithArgs into helper functions and use LLVM style (#135031)
I've always found this hard to read. Some upcoming changes make similar
computations, so I thought it's a good time to factor out this logic
into re-usable helpers and clean it up using LLVM's preferred
early-return style.
2025-04-10 09:39:58 +01:00
Jacob Lalonde
e98d1380a0
[NFC][LLDB] Clean up comments/some code in MinidumpFileBuilder (#134961)
I've recently been working on Minidump File Builder again, and some of
the comments are out of date, and many of the includes are no longer
used. This patch removes unneeded includes and rephrases some comments
to better fit with the current state after the read write chunks pr.
2025-04-09 10:55:30 -07:00
Vy Nguyen
e3f5a1bfc5
[LLDB][NFC]Also includes the error in log msg. (#134922)
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-04-09 10:23:48 -04:00
David Spickett
a29be9f28e
Revert "[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server dependencies" (#134995)
Reverts llvm/llvm-project#132274

Broke a test on LLDB Widows on Arm:
https://lab.llvm.org/buildbot/#/builders/141/builds/7726
```
FAIL: test_dwarf (lldbsuite.test.lldbtest.TestExternCSymbols.test_dwarf)
<...>
    self.assertTrue(self.res.Succeeded(), msg + output)

AssertionError: False is not true : Command 'expression -- foo()' did not return successfully

Error output:

error: Couldn't look up symbols:

  int foo(void)

Hint: The expression tried to call a function that is not present in the target, perhaps because it was optimized out by the compiler.
```
2025-04-09 13:16:23 +01:00
Pavel Labath
ea7dd70b53
[lldb] Remove unused UnwindPlan functions (#134630)
`GetLSDAAddress` and `GetPersonalityRoutinePtrAddress` are unused and
they create a bit of a problem for discontinuous functions, because the
unwind plan for these consists of multiple eh_frame descriptors and (at
least in theory) each of them could have a different value for these
entities.

We could say we only support functions for which these are always the
same, or create some sort of a Address2LSDA lookup map, but I think it's
better to leave this question to someone who actually needs this.
2025-04-09 11:04:45 +02:00
yingopq
8877b913ae
[LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target (#132688)
Now, because we do not support mips debugging, if we compile LLVM on
mips target, would report error `static assertion failed:Value mismatch
for signal number SIGBUS`, so add this condition to avoid error.
2025-04-09 10:53:47 +02:00
Pavel Labath
e348173bef
Reapply "[lldb] Remove UnwindPlan::Row shared_ptrs" (#134821)
This reverts commit
48864a52ef,
reapplying d7cea2b187.
It also fixes the dangling
pointers caused by the previous version by creating copies of the Rows
in x86AssemblyInspectionEngine.
2025-04-09 08:22:15 +02:00
Dmitry Vasilyev
fbc6241d3a
[LLDB] Refactored CPlusPlusLanguage::MethodName to break lldb-server dependencies (#132274)
This patch addresses the issue #129543.
After this patch the size of lldb-server is reduced by 9MB.

Co-authored-by: @bulbazord Alex Langford
2025-04-09 09:11:56 +04:00
Jason Molenda
50e218ad9c Revert "[lldb] Clear thread-creation breakpoints in ProcessGDBRemote::Clear (#134397)"
This reverts commit 232525f06942adb3b9977632e38dcd5f08c0642d.

This change is causing test crashes while running
TestCompletion.py on Darwin systems, most of the CI runs
have failed since it has been merged in.
2025-04-08 21:05:50 -07:00
Jason Molenda
76d722732d [lldb][Minidump] Fix MAX_WRITE_CHUNK_SIZE type
MinidumpFileBuilder calls std::min(MAX_WRITE_CHUNK_SIZE,
func_returning_uint64_t) and on Darwin this errors out with
unsigned long long & unsigned long not being the same type.
2025-04-08 14:00:42 -07:00
cmtice
c4c0ff6865
[LLDB] Fix warnings in DIL. (#134778)
This fixes 3 warnings from compiling the DILParser:

DILParser.h:53:12: warning: returning address of local temporary object
[-Wreturn-stack-address]

DILParser.h:119:8: warning: private field 'm_fragile_ivar' is not used
[-Wunused-private-field]

DILParser.h:120:8: warning: private field 'm_check_ptr_vs_member' is not
used [-Wunused-private-field]
2025-04-08 11:37:54 -07:00
Dmitry Vasilyev
7e70d708a3
[LLDB][NFC] Remove Debugger dependency in SystemLifetimeManager (#134383)
It reduces the memory usage in lldb-server.
2025-04-08 22:24:59 +04:00
Jonas Devlieghere
e84a804085
[lldb] Make sure the process is stopped when computing the symbol context (#134757)
Make sure the process is stopped when computing the symbol context. Both
Adrian and Felipe reported a handful of crashes in GetSymbolContext
called from Statusline::Redraw on the default event thread.

Given that we're handling a StackFrameSP, it's not clear to me how that
could have gotten invalidated, but Jim points out that it doesn't make
sense to compute the symbol context for the frame when the process isn't
stopped.
2025-04-08 11:06:05 -07:00
Adrian Prantl
2721d50d87 Revert "[dsymutil] Avoid copying binary swiftmodules built from textual"
This reverts commit 39ace8a63012af7d6ad7bf065c233fd3d5df44a3.

while investigating Linux bot failures.
2025-04-08 09:49:36 -07:00
Jacob Lalonde
f869d6efee
[LLDB][Minidump]Update MinidumpFileBuilder to read and write in chunks (#129307)
I recently received an internal error report that LLDB was OOM'ing when
creating a Minidump. In my 64b refactor we made a decision to acquire
buffers the size of the largest memory region so we could read all of
the contents in one call. This made error handling very simple (and
simpler coding for me!) but had the trade off of large allocations if
huge pages were enabled.

This patch is one I've had on the back burner for awhile, but we can
read and write the Minidump memory sections in discrete chunks which we
already do for writing to disk.

I had to refactor the error handling a bit, but it remains the same. We
make a best effort attempt to read as much of the memory region as
possible, but fail immediately if we receive an error writing to disk. I
did not add new tests for this because our existing test suite is quite
good, but I did manually verify a few Minidumps couldn't read beyond the
red_zone.

```
(lldb) reg read $sp
     rsp = 0x00007fffffffc3b0
(lldb) p/x 0x00007fffffffc3b0 - 128
(long) 0x00007fffffffc330
(lldb) memory read 0x00007fffffffc330
0x7fffffffc330: 60 c3 ff ff ff 7f 00 00 60 cd ff ff ff 7f 00 00  `.......`.......
0x7fffffffc340: 60 c3 ff ff ff 7f 00 00 65 e6 26 00 00 00 00 00  `.......e.&.....
(lldb) memory read 0x00007fffffffc329
error: could not parse memory info (Success!)
```

I'm not sure how to quantify the memory improvement other than we would
allocate the largest size regardless of the size. So a 2gb unreadable
region would cause a 2gb allocation even if we were reading 4096 kb. Now
we will take the range size or the max chunk size of 128 mb.
2025-04-08 09:47:52 -07:00
Adrian Prantl
5615061445
[dsymutil] Avoid copying binary swiftmodules built from textual (#134719)
.swiftinterface files into the dSYM bundle. These typically come only
from the SDK (since textual interfaces require library evolution) and
thus are a waste of space to copy into the bundle.

The information about this is being parsed out of the control block,
which means duplicating 5 constants from the Swift frontend. If a file
cannot be parsed, dsymutil errs on the side of copying the file anyway.

rdar://138186524
2025-04-08 08:03:32 -07:00
David Spickett
db7fb704f6 [lldb][test] Explain why TestExprFromNonZeroFrame is disabled on Windows
It's not scientific but I think the PDB we produce on the Windows on Arm
bot simply doesn't have the information needed. Could also be that clang
is producing some DWARF, but link.exe is dropping it from the final executable,
the effect is the same.
2025-04-08 12:17:07 +00:00
Tom Yang
65813e0e94
Control Darwin parallel image loading with target.parallel-module-load (#134437)
A requested follow-up from
https://github.com/llvm/llvm-project/pull/130912 by @JDevlieghere to
control Darwin parallel image loading with the same
`target.parallel-module-load` that controls the POSIX dyld parallel
image loading. Darwin parallel image loading was introduced by
https://github.com/llvm/llvm-project/pull/110646.

This small change:
* removes
`plugin.dynamic-loader.darwin.experimental.enable-parallel-image-load`
and associated code.
* changes setting call site in
`DynamicLoaderDarwin::PreloadModulesFromImageInfos` to use the new
setting.

Tested by running `ninja check-lldb` and loading some targets.

Co-authored-by: Tom Yang <toyang@fb.com>
2025-04-07 16:33:48 -07:00
Jason Molenda
df28c81f5a [lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)
debugserver takes the address of a watchpoint exception and calculates
which watchpoint was responsible for it. There was an off-by-one error
in the range calculation which causes two watchpoints on consecutive
ranges to not correctly identify hits to the second watchpoint. The
result is that lldb wouldn't show the second watchpoint as ever being
hit.

Re-landing this test with a modification to only require two
watchpoints in the test, instead of four.  If four watchpoints can
be set, it will test them.

rdar://145107575
2025-04-07 13:50:31 -07:00
Jason Molenda
369c7739d0 Revert "[lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)"
This reverts commit 21d912121c9f41385b165a736be787527f5bd7c2.

Failure on the aarch64 ubuntu bot when setting the 4th watchpoint;
may be a hardware limitation on that bot.  I thought creating four
watchpoints would be generally safe, but I don't need to do that
for my test, will re-land without it.
2025-04-07 11:21:58 -07:00
Jason Molenda
21d912121c
[lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)
debugserver takes the address of a watchpoint exception and calculates
which watchpoint was responsible for it. There was an off-by-one error
in the range calculation which causes two watchpoints on consecutive
ranges to not correctly identify hits to the second watchpoint. The
result is that lldb wouldn't show the second watchpoint as ever being
hit.

rdar://145107575
2025-04-07 11:11:31 -07:00
Julian Lettner
4b90f24db8
[LLDB] Add integration test for libsanitizers trace collection (#134323)
Add integration test for libsanitizers trace collection
(`SanitizersAllocationTraces=all`).
    
rdar://144244084
2025-04-07 08:33:27 -07:00
Martin Storsjö
fcead25550 [lldb] Fix building with GCC without asserts
This case was missed in 03604a784011bec2292f900b118d825f34f8cf89.
2025-04-05 16:55:36 +03:00