725 Commits

Author SHA1 Message Date
John Harrison
e9799e51ed
[lldb-dap] Improve support for variables with anonymous fields and types (#186482)
While looking at the '[raw]' value of a std::vector I noticed we didn't
handle the anonymous inner struct very well. The 'evaluateName' was
incorrect (e.g. the evaluateName would return `<var>.` for the anonymous
struct).

This improves support for variables with anonymous fields and anonymous
types.

* Changed the name of anonymous fields from `<null>` to `(anonymous)`,
which matches other tooling like clangd's representation and how types
are presented if the field is not defined.
* Adjusts variables to not return an 'evaluateName' for anonymous
fields.
* Adjusted '[raw]' values to be marked as 'internal' which deemphasizes
them in the UI.

While working in this area, I also consolidated some helpers that are
only used within Variables.cpp.

Before my changes:
<img width="513" height="460" alt="before"
src="https://github.com/user-attachments/assets/3da0aada-8ba3-415d-bbec-56b41a9b9415"
/>

After my changes:
<img width="414" height="467" alt="after"
src="https://github.com/user-attachments/assets/66a47108-ee44-4e01-8eab-e89edb348fde"
/>
2026-03-18 11:39:22 -07:00
Sergei Druzhkov
7899b26e88
[lldb-dap] Allow expressions in setVariable request (#185611)
This paths allows expressions in `setVariable` request. It is small
extension of original semantics from DAP specification. DAP has
`setExpression` request to this purpose, but it is too general. So I
prefer to keep this simple solution.
2026-03-18 10:19:46 +03:00
Sergei Druzhkov
fa40c361fc
[lldb-dap] Mark return value as readonly (#186329)
Marked return value as readonly to give VS Code a hint that this
variable doesn't support `setVariable` request.
2026-03-16 12:43:47 +03:00
Jonas Devlieghere
f002fc0ee8
[lldb] Skip tests that are incompatible with MTE (#186043)
Skip tests that are incompatible with MTE. 

Depends on:
- https://github.com/llvm/llvm-project/pull/185780
2026-03-14 11:19:26 -07:00
John Harrison
bb93279edf
[lldb-dap] Fix a regression in synthetic variables. (#186180)
In PR#183176 there was a regression mixing up `GetSyntheticValue` and
`GetNonSyntheticValue` that results in `[raw]` variables not correctly
representing the underlying value.

Addressing this regression and adjusting the naming of a few helpers to
better match existing naming styles in lldb.
2026-03-13 09:39:47 -07:00
Ebuka Ezike
919ae1cd2f
[lldb-dap] Skip return_variable_with_children on arm64 (#184132)
In lldb arm64 does not support scalar return types that is larger than
the register size. skip the test on that architecture.

Unblocks CI.
2026-03-02 14:42:19 +00:00
John Harrison
48eb40bee0
[lldb-dap] Adjust VariableReferenceStorage lifetime management. (#183176)
Adjusting `VariableReferenceStorage` to only need to track permanent vs
temporary storage by making `VariableStore` the common base class.

Moved the subclasses of `VariableStore` into the Variables.cpp file,
since they're no long referenced externally.

Expanding on the tests by adding an updated core dump with variables in
the argument scope we can use to validate variable storage.
2026-02-27 10:47:11 -08:00
John Harrison
a703d91091
[lldb-dap] Improve test performance for 'cancel' request. (#183632)
Update the test to more cleanly handle making a 'blocking' call using a
custom command instead of python `time.sleep`, which we cannot easily
interrupt.

This should improve the overall performance of the tests, locally they
took around 30s and now finish in around 6s.
2026-02-27 09:20:48 -08:00
Alex Langford
30969cc644
[lldb] Fix logic issue in TestDAP_stopped_events.py (#183382)
The subset should actually be the expected data because the real thread
data may have additional information.
2026-02-25 14:09:14 -08:00
Priyanshu Kumar
07053e4d2e
[LLDB]Fix logic in matches method for thread comparison (#179873)
The method claims to check if a is a subset of b, but the implementation
`a | b ==a` actually checks if b is a subset of a. This patch updated
the docstring.
2026-02-24 14:00:54 -08:00
Charles Zablit
334aa966ec
Revert "[lldb] fix Makefile.rules cross platform macros (#183090)" (#183142) 2026-02-24 19:45:06 +00:00
Charles Zablit
544e75ebd9
Revert "Merge commit '74ad4baef073' from llvm.org/main into next (#183126)" (#183135) 2026-02-24 19:30:20 +00:00
Charles Zablit
f4577641d1
Merge commit '74ad4baef073' from llvm.org/main into next (#183126) 2026-02-24 19:02:51 +00:00
Charles Zablit
980c24897e
[lldb] fix Makefile.rules cross platform macros (#183090)
This patch fixes cross platform Makefile.rules macros and adds the
`ECHO_TO_EXISTING_FILE` macros.

Using `echo` in a macro to write to a file had quoting issues.
2026-02-24 18:47:36 +00:00
John Harrison
070db69beb
Reapply "[lldb-dap] Validate utf8 protocol messages." (#181930) (#182056)
This reverts commit 977d910d005c47f884ecf838e504da301b1124b9.

Addressing build issues with gcc.
2026-02-19 08:50:19 -08:00
cmtice
a0df62be84
[lldb] Disable shared build for TestGdbRemoteCompletion.py (#182196)
Follow up to #181720. Based on [this
failure](https://lab.llvm.org/buildbot/#/builders/162/builds/41328)
2026-02-18 19:24:14 -08:00
Dave Lee
aafe5e2f14
[lldb] Disable shared build for TestAppleSimulatorOSType.py (#182167)
Follow up to #181720. Based on [this
failure](https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake-os-verficiation/275/).
2026-02-18 14:25:15 -08:00
Dave Lee
fdef40a6e5
[lldb] Disable shared builds in two more tests (#182138)
Follow up to https://github.com/llvm/llvm-project/pull/181720
2026-02-18 13:26:39 -08:00
Dave Lee
b9225e8607
[lldb] Allow tests to share a single build (#181720)
This changes Python API tests to use a single build shared across all
test functions, instead of the previous default behavior of a separate
build dir for each test function.

This build behavior opt-out, tests can use the previous behavior of one
individual (unshared) build directory per test function, by setting
`SHARED_BUILD_TESTCASE` to False (in the test class).

The motivation is to make the test suite more efficient, by not
repeatedly building the same test source. When running tests on my macOS
machine, this reduces the time of `ninja check-lldb-api` by almost 60%
(sample numbers: from ~492s down to ~207s = 58%). Almost 5min time
saved.

Each test function still calls `self.build()`, but only the first call
will do a build, in the subsequent tests `make` will be a no-op because
the sources won't have changed.
2026-02-18 10:38:45 -08:00
Sergei Druzhkov
29c768ca1a
[lldb-dap] Add hex format in setVariable request (#181968)
Added hex format support in `setVariable` request according to DAP
specification.
2026-02-18 21:35:24 +03:00
Charles Zablit
6a365b004d
[lldb-dap][windows] fix lldb-dap's self.get_stdout() method (#181813)
`DAPTestCaseBase.get_stdout()` was originally not supported on Windows
due to the lack of ConPTY support.
https://github.com/llvm/llvm-project/pull/168729 fixed that by
implenenting the ConPTY support. It was partly reverted in
https://github.com/llvm/llvm-project/pull/177610 due to hard to
reproduce test failures.

The tests are now fixed (see the 2 patches below) and removing the check
for `GetFlags().Test(lldb::eLaunchFlagLaunchInTTY);` is the last step to
re-enabling ConPTY support.

This patch requires:
- https://github.com/llvm/llvm-project/pull/181811
- https://github.com/llvm/llvm-project/pull/181809

Fixes https://github.com/llvm/llvm-project/issues/137599.

rdar://168932366
2026-02-18 17:05:29 +00:00
John Harrison
977d910d00
Revert "[lldb-dap] Validate utf8 protocol messages." (#181930)
Reverts llvm/llvm-project#181261

Breaking builds on linux, reverting while I investigate.

See https://lab.llvm.org/buildbot/#/builders/181/builds/37346
2026-02-17 14:49:53 -08:00
John Harrison
24c120406a
[lldb-dap] Validate utf8 protocol messages. (#181261)
I ran into this while debugging a different issue, but when we calcualte
the 'value' field of a variable we were not ensuring the contents were
valid utf8. If assertions are enabled then llvm::json::Value will assert
that the string contains invalid utf8.

To address this I added a wrapper type (`lldb_dap::protocol::String`)
that can be used as a thin wrapper around `std::string` to ensure a
field contains valid utf8. This is now used throughout the
`lldb_dap::protocol::*` types.
2026-02-17 14:05:50 -08:00
Ebuka Ezike
47a969ef88
[lldb-dap] Refactor variablesReference storage and scope management. (#179262)
This commit refactors the Variables class into a
VariableReferenceStorage with variableReferences of different
ReferenceKinds.

The variablesReference is now a uint32_t.
The most significant byte (bits 24 - 31) holds the reference kind and
the remaining 3 bytes (bits 0 -23) holds the actual reference.

We have (at the moment) 3 reference kinds.
Temporary => 0b0000 => 0x00
Permanent => 0b0001 => 0x01
Scope     => 0b0010 => 0x03

The actual variablesReference can be used to get a `VariableStore`.

VariableStore holds variables in a group.
It has two implementations:
- ScopeStore: Holds variables within frame scopes (locals, globals,
registers). This is lazy-loaded and only fetched when variable(s) in the
scope is requested.
- ExpandableValueStore: Holds SBValue and fetches it's variable children
when requested.

ReferenceKindPool:
   The variablesReference created starts from 1 with the mask of the
   Reference kind applied.
   It holds vector of VariableStore of one Referencekind,
   This allows constant lookup of a reference

Example:
```md

| maskedVariablesReference | Mask | variablesReference | RefrenceKind | VariableStore |
|--------------------------|------|--------------------|--------------|---------------|
| 20        -> 0x00000014  | 0x00 | 20 -> 0x00000014   | temporary    | ValueStore    |
| 268435476 -> 0x01000014  | 0x01 | 20 -> 0x00000014   | permanent    | ValueStore    |
| 536870932 -> 0x01000014  | 0x02 | 20 -> 0x00000014   | scope        | ScopeStore    |
```
2026-02-17 12:55:19 +00:00
Ilia Kuklin
80fffd527c
[lldb] Add evaluation modes to DIL (#178747)
Adding more supported operators to DIL breaks tests in `DWIMPrint` and
`lldb-dap`, which shouldn't be simply adjusted for new DIL capabilities.
They act as a check for the boundaries of what subset of expressions
`DWIMPrint` and `lldb-dap` expect to be evaluated when using
`GetValueForVariableExpressionPath` function. With this patch, the
caller can now pick a mode that limits the expressions DIL can evaluate,
which ensures the expected preexisting behavior. More operators can now
be safely added to DIL, which can still be evaluated by DIL when using
`frame var` command or the API call with Full mode selected (or not
specified at all).

DIL will only attempt evaluating expressions that contain operations
allowed by a selected mode:
 - Simple: identifiers, operators: '.'
 - Legacy: identifiers, integers, operators: '.', '->', '*', '&', '[]'
 - Full: everything supported by DIL
2026-02-13 18:34:58 +05:00
Sergei Druzhkov
b447f5d976
[lldb-dap] Add unknown request handler (#181109)
Added unknown request handler to avoid crash. Returning error in this
case looks better than stopping entire debug session.
2026-02-13 16:00:57 +03:00
Ebuka Ezike
1d5884d7cf
[lldb-dap] Fix the breakpoint events test. (#180518)
Previously the test was written in a way that may be flaky, fixed with
the following changes.
- The breakpoint are placed on functions and set during the
configuration stage of the protocol.
 - Add the rpath to the test binary.
 - Check we also hit the breakpoint we set directly using lldb.
2026-02-09 18:37:35 +00:00
Ebuka Ezike
8244528aee
[lldb-dap] Add validation for RunInTerminal client capability (#180213)
Check if the client supports RunInTerminal before attempting to run in
the preferred terminal.
One less unknown reason for failed to launch
2026-02-06 18:08:20 +00:00
Ebuka Ezike
0d020f14c9
[lldb-dap] Split the launch IO redirection tests. (#179974)
Tests in the same python file share the same build directory. 
Although they are the same binary. The logs produced are different.
2026-02-05 22:03:02 +00:00
John Harrison
35ada11f1b
[lldb-dap] Improving stability of TestDAP_launch_commands. (#179783)
Improving stability of the TestDAP_launch_commands test.

When collecting output for verifying 'stopCommands' we were not waiting
for the output to finish, which could cause issues if the test is
running very fast.
2026-02-05 08:19:14 -08:00
Ebuka Ezike
e6560a3c57
[lldb-dap] Allow evaluate requests without a frame context (#179667)
EvaluateRequests handler now uses the target's context if no valid
frameId is provided, enabling evaluation of
global variables without requiring a valid stack frame.

In repl mode it now uses the last `successful` variable or command
expression, if the provided user's expression is empty.
Try to evaluate the expression if the evaluation context is `Unknown`
2026-02-05 14:26:28 +00:00
Ebuka Ezike
f002505940
[lldb-dap] Fix flaky TestDAP_stopped_events.py (#179689)
We are waiting for both stopped event at once.
We may not get both events within the (0.25 seconds) time interval to
fetch more events. Retry with the `DEFAULT TIMEOUT` if we got one of the
event.

Increase the `EVENT_QUIET_PERIOD`'s value for ASAN mode

Fixes #179648
2026-02-05 13:39:51 +00:00
GeorgeHuyubo
23bf55eda4
[lldb]Send statistics in initialized event (#178978)
Re-attemp landing of old commit:
7fe3586cda

Co-authored-by: George Hu <georgehuyubo@gmail.com>
2026-02-04 09:10:07 -08:00
Ebuka Ezike
1c5d702175
[lldb-dap] Fix DAP_launch_io.py Test (#179295)
DAP_launch_io sends a continue request for a nonstopped process. Use
verify_process_exited instead.
2026-02-03 19:58:52 +00:00
John Harrison
51e5b6c6ac
[lldb-dap] Migrating 'stopped' event to structured types. (#176273)
Updates the 'stopped' event to use structure types. 

Additionally, I adjusted the description to include the full
`GetStopDescription` that can have more details.
2026-02-03 08:43:41 -08:00
Sergei Druzhkov
73e9c72227
[lldb-dap] Add ASan report (#178858)
Added `ASanReport` for `ExceptionInfo` request.
2026-02-03 17:14:46 +03:00
Anthony Eid
6ca8f79fc8
lldb-dap: Stop using replicated variable ids (#124232)
Closes #119784 

Probably closes #147105 as well, but I couldn't test due to #156473: 

This PR fixes two bugs:
1. It generates unique variable reference IDs per suspended debuggee
state.
2. It stores all created variables in a stopped state instead of
dropping variables in unselected scopes. So it can properly handle all
scope/variable requests

It does this by storing all variables in their respective scopes and
using that mapping in request handlers that relied on the old mapping.
It dynamically creates new variable/scope IDs instead of resetting IDs
whenever a new scope is created.

I also removed some unused code as well.

---------

Co-authored-by: Med Ismail Bennani <ismail@bennani.ma>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
2026-01-30 12:51:47 -08:00
Ebuka Ezike
a482eb793a
[lldb-dap] Conditionally check UBSan stack trace on Darwin only (#178655)
non-darwin platforms may have incorrect stop information location
heuristics. Enable assertion once UBSan stopInfo heuristic is updated.

I hit this locally, I don't see it hitting any CI bot but should, Mostly
likely the CI linux bots may not have `compiler_rt` run time enabled.
see
https://github.com/llvm/llvm-project/pull/177964#discussion_r2732271531
2026-01-29 14:24:33 +00:00
John Harrison
43dd362165
[lldb-dap] Adding more details to 'exceptionInfo'. (#176465)
In the exceptionInfo request I've added additional information for crash
data, instrumentation data and more detailed exception data.

For example, when UBSan is enabled, you now see additional information
in the exception stack trace about the detected issue:

<img width="1728" height="538" alt="Screenshot 2026-01-15 at 3 05 08 PM"
src="https://github.com/user-attachments/assets/b761af2c-90ac-4eb7-9926-3ab133f1b753"
/>

I included a new test for stopping at `lldb::eStopReasonInstrumentation`
and ensuring we have additional information reported.

---------

Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2026-01-28 17:27:45 -08:00
John Harrison
46585a3082
[lldb-dap] Improve test performance by removing negative assertions. (#178041)
Investigating some of the biggest slow downs during tests, the biggest
offender is 'wait_for_stopped' requiring a negative assertion around the
'stopped' event.

It currently waits for a negative predicate to fail before continuing.
This means it must wait for the full DEFAULT_TIMEOUT (50s) before the
test is allowed to continue.

To mitigate this, I added a new `collect_events` helper that will wait
for the given event to occur with the DEFAULT_TIMEOUT, then wait for a
quiet period (0.25s) before returning.

This greatly reduces the amount of idle waiting during tests.

Additionally, looking a the performance of individual test files,
`TestDAP_launch` is the slowest overall test. No individual test is that
slow, but the fact it has so many tests in the same file results in the
test harness waiting for that one file to finish.

To mitigate that, I split `TestDAP_launch` into individual test files
that run in parallel, reducing the runtime locally from over 2mins to
~5s.
2026-01-28 09:53:17 -08:00
Charles Zablit
c4585b44b6
[lldb][windows] do not attach to a PseudoConsole if it is not opened (#177934)
# Summary

This patch ensures lldb will not try to read from a PseudoConsole if it
has not been opened.

# Original issue

https://github.com/llvm/llvm-project/pull/168729 introduces support for
the Windows ConPTY in `lldb-dap`. This caused a regression in `lldb`
which was not caught by our tests:
https://github.com/llvm/llvm-project/issues/175652.

This patch fixes https://github.com/llvm/llvm-project/issues/175652.

`lldb_private::ProcessLauncherWindows::LaunchProcess` connects the
debuggee to a PseudoConsole only if:
```cpp
if (hPC != INVALID_HANDLE_VALUE && launch_info.GetNumFileActions() == 0 && launch_info.GetFlags().Test(lldb::eLaunchFlagLaunchInTTY))
```

lldb needs to check the same condition in
`lldb_private::PlatformWindows::DebugProcess` to ensure that it does not
read from a PseudoConsole which has not been opened.

# Side effect

This patch reverts what https://github.com/llvm/llvm-project/pull/168729
did by adding ConPTY support.
https://github.com/llvm/llvm-project/pull/175812 is the proper fix,
however it's causing tests failures which we can't reliably reproduce at
desk. Given https://github.com/llvm/llvm-project/pull/168729 breaks
`22.x` lldb, it's better to revert the change ahead of the release of
`22.x` rather than pushing for the proper fix.
2026-01-26 19:56:23 +01:00
David Spickett
e9ac1a3190
[lldb] Improve error and docs for repeating "memory region" (#177559)
"memory region" can be given an address once and then when repeated,
it will try to find a region just beyond the last one it printed.
This continues until the end of the address space.

Then it gives you an error showing the usage, which is odd because
you just saw a bunch of "memory region" with no options work.

So I've improved the error a bit to imply its to do with the repetition.
Then described the repeating behaviour in the help text.
2026-01-26 15:39:39 +00:00
Ebuka Ezike
f4d41a4efb
[lldb-dap] Fix the completion provided to the DAP client. (#177151)
Previously, completion behavior was inconsistent,
sometimes including the partial token or removing existing user text.
Since LLDB completions includes the partial token by default, we now
strip it before sending to the client.

The completion heuristic:
1. Strip the commandEscapePrefix
2. Request completions from the debugger
3. Get the line at cursor position
4. Calculate the length of any partial token
5. Offset each completion by the partial token length

In all cases, the completion starts from the cursor position. then
offsets by `Length` to the left and inserts the completion.

Examples (single quotes show whitespace and are not part of the input):
```md
| Input      | Partial Token | Length | Completion    |
|------------|---------------|--------|---------------|
| m          | m             | 1      | memory        |
| `m         | m             | 1      | memory        |
| myfoo.     | myfoo.        | 6      | myfoo.method( |
| myfoo.fi   | myfoo.fi      | 7      | myfoo.field   |
| myfoo. b   | b             | 1      | myfoo. bar    |
| 'memory '  |               | 0      | memory read   |
| memory     | memory        | 6      | memory        |
| settings s | s             | 1      | settings show |
```

Fixes #176424
2026-01-26 12:06:54 +00:00
Augusto Noronha
ac5e1b7a96
[lldb] Skip TestDAP_launch_io.py tests on asan builds (#177198)
Two out of three TestDAP_launch_io.py's test's classes have been failing
on ASAN builds ever since it was added into the repo. The ASAN failure
is not easy to debug, so skip these tests until we fix it.
2026-01-21 09:28:21 -08:00
Ebuka Ezike
3ca7a72990
[lldb-dap] Fix Completions Request crash (#176211)
lldb-dap currently crashes when the first character is non ascii. This
is because we assume that the request column is ascii based instead of
UTF16 code units,
and end up in the middle of a character code point. causing an assertion
since we cannot not send invalid UTF-8 values.

This also handles the case in multilines and the column is outside the
range of the text.

Move completion description to the `CompletionItem.detail` property.
2026-01-19 12:57:03 +00:00
Ebuka Ezike
6977e6812c
[lldb-dap] Move targetId and debuggerId into a session property (#175930)
This makes it clear the fields required for attaching to an existing
debug session.

It also makes it easier to check mutually exclusive fields required to
attach.
2026-01-15 12:37:36 +00:00
Ebuka Ezike
c745e9b67d
[lldb-dap] Add testcases for stdio redirection on different console types. (#175048)
There are some bugs when launching in terminal with args and stdio
redirection.

- lldb-dap `--stdio` args is passed to the debuggee (should we change
this to use `--` to separate debuggee args from lldb-dap args, similar
to how we handle the `--client` args? ).

#### It also changes the behaviour of stdio redirection.
If a redirection is not specified, it uses to lldb default value. e.g.
```jsonc
"stdio": ["./stdin"]` 
// now becomes 
"stdio", ["./stdio", "./default_stdout", "./default_stderr"]
// instead of 
"stdio", ["./stdin", "./stdin", "./stdin"]
// took quite some time to figure out where my output is going to.
```

Fixes [#174445](https://github.com/llvm/llvm-project/issues/174445)

Other bug I noticed but should be in a different PR.
- debuggee args that contains newline are not properly escaped when sent
to the terminal.
2026-01-13 12:11:22 +00:00
Sergei Druzhkov
c9f13b5404
[lldb-dap] Add clipboard context support (#170644)
This patch introduces support for `clipboard` context from
[DAP](https://microsoft.github.io/debug-adapter-protocol/specification#Types_Capabilities).
This feature is very useful when you want to copy all nested values from
a structure or a container instead of a summary (e.g. `size = 3` for
vector). I added new short mode for description generation to reduce
output verbosity, which is particularly useful for primitive types.
2026-01-10 16:45:49 +03:00
Charles Zablit
fb47a252ad
[lldb-dap] add timeout to spawn_and_wait test utility (#174461) 2026-01-09 14:49:21 +00:00
Charles Zablit
672a4c3f34
[NFC][lldb] fix docstring indentation (#175042)
This patch fixes the indentation of 2 docstrings in
`TestDAP_runInTerminal.py`.

Running `black` on that file with the default settings causes this
change. `darker` does not seem to catch it.

This is a prelude to https://github.com/llvm/llvm-project/pull/174635.
2026-01-08 18:18:21 +00:00