0
0
mirror of https://github.com/llvm/llvm-project.git synced 2025-04-18 06:36:43 +00:00

6727 Commits

Author SHA1 Message Date
Felipe de Azevedo Piovezan
12becfff03
[lldb] Create ThreadPlanStepOut ctor that never skips frames ()
The function QueueThreadPlanForStepOutNoShouldStop has the semantics of
"go this parent frame"; ThreadPlanStepOut needs to respect that, not
skipping over any frames it finds uninteresting. This commit creates a
constructor that respects such instruction.
2025-04-17 14:13:28 -07:00
Felipe de Azevedo Piovezan
9f9c1f9381
[lldb][nfc] Split the constructor of ThreadPlanStepOut ()
A subsequent commit will create a new constructor for ThreadPlanStepOut,
which needs to reuse much of the same logic of the existing constructor.
This commit places all of that reusable logic into a separate function.
2025-04-17 12:53:25 -07:00
Charles Zablit
f135ce6a93
[lldb] Remove CompilerType::GetIndexOfFieldWithName ()
This patch removes the unused `CompilerType::GetIndexOfFieldWithName` API (it wasn't used apart from in a single testcase). Given we have so many similarly named APIs already, it's best not to maintain this API that's not really used (and isnt tested).
2025-04-17 12:55:18 +01:00
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 ()
The original PR is .

Co-authored-by: @bulbazord Alex Langford
2025-04-14 14:30:09 +04:00
Jonas Devlieghere
d792094c26
[lldb] Remove ProcessRunLock::TrySetRunning ()
I traced the issue reported by Caroline and Pavel in  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
1e153b782e
[lldb][Format] Display only the inlined frame name in backtraces if available ()
When a frame is inlined, LLDB will display its name in backtraces as
follows:
```
* thread , queue = 'com.apple.main-thread', stop reason = breakpoint 1.3
  * frame : 0x0000000100000398 a.out`func() [inlined] baz(x=10) at inline.cpp:1:42
    frame : 0x0000000100000398 a.out`func() [inlined] bar() at inline.cpp:2:37
    frame : 0x0000000100000398 a.out`func() at inline.cpp:4:15
    frame : 0x00000001000003c0 a.out`main at inline.cpp:7:5
    frame : 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 ()
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
Pavel Labath
f4fba20726
[lldb] Remove vestigial remnants of reproducers ()
Not touching the SB API.
2025-04-13 08:55:24 +02:00
Jonas Devlieghere
70627af91f
[lldb] Synchronize access to m_statusline in the Debugger ()
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
Pavel Labath
23c9cfcb74
[lldb] Small refactor of eh_frame parsing ()
.. 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
2b984fd0e3
[lldb] Support programmatically setting the statusline format (NFC) ()
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
Pavel Labath
cdb9c6190f
[lldb] Support negative function offsets in UnwindPlans ()
These are needed for functions whose entry point is not their lowest
address.
2025-04-10 11:31:44 +02:00
Vy Nguyen
e3f5a1bfc5
[LLDB][NFC]Also includes the error in log msg. ()
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" ()
Reverts 

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 ()
`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
Pavel Labath
e348173bef
Reapply "[lldb] Remove UnwindPlan::Row shared_ptrs" ()
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 ()
This patch addresses the issue .
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
cmtice
c4c0ff6865
[LLDB] Fix warnings in DIL. ()
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 ()
It reduces the memory usage in lldb-server.
2025-04-08 22:24:59 +04:00
Jacob Lalonde
f869d6efee
[LLDB][Minidump]Update MinidumpFileBuilder to read and write in chunks ()
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
Martin Storsjö
fcead25550 [lldb] Fix building with GCC without asserts
This case was missed in 03604a784011bec2292f900b118d825f34f8cf89.
2025-04-05 16:55:36 +03:00
Jonas Devlieghere
5271dead61
[lldb] Add a {ObjectFile,SymbolFile}::GetObjectName method ()
Add ObjectFile::GetObjectName and SymbolFile::GetObjectName to retrieve
the name of the object file, including the `.a` for static libraries.

We currently do something similar in CommandObjectTarget, but the code
for dumping this is a lot more involved than what's being offered by the
new method. We have options to print he full path, the base name, and
the directoy of the path and trim it to a specific width. 

This is motivated by , where Greg pointed out that the old code
would print the static archive (the .a file) rather than the actual
object file inside of it.
2025-04-04 16:33:40 -07:00
Jonas Devlieghere
12cf6d3b9e
[lldb] Fix missing semicolon in lldbassert macro 2025-04-04 13:37:12 -07:00
Jonas Devlieghere
03604a7840
[lldb] Make lldbassert fire only once per instance ()
The `lldbassert` macro in LLDB behaves like a regular `assert` when
assertions are enabled, and otherwise prints a pretty backtrace and
prompts the user to file a bug. By default, this is emitted as a
diagnostic event, but vendors can provide their own behavior, for
example pre-populating a bug report.

Recently, we ran into an issue where an `lldbassert` (in the Swift
language plugin) would fire excessively, to the point that it was
interfering with the usability of the debugger.

Once an `lldbasser` has fired, there's no point in bothering the user
over and over again for the same problem. This PR solves the problem by
introducing a static `std::once_flag` in the macro. This way, every
`lldbasser` will fire at most once per lldb instance.

rdar://148520448
2025-04-04 12:53:10 -07:00
Pavel Labath
e4f76e3a33
Reapply "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders " ()
This reverts commit 094904303d50e0ab14bc5f2586a602f79af95953, reapplying
d7afafdbc464e65c56a0a1d77bad426aa7538306 ().

The failure ought to be fixed by
0509932bb6a291ba11253f30c465ab3ad164ae08.
2025-04-04 09:49:27 +02:00
cmtice
46e2c07fa2
[LLDB] Add DIL code for handling plain variable names. ()
Add the Data Inspection Language (DIL) implementation pieces for
handling plain local and global variable names.

See https://discourse.llvm.org/t/rfc-data-inspection-language/69893 for
information about DIL.

This change includes the basic AST, Lexer, Parser and Evaluator pieces,
as well as some tests.
2025-04-03 21:39:30 -07:00
Jacob Lalonde
8e7d6baf0e
Revert "[LLDB] Expose checking if the symbol file exists/is loaded via SBModule" ()
Reverts 

Reverting while @clayborg and I come up with a better API
2025-04-03 20:45:55 -07:00
Felipe de Azevedo Piovezan
c14b6e90bd
[lldb][NFC] Move ShouldShow/ShouldSelect logic into Stopinfo ()
This NFC patch simplifies the main loop in HandleProcessStateChanged
event by moving duplicated code into the StopInfo class, also allowing
StopInfo subclasses to override behavior.

More specifically, two functions are created:

* ShouldShow: should a Thread with such StopInfo should be printed when
the debugger stops? Currently, no StopInfo subclasses override this, but
a subsequent patch will fix a bug by making StopInfoBreakpoint check
whether the breakpoint is internal.

* ShouldSelect: should a Thread with such a StopInfo be selected? This
is currently overridden by StopInfoUnixSignal but will, in the future,
be overridden by StopInfoBreakpoint.
2025-04-03 07:41:29 -07:00
Vladislav Dzhidzhoev
094904303d Revert "[lldb] Return *const* UnwindPlan pointers from FuncUnwinders ()"
This reverts commit d7afafdbc464e65c56a0a1d77bad426aa7538306.

Caused remote Linux to Linux buildbot failure
https://lab.llvm.org/buildbot/#/builders/195/builds/7046.
2025-04-03 11:33:11 +02:00
Jacob Lalonde
b8d8405238
[LLDB] Expose checking if the symbol file exists/is loaded via SBModule ()
The motivation for this patch is that in Statistics.cpp we [check to see
if the module symfile is
loaded](990a086d9d/lldb/source/Target/Statistics.cpp (L353C60-L353C75))
to calculate how much debug info has been loaded. I have an external
utility that only wants to look at the loaded debug info, which isn't
exposed by the SBAPI.
2025-04-02 21:27:44 -07:00
David Peixotto
2026873fb8
Add enable/disable api for SystemRuntime plugins ()
This commit adds support for enabling and disabling plugins by name. The
changes are made generically in the `PluginInstances` class, but
currently we only expose the ability to SystemRuntime plugins. Other
plugins types can be added easily.

We had a few design goals for how disabled plugins should work

1. Plugins that are disabled should still be visible to the system. This
allows us to dynamically enable and disable plugins and report their
state to the user.
2. Plugin order should be stable across disable and enable changes. We
want avoid changing the order of plugin lookup. When a plugin is
re-enabled it should return to its original slot in the creation order.
3. Disabled plugins should not appear in PluginManager operations.
Clients should be able to assume that only enabled plugins will be
returned from the PluginManager.

For the implementation we modify the plugin instance to maintain a bool
of its enabled state. Existing clients external to the Instances class
expect to iterate over only enabled instance so we skip over disabed
instances in the query and snapshot apis. This way the client does not
have to manually check which instances are enabled.
2025-04-02 13:15:31 -07:00
Jonas Devlieghere
ee60f7c7a4
[lldb] Hoist UUID generation into the UUID class ()
Hoist UUID generation into the UUID class and add a trivial unit test.
This also changes the telemetry code to drop the double underscore if we
failed to generate a UUID and subsequently logs to the Host instead of
Object log channel.
2025-04-02 08:50:28 -07:00
Pavel Labath
d7afafdbc4
[lldb] Return *const* UnwindPlan pointers from FuncUnwinders ()
These plans are cached and accessed from multiple threads. Modifying
them would be a Bad Idea(tm).
2025-04-02 12:48:57 +02:00
jimingham
347c5a7af5
Add a new affordance that the Python module in a dSYM ()
So the dSYM can be told what target it has been loaded into.

When lldb is loading modules, while creating a target, it will run
"command script import" on any Python modules in Resources/Python in the
dSYM. However, this happens WHILE the target is being created, so it is
not yet in the target list. That means that these scripts can't act on
the target that they a part of when they get loaded.

This patch adds a new python API that lldb will call:

__lldb_module_added_to_target

if it is defined in the module, passing in the Target the module was
being added to, so that code in these dSYM's don't have to guess.
2025-04-01 09:54:06 -07:00
Jonas Devlieghere
aa889ed129
[lldb] Fix statusline terminal resizing
Simplify and fix the logic to clear the old statusline when the terminal
window dimensions have changed. I accidentally broke the terminal
resizing behavior when addressing code review feedback.

I'd really like to figure out a way to test this. PExpect isn't a good
fit for this, because I really need to check the result, rather than the
control characters, as the latter doesn't tell me whether any part of
the old statusline is still visible.
2025-03-31 23:53:35 -07:00
Tom Yang
a8d2d169c7
Parallelize module loading in POSIX dyld code ()
This patch improves LLDB launch time on Linux machines for **preload
scenarios**, particularly for executables with a lot of shared library
dependencies (or modules). Specifically:
* Launching a binary with `target.preload-symbols = true` 
* Attaching to a process with `target.preload-symbols = true`.
It's completely controlled by a new flag added in the first commit
`plugin.dynamic-loader.posix-dyld.parallel-module-load`, which *defaults
to false*. This was inspired by similar work on Darwin .

Some rough numbers to showcase perf improvement, run on a very beefy
machine:
* Executable with ~5600 modules: baseline 45s, improvement 15s
* Executable with ~3800 modules: baseline 25s,  improvement 10s
* Executable with ~6650 modules: baseline 67s, improvement 20s
* Executable with ~12500 modules: baseline 185s, improvement 85s
* Executable with ~14700 modules: baseline 235s, improvement 120s
A lot of targets we deal with have a *ton* of modules, and unfortunately
we're unable to convince other folks to reduce the number of modules, so
performance improvements like this can be very impactful for user
experience.

This patch achieves the performance improvement by parallelizing
`DynamicLoaderPOSIXDYLD::RefreshModules` for the launch scenario, and
`DynamicLoaderPOSIXDYLD::LoadAllCurrentModules` for the attach scenario.
The commits have some context on their specific changes as well --
hopefully this helps the review.

# More context on implementation

We discovered the bottlenecks by via `perf record -g -p <lldb's pid>` on
a Linux machine. With an executable known to have 1000s of shared
library dependencies, I ran
```
(lldb) b main
(lldb) r
# taking a while
```
and showed the resulting perf trace (snippet shown)
```
Samples: 85K of event 'cycles:P', Event count (approx.): 54615855812
  Children      Self  Command          Shared Object              Symbol
-   93.54%     0.00%  intern-state     libc.so.6                  [.] clone3
     clone3
     start_thread
     lldb_private::HostNativeThreadBase::ThreadCreateTrampoline(void*)                                                                           r
     std::_Function_handler<void* (), lldb_private::Process::StartPrivateStateThread(bool)::$_0>::_M_invoke(std::_Any_data const&)
     lldb_private::Process::RunPrivateStateThread(bool)                                                                                          n
   - lldb_private::Process::HandlePrivateEvent(std::shared_ptr<lldb_private::Event>&)
      - 93.54% lldb_private::Process::ShouldBroadcastEvent(lldb_private::Event*)
         - 93.54% lldb_private::ThreadList::ShouldStop(lldb_private::Event*)
            - lldb_private::Thread::ShouldStop(lldb_private::Event*)                                                                             *
               - 93.53% lldb_private::StopInfoBreakpoint::ShouldStopSynchronous(lldb_private::Event*)                                            t
                  - 93.52% lldb_private::BreakpointSite::ShouldStop(lldb_private::StoppointCallbackContext*)                                     i
                       lldb_private::BreakpointLocationCollection::ShouldStop(lldb_private::StoppointCallbackContext*)                           k
                       lldb_private::BreakpointLocation::ShouldStop(lldb_private::StoppointCallbackContext*)                                     b
                       lldb_private::BreakpointOptions::InvokeCallback(lldb_private::StoppointCallbackContext*, unsigned long, unsigned long)    i
                       DynamicLoaderPOSIXDYLD::RendezvousBreakpointHit(void*, lldb_private::StoppointCallbackContext*, unsigned long, unsigned lo
                     - DynamicLoaderPOSIXDYLD::RefreshModules()                                                                                  O
                        - 93.42% DynamicLoaderPOSIXDYLD::RefreshModules()::$_0::operator()(DYLDRendezvous::SOEntry const&) const                 u
                           - 93.40% DynamicLoaderPOSIXDYLD::LoadModuleAtAddress(lldb_private::FileSpec const&, unsigned long, unsigned long, bools
                              - lldb_private::DynamicLoader::LoadModuleAtAddress(lldb_private::FileSpec const&, unsigned long, unsigned long, boos
                                 - 83.90% lldb_private::DynamicLoader::FindModuleViaTarget(lldb_private::FileSpec const&)                        o
                                    - 83.01% lldb_private::Target::GetOrCreateModule(lldb_private::ModuleSpec const&, bool, lldb_private::Status*
                                       - 77.89% lldb_private::Module::PreloadSymbols()
                                          - 44.06% lldb_private::Symtab::PreloadSymbols()
                                             - 43.66% lldb_private::Symtab::InitNameIndexes()
...
```
We saw that majority of time was spent in `RefreshModules`, with the
main culprit within it `LoadModuleAtAddress` which eventually calls
`PreloadSymbols`.

At first, `DynamicLoaderPOSIXDYLD::LoadModuleAtAddress` appears fairly
independent -- most of it deals with different files and then getting or
creating Modules from these files. The portions that aren't independent
seem to deal with ModuleLists, which appear concurrency safe. There were
members of `DynamicLoaderPOSIXDYLD` I had to synchronize though: namely
`m_loaded_modules` which `DynamicLoaderPOSIXDYLD` maintains to map its
loaded modules to their link addresses. Without synchronizing this, I
ran into SEGFAULTS and other issues when running `check-lldb`. I also
locked the assignment and comparison of `m_interpreter_module`, which
may be unnecessary.

# Alternate implementations

When creating this patch, another implementation I considered was
directly background-ing the call to `Module::PreloadSymbol` in
`Target::GetOrCreateModule`. It would have the added benefit of working
across platforms generically, and appeared to be concurrency safe. It
was done via `Debugger::GetThreadPool().async` directly. However, there
were a ton of concurrency issues, so I abandoned that approach for now.

# Testing

With the feature active, I tested via `ninja check-lldb` on both Debug
and Release builds several times (~5 or 6 altogether?), and didn't spot
additional failing or flaky tests.

I also tested manually on several different binaries, some with around
14000 modules, but just basic operations: launching, reaching main,
setting breakpoint, stepping, showing some backtraces.

I've also tested with the flag off just to make sure things behave
properly synchronously.
2025-03-31 13:29:31 -07:00
Jonas Devlieghere
799e905364
[lldb] Create a default rate limit constant in Progress (NFC) ()
In , Greg suggested making the rate limit configurable through a
setting. Although adding the setting is easy, the two places where we
currently use rate limiting aren't tied to a particular debugger.
Although it'd be possible to hook up, given how few progress events
currently implement rate limiting, I don't think it's worth threading
this through, if that's even possible.

I still think it's a good idea to be consistent and make it easy to pick
the same rate limiting value, so I've moved it into a constant in the
Progress class.
2025-03-31 08:29:20 -07:00
Jonas Devlieghere
50949ebf52
[lldb] Expose the Target API mutex through the SB API ()
Expose u target API mutex through the SB API. This is motivated by
lldb-dap, which is built on top of the SB API and needs a way to execute
a series of SB API calls in an atomic manner (see ).

We can solve this problem by either introducing an additional layer of
locking at the DAP level or by exposing the existing locking at the SB
API level. This patch implements the second approach.

This was discussed in an RFC on Discourse [0]. The original
implementation exposed a move-only lock rather than a mutex [1] which
doesn't work well with SWIG 4.0 [2]. This implement the alternative
solution of exposing the mutex rather than the lock. The SBMutex
conforms to the BasicLockable requirement [3] (which is why the methods
are called `lock` and `unlock` rather than Lock and Unlock) so it can be
used as `std::lock_guard<lldb::SBMutex>` and
`std::unique_lock<lldb::SBMutex>`.

[0]: https://discourse.llvm.org/t/rfc-exposing-the-target-api-lock-through-the-sb-api/85215/6
[1]: https://github.com/llvm/llvm-project/pull/131404
[2]: https://discourse.llvm.org/t/rfc-bumping-the-minimum-swig-version-to-4-1-0/85377/9
[3]: https://en.cppreference.com/w/cpp/named_req/BasicLockable
2025-03-31 08:19:41 -07:00
Pavel Labath
9d61eaa9ec
[lldb] Make GetRowForFunctionOffset compatible with discontinuous functions ()
The function had special handling for -1, but that is incompatible with
functions whose entry point is not the first address. Use std::nullopt
instead.
2025-03-31 11:45:11 +02:00
Jordan Rupprecht
48864a52ef
Revert "[lldb] Remove UnwindPlan::Row shared_ptrs ()" ()
This reverts commit d7cea2b18717f0cc31b7da4a03f772d89ee201db. It causes
crashes in API tests.
2025-03-27 14:20:07 -05:00
Pavel Labath
17aca79d98
[lldb] Teach FuncUnwinders about discontinuous functions ()
The main change here is that we're now able to correctly look up plans
for these functions. Previously, due to caching, we could end up with
one entry covering most of the address space (because part of the
function was at the beginning and one at the end). Now, we can correctly
recognise that the part in between does not belong to that function, and
we can create a different FuncUnwinders instance for it. It doesn't help
the discontinuous function much (its plan will still be garbled), but
we can at least properly unwind out of the simple functions in between.

Fixing the unwind plans for discontinuous functions requires handling
each unwind source specially, and this setup allows us to make the
transition incrementally.
2025-03-27 12:51:20 +01:00
Pavel Labath
71d54cd4f1
[lldb] Remove (deprecated) Function::GetAddressRange ()
All uses have been replaced by GetAddressRange*s* or GetAddress.

Also fix two internal uses of the range member.
2025-03-27 11:27:56 +01:00
Pavel Labath
d7cea2b187
[lldb] Remove UnwindPlan::Row shared_ptrs ()
The surrounding code doesn't use them anymore. This removes the internal
usages.

This patch makes the Rows actual values. An alternative would be to make
them unique_ptrs. That would make vector resizes faster at the cost of
more pointer chasing and heap fragmentation. I don't know which one is
better so I picked the simpler option.
2025-03-27 11:26:42 +01:00
Jonas Devlieghere
9c18edc621
[lldb] Implement a statusline in LLDB ()
Add a statusline to command-line LLDB to display information about the
current state of the debugger. The statusline is a dedicated area
displayed at the bottom of the screen. The information displayed is
configurable through a setting consisting of LLDB’s format strings.

Enablement
----------

The statusline is enabled by default, but can be disabled with the
following setting:

```
(lldb) settings set show-statusline false
```

Configuration
-------------

The statusline is configurable through the `statusline-format` setting.
The default configuration shows the target name, the current file, the
stop reason and any ongoing progress events.

```
(lldb) settings show statusline-format
statusline-format (format-string) = "${ansi.bg.blue}${ansi.fg.black}{${target.file.basename}}{ | ${line.file.basename}:${line.number}:${line.column}}{ | ${thread.stop-reason}}{ | {${progress.count} }${progress.message}}"
```

The statusline supersedes the current progress reporting implementation.
Consequently, the following settings no longer have any effect (but
continue to exist to not break anyone's `.lldbinit`):

```
show-progress             -- Whether to show progress or not if the debugger's output is an interactive color-enabled terminal.
show-progress-ansi-prefix -- When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately before the progress message.
show-progress-ansi-suffix -- When displaying progress in a color-enabled terminal, use the ANSI terminal code specified in this format immediately after the progress message.
```

Format Strings
--------------

LLDB's format strings are documented in the LLDB documentation and on
the website: https://lldb.llvm.org/use/formatting.html#format-strings.
The current implementation is relatively limited but various
improvements have been discussed in the RFC.

One such improvement is being to display a string when a format string
is empty. Right now, when launching LLDB without a target, the
statusline will be empty, which is expected, but looks rather odd.

RFC
---

The full RFC can be found on Discourse:
https://discourse.llvm.org/t/rfc-lldb-statusline/83948
2025-03-26 14:41:05 -07:00
Dmitry Vasilyev
59c5d53199
[LLDB][NFC] Replace DWARFUnit with DWARFExpression::Delegate in DWARFExpressionList too ()
This is an update for .
2025-03-26 16:28:39 +04:00
Michael Buch
23bf98e4b5
[lldb][docs][NFC] Fix some doxygen comments ()
These weren't rendering properly (mostly mis-use the syntax for
commenting member variables).
2025-03-25 15:41:16 +00:00
Dmitry Vasilyev
2edf534f55
[LLDB][NFC] Added the interface DWARFExpression::Delegate to break dependencies and reduce lldb-server size ()
This patch addresses the issue .
After this patch DWARFExpression does not call DWARFUnit directly and does not depend on
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp and a lot of clang code.
After this patch the size of lldb-server binary (Linux Aarch64) is reduced from 47MB to 17MB.
2025-03-24 18:40:49 +04:00
Ebuka Ezike
4b419840c8
[lldb] Show target.debug-file-search-paths setting from python SBDebugger ()
When printing setting variables using the python SBDebugger API if the type is of OptionValueFileSpec
it defaults to null as the value even if it has a value. This patch fixes that.

---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-21 11:20:35 +00:00
Pavel Labath
387f3e8f98
[lldb] s/ValidRange/ValidRanges in UnwindPlan ()
To be able to describe discontinuous functions, this patch changes the
UnwindPlan to accept more than one address range.

I've also squeezed in a couple improvements/modernizations, for example
using the lower_bound function instead of a linear scan.
2025-03-21 10:46:48 +01:00