31933 Commits

Author SHA1 Message Date
Pavel Labath
85c3c98630
[lldb] Fix offset computation in RegisterContextUnwind (#137155)
AddressFunctionScope was always returning the first address range of the
function (assuming it was the only one). This doesn't work for
RegisterContextUnwind (it's only caller), when the function doesn't
start at the lowest address because it throws off the 'how many bytes
"into" a function I am' computation. This patch replaces the result with
a call to (recently introduced)
SymbolContext::GetFunctionOrSymbolAddress.
2025-05-15 09:39:11 +02:00
Kazu Hirata
539265b904
[lldb] Simplify a string comparison (NFC) (#139932) 2025-05-14 11:21:42 -07:00
Chelsea Cassanova
28d732a24e
[lldb][cmake] Set CMAKE_OSX_SYSROOT when building debugserver with CMake 4 (#138020)
CMake 4 no longer sets the `CMAKE_OSX_SYSROOT` variable by default. If
you've updated to CMake 4 on macOS (e.g. with brew) and try building
LLDB with CMake/ninja, this will yield an error when building
debugserver that clang is unable to run since it tries to compile files
that don't exist.

These files are supposed to be generated by the `mig` process. `mig`
needs the `CMAKE_OSX_SYSROOT` variable in order to work and without it,
it silently fails to generate the files that later on need to be
compiled.

This commit sets this SDK path for mig and will fatal error out of config
when building debugserver without having set CMAKE_OSX_SYSROOT.
2025-05-14 10:46:01 -07:00
John Harrison
441d382f93
[lldb-dap] Adding unit tests for Transport. (#139926)
This adds basic support for testing the Transport class and includes
tests for 'Read' and 'Write'.
2025-05-14 10:00:01 -07:00
Pavel Labath
5fb9dca14a Revert "[lldb] Call Target::ClearAllLoadedSections earlier (#138892)"
This reverts commit 97aa01bef770ec651c86978d137933e09221dd00 and
7e7871d3f58b9da72ca180fcd7f0d2da3f92ec4a due to failures on windows.
2025-05-14 18:22:02 +02:00
Jonas Devlieghere
998dca4235
[lldb-dap] Add unit test for protocol enum types (#139848)
Add dedicated unit tests for the protocol enum types.
2025-05-14 09:10:49 -07:00
Pavel Labath
7e7871d3f5 [lldb] Clear loaded sections even earlier
Follow-up to #138892 fixing breakage on windows. Calling
ClearAllLoadedSections earlier is necessary to avoid throwing out the
work done by the windows process plugin.
2025-05-14 15:38:10 +02:00
Pavel Labath
adabc83a92
[lldb] Merge/unify ABI-provided AArch64 unwind plans (#139545)
The macos and sysv ABIs return functionally equivalent unwind plans, so
they can be implemented in the base AArch64 class. The only difference
between them was that the macos plan provided a "pc=lr" rule whereas the
sysv plan called SetReturnAddressRegister (which causes the unwind
machinery to act as if that rule was present). This difference was
enough to cause `CompareUnwindPlansForIdenticalInitialPCLocation` to
return a different value and break the (temporarily reverted)
TestUnwindFramelessFaulted test.

While merging the two functions, I couldn't stop myself from simplifying
them to use the generic register number schemes -- which exposed another
bug in CompareUnwindPlansForIdenticalInitialPCLocation, namely that it
was expecting all unwind plans to use the LLDB numbering scheme. This
patch fixes that as well.
2025-05-14 11:29:56 +02:00
Pavel Labath
97aa01bef7
[lldb] Call Target::ClearAllLoadedSections earlier (#138892)
Minidump files contain explicit information about load addresses of
modules, so it can load them itself. This works on other platforms, but
fails on darwin because DynamicLoaderDarwin nukes the loaded module list
on initialization (which happens after the core file plugin has done its
work).

This used to work until #109477, which enabled the dynamic loader
plugins for minidump files in order to get them to provide access to
TLS.

Clearing the load list makes sense, but I think we could do it earlier
in the process, so that both Process and DynamicLoader plugins get a
chance to load modules. This patch does that by calling the function
early in the launch/attach/load core flows.

This fixes TestDynamicValue.py:test_from_core_file on darwin.
2025-05-14 11:16:55 +02:00
Kazu Hirata
bdf8c9984a
[lldb] Fix typos in documentation (#139839) 2025-05-13 23:34:28 -07:00
Jonas Devlieghere
ad2f7034a2
[lldb-dap] Add unit test for capabilities (#139835)
Add unit a test for the capabilities type.
2025-05-13 22:51:03 -07:00
John Harrison
1a0b82563f
[lldb-dap] Improving tests logging to understand CI failures. (#139311)
To improve logging this adjusts two properties of the existing tests:

* Forwards stderr from lldb-dap to the process in case errors are
reported to stderr.
* Adjusts `DebugAdapterServer.terminate` to close stdin and wait for the
process to exit instead of sending SIGTERM. Additionally, if we end up
with a non-zero exit status we now raise an error to note the unexpected
exit status.

With these changes, I did find one test case in
`TestDAP_console.test_diagnositcs` that was not waiting to ensure the
expected event had arrived by the time it performed an assert.
2025-05-13 21:21:43 -07:00
Jason Molenda
b8ba9636f0 [lldb] don't run TestUnwindFramelessFaulted.py on Linux
I thought I could call $(CPP) to preprocess the assembly
file, but the aarch64-ubuntu bot runs this as clang -E and
it issues a warning and no output file, apparently,

build/bin/clang -E -o interrupt-and-trap-funcs.s /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/functionalities/unwind/frameless-faulted/interrupt-and-trap-funcs.s
clang: warning: /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/functionalities/unwind/frameless-faulted/interrupt-and-trap-funcs.s: 'assembler' input unused [-Wunused-command-line-argument]

/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang -g -O0     -c -o interrupt-and-trap-funcs.o interrupt-and-trap-funcs.s
clang: error: no such file or directory: 'interrupt-and-trap-funcs.s'
clang: error: no input files
2025-05-13 18:14:57 -07:00
Jason Molenda
30b428aaa8 [lldb] try re-enabling TestUnwindFramelessFaulted.py
on Linux with a small change to the Makefile to make
preprocessing the assembly code work.
2025-05-13 17:45:03 -07:00
Jonas Devlieghere
2d57b61325
[lldb-dap] Add unit test for breakpoint types (#139792)
- Add unit test for breakpoint types for SourceBreakpoint,
  FunctionBreakpoint and DataBreakpoint.
- Rename DataBreakpointInfo to DataBreakpoint.
- Fix some mapOptions for optional fields.
2025-05-13 17:02:13 -07:00
Kazu Hirata
85bbf8c887
[lldb] Use llvm::is_contained (NFC) (#139758) 2025-05-13 15:53:20 -07:00
Kazu Hirata
cc2beddaa4
[lldb] Use std:::string::find with std::string_view (NFC) (#139679)
std::string::find accepts anything that can be converted to
std::string_view starting in C++17.  Since StringRef can be converted
to std::string_view, we do not need to create a temporary instance of
std::string here.
2025-05-13 15:48:50 -07:00
jimingham
952b680fd1
Support stepping through Darwin "branch islands" (#139301)
When an intra-module jump doesn't fit in the immediate branch slot, the
Darwin linker inserts "branch island" symbols, and emits code to jump
from branch island to branch island till it makes it to the actual
function.

The previous submissions failed because in that environment the linker
was putting the `foo.island` symbol at the same address as the `padding`
symbol we we emitting to make our faked-up large binary. This submission
jams a byte after the padding symbol so that the other symbols can't
overlap it.
2025-05-13 13:32:53 -07:00
Jonas Devlieghere
81932945d7
[lldb-dap] Add unit test for ColumnDescriptor, BreakpointMode and Breakpoint (#139627)
Implement `fromJSON` for `ColumnDescriptor`, `BreakpointMode` and
`Breakpoint` and use it to implement the corresponding unit tests.
2025-05-13 12:23:22 -07:00
Pavel Labath
91ea494993
[lldb] Move lldb_enable_attach from test_common to a separate header (#139550)
test_common is force-included into every compilation, which causes
problems when we're compiling assembly code, as we were in #138805.

This avoids that as we can include the header only when it's needed.
2025-05-13 17:52:23 +02:00
Pavel Labath
89826f0458
[lldb] Fix compilation errors from #138896 (#139711)
- s/size_t/SIZE_T to match the windows API
- case HANDLE to int64_t to avoid cast-to-int-of-different-size
errors/warnings
2025-05-13 15:05:53 +02:00
Jacques Pienaar
c78e65cc98
[lldb][plugin] Use counter directly for number of readers (#139252)
Here we were initializing & locking a shared_mutex in a thread, while
releasing it in the parent which may/often turned out to be a different
thread (shared_mutex::unlock_shared is undefined behavior if called from
a thread that doesn't hold the lock).

Switch to counter to more simply keep track of number of readers and
simply lock/unlock rather than utilizing reader mutex to verify last
freed (and so requiring this matching thread init/destroy behavior).
2025-05-13 01:52:36 -07:00
Jonas Devlieghere
23472c56c0
[lldb-dap] Remove the lldb-vscode symlink (NFC) (#139621)
Remove the `lldb-vscode` -> `lldb-dap` symlink in the `tools` directory.
I initially created the symlink when we renamed the tool to make
migration easier. I think enough time has passed that we don't need it
anymore.

My personal motivation is that the symlink causes every file in the
`lldb-dap` directory to show up twice (once under `lldb-dap` and once
under `lldb-vscode`) in Quick Open in VS Code.
2025-05-12 19:07:18 -07:00
Jonas Devlieghere
8bec5e5b88
[lldb-dap] Add unit tests for protocol types (#139502)
Add unit tests for serializing and deserializing protocol types.
2025-05-12 13:23:50 -07:00
Jonas Devlieghere
4086d5ff74
[lldb-dap] Unbreak lldb-dap 2025-05-12 11:56:57 -07:00
Ilia Kuklin
c8a0513a1a
[lldb] Restore ObjC incomplete type dereferencing fix (#139567)
Attempt an ObjC incomplete type fix even if `GetDereferencedType`
returns an error.
2025-05-12 22:59:40 +05:00
Jonas Devlieghere
fb9b43a0c5
[lldb-dap] Fix the framework build
I forgot to remove the original logic after moving it into the tool
subdirectory.
2025-05-12 09:51:15 -07:00
Michael Buch
74a588464c
[lldb][TypeSystemClang][NFC] Use GetNumBaseClasses in TypeSystemClang::GetNumChildren (#139552)
`TypeSystemClang::GetNumBaseClasses` does exactly the same base-class
accounting that we were doing in GetNumChildren. So re-use it.
2025-05-12 17:32:26 +01:00
Dhruv Srivastava
39f5a420b6
[lldb][AIX] Support for XCOFF Sections (#131304)
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

Incremental PR on ObjectFileXCOFF.cpp
This PR is intended to handle XCOFF sections.
2025-05-12 17:52:02 +05:30
Ilia Kuklin
3aacd74594
[lldb][TypeSystemClang] Allow arrays to be dereferenced in C/C++. (#135843)
Add a function `GetDereferencedType` to `CompilerType` and allow
`TypeSystemClang` to dereference arrays.
2025-05-12 16:46:58 +05:00
Jason Molenda
48a814c711 Don't run TestUnwindFramelessFaulted.py on Linux
There's something still wrong with how it's building
the test file.
2025-05-11 23:57:53 -07:00
Jason Molenda
b957cc0c7e [lldb] Provide lr value in faulting frame on arm64 (#138805)
Re-landing this patch with small tweaks to address CI bot failures
as it was run on many different configurations.  I think the test
may run on aarch64 Linux systems now.

When a frameless function faults or is interrupted asynchronously, the
UnwindPlan MAY have no register location rule for the return address
register (lr on arm64); the value is simply live in the lr register when
it was interrupted, and the frame below this on the stack -- e.g.
sigtramp on a Unix system -- has the full register context, including
that register.

RegisterContextUnwind::SavedLocationForRegister, when asked to find the
caller's pc value, will first see if there is a pc register location. If
there isn't, on a Return Address Register architecture like
arm/mips/riscv, we rewrite the register request from "pc" to "RA
register", and search for a location.

On frame 0 (the live frame) and an interrupted frame, the UnwindPlan may
have no register location rule for the RA Reg, that is valid. A
frameless function that never calls another may simply keep the return
address in the live register the whole way. Our instruction emulation
unwind plans explicitly add a rule (see Pavel's May 2024 change
https://github.com/llvm/llvm-project/pull/91321 ), but an UnwindPlan
sourced from debug_frame may not.

I've got a case where this exactly happens - clang debug_frame for arm64
where there is no register location for the lr in a frameless function.
There is a fault in the middle of this frameless function and we only
get the lr value from the fault handler below this frame if lr has a
register location of `IsSame`, in line with Pavel's 2024 change.

Similar to how we see a request of the RA Reg from frame 0 after failing
to find an unwind location for the pc register, the same style of
special casing is needed when this is a function that was interrupted.

Without this change, we can find the pc of the frame that was executing
when it was interrupted, but we need $lr to find its caller, and we
don't descend down to the trap handler to get that value, truncating the
stack.

rdar://145614545
2025-05-11 23:39:35 -07:00
Pavel Labath
9e44f0d669
Reapply "[lldb] Inherit DuplicateFileAction(HANDLE, HANDLE) handles on windows (#137978)" (#138896)
This reverts commit
a0260a95ec,
reapplying

7c5f5f3ef8,
with a fix that makes *both*
pipe handles inheritable.

The original commit description was:

This is a follow-up to https://github.com/llvm/llvm-project/pull/126935,
which enables passing handles to a child
process on windows systems. Unlike on unix-like systems, the handles
need to be created with the "inheritable" flag because there's to way to
change the flag value after it has been created. This is why I don't
respect the child_process_inherit flag but rather always set the flag to
true. (My next step is to delete the flag entirely.)

This does mean that pipe may be created as inheritable even if its not
necessary, but I think this is offset by the fact that windows (unlike
unixes, which pass all ~O_CLOEXEC descriptors through execve and *all*
descriptors through fork) has a way to specify the precise set of
handles to pass to a specific child process.

If this turns out to be insufficient, instead of a constructor flag, I'd
rather go with creating a separate api to create an inheritable copy of
a handle (as typically, you only want to inherit one end of the pipe).
2025-05-12 07:57:43 +02:00
Jonas Devlieghere
e584af5861
[lldb-dap] Add unit tests for ToError 2025-05-11 16:51:32 -07:00
Jonas Devlieghere
79fbef1712
[lldb-dap] Add unit tests for LLDBUtils (NFC) 2025-05-11 16:42:42 -07:00
Jonas Devlieghere
e62fc14a5d
[lldb-dap] Add unit tests for GetStrings 2025-05-11 16:32:43 -07:00
Jonas Devlieghere
d129790ae8
[lldb-dap] Remove GetSigned from JSONUtils (NFC)
This function was replaced by GetInteger<T> which can handle both signed
and unsigned values. It currently had one caller in JSONUtils, which
this patch updates.
2025-05-11 16:29:53 -07:00
Jonas Devlieghere
8757aa0a7e
[lldb-dap] Add unit tests for GetInteger 2025-05-11 16:22:21 -07:00
Jonas Devlieghere
5b97a5b2ae
[lldb-dap] Add unit tests for GetString and GetBoolean
These are simple functions but they're used a lot. Add some simple unit
tests for them.
2025-05-11 16:20:30 -07:00
Jonas Devlieghere
c1ecd0a92e
[lldb-dap] Don't build the unit tests on Windows 2025-05-11 16:14:03 -07:00
Jonas Devlieghere
6f84ec3496
[lldb-dap] Split lldb-dap into library and tool (NFC) (#139402)
Split lldb-dap into a library (lldbDAP) and a tool (lldb-dap). The
motivation is being able to link parts of lldb-dap separately, for
example to support unit testing and fuzzing.
2025-05-11 14:48:40 -07:00
Emmanuel Ferdman
2ccfb99d81
[lldb] Fix term settings completion tests (#139447)
# PR Summary
Small PR - Several test functions for `term-width/height` completions
had identical names, causing silent overriding. This gives them distinct
_width/_height suffixes to ensure all tests run.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
2025-05-11 14:47:21 -07:00
Kazu Hirata
fadd427777
[lldb] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139428) 2025-05-10 19:31:35 -07:00
Jonas Devlieghere
a92de02ea3
[lldb-dap] Move registration of requests into DAP (NFC) (#139397)
Make the registration of request handlers a private implementation
detail of the DAP class.
2025-05-10 11:53:46 -07:00
Kazu Hirata
d151ad650c
[lldb] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139395) 2025-05-10 11:03:09 -07:00
Kazu Hirata
cb0f6d0029
[lldb] Simplify string comparisons (NFC) (#139394) 2025-05-10 10:44:04 -07:00
Jonas Devlieghere
bae77d5b02
[lldb-dap] Skip TestDAP_module_event on Windows 2025-05-10 09:36:07 -07:00
Jonas Devlieghere
b7c449ac0b
[lldb-dap] Don't emit a removed module event for unseen modules (#139324) 2025-05-09 23:34:05 -07:00
Jason Molenda
a230bb0298 Revert "[lldb] Provide lr value in faulting frame on arm64 (#138805)"
This test is failing on the LLDB Incremental bot (arm64), which is
running an older set of tools (Xcode 15.2) and OS (macOS 14.1) and
the CFI directives must not be emitted correctly by either the tools
or the OS.  I will need to reproduce how this is compiling on that
older setup and see what the issue is.  Reverting for now so the
bots are not blocked.

This reverts commit e897cb139ee6ef5c145fed5394c4d96baa658e6b.
2025-05-09 20:41:15 -07:00
Jason Molenda
d2f6ac2c10 Revert "Fix skipIf which was doing || and I need &&"
This reverts commit 05a2b33f7b36d4fc91b7a957aa00100bc8e38f04.
2025-05-09 20:41:08 -07:00