Commit Graph

2801 Commits

Author SHA1 Message Date
Sergei Druzhkov
e82edd28f6 [lldb-dap] Migrate locations request to structured types (#171099)
This patch migrates `locations` request into structured types and adds
test for it.
2025-12-14 18:37:24 +03:00
Sergei Druzhkov
f0d7d833f5 [lldb-dap] Allow empty memory reference in disassemble arguments (#162517)
This patch implements a workaround for a VSCode bug that causes it to
send disassemble requests with empty memory reference. You can find more
detailed description
[here](https://github.com/microsoft/vscode/pull/270361). I propose to
allow empty memory reference and return invalid instructions when this
occurs.

Error log example:
```
1759923554.517830610 (stdio) --> {"command":"disassemble","arguments":{"memoryReference":"","offset":0,"instructionOffset":-50,"instructionCount":50,"resolveSymbols":true},"type":"request","seq":3}
1759923554.518007517 (stdio) queued (command=disassemble seq=3)
1759923554.518254757 (stdio) <-- {"body":{"error":{"format":"invalid arguments for request 'disassemble': malformed memory reference at arguments.memoryReference\n{\n  \"instructionCount\": 50,\n  \"instructionOffset\": -50,\n  \"memoryReference\": /* error: malformed memory reference */ \"\",\n  \"offset\": 0,\n  \"resolveSymbols\": true\n}","id":3,"showUser":true}},"command":"disassemble","request_seq":3,"seq":0,"success":false,"type":"response"}
```

I am not sure that we should add workaround here when bug on VSCode
side, but I think this bug affects our users. WDYT?
2025-12-12 12:33:07 +03:00
David Spickett
60b5d06f7c [lldb][lldb-dap] Remove unused variable
Fixes warning:
C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\tools\lldb-dap\tool\lldb-dap.cpp(446,27): warning: unused variable 'dap_sessions_condition' [-Wunused-variable]

Variable is unused since #163653 / 5ab3375b2c.
2025-12-11 13:54:19 +00:00
Sergei Druzhkov
371da58cfa [lldb-dap] Migrate pause request to structured types (#171096)
This patch migrates `pause` request into structured types and adds test
for it.
2025-12-08 21:35:24 +03:00
John Harrison
8d57635c59 [lldb-dap] Improving logging support and formatting. (#170731)
Adjusting logs in a few ways:

* The `DAP_LOG` and `DAP_LOG_ERROR` macros now include the file/line of
the log statement.
* Added support for creating a log with a prefix. This simplifies how we
create logs for the `lldb_dap::DAP` instance and `lldb_dap::Transport`
instance, allowing us to not have to pass the client name around as
much.
* Updated logging usage to take the `lldb_dap::Log` as a reference but
it now defaults to `llvm::raw_null_stream` if not configured. This
ensures more uniform access to the logger, even if its not written
anywhere.

The logs now look like:

```
1764896564.038788080 (stdio) --> {"command":"initialize","arguments":{...},"type":"request","seq":1}
1764896564.039064884 DAP.cpp:1007 (stdio) queued (command=initialize seq=1)
1764896564.039768934 (stdio) <-- {"body":{...},"command":"initialize","request_seq":1,"seq":1,"success":true,"type":"response"}
```
2025-12-05 15:43:40 -08:00
Ebuka Ezike
f827e4d1cf [lldb-dap] show a useful timestamp in log messages (#170737)
It becomes easier to see the time difference between requests and
responses
2025-12-05 12:49:34 +00:00
Augusto Noronha
d7fb086668 [lldb] Refactor LookupInfo object to be per-language (#168797)
Some months ago, the LookupInfo constructor logic was refactored to not
depend on language specific logic, and use languages plugins instead. In
this refactor, when the language type is unknown, a single LookupInfo
object will handle multiple languages. This doesn't work well, as
multiple languages might want to configure the LookupInfo object in
different ways. For example, different languages might want to set the
m_lookup_name differently from each other, but the previous
implementation would pick the first name a language provided, and
effectively ignored every other language. Other fields of the LookupInfo
object are also configured in incompatible ways.

This approach doesn't seem to be a problem upstream, since only the
C++/Objective-C language plugins are available, but it broke downstream
on the Swift fork, as adding Swift to the list of default languages when
the language type is unknown breaks C++ tests.

This patch makes it so instead of building a single LookupInfo object
for multiple languages, one LookupInfo object is built per language
instead.

rdar://159531216
2025-12-03 16:15:36 -08:00
Nicolas Miller
21f98f978c [lldb-dap] Fix format string on Mac OS (#169933)
On Mac `unsigned long long` corresponds to `uint64_t` so `%llu` is
needed.

Simply always using `%llu` and upcasting to `unsigned long long` should
make it work fine.
2025-12-03 15:33:51 -08:00
Ebuka Ezike
c5ecdec9fb [lldb-dap] start all sent protocol message from number one. (#170378)
This aligns with the DAP
[specification](https://microsoft.github.io/debug-adapter-protocol//specification.html#Base_Protocol_ProtocolMessage)

Force it to be an error in test cases.
2025-12-03 08:30:35 +00:00
John Harrison
fff45ddcc0 [lldb-dap] Follow the spec more closely on 'initialize' arguments. (#170350)
Updates `InitializeRequestArguments` to correctly follow the spec, see
https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Initialize.

This should correct which fields are tracked as optional and simplifies
some of the types to make sure they're meaningful (e.g. an
`optional<bool>` isn't anymore helpful than a `bool` since undefined and
false are basically equivalent and it requires us to handle interpreting undefined as the default value in all the places we use the `optional<bool>`).
2025-12-02 14:19:05 -08:00
Aaron
10ceca8a96 [lldb-dap] Fix segfault in JSONUtils.cpp when GetUUIDString() returns nullptr (#169844)
When creating a stack frame in JSONUtils.cpp CreateStackFrame() the code
constructs a std::string from module.GetUUIDString(), which can return
nullptr in some cases (as documented in the implementation of
SBModule::GetUUIDString()). This causes a segmentation fault when passed
to the std::string constructor.

This fix adds a null check before constructing the UUID string, falling
back to an empty string if nullptr is returned. The existing empty check
ensures the moduleId field is omitted from the JSON when no UUID exists.

rdar://163811812

---------

Co-authored-by: Ebuka Ezike <yerimyah1@gmail.com>
2025-12-01 15:06:48 +00:00
Jason Molenda
036279addf [lldb][debugserver] Return shared cache filepath in jGetSharedCacheInfo (#168474)
Add a "shared_cache_path" key-value to the jGetSharedCacheInfo response,
if we can fetch the shared cache path.

If debugserver and the inferior process are running with the same shared
cache UUID, there is a simple SPI to get debugserver's own shared cache
filepath and we will return that.

On newer OSes, there are SPI we can use to get the inferior process'
shared cache filepath, use that if necessary and the SPI are available.

The response for the jGetSharedCacheInfo packet will now look like


{"shared_cache_base_address":6609256448,"shared_cache_uuid":"B69FF43C-DBFD-3FB1-B4FE-A8FE32EA1062","no_shared_cache":false,"shared_cache_private_cache":false,"shared_cache_path":"/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_arm64e"}

when we have the full information about the shared cache in the
inferior. There are three possible types of responses:

1. inferior has not yet mapped in a shared cache (read: when stopped at
dyld_start and dyld hasn't started executing yet). In this case, no
"shared_cache_path" is listed. ("shared_cache_base_address" will be 0,
"shared_cache_uuid" will be all-zeroes uuid)

2. inferior has a shared cache, but it is different than debugserver's
and we do not have the new SPI to query the shared cache filepath. No
"shared_cache_path" is listed.

3. We were able to find the shared cache filepath, and it is included in
the response, as above.

I'm not using this information in lldb yet, but changes that build on
this will be forthcoming.

rdar://148939795
2025-11-30 21:40:13 -08:00
Sergei Druzhkov
207627f20f [lldb-dap] Add data breakpoints for bytes (#167237)
This patch adds support for `dataBreakpointInfoBytes` capability from
DAP. You can test this feature in VSCode (`Add data breakpoint at
address` button in breakpoints tab).
2025-11-28 18:20:20 +03:00
Janet Yang
5ab3375b2c [lldb-dap] Add multi-session support with shared debugger instances (#163653)
## Summary:
This change introduces a `DAPSessionManager` to enable multiple DAP
sessions to share debugger instances when needed, for things like child
process debugging and some scripting hooks that create dynamically new
targets.

Changes include:
- Add `DAPSessionManager` singleton to track and coordinate all active DAP
sessions
- Support attaching to an existing target via its globally unique target
ID (targetId parameter)
- Share debugger instances across sessions when new targets are created
dynamically
- Refactor event thread management to allow sharing event threads
between sessions and move event thread and event thread handlers to `EventHelpers`
- Add `eBroadcastBitNewTargetCreated` event to notify when new targets are
created
- Extract session names from target creation events
- Defer debugger initialization from 'initialize' request to
'launch'/'attach' requests. The only time the debugger is used currently
in between its creation in `InitializeRequestHandler` and the `Launch`
or `Attach` requests is during the `TelemetryDispatcher` destruction
call at the end of the `DAP::HandleObject` call, so this is safe.

This enables scenarios when new targets are created dynamically so that
the debug adapter can automatically start a new debug session for the
spawned target while sharing the debugger instance.

## Tests:
The refactoring maintains backward compatibility. All existing DAP test
cases pass.

Also added a few basic unit tests for DAPSessionManager
```
>> ninja DAPTests
>> ./tools/lldb/unittests/DAP/DAPTests
>>./bin/llvm-lit -v ../llvm-project/lldb/test/API/tools/lldb-dap/
```
2025-11-26 10:32:25 -08:00
Sergei Druzhkov
3694798210 [lldb-dap] Add format support for evaluate request (#169132)
This patch adds support for format option in the `evaluate` request
according to
[DAP](https://microsoft.github.io/debug-adapter-protocol/specification#Requests_Evaluate)
specification. Also, fixed typo in `LLDB_DAP_INVALID_VARRERF` constant.
2025-11-25 22:38:25 +03:00
Charles Zablit
c1f24a5205 [windows] improve python3.dll load check (#168864) 2025-11-24 18:40:45 +01:00
Charles Zablit
c9e22d3751 [lldb][windows] add color to the Python.dll not found error (#168718)
Make the `Python.dll not found` error message stand out more by using
the `llvm::WithColor::error()` method.

---

### Example

#### Before

<img width="782" height="431" alt="Screenshot 2025-11-19 at 15 50 22"
src="https://github.com/user-attachments/assets/93960c50-cbf2-41f7-aba3-2f2a8af916cc"
/>

#### After

<img width="780" height="430" alt="Screenshot 2025-11-19 at 15 54 28"
src="https://github.com/user-attachments/assets/f7f4954b-0ce3-4a4b-b9af-5af876032573"
/>

rdar://165047059
2025-11-19 17:30:31 +01:00
Chad Smith
2675dcd72d [lldb] update lldb-server platform help parsing (attempt 3) (#164904)
* original change #162730
* with windows fix #164843
* remove timeout that was pointed out in the comment above
* Remove test that starts and listens on a socket to avoid timeout
issues
2025-11-18 08:46:40 -08:00
John Harrison
c555522818 [lldb-dap] Migrating 'evaluate' to structured types. (#167720)
Adding structured types for the evaluate request handler.

This should be mostly a non-functional change. I did catch some spelling
mistakes in our tests ('variable' vs 'variables').
2025-11-17 11:08:49 -08:00
jimingham
420d56a394 Clean up MachTask.mm's handling of m_exception_thread. (#167994)
This was getting joined in ShutDownExcecptionThread (sic) but not
cleared. So this function was not safe to call twice, since you aren't
supposed to join a thread twice. Sadly, this was called in
MachTask::Clear and MachProcess::Destroy, which are both called when you
tell debugserver to detach.

This didn't seem to cause problems IRL, but the most recent ASAN detects
this as an error and calls ASAN::Die, which was causing all the tests
that ran detach to fail.

I fixed that by moving the clear & test for m_exception_thread to
ShutDownExceptionThread. I also fixed the spelling of that routine. And
that routine was claiming to return a kern_return_t which no one was
checking. It actually returns a kern_return_t if there was a Mach
failure and a Posix error if there was a join failure. Since there's
really nothing you can do but exit if this fails, which is always what
you are in the process of doing when you call this, and since we have
already done all the useful logging in ShutDownExceptionThread, I just
removed the return value.
2025-11-14 10:14:28 -08:00
Ebuka Ezike
09fd430de7 [lldb-dap] Refactor event thread (#166948)
Handle each event type in a different function
2025-11-12 14:54:13 +00:00
jeffreytan81
2acd652886 Fix lldb-dap non-leaf frame source resolution issue (#165944)
Summary
-------

While dogfooding lldb-dap, I observed that VSCode frequently displays
certain stack frames as greyed out. Although these frames have valid
debug information, double-clicking them shows disassembly instead of
source code. However, running `bt` from the LLDB command line correctly
displays source file and line information for these same frames,
indicating this is an lldb-dap specific issue.

Root Cause
----------

Investigation revealed that `DAP::ResolveSource()` incorrectly uses a
frame's PC address directly to determine whether valid source line
information exists. This approach works for leaf frames, but fails for
non-leaf (caller) frames where the PC points to the return address
immediately after a call instruction. This return address may fall into
compiler-generated code with no associated line information, even though
the actual call site has valid source location data.

The correct approach is to use the symbol context's line entry, which
LLDB resolves by effectively checking PC-1 for non-leaf frames, properly
identifying the line information for the call instruction rather than
the return address.

Testing
-------

Manually tested with VSCode debugging sessions on production workloads.
Verified that non-leaf frames now correctly display source code instead
of disassembly view.

Before the change symptom:
<img width="1013" height="216" alt="image"
src="https://github.com/user-attachments/assets/9487fbc0-f438-4892-a8d2-1437dc25399b"
/>


And here is after the fix:
<img width="1068" height="198" alt="image"
src="https://github.com/user-attachments/assets/0d2ebaa7-cca6-4983-a1d1-1a26ae62c86f"
/>

---------

Co-authored-by: Jeffrey Tan <jeffreytan@fb.com>
2025-11-12 00:31:57 +00:00
Ebuka Ezike
3149c7c518 Reapply "[lldb-dap] Use protocol types for exceptioninfo" (#166161) (#166836)
This reverts commit 6b8ca33e93. 
with the applied fix of passing std::string instead of c_str.
2025-11-07 09:16:12 +00:00
Jonas Devlieghere
fa83723bbe [debugserver] Remove unnecessary sleep in MachProcess::AttachForDebug (#166674)
Remove the unnecessary sleep in MachProcess::AttachForDebug. The
preceding comment makes it seem like it's necessary for synchronization,
though I don't believe that's the case (see below), and even if it were,
sleeping is not a reliable way to achieve that.

The reason I don't believe it's necessary is because after we return, we
synchronize with the exception thread on a state change. The latter will
call and update the process state, which is exactly what we synchronize
on. I was able to verify that this is the first time we change the
process state: i.e., `GetState` doesn't return a different value before
and after the sleep.

On top of that, there are 3 more places where we call ptrace attach
(`PosixSpawnChildForPTraceDebugging`, `SBLaunchForDebug`, and
`BoardServiceLaunchForDebug`) where we don't sleep.

rdar://163952037
2025-11-06 14:17:51 -08:00
Jonas Devlieghere
bd9030e762 [debugserver] Move constants into TaskPortForProcessID (NFC) (#166670)
I was looking at the calls to `usleep` in debugserver and noticed that
these default arguments are never overwritten. I converted them to
constants in the function, which makes it easier to reason about.
2025-11-05 16:32:36 -08:00
Ebuka Ezike
28a279ce14 [lldb-dap] expand tilde in dap executable path (#162635)
Users may have multiple devices and would like to resolve the homepath
based on the machine they are on.

expands the tilde `~` character at the front of the given file path.
2025-11-05 19:07:34 +00:00
Jonas Devlieghere
bc55f4f4f2 [debugserver] Fix debugserver build on < macOS 10.15 (#166599)
The VM_MEMORY_SANITIZER constant was added in macOs 10.15 and friends.
Support using the constant on older OSes.

Fixes #156144
2025-11-05 18:32:38 +00:00
Jonas Devlieghere
1621486d67 [lldb-dap] Add support for launching supported clients (#165941)
Support launching a supported DAP client using the lldb-dap binary.
Currently, only the official LLDB-DAP Visual Studio Code extension is
supported. It uses the VS Code launch URL format.

Here's an example:

```
lldb-dap --client vscode -- /path/to/exe foo bar
```

This will open the following URL with `code --open-url`:

```
vscode://llvm-vs-code-extensions.lldb-dap/start?program=/path/to/exe&args=foo&arg=bar
```

Fixes #125777
2025-11-03 13:37:39 -08:00
Charles Zablit
15bbdd143c [lldb][windows] print an error if python.dll is not in the DLL search path (#164893)
This is a follow up to https://github.com/llvm/llvm-project/pull/162509.

Using the `SearchPathW` API, we can ensure that the correct version of
Python is installed before `liblldb` is loaded (and `python.dll`
subsequently). If it's not, we try to add it to the search path with the
methods introduced in https://github.com/llvm/llvm-project/pull/162509.
If that fails or if that method is `#ifdef`'d out, we print an error
which will appear before lldb crashes due to the missing dll.

Before https://github.com/llvm/llvm-project/pull/162509, when invoked
from Powershell, lldb would silently crash (no error message/crash
report). After https://github.com/llvm/llvm-project/pull/162509, it
crashes without any indications that the root cause is the missing
python.dll. With this patch, we print the error before crashing.
2025-11-03 20:00:16 +00:00
David Spickett
6b8ca33e93 Revert "[lldb-dap] Use protocol types for exceptioninfo" (#166161)
Reverts llvm/llvm-project#165858 due to failures on Arm 32-bit.

```
Traceback (most recent call last):
  File "/home/tcwg-buildbot/worker/lldb-arm-ubuntu/llvm-project/lldb/test/API/tools/lldb-dap/exception/TestDAP_exception.py", line 24, in test_stopped_description
    self.assertEqual(exceptionInfo["description"], "signal SIGABRT")
AssertionError: '\x01ignal SIGABRT' != 'signal SIGABRT'
- ignal SIGABRT
? ^
+ signal SIGABRT
? ^
```
2025-11-03 13:12:27 +00:00
Ebuka Ezike
5f3f175a51 [lldb-dap] Use protocol types for exceptioninfo (#165858)
Relands the commit b8062f85dd
2025-11-03 11:34:57 +00:00
Jonas Devlieghere
128af4503a [lldb-dap] Move Options.td into tool subdirectory (NFC) (#165925) 2025-10-31 18:13:35 -07:00
John Harrison
bd0efcaa34 [lldb-dap] Correctly trigger 'entry' stop reasons. (#165901)
Noticed this while looking into test stability that the 'entry' stop
reason is not triggering correctly. This should ensure we correctly
trigger the 'entry' stop reason when launching a process with
`"stopOnEntry": true`. I've also updated the tests to ensure we receive
the 'entry' stop reason to catch this regression.
2025-10-31 13:33:34 -07:00
Ebuka Ezike
b17f1fd676 [lldb-dap] Report any errors during attach request (#165270)
Attaching using `core`, `gdbremote` or `attachInfo` may have an error.
fail early if it does.
2025-10-29 18:53:00 +00:00
jimingham
88558d52c7 Avoid stalls when MainLoop::Interrupt fails to wake up the MainLoop (#164905)
Turns out there's a bug in the current lldb sources that if you fork,
set the stdio file handles to close on exec and then exec lldb with some
commands and the `--batch` flag, lldb will stall on exit. The first
cause of the bug is that the Python session handler - and probably other
places in lldb - think 0, 1, and 2 HAVE TO BE the stdio file handles,
and open and close and dup them as needed. NB: I am NOT trying to fix
that bug. I'm not convinced running the lldb driver headless is worth a
lot of effort, it's just as easy to redirect them to /dev/null, which
does work.

But I would like to keep lldb from stalling on the way out when this
happens. The reason we stall is that we have a MainLoop waiting for
signals, and we try to Interrupt it, but because stdio was closed, the
interrupt pipe for the MainLoop gets the file descriptor 0, which gets
closed by the Python session handler if you run some script command. So
the Interrupt fails.

We were running the Write to the interrupt pipe wrapped in
`llvm::cantFail`, but in a no asserts build that just drops the error on
the floor. So then lldb went on to call std::thread::join on the still
active MainLoop, and that stalls

I made Interrupt (and AddCallback & AddPendingCallback) return a bool
for "interrupt success" instead. All the places where code was
requesting termination, I added checks for that failure, and skip the
std::thread::join call on the MainLoop thread, since that is almost
certainly going to stall at this point.

I didn't do the same for the Windows MainLoop, as I don't know if/when
the WSASetEvent call can fail, so I always return true here. I also
didn't turn the test off for Windows. According to the Python docs all
the API's I used should work on Windows... If that turns out not to be
true I'll make the test Darwin/Unix only.
2025-10-27 11:38:10 -07:00
Jason Molenda
d478737841 [lldb][debugserver] fix typeo in SME ZA register
chunk enumeartions.  Noticed by David Spickett.
NFC--no machine with a ZA register large enough to use this exists
today.
2025-10-23 14:43:51 -07:00
Adrian Prantl
aac036a7f6 Revert "[lldb] update lldb-server platform help parsing (#162730)"
This reverts commit faf7af864f.

This is failing on the Darwin bots.

https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/lldb-cmake/16164/changes#faf7af864f9258768133894764f1fae58d43bb09
2025-10-23 13:56:14 -07:00
Chad Smith
faf7af864f [lldb] update lldb-server platform help parsing (#162730)
The lldb-server platform help text is inconsistent with lldb-server
gdbserver help text. This PR modernizes the platform server to use
LLVM's [TableGen](https://llvm.org/docs/TableGen/)-based option parsing
(matching the existing gdbserver implementation), which auto-generates
option parsing code and help text.

The changes improve documentation quality by adding comprehensive option
descriptions,, adding support for `-h`/`--help` flags, and organizing
help output with DESCRIPTION and EXAMPLES sections. Internal-only
options (`--child-platform-fd`) and unused legacy options (`--debug`,
`--verbose`) are now hidden from help while maintaining backward
compatibility. All functional behavior remains unchanged—this is purely
a documentation and code modernization improvement.

## before
```
> /opt/llvm/bin/lldb-server p -h
p: unrecognized option '-h'
Usage:
  /opt/llvm/bin/lldb-server p [--log-file log-file-name] [--log-channels log-channel-list] [--port-file port-file-path] --server --listen port
```

## after
```
lldb-server p -h 
OVERVIEW: lldb-server platform

USAGE: lldb-server p [options] --listen <[host]:port> [[--] program args...]

CONNECTION OPTIONS:
  --gdbserver-port <port> Port to use for spawned gdbserver instances. If 0 or unspecified, a port will be chosen automatically. Short form: -P
  --listen <[host]:port>  Host and port to listen on. Format: [host]:port or protocol://[host]:port (e.g., tcp://localhost:1234, unix:///path/to/socket). Short form: -L
  --socket-file <path>    Write listening socket information (port number for TCP or path for Unix domain sockets) to the specified file. Short form: -f

GENERAL OPTIONS:
  --help            Display this help message and exit.
  --log-channels <channel1 categories...:channel2 categories...>
                    Channels to log. A colon-separated list of entries. Each entry starts with a channel followed by a space-separated list of categories. Common channels: lldb, gdb-remote, platform, process. Short form: -c
  --log-file <file> Destination file to log to. If empty, log to stderr. Short form: -l
  --server          Run in server mode, accepting multiple client connections sequentially. Without this flag, the server exits after handling the first connection.

OPTIONS:
  -- program args Arguments to pass to launched gdbserver instances.

DESCRIPTION
  Acts as a platform server for remote debugging. When LLDB clients connect,
  the platform server handles platform operations (file transfers, process
  launching) and spawns debug server instances (lldb-server gdbserver) to
  handle actual debugging sessions.

  By default, the server exits after handling one connection. Use --server
  to keep running and accept multiple connections sequentially.

EXAMPLES
  # Listen on port 1234, exit after first connection
  lldb-server platform --listen tcp://0.0.0.0:1234

  # Listen on port 5555, accept multiple connections
  lldb-server platform --server --listen tcp://localhost:5555

  # Listen on Unix domain socket
  lldb-server platform --listen unix:///tmp/lldb-server.sock

```

For comparison, here is the **gdbserver** help text:
```
lldb-server g -h
OVERVIEW: lldb-server

USAGE: lldb-server g[dbserver] [options] [[host]:port] [[--] program args...]

CONNECTION:
  --fd <fd>           Communicate over the given file descriptor.
  --named-pipe <name> Write port lldb-server will listen on to the given named pipe.
  --pipe <fd>         Write port lldb-server will listen on to the given file descriptor.
  --reverse-connect   Connect to the client instead of passively waiting for a connection. In this case [host]:port denotes the remote address to connect to.

GENERAL OPTIONS:
  --help            Prints out the usage information for lldb-server.
  --log-channels <channel1 categories...:channel2 categories...>
                    Channels to log. A colon-separated list of entries. Each entry starts with a channel followed by a space-separated list of categories.
  --log-file <file> Destination file to log to. If empty, log to stderr.
  --setsid          Run lldb-server in a new session.

TARGET SELECTION:
  --attach <pid-or-name> Attach to the process given by a (numeric) process id or a name.
  -- program args        Launch program for debugging.

DESCRIPTION
  lldb-server connects to the LLDB client, which drives the debugging session.
  If no connection options are given, the [host]:port argument must be present
  and will denote the address that lldb-server will listen on. [host] defaults
  to "localhost" if empty. Port can be zero, in which case the port number will
  be chosen dynamically and written to destinations given by --named-pipe and
  --pipe arguments.

  If no target is selected at startup, lldb-server can be directed by the LLDB
  client to launch or attach to a process.
```
2025-10-23 16:04:57 +01:00
Ebuka Ezike
f67880ae3d [lldb-dap] Fix mutex acquisition order for modules event. (#163821)
The modules event requires the `APIMutex` to create the module load
address. this may happen at the same time the `module request` is
handled.

The modules request also requires the `APIMutex` and the `modules_mutex,
set the order to acquire the mutexes.
2025-10-22 17:37:59 +01:00
Walter Lee
7c826d4b4e Revert "[lldb-dap] Use protocol types for exceptioninfo" (#164631)
Reverts llvm/llvm-project#164318

2 failures from LLVM Buildbot.
2025-10-22 14:26:02 +00:00
Ebuka Ezike
b8062f85dd [lldb-dap] Use protocol types for exceptioninfo (#164318)
It also separates the `ProtocolRequestsTests` from `ProtocolTypesTests`
as I did not want to increase the work in
https://github.com/llvm/llvm-project/pull/144595
2025-10-22 12:44:42 +01:00
John Harrison
e29d4ebb89 [lldb-dap] Correct lldb-dap seq handling. (#164306)
We've been treating the `seq` attribute incorrectly in lldb-dap.
Previously, we always had `seq=0` for events and responses. We only
filled in the `seq` field on reverse requests.

However, looking at the spec and other DAP implementations, we are
supposed to fill in the `seq` field for each request we send to the DAP
client.

I've updated our usage to fill in `seq` in `DAP::Send` so that all
events/requests/responses have a properly filled `seq` value.
2025-10-21 15:21:27 -07:00
John Harrison
841e1e1e17 [lldb-dap] Send a 'process' event on restart. (#163833)
When we restart a process, send an updated 'process' event describing
the newly launched process.

I also updated the `isLocalProcess` value based on if we're on the
'host' platform or not.
2025-10-21 14:47:12 -07:00
Ebuka Ezike
dc718313ec [lldb-dap] use workspaceFolder in vscode configurations. (#164320)
`workspaceRoot` was deprecated in [september 2017
release](https://code.visualstudio.com/updates/v1_17#_workspacefolder-in-launchjson-and-tasksjson)
2025-10-20 23:02:23 +01:00
Ebuka Ezike
cd67ca2f11 [lldb-dap] Send an Invalidated event on thread stack change. (#163976)
When the user send `thread return <expr>` command this changes the stack
length but the UI does not update.
Send stack invalidated event to the client to update the stack.
2025-10-20 21:54:13 +01:00
Felipe de Azevedo Piovezan
9e9d67dc9c [debugserver][NFC] Fix unused variable warning
This variable is only read from.
2025-10-20 13:46:56 -07:00
Ebuka Ezike
4a5dbd5633 [lldb-dap][NFC] avoid copy in launch process (#164243) 2025-10-20 15:49:39 +01:00
John Harrison
db530bf7aa [lldb-dap] Improve the runInTerminal ux. (#163830)
This updates lldb-dap to clear the screen when using `"console":
"integratedTerminal"` or `"console": "externalTerminal"`.

VSCode will reuse the same terminal for a given debug configuration.
After the process exits it will return to the shell but if the debug
session is launched again it will be invoked in the same terminal.
VSCode is sending the terminal the launch args as terminal input which
means the terminal would now have a string like `lldb-dap --comm-file
... --launch-target ...` and the scrollback buffer from any previous
output or shell commands used in the terminal.

To address this, I've updated LaunchRunInTerminalTarget to reset the
cursor, clear the screen and clear the scrollback buffer to soft 'reset'
the terminal prior to launching the process.

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-10-16 13:28:09 -07:00
Sergei Druzhkov
441587af3f [lldb-dap] Add stdio redirection for integrated and external terminals (#161089)
This patch extends stdio redirection support to integrated and external
terminals. Currently, these cases are not covered by the standard logic
because `attach` is used instead of `launch`. To be honest,
`runInTerminal` in
[VSCode](https://github.com/microsoft/vscode/blob/main/src/vs/workbench/contrib/debug/node/terminals.ts#L188)
request supports `>` and `<` for redirection, but not `2>`. We could use
the `argsCanBeInterpretedByShell` option to use full power of shell,
however it requieres proper escaping of arguments on lldb-dap side. So,
I think it will be better to have the only one option to control stdio
redirection that works consistently across all console modes.

Also, fixed a small typo in a comparison that was leading to
out-of-bound access, and added `null` as a possible value for `stdio`
array in package.json.
2025-10-16 00:24:42 +03:00
Sergei Druzhkov
995eb4ca2e [lldb-dap] Add readOnly attribute for variables (#151884)
This patch adds `readOnly`
[attribute](https://microsoft.github.io/debug-adapter-protocol/specification#Types_VariablePresentationHint)
for variables. When this attribute is returned for a variable, VS Code
prevents editing (and grays out the `Set Value` button). Without this,
users might be confused if the UI allows edits but the debug adapter
often returns an error. I checked `SetValueFromCString` function
implementation and found that it doesn't support aggregate data types,
so I added simple check for them. Also, I found that I can update value
of registers sets (but without any effects). So I also added checks for
those as well.
2025-10-15 23:46:07 +03:00