Skip to content

feat: an attach can start the debug adapter, for GDB, edb, netcoredbg and perl-dap - #2375

Merged
lagergren merged 4 commits into
redhat-developer:mainfrom
lagergren:feat/dap-attach-starts-the-server
Nov 30, 2026
Merged

lagergren merged 4 commits into
redhat-developer:mainfrom
lagergren:feat/dap-attach-starts-the-server

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2337.

The Attach debug mode started no process: it connected to a debug adapter that was already running, at the address and port of the Attach tab. GDB's, edb's, netcoredbg's and perl-dap's debug adapters talk DAP only over their standard input and output, and attach to the program themselves. So, from LSP4IJ, they could attach to nothing, or only to a copy that the user had started on a port.

What changes

  • Attach tab: a new checkbox, Start the debug adapter, and send it the attach request, makes an attach start the Command of the Server tab, connect to it as a launch does, and send it the attach request. The Address and Port fields are disabled while it is checked. Stopping the session ends the debug adapter's process. LSP4IJ disconnects without asking the adapter to terminate the program.
  • Templates: a template sets it with "attach": {"startServer": true}. It's off by default, so every existing attach configuration keeps connecting as before.
  • Where the setting lives: it is kept like the attach address and port: in the run configuration, in the user-defined server's settings, and in the template.
  • Templates that now attach:
    • GDB: Attach to a process (pid) and Attach to a gdbserver (target, with program from the File field).
    • edb: Attach to node mynode@localhost, as edb's README gives it.
    • netcoredbg: Attach to a .NET process now starts netcoredbg. Its $port stays, for a netcoredbg that the user starts with --server and connects to once the setting is unchecked.
    • perl-dap: Attach by PID and Attach by TCP now start perl-dap. Attach by TCP takes 127.0.0.1 instead of localhost, which perl-dap 0.17.0 refuses with "invalid socket address syntax". So that configuration never worked.
  • Docs: an Attach section in the DAP user guide, the template field, and the attach sections of the GDB, edb, netcoredbg and perl-dap pages.

There are four commits, one change each, so that each gets its own line in the release notes: please rebase-merge.

Behaviour changes

Before After
An attach never started the debug adapter It does when Start the debug adapter, and send it the attach request is checked, which the GDB, edb, netcoredbg and perl-dap templates do
The GDB and edb templates had no attach configuration They have one, and the edb page no longer says that attaching is impossible
netcoredbg's and perl-dap's attach configurations needed a debug adapter that the user started on a port They start the debug adapter. Unchecking the setting brings the old behaviour back
perl-dap's Attach by TCP sent "host": "localhost" It sends 127.0.0.1

Live checks

Each debug adapter was started over its standard input and output, as an attach with the setting starts it. Each got initialize and the template's attach configuration, then configurationDone, threads and disconnect:

Debug adapter Attached to Result
GDB 15.1 (gdb -i dap, Ubuntu 24.04 container) a running sleep, by pid attached, stopped with reason attach, its thread listed; after disconnect the process kept running
GDB 15.1 a gdbserver :1234 /usr/bin/sleep, by target attached, its thread listed
edb 1.0.0 (Erlang/OTP 29) a node started with erl -sname mynode@localhost -setcookie mycookie +D attached and paused it, its processes listed; after disconnect the node kept running
netcoredbg 3.2.0 (macOS arm64) a running .NET 11 console program, by processId attached, its 3 threads listed; after disconnect the program kept running
perl-dap 0.17.0 (macOS arm64) a running Perl script, by processId attached (signal-control mode), stopped with reason attach
perl-dap 0.17.0 Attach by TCP, nothing listening localhost fails with "invalid socket address syntax", 127.0.0.1 with "Failed to connect", as expected

Tests

  • DAPAttachStartsTheDebugAdapterSessionTest: a real debug session whose attach starts a small DAP adapter as a process of its own, over stdio (StdioAttachAdapter). The adapter gets attach {processId=4242} and no launch, and stopping the session ends its process.
  • DAPCommandLineStateTest, DebugAdapterDescriptorTest, DAPRunConfigurationCheckTest:
    • an attach with the setting starts the debug adapter;
    • it connects as a launch does, not at the attach port;
    • it needs no port.
  • DebugAdapterManagerAttachSettingsTest: the setting is kept in the server definition and its settings, and a change of it is a change of the server.
  • AttachStartServerTemplatesTest, BundledDebugAdapterTemplatesTest: the GDB, edb, netcoredbg and perl-dap templates start the debug adapter, with their attach configurations. go-delve, python-debugpy and vscode-js-debug don't.
  • Whole suite: 2,799 tests, 0 failures, 7 skipped.

…debug adapter that attaches to the program itself

The Attach debug mode started no process: it connected to a debug adapter
which runs, at the address and port of the Attach tab. So a debug adapter
that talks DAP only over its standard input and output, and attaches to the
program itself, as GDB's, edb's, netcoredbg's and perl-dap's do, could
attach to nothing from LSP4IJ.

"Start the debug adapter, and send it the attach request", in the Attach
tab, makes an attach start the command of the Server tab, connect to it as a
launch does, and send it the attach request. The Address and the Port don't
apply then, and stopping the session ends the debug adapter's process. A
template sets it with "attach": {"startServer": true}. It is off by default,
so an attach which connects to a debug adapter keeps doing so.

Part of redhat-developer#2337
The template's "Attach to node mynode@localhost" configuration, as edb's
README gives it, starts edb, which attaches to a node started with +D, and
pauses it. Stopping the session detaches edb, and the node keeps running.

Part of redhat-developer#2337
…p, and its TCP attach takes an IP address

"Attach by PID" and "Attach by TCP" are attach requests that perl-dap
handles itself, so they now start perl-dap, instead of connecting to a
perl-dap that the user started with --socket. perl-dap 0.17.0 refuses the
host "localhost" of "Attach by TCP" ("invalid socket address syntax"), so
that configuration never worked: it takes 127.0.0.1.

Part of redhat-developer#2337
…he netcoredbg template's attach starts netcoredbg

GDB's debug adapter attaches itself, to a process by its pid or to a
gdbserver by its target: the template's "Attach to a process" and "Attach
to a gdbserver" start gdb -i dap and send it the attach request. Unlike
launch, attach works with GDB 15 too. netcoredbg's "Attach to a .NET
process" now starts netcoredbg too, instead of connecting to one that the
user started with --server, which it still does once the setting is
unchecked.

Fixes redhat-developer#2337
@lagergren lagergren added this to the 0.30.3 milestone Nov 30, 2026
@lagergren lagergren added enhancement New feature or request dap Debugging Adapter Protocol labels Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • Attach configurations can now start the debug adapter and send an attach request, or connect to an already-running adapter. The settings interface clarifies these options and adjusts address and port fields accordingly.
    • Added and updated attach configurations for Erlang, GDB, .NET, and Perl, including process, node, and server connection workflows.
    • Stopping an attach session ends the adapter process without terminating the attached program.
  • Documentation
    • Updated the DAP guide and adapter-specific guides with attach setup and session behavior.

Attach configurations can now start the configured DAP server command and send an attach request. The new option is carried through run configurations, templates, and user-defined server settings. Bundled adapter templates and documentation are updated to describe supported attach workflows.

Changes: Attach Server Startup

Layer / File(s) Summary
Option model and server settings
src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/*, src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/options/AttachConfigurable.java, src/main/java/com/redhat/devtools/lsp4ij/dap/definitions/userdefined/*, src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterServerListener.java, src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/*, src/main/java/com/redhat/devtools/lsp4ij/dap/settings/*
The attach-start-server option is added to configuration and template models. The server settings UI loads and saves it, and user-defined server settings persist it and report changes.
Attach execution and readiness
src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterDescriptor.java, src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPCommandLineState.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/*, src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/*, src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterDescriptorTest.java
When configured to start the adapter, attach starts the server command and tracks readiness using launch-mode behavior. The attach address and port are not used in this mode. Tests verify attach requests reach the started adapter and that the process stops with the session.
Bundled adapter templates and guidance
src/main/resources/templates/dap/*, src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/*, docs/dap/UserGuide.md, docs/dap/user-defined-dap/*
GDB, edb, netcoredbg, and Perl templates gain attach configurations or start-server settings. Documentation describes these workflows and explains how to connect to an already-running server.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DAPCommandLineState
  participant DebugAdapterDescriptor
  participant DAPServerReadyTracker
  participant DAPClient
  participant DAPServer
  DAPCommandLineState->>DebugAdapterDescriptor: startServer(ATTACH)
  DebugAdapterDescriptor->>DAPServer: start configured adapter command
  DAPCommandLineState->>DAPServerReadyTracker: track readiness using LAUNCH mode
  DAPClient->>DAPServer: send attach request
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to e0de3

Attach can now optionally start the configured debug adapter and send it an attach request. The option is off by default, so existing attach setups behave as before. The review found no concrete defect, and the bundled GDB, edb, netcoredbg and perl-dap templates and their docs are consistent with the new behavior. The risk of merging is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "feat: an attach can start the debug adapter, for GDB, edb, netcoredbg and perl-dap" matches the main change: an opt-in Attach setting that starts the debug adapter, applied to the GDB, edb,…
Description check Passed The description relates directly to the changeset. It explains the new 'Start the debug adapter, and send it the attach request' checkbox, the template changes for GDB, edb, netcoredbg and perl-dap, t…
Linked Issues check Passed Directly linked issue #2337 has coding requirements. The PR meets them as follows, based on the whole-PR summary and the listed changes.

1. Opt-in setting in the Server tab and templates [#2337]: `De…
Out of Scope Changes check Passed Every changed area connects to #2337 or supports it.

- Core setting plumbing: DebugAdapterManager, UserDefinedDebugAdapterServerDefinition, UserDefinedDebugAdapterServerSettings, `DAPRunConfigu…
Full details: Title check

Explanation

The title "feat: an attach can start the debug adapter, for GDB, edb, netcoredbg and perl-dap" matches the main change: an opt-in Attach setting that starts the debug adapter, applied to the GDB, edb, netcoredbg and perl-dap templates. It is somewhat long at 82 characters, but it is specific and not misleading.

Full details: Description check

Explanation

The description relates directly to the changeset. It explains the new 'Start the debug adapter, and send it the attach request' checkbox, the template changes for GDB, edb, netcoredbg and perl-dap, the perl-dap 127.0.0.1 fix, the docs, and the tests. It references issue #2337 and includes live-check results.

Full details: Linked Issues check

Explanation

Directly linked issue #2337 has coding requirements. The PR meets them as follows, based on the whole-PR summary and the listed changes.

  1. Opt-in setting in the Server tab and templates [#2337]: DebugAdapterServerPanel adds a checkbox. DAPTemplate adds ATTACH_START_SERVER_PROPERTY. DAPTemplateDeserializer reads attach.startServer. The setting is stored in UserDefinedDebugAdapterServerDefinition, UserDefinedDebugAdapterServerSettings, DAPRunConfigurationOptions and DebugAdapterManager. Default is false.

  2. With the setting on, Attach starts the server command, connects as Launch does, and sends attach [#2337]: DebugAdapterDescriptor.isServerStartedForAttach() makes startServer(DebugMode.ATTACH) start the process. DAPCommandLineState passes DebugMode.LAUNCH to DAPServerReadyTracker in that case. getServerReadyConfig skips the attach address and port. DAPClient sends attach from the debug mode. Test DAPAttachStartsTheDebugAdapterSessionTest covers an attach over stdio with no launch request.

  3. Existing configurations unchanged when off [#2337]: the default is false. Tests in DebugAdapterDescriptorTest, DAPCommandLineStateTest and DAPRunConfigurationCheckTest cover the default path. AttachStartServerTemplatesTest checks that go-delve, python-debugpy and vscode-js-debug do not start a server.

  4. GDB pid and target attach configurations [#2337]: gdb/attach.pid.json and gdb/attach.gdbserver.json are added. gdb/template.json sets startServer: true. BundledDebugAdapterTemplatesTest checks them.

  5. edb attach to a running node [#2337]: erlang-edb/attach.node.json is added. erlang-edb/template.json sets startServer: true. AttachStartServerTemplatesTest.testTheEdbTemplateStartsEdbToAttachToANode() checks it.

  6. netcoredbg and perl-dap attach without a hand-started adapter [#2337]: both templates set startServer: true. The perl-dap TCP template uses 127.0.0.1. AttachStartServerTemplatesTest and BundledDebugAdapterTemplatesTest check these.

  7. Live checks [#2337]: the PR reports live checks for GDB 15.1, edb 1.0.0, netcoredbg 3.2.0 and perl-dap 0.17.0. These are manual checks and are not coding requirements. I did not reproduce them.

No concrete coding requirement of #2337 is unmet in the evidence reviewed.

Full details: Out of Scope Changes check

Explanation

Every changed area connects to #2337 or supports it.

  • Core setting plumbing: DebugAdapterManager, UserDefinedDebugAdapterServerDefinition, UserDefinedDebugAdapterServerSettings, DAPRunConfiguration, DAPRunConfigurationOptions, DAPSettingsEditor, AttachConfigurable, UserDefinedDebugAdapterDescriptorFactory, NewDebugAdapterServerDialog, DebugAdapterServerView, DebugAdapterServerListener. These carry the new flag through the server definition, run configuration and UI.
  • Attach startup logic: DebugAdapterDescriptor, DAPCommandLineState, and the attach-port validation change in DAPRunConfiguration. These implement the requested behavior.
  • Templates: GDB, edb, netcoredbg and perl-dap. Each change is an attach configuration or the startServer key the issue asks for. The perl-dap host change from localhost to 127.0.0.1 alters only the perl-dap TCP attach template. The PR states that perl-dap 0.17.0 rejects localhost. This change is part of the perl-dap attach work the issue names.
  • Messages: DAPBundle.properties adds labels for the new option.
  • Docs: the DAP user guide and the GDB, edb, netcoredbg and perl-dap pages describe the new attach behavior.
  • Tests: all added or changed tests cover the new setting, the attach path, or the templates.

I found no change that lacks a connection to #2337. The PR's note about rebase-merging and commit layout is a process note, not a code change.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8118eb87-2af5-43d0-a60a-08a1587490ee
Commits

Reviewing files that changed from the base of the PR and between febaf86 and e0de337.

Files selected for processing: 38

  • docs/dap/UserGuide.md
  • docs/dap/user-defined-dap/erlang-edb.md
  • docs/dap/user-defined-dap/gdb.md
  • docs/dap/user-defined-dap/netcoredbg.md
  • docs/dap/user-defined-dap/perl-dap.md
  • src/main/java/com/redhat/devtools/lsp4ij/dap/DebugAdapterManager.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPCommandLineState.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfiguration.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationOptions.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPSettingsEditor.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/configurations/options/AttachConfigurable.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/definitions/userdefined/UserDefinedDebugAdapterDescriptorFactory.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/definitions/userdefined/UserDefinedDebugAdapterServerDefinition.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterDescriptor.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterServerListener.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/DAPTemplate.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/DAPTemplateDeserializer.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/settings/UserDefinedDebugAdapterServerSettings.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/settings/ui/DebugAdapterServerPanel.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/settings/ui/DebugAdapterServerView.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/settings/ui/NewDebugAdapterServerDialog.java
  • src/main/resources/messages/DAPBundle.properties
  • src/main/resources/templates/dap/erlang-edb/attach.node.json
  • src/main/resources/templates/dap/erlang-edb/template.json
  • src/main/resources/templates/dap/gdb/attach.gdbserver.json
  • src/main/resources/templates/dap/gdb/attach.pid.json
  • src/main/resources/templates/dap/gdb/template.json
  • src/main/resources/templates/dap/netcoredbg/template.json
  • src/main/resources/templates/dap/perl-dap/attach.tcp.json
  • src/main/resources/templates/dap/perl-dap/template.json
  • src/test/java/com/redhat/devtools/lsp4ij/dap/DebugAdapterManagerAttachSettingsTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPAttachStartsTheDebugAdapterSessionTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/StdioAttachAdapter.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPCommandLineStateTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/configurations/DAPRunConfigurationCheckTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/DebugAdapterDescriptorTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/AttachStartServerTemplatesTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/descriptors/templates/BundledDebugAdapterTemplatesTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.12121% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.67%. Comparing base (febaf86) to head (e0de337).

Files with missing lines Patch % Lines
...lsp4ij/dap/settings/ui/DebugAdapterServerView.java 0.00% 6 Missing ⚠️
...edhat/devtools/lsp4ij/dap/DebugAdapterManager.java 57.14% 3 Missing ⚠️
...sp4ij/dap/settings/ui/DebugAdapterServerPanel.java 76.92% 3 Missing ⚠️
...j/dap/settings/ui/NewDebugAdapterServerDialog.java 0.00% 3 Missing ⚠️
...dap/configurations/options/AttachConfigurable.java 0.00% 2 Missing ⚠️
...lsp4ij/dap/descriptors/DebugAdapterDescriptor.java 33.33% 0 Missing and 2 partials ⚠️
...lsp4ij/dap/configurations/DAPRunConfiguration.java 80.00% 1 Missing ⚠️
...dap/configurations/DAPRunConfigurationOptions.java 80.00% 1 Missing ⚠️
...fined/UserDefinedDebugAdapterServerDefinition.java 66.66% 1 Missing ⚠️
...ij/dap/descriptors/DebugAdapterServerListener.java 75.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2375      +/-   ##
==========================================
+ Coverage   59.58%   59.67%   +0.08%     
==========================================
  Files         856      857       +1     
  Lines       37220    37281      +61     
  Branches     7716     7721       +5     
==========================================
+ Hits        22178    22247      +69     
+ Misses      11991    11984       -7     
+ Partials     3051     3050       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Action not completed

Already reviewed the last commit. Use @coderabbitai full review to rerun a review of the entire changeset.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit e9d1f69 into redhat-developer:main Nov 30, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dap Debugging Adapter Protocol enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant