Commit Graph

6579 Commits

Author SHA1 Message Date
Pavel Labath
66a88f62cd [lldb] Add Function::GetAddress and redirect some uses (#115836)
Many calls to Function::GetAddressRange() were not interested in the
range itself. Instead they wanted to find the address of the function
(its entry point) or the base address for relocation of function-scoped
entities (technically, the two don't need to be the same, but there's
isn't good reason for them not to be). This PR creates a separate
function for retrieving this, and changes the existing
(non-controversial) uses to call that instead.
2025-01-10 09:56:55 +01:00
Lakshmi-Surekha
b1893caeb6 [lldb][AIX] Added support for AIX in HostInfo section (#122301)
This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
https://github.com/llvm/llvm-project/issues/101657
2. The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
Added support for AIX in HostInfo section

Review Request : @DavidSpickett @labath @DhruvSrivastavaX
2025-01-10 07:21:10 +05:30
David Spickett
d3f1b864ae [lldb][NFC] clang-format MemoryRegionInfo.h
To clean up future changes for shadow stack regions.
2025-01-09 10:54:52 +00:00
Pavel Labath
a261eee612 [lldb] Store *signed* ranges in lldb_private::Block (#120224)
This is to support functions whose entry points aren't their lowest
address

(https://discourse.llvm.org/t/rfcish-support-for-discontinuous-functions/83244).
The alternative is to keep blocks relative to the lowest address, but
then introduce a separate concept for the function entry point, which I
think would be more confusing.

This patch just changes the type signedness, it doesn't create any
negative offsets yet. Since combining values with different signs can
sometimes produce unexpected results, and since this is the first use of
RangeVector with a signed type, I'm adding a test to verify that at
least the core functionality works correctly.
2025-01-09 10:52:04 +01:00
Jacob Lalonde
774c226863 [LLDB] Add external progress bit category (#120171)
As feedback on #119052, it was recommended I add a new bit to delineate
internal and external progress events. This patch adds this new
category, and sets up Progress.h to support external events via
SBProgress.
2025-01-06 12:49:15 -08:00
rchamala
b6960e2a63 [lldb][ResolveSourceFileCallback] Update SBModule (#120832)
Summary:
RFC
https://discourse.llvm.org/t/rfc-python-callback-for-source-file-resolution/83545

SBModule will be used for resolve source file callback as Python
function arguments. This diff allows these things.

Can be instantiated from SBPlatform.
Can be passed to/from Python.

Test Plan:
N/A. The next set of diffs in the stack have unittests and shell test
validation

Co-authored-by: Rahul Reddy Chamala <rachamal@fb.com>
2025-01-06 09:17:58 -08:00
Dhruv Srivastava
3a7a9c9286 [lldb][AIX] HostInfoAIX Support (#117906)
This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

Added a HostInfoAIX file for the AIX platform. 
Most of the common functionalities are handled by the parent
HostInfoPosix now,
So we just have some basic functions implemented here.
2025-01-06 10:27:48 +00:00
Adrian Prantl
d9cc37fea7 [lldb] Expose structured errors in SBError (#120784)
Building on top of previous work that exposed expression diagnostics via
SBCommandReturnObject, this patch generalizes the support to expose any
SBError as machine-readable structured data. One use-case of this is to
allow IDEs to better visualize expression diagnostics.

rdar://139997604
2024-12-20 13:02:54 -08:00
Dhruv Srivastava
385b144c94 [lldb][Linux] Moving generic APIs from HostInfoLinux to HostInfoPosix (#119694)
This change is related merging some of the APIs in HostInfoLinux into
HostInfoPosix.

Here is the reference PR comment:

https://github.com/llvm/llvm-project/pull/117906#discussion_r1865427495,
https://github.com/llvm/llvm-project/pull/117906#discussion_r1861616945
2024-12-20 11:31:35 +00:00
Dhruv Srivastava
eba7690d2b [lldb][AIX] GetOpt support in AIX (#120574)
This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

Adding changes for minimal build for lldb binary on AIX. 
getopt.h is missing in AIX, so instead relying on LLDB's getopt
functions.
2024-12-19 13:50:27 +00:00
Jonas Devlieghere
83643ddf2f [lldb] Improve error reporting in GetLocation_DW_OP_addr (#120162)
Instead of simply raising an error flag, use an llvm::Expected to
propagate a meaningful error to the caller, who can report it.

rdar://139705570
2024-12-17 11:25:04 -08:00
Jonas Devlieghere
3dfc1d9b0b [lldb] Use the terminal height for paging editline completions (#119914)
Currently, we arbitrarily paginate editline completions to 40 elements.
On large terminals, that leaves some real-estate unused. On small
terminals, it's pretty annoying to not see the first completions. We can
address both issues by using the terminal height for pagination.

This builds on the improvements of #116456.
2024-12-16 11:11:17 -08:00
Pavel Labath
0dbdc23e78 [lldb] Add ability to rate-limit progress reports (#119377)
For high-frequency multithreaded progress reports, the contention of
taking the progress mutex and the overhead of generating event can
significantly slow down the operation whose progress we are reporting.

This patch adds an (optional) capability to rate-limit them. It's
optional because this approach has one drawback: if the progress
reporting has a pattern where it generates a burst of activity and then
blocks (without reporting anything) for a large amount of time, it can
appear as if less progress was made that it actually was (because we
only reported the first event from the burst and dropped the other
ones).

I've also made a small refactor of the Progress class to better
distinguish between const (don't need protection), atomic (are used on
the hot path) and other (need mutex protection) members.
2024-12-16 11:35:43 +01:00
Pavel Labath
fb8df8cb65 [lldb/DWARF] s/DWARFRangeList/llvm::DWARFAddressRangeVector (#116620)
The main difference is that the llvm class (just a std::vector in
disguise) is not sorted. It turns out this isn't an issue because the
callers either:
- ignore the range list;
- convert it to a different format (which is then sorted);
- or query the minimum value (which is faster than sorting)

The last case is something I want to get rid of in a followup as a part
of removing the assumption that function's entry point is also its
lowest address.
2024-12-13 14:29:59 +01:00
jimingham
186fac33d0 Convert the StackFrameList mutex to a shared mutex. (#117252)
In fact, there's only one public API in StackFrameList that changes
 the list explicitly.  The rest only change the list if you happen to
ask for more frames than lldb has currently fetched and that 
always adds frames "behind the user's back".  So we were
much more prone to deadlocking than we needed to be.

This patch uses a shared_mutex instead, and when we have to add more
frames (in GetFramesUpTo) we switches to exclusive long enough to add
the frames, then goes back to shared.
    
Most of the work here was actually getting the stack frame list locking
to not
require a recursive mutex (shared mutexes aren't recursive). 
    
I also added a test that has 5 threads progressively asking for more
frames simultaneously to make sure we get back valid frames and don't
deadlock.
2024-12-12 12:48:41 -08:00
Adrian Prantl
87659a17d0 Reland: [lldb] Implement a formatter bytecode interpreter in C++
Compared to the python version, this also does type checking and error
handling, so it's slightly longer, however, it's still comfortably
under 500 lines.

Relanding with more explicit type conversions.
2024-12-10 16:37:53 -08:00
Sylvestre Ledru
a2fb70523a Revert "[lldb] Add cast to fix compile error on 32-bit platforms"
This reverts commit f6012a209d.

Revert "[lldb] Add cast to fix compile error on 32-but platforms"

This reverts commit d300337e93.

Revert "[lldb] Improve log message to include missing strings"

This reverts commit 0be3348485.

Revert "[lldb] Add comment"

This reverts commit e2bb47443d.

Revert "[lldb] Implement a formatter bytecode interpreter in C++"

This reverts commit 9a9c1d4a61.
2024-12-11 00:00:44 +01:00
Adrian Prantl
9a9c1d4a61 [lldb] Implement a formatter bytecode interpreter in C++
Compared to the python version, this also does type checking and error
handling, so it's slightly longer, however, it's still comfortably
under 500 lines.
2024-12-10 09:36:38 -08:00
Dave Lee
1a650fde4a [lldb] Load embedded type summary section (#7859) (#8040)
Add support for type summaries embedded into the binary.

These embedded summaries will typically be generated by Swift macros,
but can also be generated by any other means.

rdar://115184658
2024-12-10 09:36:38 -08:00
Adrian Prantl
01d8e0fc75 [lldb] Add a per-CU API to read the SDK (#119022)
The Swift plugin would find this useful.
2024-12-06 14:14:11 -08:00
John Harrison
384562495b [lldb] For a host socket, add a method to print the listening address. (#118330)
This is most useful if you are listening on an address like
'localhost:0' and want to know the resolved ip + port of the socket
listener.
2024-12-03 11:11:32 -08:00
Alex Langford
0ca8a593e5 [lldb][NFC] Remove unused field Platform::m_remote_url (#118411)
Related:
https://discourse.llvm.org/t/rfc-lldb-a-proposal-to-refactor-platform/82697
2024-12-03 10:31:38 -08:00
Pavel Labath
51b74bb9f6 Reapply "[lldb] Use the function block as a source for function ranges (#117996)"
This reverts commit 2526d5b168, reapplying
ba14dac481 after fixing the conflict with
 #117532. The change is that Function::GetAddressRanges now recomputes
the returned value instead of returning the member. This means it now
returns a value instead of a reference type.
2024-12-03 11:58:36 +01:00
Pavel Labath
2526d5b168 Revert "[lldb] Use the function block as a source for function ranges (#117996)"
This reverts commit ba14dac481. I guess
"has no conflicts" doesn't mean "it will build".
2024-12-03 10:27:31 +01:00
Pavel Labath
ba14dac481 [lldb] Use the function block as a source for function ranges (#117996)
This is a follow-up/reimplementation of #115730. While working on that
patch, I did not realize that the correct (discontinuous) set of ranges
is already stored in the block representing the whole function. The
catch -- ranges for this block are only set later, when parsing all of
the blocks of the function.

This patch changes that by populating the function block ranges eagerly
-- from within the Function constructor. This also necessitates a
corresponding change in all of the symbol files -- so that they stop
populating the ranges of that block. This allows us to avoid some
unnecessary work (not parsing the function DW_AT_ranges twice) and also
results in some simplification of the parsing code.
2024-12-03 10:21:04 +01:00
Pavel Labath
59bb9b915e [lldb] Expose discontinuous functions through SBFunction::GetRanges (#117532)
SBFunction::GetEndAddress doesn't really make sense for discontinuous
functions, so I'm declaring it deprecated. GetStartAddress sort of makes
sense, if one uses it to find the functions entry point, so I'm keeping
that undeprecated.

I've made the test a Shell tests because these make it easier to create
discontinuous functions regardless of the host os and architecture. They
do make testing the python API harder, but I think I've managed to come
up with something not entirely unreasonable.
2024-12-03 10:14:33 +01:00
Dave Lee
0a96161beb [lldb] Simplify DumpValueObjectOptions::PointerDepth (NFC) (#117504)
`Mode::Always` and `Mode::Default` are handled identically.
`Mode::Never` is the same as having a count of 0.
2024-12-02 16:23:26 -08:00
Pavel Labath
c1dff71525 [lldb] Remove child_process_inherit from the socket classes (#117699)
It's never set to true. Also, using inheritable FDs in a multithreaded
process pretty much guarantees descriptor leaks. It's better to
explicitly pass a specific FD to a specific subprocess, which we already
mostly can do using the ProcessLaunchInfo FileActions.
2024-11-28 08:27:36 +01:00
Pavel Labath
e8a01e75e6 [lldb] Make sure Blocks always have a parent (#117683)
It's basically true already (except for a brief time during
construction). This patch makes sure the objects are constructed with a
valid parent and enforces this in the type system, which allows us to
get rid of some nullptr checks.
2024-11-27 09:51:59 +01:00
Pavel Labath
0723870420 [lldb] Add timeout argument to Socket::Accept (#117691)
Allows us to stop waiting for a connection if it doesn't come in a
certain amount of time. Right now, I'm keeping the status quo (infitnite
wait) in the "production" code, but using smaller (finite) values in
tests. (A lot of these tests create "loopback" connections, where a
really short wait is sufficient: on linux at least even a poll (0s wait)
is sufficient if the other end has connect()ed already, but this doesn't
seem to be the case on Windows, so I'm using a 1s wait in these cases).
2024-11-27 09:50:33 +01:00
Kazuki Sakamoto
c2ffb42893 [lldb] Fix TestLoadUnload.py (#117416)
ELF core debugging fix #117070 broke TestLoadUnload.py tests due to
GetModuleSpec call, ProcessGDBRemote fetches modules from remote. Revise
the original PR, renamed FindBuildId to FindModuleUUID.
2024-11-24 11:04:47 -08:00
Adrian Prantl
6a8a4d51a4 [lldb] Refactor UserExpression::Evaluate to only have one error channel. (#117186)
Prior to this patch, the function returned an exit status, sometimes a
ValueObject with an error and a Status object. This patch removes the
Status object and ensures the error is consistently returned as the
error of the ValueObject.
2024-11-21 15:37:04 -08:00
Jonas Devlieghere
4b5a8d6835 [lldb] Make sure completions don't end with newlines (#117054)
The logic that prints completions and their descriptions assumes neither
the completion itself nor the description ends with a newline. I
considered making this an assert, but decided against it as completions
can indirectly come from user input (e.g. oddly crafted names). Instead,
avoid the potential for mistakes by defensively stripping them.
2024-11-21 08:00:32 -08:00
Adrian Prantl
6473a36edc Make SBFrame::GetLanguageSpecificData() const (#117019)
One last diff I missed between Swift and LLVM.
2024-11-20 10:07:23 -08:00
Adrian Prantl
8f8dcedb00 Rename GetLanguageInfo to GetLanguageSpecificData (#117012)
Unbeknownst to me the Swift LLDB branch already had an almost identical
API with this name, so it makes sense to merge the two.
2024-11-20 09:43:57 -08:00
Adrian Prantl
e660e6503b [lldb] Add an API to derive language-specific runtime information (#116904)
This is motivated by exposing some Swift language-specific flags through
the API, in the example here it is used to communicate the Objective-C
runtime version. This could also be a meaningful extension point to get
information about "embedded: languages, such as extracting the C++
version in an Objective-C++ frame or something along those lines.
2024-11-20 08:49:07 -08:00
Jonas Devlieghere
dd78d7c7be [lldb] Improve editline completion formatting (#116456)
This patch improves the formatting of editline completions. The current
implementation is naive and doesn't account for the terminal width.

Concretely, the old implementation suffered from the following issues:

- We would unconditionally pad to the longest completion. If that
completion exceeds the width of the terminal, that would result in a lot
of superfluous white space and line wrapping.
- When printing the description, we wouldn't account for the presence of
newlines, and they would continue without leading padding.

The new code accounts for both. If the completion exceeds the available
terminal width, we show what fits on the current lined followed by
ellipsis. We also no longer pad beyond the length of the current line.
Finally, we print the description line by line, with the proper leading
padding. If a line of the description exceeds the available terminal
width, we print ellipsis and won't print the next line.

Before:

```
Available completions:
        _regexp-attach    -- Attach to process by ID or name.
        _regexp-break     -- Set a breakpoint using one of several shorthand
 formats.
        _regexp-bt        -- Show backtrace of the current thread's call sta
ck. Any numeric argument displays at most that many frames. The argument 'al
l' displays all threads. Use 'settings set frame-format' to customize the pr
inting of individual frames and 'settings set thread-format' to customize th
e thread header. Frame recognizers may filter thelist. Use 'thread backtrace
 -u (--unfiltered)' to see them all.
        _regexp-display   -- Evaluate an expression at every stop (see 'help
 target stop-hook'.)

```

After:
```
 Available completions:
        _regexp-attach    -- Attach to process by ID or name.
        _regexp-break     -- Set a breakpoint using one of several shorth...
        _regexp-bt        -- Show backtrace of the current thread's call ...
        _regexp-display   -- Evaluate an expression at every stop (see 'h...
```

rdar://135818198
2024-11-19 10:46:57 -08:00
Pavel Labath
55068dc3b7 [lldb] Add timed callbacks to the MainLoop class (#112895)
The motivating use case is being able to "time out" certain operations
(by adding a timed callback which will force the termination of the
loop), but the design is flexible enough to accomodate other use cases
as well (e.g. running a periodic task in the background).

The implementation builds on the existing "pending callback" mechanism,
by associating a time point with each callback -- every time the loop
wakes up, it runs all of the callbacks which are past their point, and
it also makes sure to sleep only until the next callback is scheduled to
run.

I've done some renaming as names like "TriggerPendingCallbacks" were no
longer accurate -- the function may no longer cause any callbacks to be
called (it may just cause the main loop thread to recalculate the time
it wants to sleep).
2024-11-19 08:37:51 +01:00
jimingham
b42a816314 Convert ThreadPlanStack's mutex to a shared mutex. (#116438)
I have some reports of A/B inversion deadlocks between the
ThreadPlanStack and the StackFrameList accesses. There's a fair bit of
reasonable code in lldb that does "While accessing the ThreadPlanStack,
look at that threads's StackFrameList", and also plenty of "While
accessing the ThreadPlanStack, look at the StackFrameList."

In all the cases I've seen so far, there was at most one of the locks
taken that were trying to mutate the list, the other three were just
reading. So we could solve the deadlock by converting the two mutexes
over to shared mutexes.

This patch is the easy part, the ThreadPlanStack mutex.  

The tricky part was because these were originally recursive mutexes, and
recursive access to shared mutexes is undefined behavior according to
the C++ standard, I had to add a couple NoLock variants to make sure it
didn't get used recursively. Then since the only remaining calls are out
to ThreadPlans and ThreadPlans don't have access to their containing
ThreadPlanStack, converting this to a non-recursive lock should be safe.
2024-11-18 13:23:17 -08:00
Chelsea Cassanova
589ab28d87 [lldb][sbapi][NFC] Remove commented out typedef from SBBreakpointName (#116434)
SBBreakpointName has a typedef for BreakpointHitCallback used in
SetCallback(), but this typedef has been commented out in
SBBreakpointName and added instead to SBDefines. Since SB API callbacks
are placed in SBDefines, this commit removes this commented out portion.
2024-11-18 10:08:44 -08:00
Pavel Labath
c25c6c3249 [lldb] Unify/improve MainLoop signal handling (#115197)
Change the signal handler to use a pipe to notify about incoming
signals. This has two benefits:
- the signal no longer has to happen on the MainLoop thread. With the
previous implementation, this had to be the case as that was the only
way to ensure that ppoll gets interrupted correctly. In a multithreaded
process, this would mean that all other threads have to have the signal
blocked at all times.
- we don't need the android-specific workaround, which was necessary due
to the syscall being implemented in a non-atomic way

When the MainLoop class was first implemented, we did not have the
interrupt self-pipe, so syscall interruption was the most
straight-forward implementation. Over time, the class gained new
abilities (the pipe being one of them), so we can now piggy-back on
those.

This patch also changes the kevent-based implementation to use the pipe
for signal notification as well. The motivation there is slightly
different:
- it makes the implementations more uniform
- it makes sure we handle all kinds of signals, like we do with the
linux version (EVFILT_SIGNAL only catches process-directed signals)
2024-11-18 12:44:06 +01:00
jeffreytan81
24feaab838 Fix statistics dump to report per-target (#113723)
"statistics dump" currently report the statistics of all targets in
debugger instead of current target. This is wrong because there is a
"statistics dump --all-targets" option that supposed to include
everything.

This PR fixes the issue by only report statistics for current target
instead of all. It also includes the change to reset statistics debug
info/symbol table parsing/indexing time during debugger destroy. This is
required so that we report current statistics if we plan to reuse
lldb/lldb-dap across debug sessions

---------

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2024-11-17 20:36:54 -08:00
Med Ismail Bennani
9c7701fa78 [lldb/API] Hoist some of SBFrame logic to lldb_private::StackFrame (NFC) (#116298)
This patch moves some of the logic implemented in the SBFrame APIs to
the lldb_private::StackFrame class so it can be re-used elsewhere.

Signed-off-by: Med Ismail Bennani <ismail@bennani.ma>
2024-11-14 15:37:34 -08:00
Jonas Devlieghere
c923ac08f0 [lldb] Make Doxygen commits consistent with the rest of LLDB (NFC) (#116269)
This fixes a warning that '\class' command should not be used in a
comment attached to a non-class declaration. It also makes the Doxygen
comments in SBSaveCoreOptions consistent with the rest of LLDB.

rdar://139848370
2024-11-14 11:12:11 -08:00
cmtice
310351d94d [LLDB] Add framework for Data Inspection Language (DIL) work. (#115666)
Add the framework code for hooking up and calling the Data Inspection
Language (DIL) implementation, as an alternate implementation for the
'frame variable' command. For now, this is an opt-in option, via a
target setting 'target.experimental.use-DIL'. See
https://discourse.llvm.org/t/rfc-data-inspection-language/69893 for more
information about this project.

This PR does not actually call any of the DIL code; instead the piece
that will eventually call the DIL code
(StackFrame::DILEvaluateVariableExpression) calls back into the original
'frame variable' implementation.
2024-11-14 08:53:16 -08:00
Pavel Labath
39b2979a43 [lldb] Fix source display for artificial locations (#115876)
When retrieving the location of the function declaration, we were
dropping the file component on the floor, which resulted in an amusingly
confusing situation were we displayed the file containing the
implementation of the function, but used the line number of the
declaration. This patch fixes that.

It required a small refactor Function::GetStartLineSourceLineInfo to
return a SupportFile (instead of just the file spec), which in turn
necessitated changes in a couple of other places as well.
2024-11-13 09:56:00 +01:00
Pavel Labath
ae7b5af904 [lldb] Remove ConnectionFileDescriptor::child_process_inherit (#115861)
It's never set to true. Inheritable FDs are also dangerous as they can
end up processes which know nothing about them. It's better to
explicitly pass a specific FD to a specific subprocess, which we already
mostly can do using the ProcessLaunchInfo FileActions.
2024-11-13 08:59:42 +01:00
Jonas Devlieghere
4714215efb [lldb] Support true/false in ValueObject::SetValueFromCString (#115780)
Support "true" and "false" (and "YES" and "NO" in Objective-C) in
ValueObject::SetValueFromCString.

Fixes #112597
2024-11-12 21:18:22 -08:00
Pavel Labath
2a3c08f620 [lldb] (Begin to) support discontinuous lldb_private::Functions (#115730)
This is the beginning of a different, more fundamental approach to
handling. This PR tries to tries to minimize functional changes. It only
makes sure that we store the true set of ranges inside the function
object, so that subsequent patches can make use of it.
2024-11-12 09:34:53 +01:00
Jonas Devlieghere
f109517d15 [lldb] Support overriding the disassembly CPU & features (#115382)
Add the ability to override the disassembly CPU and CPU features through
a target setting (`target.disassembly-cpu` and
`target.disassembly-features`) and a `disassemble` command option
(`--cpu` and `--features`).

This is especially relevant for architectures like RISC-V which relies
heavily on CPU extensions.

The majority of this patch is plumbing the options through. I recommend
looking at DisassemblerLLVMC and the test for the observable change in
behavior.
2024-11-11 16:27:15 -08:00