Repository navigation
Description
LSP4IJ's Attach debug mode never starts the debug adapter, so an adapter which talks DAP only over its standard input and output cannot attach to anything from LSP4IJ. Found while writing the GDB and netcoredbg templates of #2336.
How the two modes work today
Launchstarts the command of the DAP server, talks to it over its standard input and output (or over${port}, or the port its log pattern gives), and sends alaunchrequest.Attachstarts no process:DebugAdapterDescriptor.startServer(DebugMode.ATTACH)returns aNopProcessHandler. The client connects to the address and port ofgetServerReadyConfig(DebugMode.ATTACH), from theAttachtab or the template'sattach($port,$connect.host), and sends anattachrequest.
DAPClient sends launch or attach from the debug mode alone. So the attach request reaches only a debug adapter which already listens on a port.
That suits debugpy, whose debuggee listens itself, and the adapters that have a socket mode. But many adapters do the attaching themselves: they get an attach request with a process id, a remote target or a node, from a client which started them over stdio. That combination has no way in.
Adapters it affects
| Adapter | Template | Its attach |
With LSP4IJ today |
|---|---|---|---|
GDB, gdb -i dap |
gdb (#2336) |
pid, or target for a gdbserver |
not possible: GDB's adapter has no socket mode, so the template has only a launch configuration |
edb, edb dap |
erlang-edb |
a running node | not possible, as its page says |
| netcoredbg | netcoredbg (#2336) |
processId |
possible only by starting netcoredbg --interpreter=vscode --server=4711 yourself; LSP4IJ then connects to 4711. Checked live on macOS |
| perl-dap | perl-dap |
Attach by PID, Attach by TCP |
possible only by starting perl-dap --socket --port 13603 yourself, as its DAP user guide says. The template has no attach port, and LSP4IJ's Perl page doesn't say this. Not checked live |
The hook exists for plugins: DebugAdapterDescriptor.startServer(DebugMode) says a descriptor whose adapter is reached through its process can override it to start the process for an attach too. A user-defined DAP server, and so every template, has no such option.
Proposal
Let a DAP server start its command for Attach too, as an opt-in, so that existing attach configurations which connect to a listening debuggee or adapter (debugpy, swift-lldb, VSCode JS Debug, and perl-dap's socket mode) keep working as they do:
- a setting of the DAP server, in the
Servertab, and a template key, for example"attach": {"startServer": true}; - with it,
Attachstarts the command asLaunchdoes, connects in the same way, and sends the configuration's JSON as anattachrequest; - then the GDB template gets
Attach to a process(pid) andAttach to a gdbserver(target), and edb its attach to a node. The netcoredbg and perl-dap templates can attach without a hand-started adapter.
Each would need a live check with its adapter, as #2336 did for the launch configurations.
Activity
feat: an attach can start the debug adapter, as a launch does, for a …
feat: the edb template attaches to a running node
fix: the attach configurations of the perl-dap template start perl-da…