7983 Commits

Author SHA1 Message Date
Jonas Devlieghere
c87dc2b7d4
[lldb-dap] Speed up TestDAP_Progress (#134048)
While trying to make progress on #133782, I noticed that
TestDAP_Progress was taking 90 seconds to complete. This patch brings
that down to 10 seocnds by making the following changes:

1. Don't call `wait_for_event` with a 15 second timeout. By the time we
call this, all progress events have been emitted, which means that we're
just sitting there until we hit the timeout.

2. Don't use 10 steps (= 10 seconds) for indeterminate progress. We have
two indeterminate progress tests so that's 6 seconds instead of 20.

3. Don't launch the process over and over. Once we have a dap session,
we can clear the progress vector and emit new progress events.
2025-04-02 12:41:47 -07:00
Adrian Prantl
a3ac318e5f [lldb] Skip test with older version of clang 2025-04-02 10:31:44 -07:00
Julian Lettner
c8764f0c65
Fix handling of auto_continue for stop hooks (#129622)
Follow-up fix discussed here:
https://github.com/llvm/llvm-project/pull/129578#issuecomment-2695838042

---------

Co-authored-by: Jim Ingham <jingham@apple.com>
2025-04-01 15:36:35 -07:00
David Peixotto
782e0cef76
[lldb] Fix intel trace plugin tests (#133826)
The tests for the

[intel-pt](3483740289/lldb/docs/use/intel_pt.rst)
trace plugin were failing for multiple reasons.

On machines where tracing is supported many of the tests were crashing
because of a nullptr dereference. It looks like the `core_file`
parameter in `ProcessTrace::CreateInstance` was once ignored, but was
changed to always being dereferenced. This caused the tests to fail even
when tracing was supported.

On machines where tracing is not supported we would still run tests that
attempt to take a trace. These would obviously fail because the required
hardware is not present. Note that some of the tests simply read
serialized json as trace files which does not require any special
hardware.

This PR fixes these two issues by guarding the pointer dereference and
then skipping unsupported tests on machines. With these changes the
trace tests pass on both types of machines.

We also add a new unit test to validate that a process can be created
with a nullptr core_file through the generic process trace plugin path.
2025-04-01 12:55:41 -07:00
jimingham
347c5a7af5
Add a new affordance that the Python module in a dSYM (#133290)
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
John Harrison
a417a868cd
[lldb-dap] Enable runInTerminal tests on macOS. (#133824)
These tests are currently filtered on macOS if your on an M1 (or newer)
device. These tests do work on macOS, for me at least on M1 Max with
macOS 15.3.2 and Xcode 16.2.

Enabling them again, but if we have CI problems with them we can keep
them disabled.
2025-03-31 19:50:36 -07:00
Jonas Devlieghere
50949ebf52
[lldb] Expose the Target API mutex through the SB API (#133295)
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 #131242).

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
Jacob Lalonde
2f5c836e08
[SBProgress] Add swig support for with statement in Python (#133527)
We recently added an explicit finalize to SBProgress, #128966. I
realized while adding some additional implementations of SBProgress that
we should to add `with` support for ease of use. This patch addresses
adding and `__enter()__` method (which a no-op) and an `__exit()__` to
swig. I also refactor the emitter for the test to leverage `with`
instead of explicitly calling finalize, and I've updated the docstrings.
2025-03-29 15:21:51 -07:00
John Harrison
6526cda5d8
[lldb-dap] Migrating DAP 'initialize' to new typed RequestHandler. (#133007)
This adds new types and helpers to support the 'initialize' request with
the new typed RequestHandler. While working on this I found there were a
few cases where we incorrectly treated initialize arguments as
capabilities. The new `lldb_dap::protocol::InitializeRequestArguments`
and `lldb_dap::protocol::Capabilities` uncovered the inconsistencies.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-28 09:13:10 -07:00
Michael Buch
8ea3f818de [lldb][test] TestCCallingConventions.py: skip on older AArch64 compilers
With our Clang-15 arm64 CI this test-case crashes when compiling the test program:
```
user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c
Unexpected callee-save save/restore opcode!
UNREACHABLE executed at /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1501/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp:1129!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/clang_1501_build/bin/clang -g -O0 -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -arch arm64 -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make/../../../../..//include -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/lldb-build/tools/lldb/include -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions -I/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make -include /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/packages/Python/lldbsuite/test/make/test_common.h -fno-limit-debug-info -Werror=ignored-attributes -MT ms_abi.o -MD -MP -MF ms_abi.d -c -o ms_abi.o /Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c
1.	<eof> parser at end of file
2.	Code generation
3.	Running pass 'Function Pass Manager' on module '/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake-matrix/llvm-project/lldb/test/API/lang/c/calling-conventions/ms_abi.c'.
4.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@func'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  clang-15                 0x0000000105d512b0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  clang-15                 0x0000000105d500e4 llvm::sys::RunSignalHandlers() + 112
2  clang-15                 0x0000000105d507c4 llvm::sys::CleanupOnSignal(unsigned long) + 232
3  clang-15                 0x0000000105c79d78 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) + 128
4  clang-15                 0x0000000105c79f94 CrashRecoverySignalHandler(int) + 124
5  libsystem_platform.dylib 0x0000000185ecba24 _sigtramp + 56
6  libsystem_pthread.dylib  0x0000000185e9ccc0 pthread_kill + 288
7  libsystem_c.dylib        0x0000000185daca40 abort + 180
8  clang-15                 0x0000000105c88508 llvm::install_out_of_memory_new_handler() + 0
9  clang-15                 0x0000000104af7404 fixupCalleeSaveRestoreStackOffset(llvm::MachineInstr&, unsigned long long, bool, bool*) + 0
10 clang-15                 0x0000000104af53e0 llvm::AArch64FrameLowering::emitPrologue(llvm::MachineFunction&, llvm::MachineBasicBlock&) const + 3564
```
2025-03-28 15:32:18 +00:00
Pavel Labath
b82fd71109
[lldb] Adjust skips on reverse continue tests (#133240)
The x86-specific issue has been fixed with #132122. Watchpoint tests
fail on aarch64 with macos<15.0 due to a kernel bug.
2025-03-28 09:41:56 +00:00
Pavel Labath
17aca79d98
[lldb] Teach FuncUnwinders about discontinuous functions (#133072)
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
Jonas Devlieghere
9c18edc621
[lldb] Implement a statusline in LLDB (#121860)
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
jimingham
870463519b
Fix the managing of the session dictionary when you have nested wrappers (#132846)
Since the inner wrapper call might have removed one of the entries from
the global dict that the outer wrapper ALSO was going to delete, make
sure that we check that the key is still in the global dict before
trying to act on it.
2025-03-25 09:56:58 -07:00
Georgiy Samoylov
ec9546d169
[lldb] Fix TestGdbRemoteForkNonStop.py test (#131293)
During lldb testing on remote targets TestGdbRemoteForkNonStop.py
freezes because in this test we try to create file on remote machine
using absolute file path from local machine. This patch fixes this error
2025-03-24 09:33:08 +01:00
David Peixotto
f8865aa876
[lldb] Fix tests to resolve symlinks when checking paths (#132053)
The inferior used in the process launch test prints out its working
directory using the `getcwd` function, which is not allowed to return
symbolic links in the path components. When testing against the output
from `getcwd` we should resolve the full path to match the expected
output.

The source manager test sets a breakpoint on a main-copy.c file that is
copied into the build output directory. The source manager resolves this
path to its real location. When testing the output from the source cache
we need to resolve the expected path in the test to remove symlinks.
2025-03-21 09:02:27 -07:00
Ebuka Ezike
fa4bf3a11a
[lldb][NFC] Fix test settings JSON check to compare expected path list. (#132410)
Previously, the test compared the JSON output to `setting_value` which
was incorrect. Updated the assertion to validate against the correct
list of paths `[path1, path2]` to ensure accurate test behavior.

Ran the test on the local computer

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
2025-03-21 15:44:41 +00:00
Ebuka Ezike
5286511adc
[lldb][NFC] use platform independent path separator in testSettings.py. (#132392)
The build bot was failing when running remote test from windows to
linux.

From  #131683

---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Pavel Labath <pavel@labath.sk>
2025-03-21 14:02:52 +00:00
Ebuka Ezike
4b419840c8
[lldb] Show target.debug-file-search-paths setting from python SBDebugger (#131683)
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
Robert O'Callahan
f89a7fa319
[lldb] Ignore registers that the debugserver fails to read (#132122)
On Mac x86-64, the debugserver reports a register ('ds' at least) but
returns an error when we try to read it. Just skip storing such
registers in snapshots so we won't try to restore them.
2025-03-21 10:10:54 +01:00
Jason Molenda
ad5cac3b06
[lldb][debugserver] remove g/G packet handling from debugserver (#132127)
In 2013 we added the QSaveRegisterState and QRestoreRegisterState
packets to checkpoint a thread's register state while executing an
inferior function call, instead of using the g packet to read all
registers into lldb, then the G packet to set them again after the func
call.

Since then, lldb has not sent g/G (except as a bug) - it either asks for
registers individually (p/P) or or asks debugserver to save and restore
the entire register set with these lldb extensions.

Felipe recently had a codepath that fell back to using g/G and found
that it does not work with the modern signed fp/sp/pc/lr registers that
we can get -- it sidesteps around the clearing of the non-addressable
bits that we do when reading/writing them, and results in a crash. (
https://github.com/llvm/llvm-project/pull/132079 )

Instead of fixing that issue, I am removing g/G from debugserver because
it's not needed by lldb, and it will would be easy for future bugs to
creep in to this packet that lldb should not use, but it can
accidentally fall back to and result in subtle bugs.

This does mean that a debugger using debugserver on darwin which doesn't
use QSaveRegisterState/QRestoreRegisterState will need to fall back to
reading & writing each register individually. I'm open to re-evaluating
this decision if this proves to be needed, and supporting these lldb
extensions is onerous.
2025-03-20 13:32:52 -07:00
Pavel Labath
fdeb2ff304
[lldb] Fix prologue size calculation for discontinuous functions (#131597)
When searching for the end of prologue, I'm only iterating through the
address range (~basic block) which contains the function entry point.
The reason for that is that even if some other range somehow contained
the end-of-prologue marker, the fact that it's in a different range
would imply it's reachable through some form of control flow, and that's
usually not a good place to set an function entry breakpoint.
2025-03-20 16:01:24 +01:00
David Peixotto
58027fa989
[lldb] Require wide char support in unicode test (#131951)
The unicode test sends some unicode input to lldb through pexpect and
expects the output to be echoed back in an error message. This only
works correctly when editline was compiled with wide character support.

This commit modifies the test to require the necessary libedit
configuration.
2025-03-19 08:17:59 -07:00
Pavel Labath
861efd4b3f [lldb] Skip reverse continue tests on x86_64-darwin
Tests are failing because some registers (at least `ds`) are unreadable.
2025-03-19 13:35:14 +01:00
Dave Lee
57288136fe
[lldb] Fix TestBreakpointLocations (#131890) 2025-03-18 22:57:35 -07:00
Pavel Labath
6d38dbf6eb [lldb] Skip reverse continue tests on macos<15.0
They're failing for unknown reasons.
2025-03-18 17:52:36 +01:00
Dave Lee
6d2b8285b3
[lldb] Support ordered patterns in lldbtest.expect (#131475)
Change `lldbtest.expect` to require the regexes in `patterns` be found in order – when the
`ordered` parameter is true. This matches the behavior of `substrs`.

The `ordered` parameter is true by default, so this change also fixes tests by either
tweaking the patterns to work in order, or by setting `ordered=False`.

I have often wanted to test with `patterns` and also verify the order. This change
allows that.
2025-03-17 14:30:39 -07:00
Pavel Labath
1b237198dc
Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (#128156)
This reverts commit
87b7f63a11,
reapplying

7e66cf74fb
with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot
issues.
2025-03-17 16:06:25 +01:00
Ebuka Ezike
125c4db730
[lldb][lldb-dap] setVariable request should send the correct response (#130773)
The display value was incorrectly sent as "result" instead of "value".
2025-03-16 23:28:25 +00:00
Dave Lee
65e68a3078
[lldb] Update dwim-print to show expanded objc instances (#117500)
When printing an ObjC object, which is a pointer, lldb has handled it
the same way it treats any other pointer – printing only class name and
pointer address. The object is not expanded, its children are not shown.

This change updates `dwim-print` to print objc pointers by expanding (ie
dereferencing), with the assumption that it's what the user wants.

Note that this is currently possible using the `--ptr-depth`/`-P` flag.
With this change, when `dwim-print` prints root level objc objects, it's
the same effect as using `--ptr-depth 1`.
2025-03-15 08:57:51 -07:00
David Peixotto
d1deaed0d2
[lldb] Split some lldb-server tests to avoid timeout (#129614)
Split test cases out of TestLldbGdbServer.py and TestGdbRemoteFork.py
into separate files to avoid hitting the 600s timeout limit. The
inferior used by these tests (main.cpp) takes approximately 20s to
compile with a Debug build of clang, causing timeouts when a single test
file contains many tests. By grouping similar tests into separate files,
we can prevent timeouts and improve overall test efficiency.
2025-03-13 15:54:45 -07:00
John Harrison
7790d69cce
[lldb-dap] Refactoring IOStream into Transport handler. (#130026)
Instead of having two discrete InputStream and OutputStream helpers,
this merges the two into a unifed 'Transport' handler.

This handler is responsible for reading the DAP message headers, parsing
the resulting JSON and converting the messages into
`lldb_dap::protocol::Message`s for both input and output.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-12 12:29:05 -07:00
David Peixotto
1d1b20a19e
[lldb] Avoid force loading symbol files in statistics collection (#129593)
This commit modifies the `DebuggerStats::ReportStatistics`
implementation to avoid loading symbol files for unloaded symbols. We
collect stats on debugger shutdown and without this change it can cause
the debugger to hang for a long while on shutdown if they symbols were
not previously loaded (e.g. `settings set target.preload-symbols
false`).

The implementation is done by adding an optional parameter to
`Module::GetSymtab` to control if the corresponding symbol file will be
loaded in the same way that can control it for `Module::GetSymbolFile`.
2025-03-10 10:54:11 -07:00
John Harrison
414e5c58cb
[lldb-dap] Migrating terminated statistics to the event body. (#130454)
Per the DAP spec, the event 'body' field should contain any additional
data related to the event. I updated the lldb-dap 'statistics' extension
into the terminated event's body like:

```
{
  "type": "event",
  "seq": 0,
  "event": "terminated",
  "body": {
    "$__lldb_statistics": {...}
  }
}
```

This allows us to more uniformly handle event messages.
2025-03-10 10:00:10 -07:00
Michael Buch
6a9df5b4dd Revert "[lldb][asan] Add temporary logging to ReportRetriever"
This reverts commit 39a4da20d88d797824f0e7be0f732ccaf0c7eee4.

We skipped the failing tests in `6cc8b0bef07f4270303bec0fc203f251a2fde262`.
2025-03-10 11:37:13 +00:00
David Spickett
fe544d404d
[lldb] Add more ARM checks in TestLldbGdbServer.py (#130277)
When https://github.com/llvm/llvm-project/pull/130034 enabled RISC-V
here I noticed that these should run for ARM as well.

ARM only has 4 argument registers, which matches Arm's ABI for it:
https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst#core-registers

The ABI defines a link register LR, and I assume that's what becomes
'ra' in LLDB.

Tested on ARM and AArch64 Linux.
2025-03-10 10:10:19 +00:00
Jonas Devlieghere
a1b14dbc47
[lldb] Remove progress report coalescing (#130329)
Remove support for coalescing progress reports in LLDB. This
functionality was motivated by Xcode, which wanted to listen for less
frequent, aggregated progress events at the cost of losing some detail.
See the original RFC [1] for more details. Since then, they've
reevaluated this trade-off and opted to listen for the regular, full
fidelity progress events and do any post processing on their end.

rdar://146425487
2025-03-08 09:10:46 -08:00
Greg Clayton
8ac359ba0d
Add complete ObjectFileJSON support for sections. (#129916)
Sections now support specifying:
- user IDs
- file offset/size
- alignment
- flags
- bool values for fake, encrypted and thread specific sections
2025-03-07 15:34:27 -08:00
Michael Buch
6cc8b0bef0
[lldb][test] Skip libsanitizers tests for now (#130305)
These are macOS tests only and are currently failing on the x86_64 CI
and on arm64 on recent versions of macOS/Xcode.

The tests are failing because we're stopping in:
```
Process 17458 stopped
* thread #1: tid = 0xbda69a, 0x00000002735bd000
  libsystem_malloc.dylib`purgeable_print_self.cold.1, stop reason = EXC_BREAKPOINT (code=1, subcode=0x2735bd000)
```
instead of the libsanitizers library. This seems to be related to
`-fsanitize-trivial-abi` support

Skip these for now until we figure out the root cause.
2025-03-07 21:04:24 +00:00
Georgiy Samoylov
9c08e650cd
[lldb] Adapt llgs tests for RISC-V (#130034)
Some lldb tests from llgs category fail on RISC-V target due to lack of
necessary condition checks. This patch adapts these tests by taking into
account the peculiarities of the RISC-V architecture
2025-03-07 09:27:39 +00:00
Michael Buch
39a4da20d8 [lldb][asan] Add temporary logging to ReportRetriever
`TestReportData.py` is failing on the macOS CI with:
```
Traceback (most recent call last):
  File "/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 1784, in test_method
    return attrvalue(self)
  File "/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/decorators.py", line 148, in wrapper
    return func(*args, **kwargs)
  File "/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/test/API/functionalities/asan/TestReportData.py", line 28, in test_libsanitizers_asan
    self.asan_tests(libsanitizers=True)
  File "/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/test/API/functionalities/asan/TestReportData.py", line 60, in asan_tests
    self.expect(
  File "/Users/ec2-user/jenkins/workspace/llvm.org/lldb-cmake/llvm-project/lldb/packages/Python/lldbsuite/test/lldbtest.py", line 2490, in expect
    self.fail(log_msg)
AssertionError: Ran command:
"thread list"

Got output:
Process 3474 stopped
* thread #1: tid = 0x38b5e9, 0x00007ff80f563b52 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT

Expecting sub string: "stopped" (was found)
Expecting sub string: "stop reason = Use of deallocated memory" (was not found)
Process should be stopped due to ASan report
```

There isn't much to go off of in the log, so adding more to help us debug this.
2025-03-07 07:09:18 +00:00
Jason Molenda
1a31bb38a4 [lldb][Mach-O] Don't read symbol table of specially marked binary (#129967)
We have a binary image on Darwin that has no code, only metadata. It has
a large symbol table with many external symbol names that will not be
needed in the debugger. And it is possible to not have this binary on
the debugger system - so lldb must read all of the symbol names out of
memory, one at a time, which can be quite slow.

We're adding a section __TEXT,__lldb_no_nlist, to this binary to
indicate that lldb should not read the nlist symbols for it when we are
reading out of memory. If lldb is run with an on-disk version of the
binary, we will load the symbol table as we normally would, there's no
benefit to handling this binary differently.

I added a test where I create a dylib with this specially named section,
launch the process. The main binary deletes the dylib from the disk so
lldb is forced to read it out of memory. lldb attaches to the binary,
confirms that the dylib is present in the process and is a memory
Module. If the binary is not present, or lldb found the on-disk copy
because it hasn't been deleted yet, we delete the target, flush the
Debugger's module cache, sleep and retry, up to ten times. I create the
specially named section by compiling an assembly file that puts a byte
in the section which makes for a bit of a messy Makefile (the pre-canned
actions to build a dylib don't quite handle this case) but I don't think
it's much of a problem. This is a purely skipUnlessDarwin test case.

Relanding this change with a restructured Makefiles for the test case
that should pass on the CI bots.

rdar://146167816
2025-03-06 21:29:38 -08:00
Jason Molenda
82af9888db Revert "[lldb][Mach-O] Don't read symbol table of specially marked binary (#129967)"
This reverts commit 397696bb3d26c1298bf265e4907b0b6416ad59c9.

This breaks the macOS CI bots, I need to use $LDFLAGS in the $LD
invocation when building the dylib to get the dylibs to build on
the CI bots.  But I've added "-lno-nlists -lhas-nlists" to the LDFLAGS
for the main binary in the same directory, so using LDFLAGS will
result in a compile error for the dylibs.  I'll need to build the
dylibs in a subdir with a different Makefile, will reland with that
change in a bit.
2025-03-06 17:19:43 -08:00
Jason Molenda
cec36e279c Revert "Add LDFLAGS to fix bot failure"
This reverts commit 00fdc5297e2ac325eeaa08e1bc8ebe3b8b5f7977.
2025-03-06 17:19:43 -08:00
Jason Molenda
00fdc5297e Add LDFLAGS to fix bot failure
a CI bot is failing with my manual $(LD) invocations,
I see another test invoking ld like this which also
passes $LDFLAGS, let's see if that does it.
2025-03-06 17:03:16 -08:00
Jason Molenda
397696bb3d
[lldb][Mach-O] Don't read symbol table of specially marked binary (#129967)
We have a binary image on Darwin that has no code, only metadata. It has
a large symbol table with many external symbol names that will not be
needed in the debugger. And it is possible to not have this binary on
the debugger system - so lldb must read all of the symbol names out of
memory, one at a time, which can be quite slow.

We're adding a section __TEXT,__lldb_no_nlist, to this binary to
indicate that lldb should not read the nlist symbols for it when we are
reading out of memory. If lldb is run with an on-disk version of the
binary, we will load the symbol table as we normally would, there's no
benefit to handling this binary differently.

I added a test where I create a dylib with this specially named section,
launch the process. The main binary deletes the dylib from the disk so
lldb is forced to read it out of memory. lldb attaches to the binary,
confirms that the dylib is present in the process and is a memory
Module. If the binary is not present, or lldb found the on-disk copy
because it hasn't been deleted yet, we delete the target, flush the
Debugger's module cache, sleep and retry, up to ten times. I create the
specially named section by compiling an assembly file that puts a byte
in the section which makes for a bit of a messy Makefile (the pre-canned
actions to build a dylib don't quite handle this case) but I don't think
it's much of a problem. This is a purely skipUnlessDarwin test case.

rdar://146167816
2025-03-06 16:34:13 -08:00
John Harrison
27c788de75
[lldb-dap] Restore the override FD used by the output redirect on stop. (#129964)
While running lldb-dap over stdin/stdout the `stdout` and `stderr` FD's
are replaced with a pipe that is reading the output to forward to the
dap client. During shutdown we were not properly restoring those FDs,
which means if any component attempted to write to stderr it would
trigger a SIGPIPE due to the pipe being closed during the shutdown
process. This can happen if we have an error reported from the
`DAP::Loop` call that would then log to stderr, such as an error parsing
a malformed DAP message or if lldb-dap crashed and it was trying to
write the stack trace to stderr.

There is one place we were not handling an `llvm::Error` if there was no
logging setup that could trigger this condition.

To address this, I updated the OutputRedirector to restore the FD to the
prior state when `Stop` is called.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-06 13:57:06 -08:00
ita-sc
8eec3d77a9
[lldb][tests] Add ability to run API tests with qemu-user simulator (#89765) 2025-03-06 09:57:03 +00:00
Jacob Lalonde
02f024ca97
[LLDB-DAP] SBDebugger don't prefix title on progress updates (#124648)
In my last DAP patch (#123837), we piped the DAP update message into the
update event. However, we had the title embedded into the update
message. This makes sense for progress Start, but makes the update
message look pretty wonky.


![image](https://github.com/user-attachments/assets/9f6083d1-fc50-455c-a1a7-a2f9bdaba22e)

Instead, we only use the title when it's the first message, removing the
duplicate title problem.

![image](https://github.com/user-attachments/assets/ee7aefd1-1852-46f7-94bc-84b8faef6dac)
2025-03-05 12:02:44 -08:00
Adrian Prantl
878a64f94a
[lldb] Upgrade CompilerType::GetBitSize to return llvm::Expected (#129601)
This patch pushes the error handling boundary for the GetBitSize()
methods from Runtime into the Type and CompilerType APIs. This makes it
easier to diagnose problems thanks to more meaningful error messages
being available. GetBitSize() is often the first thing LLDB asks about a
type, so this method is particularly important for a better user
experience.

rdar://145667239
2025-03-05 10:21:19 -08:00