2516 Commits

Author SHA1 Message Date
Alexandre Ganea
715c61e9a7 [lldb][lldbp-dap] On Windoows, silence warnings when building with MSVC
Fixes:
```
[6373/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\DAP.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\DAP.cpp(725) : warning C4715: '`lldb_dap::DAP::HandleObject'::`30'::<lambda_2>::operator()': not all control paths return a value
[6421/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Protocol\ProtocolTypes.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(203) : warning C4715: 'lldb_dap::protocol::ToString': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(98) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(72) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolTypes.cpp(111) : warning C4715: 'lldb_dap::protocol::toJSON': not all control paths return a value
[6426/7138] Building CXX object tools\lldb\tools\lldb-dap\CMakeFiles\lldb-dap.dir\Protocol\ProtocolBase.cpp.obj
C:\git\llvm-project\lldb\tools\lldb-dap\Protocol\ProtocolBase.cpp(287) : warning C4715: 'lldb_dap::protocol::fromJSON': not all control paths return a value
```
2025-04-11 17:50:15 -04:00
Jonas Devlieghere
6493345c5a
[lldb] Handle signals in a separate thread in the driver (#134956)
Handle signals in a separate thread in the driver so that we can stop
worrying about signal safety of functions in libLLDB that may get called
from a signal handler.
2025-04-10 11:04:05 -07:00
Dmitry Vasilyev
7e70d708a3
[LLDB][NFC] Remove Debugger dependency in SystemLifetimeManager (#134383)
It reduces the memory usage in lldb-server.
2025-04-08 22:24:59 +04:00
Jason Molenda
df28c81f5a [lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)
debugserver takes the address of a watchpoint exception and calculates
which watchpoint was responsible for it. There was an off-by-one error
in the range calculation which causes two watchpoints on consecutive
ranges to not correctly identify hits to the second watchpoint. The
result is that lldb wouldn't show the second watchpoint as ever being
hit.

Re-landing this test with a modification to only require two
watchpoints in the test, instead of four.  If four watchpoints can
be set, it will test them.

rdar://145107575
2025-04-07 13:50:31 -07:00
Jason Molenda
369c7739d0 Revert "[lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)"
This reverts commit 21d912121c9f41385b165a736be787527f5bd7c2.

Failure on the aarch64 ubuntu bot when setting the 4th watchpoint;
may be a hardware limitation on that bot.  I thought creating four
watchpoints would be generally safe, but I don't need to do that
for my test, will re-land without it.
2025-04-07 11:21:58 -07:00
Jason Molenda
21d912121c
[lldb][debugserver] Fix an off-by-one error in watchpoint identification (#134314)
debugserver takes the address of a watchpoint exception and calculates
which watchpoint was responsible for it. There was an off-by-one error
in the range calculation which causes two watchpoints on consecutive
ranges to not correctly identify hits to the second watchpoint. The
result is that lldb wouldn't show the second watchpoint as ever being
hit.

rdar://145107575
2025-04-07 11:11:31 -07:00
Jason Molenda
f1c6612202 [lldb][debugserver] Save and restore the SVE/SME register state (#134184)
debugserver isn't saving and restoring the SVE/SME register state around
inferior function calls.

Making arbitrary function calls while in Streaming SVE mode is generally
a poor idea because a NEON instruction can be hit and crash the
expression execution, which is how I missed this, but they should be
handled correctly if the user knows it is safe to do.

Re-landing this change after fixing an incorrect behavior on systems
without SME support.

rdar://146886210
2025-04-03 15:48:54 -07:00
John Harrison
bc6cd825ec
[lldb-dap] Creating a common configuration structure for launch and attach requests. (#133960)
This moves all the common settings of the launch and attach operations
into the `lldb_dap::protocol::Configuration`. These common settings
can be in both `launch` and `attach` requests and allows us to isolate
the DAP configuration operations into a single common location.

This is split out from #133624.
2025-04-03 09:45:00 -07:00
Jonas Devlieghere
bec5cfd970
[lldb-dap] Protect SetBreakpoint with the API mutex (#134030)
Protect the various SetBreakpoint functions with the API mutex. This
fixes a race condition between the breakpoint being created and the DAP
label getting added. This was causing `TestDAP_breakpointEvents.py` to
be flaky.

Fixes #131242.
2025-04-03 09:08:23 -07:00
Jason Molenda
a19c018379 Revert "[lldb][debugserver] Save and restore the SVE/SME register state (#134184)"
This reverts commit 4e40c7c4bd66d98f529a807dbf410dc46444f4ca.

arm64 CI is getting a failure in
lldb-api.tools/lldb-server.TestGdbRemoteRegisterState.py
with this commit, need to investigate and re-land.
2025-04-02 23:01:51 -07:00
Jason Molenda
4e40c7c4bd
[lldb][debugserver] Save and restore the SVE/SME register state (#134184)
debugserver isn't saving and restoring the SVE/SME register state around
inferior function calls.

Making arbitrary function calls while in Streaming SVE mode is generally
a poor idea because a NEON instruction can be hit and crash the
expression execution, which is how I missed this, but they should be
handled correctly if the user knows it is safe to do.

rdar://146886210
2025-04-02 20:37:07 -07:00
Jonas Devlieghere
18c43d01fc
[lldb-dap] Add a -v/--version command line argument (#134114)
Add a -v/--version command line argument to print the version of both
the lldb-dap binary and the liblldb it's linked against.

This is motivated by me trying to figure out which lldb-dap I had in my
PATH.
2025-04-02 18:40:37 -07:00
Doeke Wartena
a03fce4e20
Update README.md - fixed invalid json in example (#133890)
A period (`,`) is required or you get an error.
2025-04-01 08:49:36 -07:00
David Spickett
7581cb68f9
[lldb] Remove lldb-server min and max gdbserver port options (#133275)
Since lldb 20, these have had no effect:
https://releases.llvm.org/20.1.0/docs/ReleaseNotes.html#changes-to-lldb

> lldb-server now listens to a single port for gdbserver connections and
> provides that port to the connection handler processes. This means
that
> only 2 ports need to be opened in the firewall (one for the
lldb-server
> platform, one for gdbserver connections). In addition, due to this
work,
lldb-server now works on Windows in the server mode.

Remove them.
2025-04-01 10:05:11 +01:00
Jonas Devlieghere
46457ed1df
[lldb] Convert Breakpoint & Watchpoints structs to classes (NFC) (#133780)
Convert Breakpoint & Watchpoints structs to classes to provide proper
access control. This is in preparation for adopting SBMutex to protect
the underlying SBBreakpoint and SBWatchpoint.
2025-03-31 16:04:31 -07:00
John Harrison
4492632432
[lldb-dap] Do not take ownership of stdin. (#133811)
There isn't any benefit to taking ownership of stdin and it may cause
issues if `Transport` is dealloced.
2025-03-31 15:51:07 -07:00
Jonas Devlieghere
0bdc9e6d08
[lldb-dap] Replace GetBreakpointLabel with kDAPBreakpointLabel constant (NFC) (#133746)
Replace GetBreakpointLabel with kDAPBreakpointLabel constant to avoid an
unnecessary function call.
2025-03-31 11:46:23 -07:00
Yuval Deutscher
945c494e2c
[lldb] Use correct path for lldb-server executable (#131519)
Hey,

This solves an issue where running lldb-server-20 with a non-absolute
path (for example, when it's installed into `/usr/bin` and the user runs
it as `lldb-server-20 ...` and not `/usr/bin/lldb-server-20 ...`) fails
with `error: spawn_process failed: execve failed: No such file or
directory`. The underlying issue is that when run that way, it attempts
to execute a binary named `lldb-server-20` from its current directory.
This is also a mild security hazard because lldb-server is often being
run as root in the directory /tmp, meaning that an unprivileged user can
create the file /tmp/lldb-server-20 and lldb-server will execute it as
root. (although, well, it's a debugging server we're talking about, so
that may not be a real concern)

I haven't previously contributed to this project; if you want me to
change anything in the code please don't hesitate to let me know.
2025-03-31 08:20:40 -07:00
John Harrison
5b6386dcbd
[lldb-dap] Swapping to not use FLAG_ENUM and just defining typed enums. (#133622)
Small tweak to the previous patch to make the enums in
`lldb_dap::protocol` typed to work with types like `llvm::DenseSet`
found by ubsan.
2025-03-30 16:42:49 -07:00
Kazu Hirata
b33cc642ed
[lldb] Use *Set::insert_range and a range constructor (NFC) (#133548)
This patch uses *Set::insert_range and a range constructor of DenseSet
to clean up the code to populate sets.
2025-03-28 19:54:30 -07:00
John Harrison
539ef5eee2
[lldb-dap] Addressing ubsan enum usage. (#133542)
Running tests with ubsan enabled showed that the current
`protocol::AdapterFeature` and `protocol::ClientFeature` enums are
incorrectly defined if we want to use them in a `llvm::DenseSet`. The
enums are currently untyped and this results in the undefined behavior.

Adding `FLAGS_ENUM()` wrappers to all the enums in the
`lldb-dap::protocol` namespace to ensure they're typed so they can be
used with types like `llvm::DenseSet`.
2025-03-28 20:35:19 -05:00
Jonas Devlieghere
812efdb094
[lldb-dap] Bump the version to 0.2.11 2025-03-28 13:20:37 -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
Matthew Bastien
0d4f12ee00
[lldb-dap] Allow providing debug adapter arguments in the extension (#129262)
Added a new setting called `lldb-dap.arguments` and a debug
configuration attribute called `debugAdapterArgs` that can be used to
set the arguments used to launch the debug adapter. Right now this is
mostly useful for debugging purposes to add the `--wait-for-debugger`
option to lldb-dap.

Additionally, the extension will now check for a changed lldb-dap
executable or arguments when launching a debug session in server mode. I
had to add a new `DebugConfigurationProvider` to do this because VSCode
will show an unhelpful error modal when the
`DebugAdapterDescriptorFactory` returns `undefined`.

In order to facilitate this, I had to add two new properties to the
launch configuration that are used by the
`DebugAdapterDescriptorFactory` to tell VS Code how to launch the debug
adapter:

- `debugAdapterHostname` - the hostname for an existing lldb-dap server
- `debugAdapterPort` - the port for an existing lldb-dap server

I've also removed the check for the `executable` argument in
`LLDBDapDescriptorFactory.createDebugAdapterDescriptor()`. This argument
is only set by VS Code when the debug adapter executable properties are
set in the `package.json`. The LLDB DAP extension does not currently do
this (and I don't think it ever will). So, this makes the debug adapter
descriptor factory a little easier to read.

The check for whether or not `lldb-dap` exists has been moved into the
new `DebugConfigurationProvider` as well. This way the extension won't
get in the user's way unless they actually try to start a debugging
session. The error will show up as a modal which will also make it more
obvious when something goes wrong, rather than popping up as a warning
at the bottom right of the screen.
2025-03-27 14:09:09 -07:00
Michael Buch
52de49e4b9
[lldb][debugserver][MacOSX] Work around sanitizer misaligned address errors when reading exception data (#132193)
We've been dealing with UBSAN issues around this code for some time now
(see `9c36859b33b386fbfa9599646de1e2ae01158180` and
`1a2122e9e9d1d495fdf337a4a9445b61ca56df6f`). On recent macOS versions, a
UBSAN-enabled debugserver will crash when performing a `memcpy` of the
input `mach_exception_data_t`. The pointer to the beginning of the
exception data may not be aligned on a doubleword boundary, leading to
UBSAN failures such as:
```
$ ./bin/debugserver 0.0.0.0:5555 /Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/build-sanitized-release/tools/lldb/test/Shell/Recognizer/Output/verbose_trap.test.tmp.out
/Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/lldb/tools/debugserver/source/MacOSX/MachException.cpp:35:12: runtime error: store to misaligned address 0x00016ddfa634 for type 'mach_exception_data_type_t *' (aka 'long long *'), which requires 8 byte alignment
0x00016ddfa634: note: pointer points here
  02 00 00 00 03 00 01 00  00 00 00 00 11 00 00 00  00 00 00 00 00 00 00 00  08 00 00 00 00 00 00 00
              ^
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /Volumes/SSD/llvm-builds/llvm-worktrees/clang-work/lldb/tools/debugserver/source/MacOSX/MachException.cpp:35:12
```

Work around these failures by pretending the input data is a `char*`
buffer.

Drive-by changes:
* I factored out some duplicated code into a static
`AppendExceptionData` and made the types consistent

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-21 11:21:29 +00:00
John Harrison
30bb0c443e
[lldb-dap] Adding a DAPError for showing users error messages. (#132255)
The `DAPError` can be used to craft an error message that is displayed
to a user (with showUser=true).

Any request handler implementation using subclassing `RequestHandler<>`
should be able to use this.

I updated SourceRequestHandler to report DAPError's specifically.
2025-03-20 15:33:05 -07:00
Jason Molenda
ad5cac3b06
[lldb][debugserver] remove g/G packet handling from debugserver (#132127)
In 2013 we added the QSaveRegisterState and QRestoreRegisterState
packets to checkpoint a thread's register state while executing an
inferior function call, instead of using the g packet to read all
registers into lldb, then the G packet to set them again after the func
call.

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

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

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

This does mean that a debugger using debugserver on darwin which doesn't
use QSaveRegisterState/QRestoreRegisterState will need to fall back to
reading & writing each register individually. I'm open to re-evaluating
this decision if this proves to be needed, and supporting these lldb
extensions is onerous.
2025-03-20 13:32:52 -07:00
Jason Molenda
e60e064158
[lldb][debugserver] Interrupt should reset outstanding SIGSTOP (#132128)
This fixes an uncommon bug with debugserver controlling an inferior
process that is hitting an internal breakpoint & continuing when
multiple interrupts are sent by SB API to lldb -- with the result being
that lldb never stops the inferior process, ignoring the interrupt/stops
being sent by the driver layer (Xcode, in this case).

In the reproducing setup (which required a machine with unique timing
characteristics), lldb is sent SBProcess::Stop and then shortly after,
SBProcess::SendAsyncInterrupt. The driver process only sees that the
inferior is publicly running at this point, even though it's hitting an
internal breakpoint (new dylib being loaded), disabling the bp, step
instructioning, re-enabling the breakpoint, then continuing.

The packet sequence lldb sends to debugserver looks like

1. vCont;s   // instruction step
2. ^c        // async interrupt
3. Z....     // re-enable breakpoint
4. c         // resume inferior execution
5. ^c        // async interrupt

When debugserver needs to interrupt a running process
(`MachProcess::Interrupt`), the main thread in debugserver sends a
SIGSTOP posix signal to the inferior process, and notes that it has sent
this signal by setting `m_sent_interrupt_signo`.

When we send the first async interrupt while instruction stepping, the
signal is sent (probably after the inferior has already stopped) but
lldb can only *receive* the mach exception that includes the SIGSTOP
when the process is running. So at the point of step (3), we have a
SIGSTOP outstanding in the kernel, and
`m_sent_interrupt_signo` is set to SIGSTOP.

When we resume the inferior (`c` in step 4), debugserver sees that
`m_sent_interrupt_signo` is still set for an outstanding SIGSTOP, but at
this point we've already stopped so it's an unnecessary stop. It records
that (1) we've got a SIGSTOP still coming that debugserver sent and (2)
we should ignore it by also setting `m_auto_resume_signo` to the same
signal value.

Once we've resumed the process, the mach exception thread
(`MachTask::ExceptionThread`) receives the outstanding mach exception,
adds it to a queue to be processed
(`MachProcess::ExceptionMessageReceived`) and when we've collected all
outstanding mach exceptions, it calls
`MachProcess::ExceptionMessageBundleComplete` top evaluate them.

`MachProcess::ExceptionMessageBundleComplete` halts the process (without
updating the MachProcess `m_state`) while evaluating them. It sees that
this incoming SIGSTOP was meant to be ignored (`m_auto_resume_signo` is
set), so it `MachProcess::PrivateResume`'s the process again.

At the same time `MachTask::ExceptionThread` is receiving and processing
the ME, `MachProcess::Interrupt` is called with another interrupt that
debugserver received. This method checks that we're still eStateRunning
(we are) but then sees that we have an outstanding SIGSTOP already
(`m_sent_interrupt_signo`) and does nothing, assuming that we will stop
shortly from that one. It then returns to call
`RNBRemote::HandlePacket_last_signal` to print the status -- but because
the process is still `eStateRunning`, this does nothing.

So the first ^c (resulting in a pending SIGSTOP) is received and we
resume the process silently. And the second ^c is ignored because we've
got one interrupt already being processed.

The fix was very simple. In `MachProcess::Interrupt` when we detect that
we have a SIGSTOP out in the wild (`m_sent_interrupt_signo`), we need to
clear `m_auto_resume_signo` which is used to indicate that this SIGSTOP
is meant to be ignored, because it was from before our most recent
resume.

MachProcess::Interrupt holds the `m_exception_and_signal_mutex` mutex
already (after Jonas's commit last week), and all of
`MachProcess::ExceptionMessageBundleComplete` holds that same mutex, so
we know we can modify `m_auto_resume_signo` here and it will be handled
correctly when the outstanding mach exception is finally processed.

rdar://145872120
2025-03-20 13:31:46 -07:00
Jonas Devlieghere
2e5a751ee9
[lldb-dap] Stop linking explicitly against pthread (#132111)
I can't figure out why this would be necessary. Nothing is checking if
libpthread is available, nothing in lldb-dap is relying on libpthread
directly and nothing else in LLDB is doing this.
2025-03-19 15:59:56 -07:00
John Harrison
7af0bfe62f
[lldb-dap] Ensure logging statements are written as a single chunk. (#131916)
I noticed this while debugging some unit tests that the logs
occasionally would intersperse two log statements.

Previously, it was possible for a log statement to have two messages
interspersed since the timestamp and log statement were two different
writes to the log stream.

I created a Log helper to ensure we have a lock while attempting to write
to the logs.
2025-03-19 09:16:53 -07:00
Jonas Devlieghere
1028ea9e26
[lldb-dap] RequestHandler::getCommand -> RequestHandler::GetCommand (NFC)
Chang the capitalization of getCommand to comply with LLDB's code style.
2025-03-18 19:59:33 -07:00
Jonas Devlieghere
4088557278
[lldb-dap] Move request capabilities into request handlers (NFC) (#131943)
This distributes the registration of request related capabilities to the
corresponding request handler. Global and unsupported capabilities are
registered at the DAP level.
2025-03-18 19:56:04 -07:00
John Harrison
fbb8929c9d
[lldb-dap] Updating RequestHandler to encode/decode arguments and response. (#130090)
This is a work in progress refactor to add explicit types instead of
generic 'llvm::json::Value' types to the DAP protocol.

This updates RequestHandler to have take the type of the arguments and
response body for serialization for requests.

The 'source' and 'disconnect' request is updated to show how the new
flow
works and includes serialization handling for optional arguments and
'void'
responses.

This is built on top of #130026

---------

Co-authored-by: Adrian Vogelsgesang <adrian.vogelsgesang@tum.de>
2025-03-17 10:13:11 -07:00
Pavel Labath
1b237198dc
Reapply "[lldb] Implement basic support for reverse-continue (#125242)" (again) (#128156)
This reverts commit
87b7f63a11,
reapplying

7e66cf74fb
with a small (and probably temporary)
change to generate more debug info to help with diagnosing buildbot
issues.
2025-03-17 16:06:25 +01:00
Ebuka Ezike
3af6c9fa83
[lldb][lldb-dap][NFC] Fix swapped logging directions for DAP messages. (#131544)
The logging markers for incoming ("<--") and outgoing ("-->") messages
were incorrectly reversed. from #7790d69
2025-03-17 07:58:55 +00:00
Ebuka Ezike
125c4db730
[lldb][lldb-dap] setVariable request should send the correct response (#130773)
The display value was incorrectly sent as "result" instead of "value".
2025-03-16 23:28:25 +00:00
Jonas Devlieghere
b4f5dcc65a
[lldb-dap] Reword the description in package.json
Match the description of the Visual Studio Code extension with the
wording used by popular/official extensions. Most extension spell out
"Visual Studio Code" and use "in" instead of "from".
2025-03-14 16:49:06 -07:00
Ebuka Ezike
217fc6579b
[lldb][lldb-dap] Return optional from json utils (#129919)
Completion of #129818 

Did not want to put `llvm::StringRef()` as the default value instead it
was `""`
2025-03-14 10:17:18 -07:00
Dhruv Srivastava
ec95ce358c
[lldb][AIX] Added base files for NativeProcess Support for AIX (#118160)
This PR is in reference to porting LLDB on AIX.

Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

Added base files for NativeProcess Support for AIX. 
Will be adding further support in consequent incremental PR.
2025-03-14 16:52:41 +05:30
Adrian Vogelsgesang
8b9031f245
[lldb-dap] Support vscode launch URLs (#125843)
This commit adds support for starting debug sessions through special
`vscode://llvm-vs-code-extensions.lldb-dap/start?config={launch-config}`
URIs. This allows tighter integration with custom scripts. One potential
use case is providing similar functionality to `xcdebug`, see #125777
for some discussion on that use case.

The functionality was inspired by @vadimcn's CodeLLDB extension, which
[provides similar
functionality](https://github.com/vadimcn/codelldb/blob/master/MANUAL.md#debugging-externally-launched-code).
2025-03-13 23:49:05 +01:00
Jonas Devlieghere
998511c8ef
[debugserver] Fix mutex scope in RNBRemote::CommDataReceived (#131077)
The mutex in RNBRemote::CommDataReceived protects m_rx_packets and
should extend to the end of the function to cover the read where we
check if the list is empty.
2025-03-13 15:12:19 -07:00
Jonas Devlieghere
e823449f66
[lldb][debugserver] Synchronize interrupt and resume signals (#131073)
This PR fixes a race condition in debugserver where the main thread
calls MachProcess::Interrupt, setting `m_sent_interrupt_signo` while the
exception monitoring thread is checking the value of the variable.

I was on the fence between introducing a new mutex and reusing the
existing exception mutex. With the notable exception of
MachProcess::Interrupt, all the other places where we were already
locking this mutex before accessing the variable. I renamed the mutex to
make it clear that it's now protecting more than the exception messages.

Jason, while investigating a real issue, had a suspicion there was race
condition related to interrupts and I was able to narrow it down by
building debugserver with TSan.
2025-03-13 13:54:13 -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
John Harrison
f62e168d3f
[lldb-dap] Validate server mode support prior to invoking lldb-dap. (#130855)
This should ensure the extension only uses server mode if the binary
supports the feature, otherwise it will fallback to the existing
behavior.

Fixes #130854
2025-03-12 10:43:09 -07:00
John Harrison
f1598367b6
[lldb-dap] Adding logging helpers. (#130653)
Improving logging by defining new helpers for more uniform log handling.
This should help us clearly identify log messages and helps abstract the
underlying log type within the macro in case we want to update the log
handler in the future.
2025-03-11 09:36:48 -07:00
John Harrison
414e5c58cb
[lldb-dap] Migrating terminated statistics to the event body. (#130454)
Per the DAP spec, the event 'body' field should contain any additional
data related to the event. I updated the lldb-dap 'statistics' extension
into the terminated event's body like:

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

This allows us to more uniformly handle event messages.
2025-03-10 10:00:10 -07:00
John Harrison
2894719314
[lldb-dap] Updating naming and documentation to follow style guide. (#130202)
Updating the naming and adding documentation to better follow the style
guide.
2025-03-07 06:42:26 +01:00
John Harrison
e415721858
[lldb-dap] Correct the variable name from a half finished merge. (#130186) 2025-03-06 14:15:30 -08:00
John Harrison
27c788de75
[lldb-dap] Restore the override FD used by the output redirect on stop. (#129964)
While running lldb-dap over stdin/stdout the `stdout` and `stderr` FD's
are replaced with a pipe that is reading the output to forward to the
dap client. During shutdown we were not properly restoring those FDs,
which means if any component attempted to write to stderr it would
trigger a SIGPIPE due to the pipe being closed during the shutdown
process. This can happen if we have an error reported from the
`DAP::Loop` call that would then log to stderr, such as an error parsing
a malformed DAP message or if lldb-dap crashed and it was trying to
write the stack trace to stderr.

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

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

---------

Co-authored-by: Jonas Devlieghere <jonas@devlieghere.com>
2025-03-06 13:57:06 -08:00
Jonas Devlieghere
b5e70d0682
[lldb-dap] Use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER (#129948)
Consistently use LLDB_INVALID_LINE_NUMBER & LLDB_INVALID_COLUMN_NUMBER
when parsing line and column numbers respectively.
2025-03-05 16:19:36 -08:00