70 Commits

Author SHA1 Message Date
John Harrison
13eca5248c
[lldb-dap] Re-land refactor of DebugCommunication. (#147787)
Originally commited in 362b9d78b4ee9107da2b5e90b3764b0f0fa610fe and then
reverted in cb63b75e32a415c9bfc298ed7fdcd67e8d9de54c.

This re-lands a subset of the changes to
dap_server.py/DebugCommunication and addresses the python3.10
compatibility issue.

This includes less type annotations since those were the reason for the
failures on that specific version of python.

I've done additional testing on python3.8, python3.10 and python3.13 to
further validate these changes.
2025-08-21 10:20:01 -07:00
Ely Ronnen
8b64cd8be2
[lldb-dap] Add module symbol table viewer to VS Code extension #140626 (#153836)
- VS Code extension:
- Add module symbol table viewer using
[Tabulator](https://tabulator.info/) for sorting and formatting rows.
  - Add context menu action to the modules tree.
 - lldb-dap
   -  Add `DAPGetModuleSymbolsRequest` to get symbols from a module.
 
Fixes #140626

[Screencast From 2025-08-15
19-12-33.webm](https://github.com/user-attachments/assets/75e2f229-ac82-487c-812e-3ea33a575b70)
2025-08-21 00:31:48 +02:00
Ely Ronnen
4d3feaea66
[lldb-dap] persistent assembly breakpoints (#148061)
Resolves #141955

- Adds data to breakpoints `Source` object, in order for assembly
breakpoints, which rely on a temporary `sourceReference` value, to be
able to resolve in future sessions like normal path+line breakpoints
- Adds optional `instructions_offset` parameter to `BreakpointResolver`
2025-08-08 22:29:47 +02:00
John Harrison
93d94690c9
[lldb-dap] Updating protocol memory references to lldb::addr_t. (#148037)
This updates all the existing memory reference fields to use
`lldb::addr_t` directly.

A few places were using `std::string` and decoding the value in the
request handler and other places had unique ways of parsing addresses.

This unifies all of these references with the `DecodeMemoryReference`
helper in JSONUtils.h.

Additionally, for the types I updated, I tried to simplify the POD types
some and moved default values out of RequestHandlers and into the
protocol POD types.
2025-07-11 16:14:52 -07:00
Druzhkov Sergei
9098bffb03
[lldb-dap] Add external terminal support (#146950)
This patch deprecates the `runInTerminal` option in favour of `console`
which allow the user the specify an integrated or external option.
2025-07-11 11:14:59 +01:00
Santhosh Kumar Ellendula
76b1dcfac5
[lldb][lldb-dap] Added support for "WriteMemory" request. (#131820)
Added debug adapter support for write memory.

---------

Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-hyd.qualcomm.com>
Co-authored-by: Santhosh Kumar Ellendula <sellendu@hu-sellendu-lv.qualcomm.com>
2025-07-10 01:59:20 +05:30
Ebuka Ezike
03a27230c9
[lldb-dap] Use protocol types for modules request and events. (#146966)
Update tests to fix silently failing test and handle when a module is
removed.
2025-07-08 22:43:53 +01:00
Ebuka Ezike
5c22793ead
[lldb-dap][test] Refactor runInTerminal Tests. (#144954)
Replace `isTestSupported` function with `skipIfBuildType` annotation.

Test that uses the `IsTestSupported` function are no longer run, as the
size of lldb-dap binary is now more than `1mb`.

Update the broken test. 

Fixes #108621  

We could probably check if the test now passes on `linux arm` since it
was disabled because it timed out. I experienced the timeout after
replacing the `IsTestSupported` with `skipIfBuildType`.
2025-06-23 10:32:46 +01:00
John Harrison
cb63b75e32
Revert "[lldb-dap] Refactoring DebugCommunication to improve test consistency. (#143818)
This reverts commit 362b9d78b4ee9107da2b5e90b3764b0f0fa610fe.

Buildbots using python3.10 are running into errors from this change.
2025-06-17 16:01:40 -07:00
John Harrison
362b9d78b4
[lldb-dap] Refactoring DebugCommunication to improve test consistency. (#143818)
In DebugCommunication, we currently are using 2 thread to drive
lldb-dap. At the moment, they make an attempt at only synchronizing the
`recv_packets` between the reader thread and the main test thread. Other
stateful properties of the debug session are not guarded by a
locks/mutex.

To mitigate this, I am moving any state updates to the main thread
inside the `_recv_packet` method to ensure that between calls to
`_recv_packet` the state does not change out from under us in a test.

This does mean the precise timing of events has changed slightly as a
result and I've updated the existing tests that fail for me locally with
this new behavior.

I think this should result in overall more predictable behavior, even if
the test is slow due to the host workload or architecture differences.

---------

Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
2025-06-17 14:42:06 -07:00
John Harrison
6421bd94ea
[lldb-dap] Creating protocol types for setExceptionBreakpoints. (#144153)
This adds new types for setExceptionBreakpoints and adds support for
`supportsExceptionFilterOptions`, which allows exception breakpoints to
set a condition.

While testing this, I noticed that obj-c exception catch breakpoints may
not be working correctly in lldb-dap.
2025-06-16 17:24:48 -07:00
Ebuka Ezike
539cf82425
[lldb-dap] Use structured types for stepInTargets request (#144072)
uses the `SendTargetCapabilities` from #142831
2025-06-16 19:24:59 +01:00
John Harrison
07a1d479cc
[lldb-dap] Creating a 'capabilities' event helper. (#142831)
This adds a new 'CapabilitiesEventBody' type for having a well
structured type for the event and updates the 'restart' request
to dynamically set their capabilities.
2025-06-10 10:49:07 -07:00
John Harrison
52075f01a7
[lldb-dap] Migrating 'threads' request to structured types. (#142510)
Moving `threads` request to structured types. Adding helper types for
this and moving helpers from JSONUtils to ProtocolUtils.

---------

Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-06-05 15:58:30 -07:00
Jonas Devlieghere
d8ba707b0c
Revert "[lldb-dap] Use structured types for stepInTargets request (#142439)" (#142891)
This reverts commit 4b6c608615a285d81132acf8e33b81b2ec2c9bf9 and
follow-up commits 159de3633640a5cb2d322ebe8cc4ec0c1c9a896d and
c9e1c52e2e75a91a44a98df818cc9bd11655e51d because this breaks
TestDAP_stepInTargets.py on Darwin.

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake
2025-06-04 20:19:56 -07:00
Ebuka Ezike
4b6c608615
[lldb-dap] Use structured types for stepInTargets request (#142439) 2025-06-04 08:05:31 +01:00
Ely Ronnen
81602769d8
[lldb-dap] Synchronously wait for breakpoints resolves in tests (#140470)
Attempt to improve tests by synchronously waiting for breakpoints to
resolve. Not sure if it will fix all the tests but I think it should
make the tests more stable
2025-05-31 16:59:46 +02:00
David Spickett
114192f586 Revert "[lldb-dap] Test Gardening, improving DebugCommunication. (#141689)"
This reverts commit 8a49db35f45e56c92522c6079e51553e80c07aec.

Due to failures on Arm and AArch64 Linux:
https://lab.llvm.org/buildbot/#/builders/59/builds/18540
https://lab.llvm.org/buildbot/#/builders/18/builds/16759

  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py", line 22, in assertEvaluateFailure
    self.assertNotIn(
AssertionError: 'result' unexpectedly found in {'memoryReference': '0xFFFFF7CB3060', 'result': '0x0000000000000000', 'type': 'int *', 'variablesReference': 7}

FAIL: test_generic_evaluate_expressions (TestDAP_evaluate.TestDAP_evaluate)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py", line 228, in test_generic_evaluate_expressions
    self.run_test_evaluate_expressions(enableAutoVariableSummaries=False)
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py", line 117, in run_test_evaluate_expressions
    self.assertEvaluateFailure("list")  # local variable of a_function
  File "/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/evaluate/TestDAP_evaluate.py", line 22, in assertEvaluateFailure
    self.assertNotIn(
AssertionError: 'result' unexpectedly found in {'memoryReference': '0xFFFFF7CB3060', 'result': '0x0000000000000000', 'type': 'int *', 'variablesReference': 7}
Config=aarch64-/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang

The second one is because our bots have the libc debug info package installed,
the first, no idea.
2025-05-30 08:48:29 +00:00
John Harrison
8a49db35f4
[lldb-dap] Test Gardening, improving DebugCommunication. (#141689)
Improving the readability and correctness of DebugCommunication by
adding type annotations to many parts of the library and trying to
improve the implementation of a few key areas of the code to better
handle correctness.

Specifically, this refactored the
`DebugCommunication._handle_recv_packet` function to ensure consistency
with the reader thread when handling state changes and improved the
`DebugCommunication._recv_packet` helper to make it easier to follow by
adding some additional helpers.
2025-05-29 09:51:27 -07:00
A. Jiang
4304d90f0a
[libc++][lldb-dap][test] Fix CI for bootstrapping-build (#141543)
#140107 changed the default argument of `disableASLR` of related
functions from `False` to `True`. libc++ CI has been stably failing for
`TestDAP_subtleFrames.py` (in bootstrapping-build) since then. The error
message "personality set failed: Operation not permitted" seems related
to ASLR.

This PR attempts to fix the CI failure by changing the default value of
`disableASLR` in `dap_server.py` to `False`.
2025-05-28 14:30:45 -04:00
Ely Ronnen
e972d8cbbf
[lldb-dap] assembly breakpoints (#139969)
* Support assembly source breakpoints
* Change `sourceReference` to be the symbol load address for simplicity
and consistency across threads/frames

[Screencast From 2025-05-17
23-57-30.webm](https://github.com/user-attachments/assets/2e7c181d-42c1-4121-8f13-b180c19d0e33)
2025-05-21 21:13:32 +02:00
Ely Ronnen
9d0614e77a
[lldb-dap] fix disassembly request instruction offset handling (#140486)
Fix the handling of the `instructionOffset` parameter, which resulted in
always returning the wrong disassembly because VSCode always uses
`instructionOffset = -50` and expects 50 instructions before the given
address, instead of 50 bytes before
2025-05-21 06:50:13 +02:00
John Harrison
0e0b501bf5
[lldb-dap] Take two at refactoring the startup sequence. (#140331)
This is more straight forward refactor of the startup sequence that
reverts parts of ba29e60f9a2222bd5e883579bb78db13fc5a7588. Unlike my
previous attempt, I ended up removing the pending request queue and not
including an `AsyncReqeustHandler` because I don't think we actually
need that at the moment.

The key is that during the startup flow there are 2 parallel operations
happening in the DAP that have different triggers.

* The `initialize` request is sent and once the response is received the
`launch` or `attach` is sent.
* When the `initialized` event is recieved the `setBreakpionts` and
other config requests are made followed by the `configurationDone`
event.

I moved the `initialized` event back to happen in the `PostRun` of the
`launch` or `attach` request handlers. This ensures that we have a valid
target by the time the configuration calls are made. I added also added
a few extra validations that to the `configurationeDone` handler to
ensure we're in an expected state.

I've also fixed up the tests to match the new flow. With the other
additional test fixes in 087a5d2ec7897cd99d3787820711fec76a8e1792 I
think we've narrowed down the main source of test instability that
motivated the startup sequence change.
2025-05-16 19:28:34 -07:00
John Harrison
087a5d2ec7
[lldb-dap] Adding additional asserts to unit tests. (#140107)
Adding an assert that the 'continue' request succeeds caused a number of
tests to fail. This showed a number of tests that were not specifying if
they should be stopped or not at key points in the test. This is likely
contributing to these tests being flaky since the debugger is not in the
expected state.

Additionally, I spent a little time trying to improve the readability of
the dap_server.py and lldbdap_testcase.py.
2025-05-16 08:47:01 -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
Jonas Devlieghere
b7c449ac0b
[lldb-dap] Don't emit a removed module event for unseen modules (#139324) 2025-05-09 23:34:05 -07:00
Jonas Devlieghere
aeeb9a3c09
[lldb-dap] Change the launch sequence (#138219) (reland)
This PR changes how we treat the launch sequence in lldb-dap.

 - Send the initialized event after we finish handling the initialize
   request, rather than after we finish attaching or launching.
 - Delay handling the launch and attach request until we have handled
   the configurationDone request. The latter is now largely a NO-OP and
   only exists to signal lldb-dap that it can handle the launch and
   attach requests.
 - Delay handling the initial threads requests until we have handled
   the launch or attach request.
 - Make all attaching and launching synchronous, including when we have
   attach or launch commands. This removes the need to synchronize
   between the request and event thread.

Background:
https://discourse.llvm.org/t/reliability-of-the-lldb-dap-tests/86125
2025-05-07 16:20:47 -07:00
David Spickett
47c7e73e57 Revert "[lldb-dap] Change the launch sequence (#138219)"
This reverts commit ba29e60f9a2222bd5e883579bb78db13fc5a7588.

As it broke tests on Windows on Arm: https://lab.llvm.org/buildbot/#/builders/141/builds/8500

********************
Unresolved Tests (2):
  lldb-api :: tools/lldb-dap/completions/TestDAP_completions.py
  lldb-api :: tools/lldb-dap/startDebugging/TestDAP_startDebugging.py
********************
Timed Out Tests (1):
  lldb-api :: tools/lldb-dap/send-event/TestDAP_sendEvent.py
********************
Failed Tests (6):
  lldb-api :: tools/lldb-dap/console/TestDAP_console.py
  lldb-api :: tools/lldb-dap/console/TestDAP_redirection_to_console.py
  lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py
  lldb-api :: tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
  lldb-api :: tools/lldb-dap/stackTraceDisassemblyDisplay/TestDAP_stackTraceDisassemblyDisplay.py
  lldb-api :: tools/lldb-dap/variables/children/TestDAP_variables_children.py
2025-05-07 09:11:09 +00:00
Jonas Devlieghere
5e70460d01
Revert "[lldb-dap] Don't make stopOnAttach the default in attach tests"
This reverts commit 69a0af35a5860156836e9e295ecef9de3474db11 as it's
timing out on the bots.
2025-05-06 19:52:00 -07:00
Jonas Devlieghere
69a0af35a5
[lldb-dap] Don't make stopOnAttach the default in attach tests
Make stopOnAttach=False the default again and explicitly pass
stopOnAttach=True where the tests relies on that. I changed the default
in the launch sequence PR (#138219) because that was implicitly the
assumption (the tests never send the configurationDone request).
2025-05-06 18:19:37 -07:00
Jonas Devlieghere
ba29e60f9a
[lldb-dap] Change the launch sequence (#138219)
This PR changes how we treat the launch sequence in lldb-dap.

 - Send the initialized event after we finish handling the initialize
   request, rather than after we finish attaching or launching.
 - Delay handling the launch and attach request until we have handled
   the configurationDone request. The latter is now largely a NO-OP and
   only exists to signal lldb-dap that it can handle the launch and
   attach requests.
 - Delay handling the initial threads requests until we have handled
   the launch or attach request.
 - Make all attaching and launching synchronous, including when we have
   attach or launch commands. This removes the need to synchronize
   between the request and event thread.

Background:
https://discourse.llvm.org/t/reliability-of-the-lldb-dap-tests/86125
2025-05-06 15:58:44 -07:00
Wanyi
47de54e9a2
[lldb-dap] Fix TestDap_attach.py flakiness (#137278)
# Summary
This patch makes the `request_attach` wait for events `process` and
`initialized` just like `request_launch`. This ensure the DAP session
can move forward somewhat correctly.

Recently `TestDap_attach.test_terminate_commands` became flaky.
It's hitting:
```
lldbsuite/test/tools/lldb-dap/dap_server.py", line 350, in send_recv
    raise ValueError(desc)
ValueError: no response for "disconnect"
```
I took a look at the DAP msg from that test case and noticed:
- It's not using the regular attaching, instead it's using the
`attachCommands` to launch debug the binary and it will stop at entry.
- The `initialized` event returned after the `disconnect` request. Which
means lldb-dap didn't really get ready yet.

### NOTE
The `dap_server.py` is doing things to mimic the VSCode (or other dap
clients) but it had some assumptions. For example, it's still missing
the `configurationDone` request and response because it relies on a
continue action to trigger the `configurationDone` request.

# Test Plan
```
./bin/llvm-lit -va /Users/wanyi/llvm-upstream/llvm-project/lldb/test/API/tools/lldb-dap/attach/TestDAP_attach.py
./bin/llvm-lit -va /Users/wanyi/llvm-upstream/llvm-project/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py
```

To test the `wait_for_events` timeout case
```
events = self.wait_for_events(["process", "initialized", "fake", "event"], 1)
if events:
    raise ValueError(f'no events {",".join(events)} found for within timeout 1')
```
Observed
<img width="696" alt="image"
src="https://github.com/user-attachments/assets/bc97c0ef-d91f-4561-8272-4d36f5f5d4e6"
/>

### Also
Looks like some test cases should be re-enabled in
0b8dfb5762
But only comments was removed. The skip statements survived the change.
2025-04-28 18:32:51 -04:00
Jonas Devlieghere
b546baff48
[lldb-dap] Support the Module Event (#137380)
The module event indicates that some information about a module has
changed. The event is supported by the Emacs and Visual Studio DAP
clients. This PR adds support for emitting the event from lldb-dap.

Fixes #137058
2025-04-27 10:21:19 -07:00
Ely Ronnen
5c197236ed
[lldb-dap] Fix broken tests with commanEscapePrefix="" (#137384)
* Fix broken tests that use commanEscapePrefix="", in my case
`TestDAP_stackTraceMissingModule.test_missingModule`
2025-04-25 13:07:34 -07:00
John Harrison
a0aa5f8933
[lldb-dap] Refactoring lldb-dap 'launch' request to use typed RequestHandler<>. (#133624)
This converts a number of json::Value's into well defined types that are
used throughout lldb-dap and updates the 'launch' command to use the new
well defined types.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-04-25 09:50:42 -07:00
Jonas Devlieghere
262158b8aa
[lldb-dap] Support StackFrameFormat (#137113)
The debug adapter protocol supports an option to provide formatting
information for a stack frames as part of the StackTrace request.
lldb-dap incorrectly advertises it supports this, but until this PR that
support wasn't actually implemented.

Fixes #137057
2025-04-24 16:25:31 -07:00
John Harrison
ec6828c1ec
[lldb-dap] Remove an incorrect assumption on reverse requests. (#136210)
Reverse requests do have a 'seq' set still from VSCode. I incorrectly
interpreted
dede7bb4b7/src/vs/workbench/contrib/debug/common/abstractDebugAdapter.ts (L65)
to mean they have a 'seq' of '0', however the 'seq' is set in
'internalSend' here
dede7bb4b7/src/vs/workbench/contrib/debug/common/abstractDebugAdapter.ts (L178).

Removing the check that 'seq=0' on reverse requests and updating the
dap_server.py impl to also set the seq.
2025-04-19 13:45:59 -07:00
Wanyi
7a41761407
[lldb] Make SBProcess thread related actions listen to StopLocker (#134339)
# Summary

This PR updates `SBProcess::GetNumThreads()` and
`SBProcess::GetThreadAtIndex()` to listen to the stop locker.
`SBProcess::GetNumThreads()` will return 0 if the process is running.

## Problem Description

Recently upon debugging a program with thousands of threads in VS Code,
lldb-dap would hang at a `threads` request sent right after receiving
the `configurationDone` response. Soon after it will end the debug
session with the following error
```
Process <pid> exited with status = -1 (0xffffffff) lost connection
```

This is because LLDB is still in the middle of resuming all the threads.
And requesting threads will end up interrupt the process on Linux. From
the gdb-remote log it ended up getting `lldb::StateType::eStateInvalid`
and just exit with status -1.

I don't think it's reasonable to allow getting threads from a running
process. There are a few approaches to fix this:
1) Send the stopped event to IDE after `configurationDone`. This aligns
with the CLI behavior.
2) However, the above approach will break the existing user facing
behavior. The alternative will be reject the `threads` request if the
process is not stopped.
3) Improve the run lock. This is a synchronize issue where process was
in the middle of resuming while lldb-dap attempts to interrupt it.

**This PR implements the option 3**

## HOWEVER

This fixed the "lost connection" issue below but new issue has surfaced.
From testing, and also from checking the [VSCode source
code](174af221c9/src/vs/workbench/contrib/debug/browser/debugSession.ts (L791)),
it expects having threadID to perform `pause`. So after attaching,
without any threads reported to the client, the user will not be able to
pause the attached process. `setBreakpoint` will still work and once we
make a stop at the bp (or any stop that will report threads, client can
perform pause again.

## NEXT
1) Made an attempt to return initial thread list so that VSCode can
pause (second commit in the PR)
2) Investigate why threads will trigger unwinding the second frame of a
thread, which leads to sending the interrupt
3) Decided if we want to support `stopOnEntry` for attaching, given
  i. This is not an official specification
ii. If enable stopOnEntry, we need to fix attaching on Linux, to send
only one stopped event. Currently, all threads upon attaching will have
stop reason `SIGSTOP` and lldb-dap will send `stopped` event for each
one of them. Every `stopped` will trigger the client request for
threads.
iii. Alternatively, we can support auto continue correspond to `(lldb)
process attach --continue`. This require the ii above.


### Additionally

lldb-dap will not send a `continued` event after `configurationDone`
because it checks `dap.focus_tid == LLDB_INVALID_THREAD_ID` (so that we
don't send it for `launch` request). Notice `dap.focus_tid` will only
get assigned when handling stop or stepping.

According to DAP

> Please note: a debug adapter is not expected to send this event in
response to a request that implies that execution continues, e.g. launch
or continue.
It is only necessary to send a continued event if there was no previous
request that implied this.

So I guess we are not violating DAP if we don't send `continued` event.
But I'd like to get some sense about this.


## Test Plan
Used following program for testing:
https://gist.github.com/kusmour/1729d2e07b7b1063897db77de194e47d
**NOTE: Utilize stdin to get pid and attach AFTER hitting enter. Attach
should happen when all the threads start running.**

DAP messages before the change
<img width="1165" alt="image"
src="https://github.com/user-attachments/assets/a9ad85fb-81ce-419c-95e5-612639905c66"
/>

DAP message after the change - report zero threads after attaching
<img width="1165" alt="image"
src="https://github.com/user-attachments/assets/a1179e18-6844-437a-938c-0383702294cd"
/>

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-04-15 13:46:15 -04:00
Jonas Devlieghere
3f7ca88267
[lldb-dap] Add progress events to the packet list (#134157)
Before #134048, TestDAP_Progress relied on wait_for_event to block until
the progressEnd came in. However, progress events were not added to the
packet list, so this call would always time out. This PR makes it so
that packets are added to the packet list, and you can block on them.
2025-04-02 15:33:07 -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
John Harrison
5720a792a9
[lldb-dap] Waiting for the test binary to exit prior to dumping logs. (#131917)
This should ensure we have the full logs prior to dumping the logs.
Additionally, printing log dumps to stderr so they are adjacent to
assertion failures.
2025-03-19 08:49:52 -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
Jonas Devlieghere
fb191efa70
[lldb-dap] Adaptor -> Adapter (NFC) (#129110)
Both spellings are considered correct and acceptable, with adapter being
more common in American English. Given that DAP stands for Debug Adapter
Protocol (with an e) let's go with that as the canonical spelling.
2025-02-27 19:56:56 -06:00
John Harrison
162eb32e74
[lldb-dap] Add 'source' references to stack frames without source files. (#128268)
This adds 'source' references to all stack frames. When opening a stack
frame users will see the disassembly of the frame if the source is not
available.

This works around the odd behavior of navigating frames without the
VSCode disassembly view open, which causes 'step' to step in the first
frame with a source instead of the active frame.

This fixes #128260

Old behavior:

https://github.com/user-attachments/assets/3f40582d-ac96-451a-a5ae-498a323bf30e

New behavior:

https://github.com/user-attachments/assets/3a3f9ac6-3e6c-4795-9bb2-1132b3916b6f

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-02-24 14:56:28 -08:00
John Harrison
998b28f196
[lldb-dap] Refactoring lldb-dap port listening mode to allow multiple connections. (#116392)
This adjusts the lldb-dap listening mode to accept multiple clients.
Each client initializes a new instance of DAP and an associated
`lldb::SBDebugger` instance.

The listening mode is configured with the `--connection` option and
supports listening on a port or a unix socket on supported platforms.

When running in server mode launch and attach performance should
be improved by lldb sharing symbols for core libraries between debug
sessions.
2025-02-21 18:30:43 -08:00
Adrian Vogelsgesang
8e6fa15bc3
[lldb-dap] Support column breakpoints (#125347)
This commit adds support for column breakpoints to lldb-dap

To do so, support for the `breakpointLocations` request was
added. To find all available breakpoint positions, we iterate over
the line table.

The `setBreakpoints` request already forwarded the column correctly to
`SBTarget::BreakpointCreateByLocation`. However, `SourceBreakpointMap`
did not keep track of multiple breakpoints in the same line. To do so,
the `SourceBreakpointMap` is now indexed by line+column instead of by
line only.

This was previously submitted as #113787, but got reverted due to
failures on ARM and macOS. This second attempt has less strict test
case expectations. Also, I added a release note.
2025-02-04 01:23:28 +01:00
Michael Buch
ceeb08b9e0 Revert "[lldb-dap] Support column breakpoints (#113787)"
This reverts commit 4f48a81a620bc9280be4780f3554cdc9bda55bd3.

The newly added test was failing on the public macOS Arm64 bots:
```
======================================================================
FAIL: test_column_breakpoints (TestDAP_breakpointLocations.TestDAP_setBreakpoints)
   Test retrieving the available breakpoint locations.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/test/API/tools/lldb-dap/breakpoint/TestDAP_breakpointLocations.py", line 77, in test_column_breakpoints
    self.assertEqual(
AssertionError: Lists differ: [{'co[70 chars]e': 41}, {'column': 3, 'line': 42}, {'column': 18, 'line': 42}] != [{'co[70 chars]e': 42}, {'column': 18, 'line': 42}]

First differing element 2:
{'column': 3, 'line': 41}
{'column': 3, 'line': 42}

First list contains 1 additional elements.
First extra element 4:
{'column': 18, 'line': 42}

  [{'column': 39, 'line': 40},
   {'column': 51, 'line': 40},
-  {'column': 3, 'line': 41},
   {'column': 3, 'line': 42},
   {'column': 18, 'line': 42}]
Config=arm64-/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/lldb-build/bin/clang
----------------------------------------------------------------------
Ran 1 test in 1.554s

FAILED (failures=1)
```
2024-11-18 16:15:06 +00:00
Adrian Vogelsgesang
4f48a81a62
[lldb-dap] Support column breakpoints (#113787)
This commit adds support for column breakpoints to lldb-dap.

To do so, support for the `breakpointLocations` request was
added. To find all available breakpoint positions, we iterate over
the line table.

The `setBreakpoints` request already forwarded the column correctly to
`SBTarget::BreakpointCreateByLocation`. However, `SourceBreakpointMap`
did not keep track of multiple breakpoints in the same line. To do so,
the `SourceBreakpointMap` is now indexed by line+column instead of by
line only.

See http://jonasdevlieghere.com/post/lldb-column-breakpoints/ for a
high-level introduction to column breakpoints.
2024-11-16 19:01:12 +01:00
Michael Buch
b4e1af0096
[lldb-dap] Always pass disableASLR to the DAP executable (#113891)
More context can be found in
https://github.com/llvm/llvm-project/pull/110303

For DAP tests running in constrained environments (e.g., Docker
containers), disabling ASLR isn't allowed. So we set `disableASLR=False`
(since https://github.com/llvm/llvm-project/pull/113593).

However, the `dap_server.py` will currently only forward the value
of `disableASLR` to the DAP executable if it's set to `True`. If the
DAP executable wasn't provided a `disableASLR` field it defaults to
`true` too:
f147437945/lldb/tools/lldb-dap/lldb-dap.cpp (L2103-L2104)

This means that passing `disableASLR=False` from the tests is currently
not possible.

This is also true for many of the other boolean arguments of
`request_launch`. But this patch only addresses `disableASLR` for now
since it's blocking a libc++ patch.
2024-10-29 18:40:06 +00:00
John Harrison
c5c11f3404
[lldb-dap] Creating an API for sending dap events from a script in lldb-dap. (#112384)
Custom DAP events can be detected using
https://code.visualstudio.com/api/references/vscode-api#debug.onDidReceiveDebugSessionCustomEvent.

This API allows an lldb python script to send events to the DAP
client to allow extensions to handle these custom events.
2024-10-16 17:19:51 -07:00