31 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
David Spickett
0fca1e4e06 [lldb][lldb-dap][test] Correct skip in TestDAP_launch
Fixes 4f65345ab5f2787a4704efb5828657c50be6d65a

Yet again I forgot it's skip[I]f.
2025-08-15 12:29:26 +00:00
David Spickett
4f65345ab5 [lldb][lldb-dap][test] Disable part of TestDAP_launch on Arm 32-bit
This test has been flakey on our bot:
https://lab.llvm.org/buildbot/#/builders/18/builds/20410

```
======================================================================
FAIL: test_extra_launch_commands (TestDAP_launch.TestDAP_launch)
    Tests the "launchCommands" with extra launching settings
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/launch/TestDAP_launch.py", line 482, in test_extra_launch_commands
    self.verify_commands("stopCommands", output, stopCommands)
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/packages/Python/lldbsuite/test/tools/lldb-dap/lldbdap_testcase.py", line 228, in verify_commands
    self.assertTrue(
AssertionError: False is not true : verify 'frame variable' found in console output for 'stopCommands'
Config=arm-/home/tcwg-buildbot/worker/lldb-arm-ubuntu/build/bin/clang
----------------------------------------------------------------------
```

Likely a timing issue waiting for the command output on a slower
machine.

General tracking issue - https://github.com/llvm/llvm-project/issues/137660
2025-08-15 12:26:45 +00: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
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
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
Jason Molenda
6d6feaf7e3 [lldb][NFC] update API tests which skip/expect-fail arm
The architectures provided to skipIf / expectedFail are regular
expressions (v. _match_decorator_property() in decorators.py
so on Darwin systems "arm64" would match the skips for "arm" (32-bit
Linux).  Update these to "arm$" to prevent this, and also update
three tests (TestBuiltinFormats.py, TestCrossDSOTailCalls.py,
TestCrossObjectTailCalls.py) that were skipped for arm64 via this
behavior, and need to be skipped or they will fail.

This was moviated by the new TestDynamicValue.py test which has
an expected-fail for arm, but the test was passing on arm64 Darwin
resulting in failure for the CIs.
2025-05-27 18:41:16 -07: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
03896403d3
[lldb-dap] Migrate attach to typed RequestHandler. (#137911)
This updates the `attach` request to the typed
`RequestHandler<protocol::AttachRequestArguments,
protocol::AttachResponse>`.

Added a few more overlapping configurations to
`lldb_dap::protocol::Configuration` that are shared between launching
and attaching.

There may be some additional code we could clean-up that is no longer
referenced now that this has migrated to use well defined types.
2025-05-08 14:12:49 -07:00
David Spickett
2668167e2c [lldb] Disable some lldb-dap tests on Windows
Since https://github.com/llvm/llvm-project/pull/138981 / aeeb9a3c09
were landed and tests re-enabled, these tests have been failing
on our Windows on Arm bot:
https://lab.llvm.org/buildbot/#/builders/141/builds/8523

********************
Unresolved Tests (1):
  lldb-api :: tools/lldb-dap/send-event/TestDAP_sendEvent.py
********************
Failed Tests (2):
  lldb-api :: tools/lldb-dap/launch/TestDAP_launch.py
  lldb-api :: tools/lldb-dap/stackTrace/TestDAP_stackTrace.py
2025-05-08 08:47:12 +00: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
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
David Spickett
5afe9c72e4 [lldb][lldb-dap] Disable launch tests that rely on get_stdout()
This appears not to work on Windows.

See https://github.com/llvm/llvm-project/issues/137599.
2025-04-28 09:10:12 +00: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
Ebuka Ezike
fb01f19f3c
[lldb][lldb-dap] fix repeating commands in repl mode (#135008)
Fixes #131589
Add a new parameter to the RunCommands functions to control the echoing of
commands
---------

Signed-off-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Walter Erquinigo <a20012251@gmail.com>
2025-04-25 02:32:52 +01:00
John Harrison
2d30a60e9f
[lldb-dap] Adding support for cancelling a request. (#130169)
Adding support for cancelling requests.

There are two forms of request cancellation.

* Preemptively cancelling a request that is in the queue.
* Actively cancelling the in progress request as a best effort attempt
using `SBDebugger.RequestInterrupt()`.
2025-04-14 08:29:02 -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
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
Da-Viper
d4c1789112
Make env and source map dictionaries #95137 (#106919)
Fixes #95137
2024-10-07 12:38:36 -04:00
David Spickett
b2a820faea [lldb][lldb-dap][test] Enable Launch tests
Add Windows include equivalents for includes and shell command.
2024-08-29 11:55:35 +00:00
jeffreytan81
db9ac92501
Add lldb version into initialize response lldb-dap (#98703)
Frequently, while troubleshooting user's debugging issues in VScode, we
would like to know lldb version so that we can confirm if certain
patch/feature is in or not.

This PR adds version string into `initialize` response so that telemetry
can track it.

---------

Co-authored-by: jeffreytan81 <jeffreytan@fb.com>
2024-07-15 20:03:50 -04:00
Jonas Devlieghere
bf3e3289d6
[lldb] Unify Platform::ResolveExecutable (#96256)
The Platform class currently has two functions to resolve an executable:
`ResolveExecutable` and `ResolveRemoteExecutable`. The former strictly
deals with local files while the latter can handle potentially remote
files. I couldn't figure out why the distinction matters, at the latter
is a super-set of the former.

To make things even more confusion, we had a similar but not identical
implementation in RemoteAwarePlatform where its implementation of
`ResolveExecutable` could handle remote files. To top it all off, we had
copy-pasted implementation, dead code included in
`PlatformAppleSimulator` and `PlatformRemoteDarwinDevice`.

I went ahead and unified all the different implementation on the
original `ResolveRemoteExecutable` implementation. As far as I can tell,
it should work for every other platform, and the test suite (on macOS)
seems to agree with me, except for a small wording change.
2024-06-21 11:29:49 -07:00
Miro Bucko
11a4d43f4a
Fix flaky TestDAP_console test. (#94494)
Test Plan:
llvm-lit
llvm-project/lldb/test/API/tools/lldb-dap/console/TestDAP_console.py
2024-06-12 06:21:17 +07:00
Pavel Labath
fa6377119c
[lldb-dap] Automatically skip lldb-dap tests for remote platforms (#93169)
The don't currently work (and they're also not particularly useful,
since all of the remote stuff happens inside lldb).

This saves us from annotating tests one by one.
2024-05-24 08:52:32 +02:00
Shubham Sandeep Rastogi
82c1bfc44e
Increase timeout to reduce test failure rate. (#83312)
The timeout for this test was set to 1.0s which is very low, it should
be a default of 10s and be increased by a factor of 10 if ASAN is
enabled. This will help reduce the falkiness of the test, especially in
ASAN builds.
2024-02-29 13:12:03 -08:00
John Harrison
ae8facc1f8
[lldb-dap] Do not write over the existing error if launchCommands fail during debugger launch. (#82051)
This fixes an issue where the error is lost if a command while executing
`launchCommands` when launching the debugger.

This should fix #82048
2024-02-20 09:35:15 -08:00
Jonas Devlieghere
80fcecb13c
[lldb] Replace assertEquals with assertEqual (NFC) (#82073)
assertEquals is a deprecated alias for assertEqual and has been removed
in Python 3.12. This wasn't an issue previously because we used a
vendored version of the unittest module. Now that we use the built-in
version this gets updated together with the Python version used to run
the test suite.
2024-02-16 20:58:50 -08:00
Jonas Devlieghere
01263c6c6f
[lldb] Rename lldb-vscode to lldb-dap (#69264)
Rename lldb-vscode to lldb-dap. This change is largely mechanical. The
following substitutions cover the majority of the changes in this
commit:

  s/VSCODE/DAP/
  s/VSCode/DAP/
  s/vscode/dap/
  s/g_vsc/g_dap/

Discourse RFC:
https://discourse.llvm.org/t/rfc-rename-lldb-vscode-to-lldb-dap/74075/
2023-10-19 09:48:54 -07:00