Skip to content

DAP: let Attach start the debug adapter, for adapters that talk only over stdio (GDB, edb) #2337

Done

Description

@lagergren

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

  • Launch starts 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 a launch request.
  • Attach starts no process: DebugAdapterDescriptor.startServer(DebugMode.ATTACH) returns a NopProcessHandler. The client connects to the address and port of getServerReadyConfig(DebugMode.ATTACH), from the Attach tab or the template's attach ($port, $connect.host), and sends an attach request.

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 Server tab, and a template key, for example "attach": {"startServer": true};
  • with it, Attach starts the command as Launch does, connects in the same way, and sends the configuration's JSON as an attach request;
  • then the GDB template gets Attach to a process (pid) and Attach 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dapenhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions