Skip to content

feat: terminate a thread from the context menu of the Frames view of a DAP debug session - #2217

Merged
lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:feat/dap-terminate-thread-from-frames
Nov 24, 2026
Merged

lagergren merged 3 commits into
redhat-developer:mainfrom
lagergren:feat/dap-terminate-thread-from-frames

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2178

What

"Terminate Thread" (#2153) was only in the context menu of a DAP session's Threads tab. VS Code also has it in its Call Stack view. IntelliJ's Frames view had no way to terminate the thread of the selected frame.

Change

  • The Frames view's context menu (XDebugger.Frames.Tree.Popup) now has DAP.TerminateThread too. There it sends terminateThreads with the thread of the selected frame, to the DAP session of that frame, when its DAP server supports the request (supportsTerminateThreadsRequest). It isn't shown for a frame of another debugger, for a DAP server without the request, or for a DAP frame that doesn't know its thread.
  • DAPStackFrame knows its DAP thread: a new constructor DAPStackFrame(client, stackFrame, executionEpoch, threadId) and getThreadId(). The two existing constructors leave it null, so the public API stays compatible. DAPExecutionStack passes its thread to the frames it creates.
  • The selected frame: the Frames view gives its actions no data about the selected frame, in 2024.2 or 2026.3. A right-click selects the frame under the mouse, and the view makes it the session's current frame. So the action takes the session from XDebugSession.DATA_KEY, or else the project's current session, and uses its current stack frame.
  • Docs: the "Terminate a thread" section of the DAP user guide says the Frames view has it too.

Tests

DAPTerminateThreadSessionTest gets 6 tests of the Frames view's menu. They update the action in the background, as the menu does, with the data the menu has there, and right-click as the Frames view does, with setCurrentStackFrame on the selected frame. They check that:

  • the menu has Terminate Thread;
  • with the program stopped in main, Terminate Thread on worker's frame sends terminateThreads with worker's id;
  • on a frame of a child session (startDebugging), the request goes to the child session and the root session gets none;
  • it isn't offered, and performing it anyway sends nothing, for a DAP server without the request, for a frame of another debugger, and for a DAP frame without its thread.

Red-green:

  • Without the change, the first 3 tests fail.
  • With the action registered, but without DAPExecutionStack passing the thread, the 2 tests that expect a request fail.

After rebasing onto #2181:

  • DAPTerminateThreadSessionTest passes headless on IC 2024.2, 2025.3 and IU 2026.3: 16 tests each.
  • The dap.* tests pass on all three: 500 each, 0 failures, 0 skipped.

Behaviour change

Before After
Terminate Thread is only in the Threads tab's context menu It's also in the Frames view's context menu, where it terminates the thread of the selected frame

…a DAP debug session

"Terminate Thread" (DAP.TerminateThread), which redhat-developer#2153 added to the
Threads tab of a DAP debug session, is now also in the context menu of
IntelliJ's Frames view (XDebugger.Frames.Tree.Popup). There it sends
'terminateThreads' with the thread of the selected frame, to the DAP
session of that frame, when its DAP server supports the request
(supportsTerminateThreadsRequest). It isn't shown for a frame of another
debugger, for a DAP server without the request, or for a DAP frame which
doesn't know its thread.

- DAPStackFrame knows the ID of its DAP thread: the new constructor
  DAPStackFrame(client, stackFrame, executionEpoch, threadId) and
  getThreadId(). The two existing constructors leave it null.
  DAPExecutionStack passes the ID of its thread to the frames it creates.
- The Frames view gives its actions no data of the selected frame, in
  2024.2 and in 2026.3. A right-click selects the frame under the mouse,
  and the view makes the selected frame the debug session's current
  frame, which the IntelliJ actions of that menu, such as "Reset Frame",
  act on. The action takes the session's current frame too, from
  XDebugSession.DATA_KEY, or from the project's current session when the
  context has none: the split debugger of 2026.x gives a backend action
  no session, and tells the backend session the frame that its Frames
  view selects.
- In the Threads tab, the action still terminates the selected threads.

Fixes redhat-developer#2178
…e selected frame, in its own DAP session

DAPTerminateThreadSessionTest gets 6 tests of the Frames view's context
menu. They update the action in the background, as its menu does, with
the data which the menu has there in 2024.2: the project and
XDebugSession.DATA_KEY, from the session's tab, and none of the Threads
tab's selection. A right-click is done as the Frames view does it, with
XDebugSession#setCurrentStackFrame on the frame that it selects.

- The menu (XDebugger.Frames.Tree.Popup) has Terminate Thread.
- With the program stopped in 'main', Terminate Thread on the frame of
  'worker' sends 'terminateThreads' with the ID of 'worker'.
- On the frame of a child session (startDebugging), the request goes to
  the child session, and the root session gets none.
- It isn't offered, and performing it anyway sends nothing, for a DAP
  server without supportsTerminateThreadsRequest, for a frame which
  isn't a DAP frame, and for a DAP frame created without its thread.

The EDT doesn't dispatch events from the selection to the action: in the
split debugger of 2026.x, the backend session tells the frontend each
frame it is given, and the frontend's Frames view then selects one of
its own frames, which replaces a frame that the view doesn't show.

Without the change, the first 3 tests fail. With the action registered
but without DAPExecutionStack passing the thread to its frames, the 2
tests which expect a request fail.
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the enhancement New feature or request label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • New Features
    • You can now terminate a thread from the Frames view by selecting one of its frames and choosing Terminate Thread. The action is available when the selected frame’s thread supports termination.
  • Documentation
    • Updated the DAP User Guide and action description to cover terminating a thread from either the Frames view or Threads panel.

The Terminate Thread action is now available in the Frames view. DAP stack frames carry their thread IDs, and the action can send a termination request for the current frame’s thread when the client supports it.

Changes: Frames View Thread Termination

Layer / File(s) Summary
Carry thread IDs into stack frames
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionStack.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPStackFrame.java
DAPExecutionStack passes its thread ID to each created frame. DAPStackFrame stores the optional ID and provides a getter. The existing constructor remains available and leaves the ID unknown.
Wire and validate Frames view termination
src/main/java/com/redhat/devtools/lsp4ij/dap/threads/DAPTerminateThreadAction.java, src/main/resources/META-INF/plugin.xml, src/main/resources/messages/DAPBundle.properties, docs/dap/UserGuide.md, src/test/java/com/redhat/devtools/lsp4ij/dap/threads/DAPTerminateThreadSessionTest.java
The action checks the current DAP frame when no Threads-panel selection exists. It is available when the frame has a thread ID and its client supports terminateThreads, and sends that ID to the frame’s client. The Frames popup registration, descriptions, guide, and session tests cover the added path.

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant FramesView
  participant DAPTerminateThreadAction
  participant DAPStackFrame
  participant DAPClient
  FramesView->>DAPTerminateThreadAction: Invoke Terminate Thread
  DAPTerminateThreadAction->>DAPStackFrame: Read current frame thread ID
  DAPStackFrame-->>DAPTerminateThreadAction: Return thread ID
  DAPTerminateThreadAction->>DAPClient: Send terminateThreads for thread ID
Loading

Suggested reviewers: angelozerr, muescha

Merge Risk: Minimal · up to b2017

This adds a Terminate Thread action to the Frames view context menu for DAP debugging. It appears only for DAP frames with a known thread ID whose adapter supports the request. The fallback for choosing the debug session in the split debugger is not exercised by the tests, but no concrete problem was found, so the change looks safe to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: adding a Terminate Thread action to the Frames view context menu of a DAP debug session. The changeset matches this: plugin.xml registers DAP.TerminateThread in XDebu…
Description check Passed The description is related to the changeset. It explains the Frames view context menu addition, the new DAPStackFrame constructor and getThreadId, the DAPExecutionStack change, the user guide update, …
Linked Issues check Passed Only #2178 is a directly linked, active issue. Its coding requirements are:
(1) [#2178] Give DAPStackFrame its thread ID through a new constructor, keep the two existing constructors, and have DAPExec…
Out of Scope Changes check Passed All changed areas connect to #2178. DAPStackFrame and DAPExecutionStack carry the thread ID (required by #2178). DAPTerminateThreadAction extends the existing action to the Frames view (required). plu…
Full details: Title check

Explanation

The title states the main change: adding a Terminate Thread action to the Frames view context menu of a DAP debug session. The changeset matches this: plugin.xml registers DAP.TerminateThread in XDebugger.Frames.Tree.Popup, DAPTerminateThreadAction handles frame selection, and DAPStackFrame gains a thread ID.

Full details: Description check

Explanation

The description is related to the changeset. It explains the Frames view context menu addition, the new DAPStackFrame constructor and getThreadId, the DAPExecutionStack change, the user guide update, and the added tests in DAPTerminateThreadSessionTest.

Full details: Linked Issues check

Explanation

Only #2178 is a directly linked, active issue. Its coding requirements are:
(1) [#2178] Give DAPStackFrame its thread ID through a new constructor, keep the two existing constructors, and have DAPExecutionStack pass the ID. The diff summary shows DAPStackFrame(client, stackFrame, executionEpoch, threadId) and getThreadId(). DAPExecutionStack.toDAPStackFrames passes threadId. The earlier constructors remain.
(2) [#2178] Add DAP.TerminateThread to XDebugger.Frames.Tree.Popup. The plugin.xml summary shows an add-to-group registration for that menu.
(3) [#2178] Enable the action only for a DAPStackFrame whose client supports terminateThreads, and terminate that frame's thread. DAPTerminateThreadAction.update() and actionPerformed() check frame.getThreadId() and isSupportsTerminateThreadsRequest(), then call terminateThreads(List.of(threadId)) on frame.getClient(). This matches the source at the reviewed head.
(4) [#2178] Session test for the worker frame and for an adapter without the request. DAPTerminateThreadSessionTest adds 6 Frames-menu tests covering these cases, per the summary and PR description.
Unresolved: the right-click selection of the frame (the 2024.2 and 2026.3 split-debugger check named in #2178) is verified only by the test simulating setCurrentStackFrame. No real IDE right-click run is shown. The coding requirement is met; this manual check is not established by the evidence.

Full details: Out of Scope Changes check

Explanation

All changed areas connect to #2178. DAPStackFrame and DAPExecutionStack carry the thread ID (required by #2178). DAPTerminateThreadAction extends the existing action to the Frames view (required). plugin.xml registers the action in XDebugger.Frames.Tree.Popup (required). DAPBundle.properties updates the action description for the new context (supporting). The DAP UserGuide.md documents the Frames view entry (supporting documentation). DAPTerminateThreadSessionTest tests the new behavior (supporting tests). No change in the summary is unrelated to #2178. The ThreadsPanel.SELECTED_THREADS path, which is used by the Threads tab, keeps its prior behavior and takes priority in update() and actionPerformed().

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: 711e8ab1-2c22-4b2b-b09b-d0a0fbdedd10
Commits

Reviewing files that changed from the base of the PR and between 84b4ec3 and b201790.

Files selected for processing: 7

  • docs/dap/UserGuide.md
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionStack.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPStackFrame.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/threads/DAPTerminateThreadAction.java
  • src/main/resources/META-INF/plugin.xml
  • src/main/resources/messages/DAPBundle.properties
  • src/test/java/com/redhat/devtools/lsp4ij/dap/threads/DAPTerminateThreadSessionTest.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.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 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.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.98%. Comparing base (84b4ec3) to head (b201790).

Files with missing lines Patch % Lines
...s/lsp4ij/dap/threads/DAPTerminateThreadAction.java 61.11% 5 Missing and 2 partials ⚠️
...dhat/devtools/lsp4ij/dap/client/DAPStackFrame.java 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2217      +/-   ##
==========================================
+ Coverage   54.95%   54.98%   +0.03%     
==========================================
  Files         836      836              
  Lines       35478    35498      +20     
  Branches     7317     5558    -1759     
==========================================
+ Hits        19497    19520      +23     
- Misses      13126    13127       +1     
+ Partials     2855     2851       -4     

☔ 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 24, 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 24, 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 24, 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
lagergren merged commit 7b88e72 into redhat-developer:main Nov 24, 2026
9 checks passed
lagergren added a commit that referenced this pull request Nov 25, 2026
…ther thread continued alone (#2221)

Fixes #2185

## What

After a thread other than the stopped one continued alone (`continued` with `allThreadsContinued: false`), Set Value refused in the thread that was still stopped. It said "The program has run since this value was shown: show it again to set it." `DAPClient.continued` ended the execution epoch of #2150 on every `continued` event, of any thread. So every value of the stop counted as out of date, and so did Jump to Source and Jump to Value Source on them.

The findings in #2185 show the design, checked against the debug adapters' sources:
- java-debug, debugpy and vscode-js-debug keep a stopped thread's references valid while another thread runs alone.
- GDB clears every reference on any resume. It's the only one that advertises `supportsSingleThreadExecutionRequests`.

## Change

- **`continued` with `allThreadsContinued: false`** no longer ends the execution epoch. The thread that continued is marked as having left its stop, as before, in the run states of #2181.
- **Frames carry their stop.** `DAPStackFrame` keeps the run-state version of its stop, which `DAPExecutionStack` passes, and its thread, from #2217.
- **The new `DAPClient.sendInExecutionEpoch(DAPStackFrame, …)`** sends a request only while both of these hold, checked in the same lock as before:
  - the frame's epoch is current;
  - the frame's thread hasn't left its stop (`DAPThreadRunStates.leftStopSince`).

  The thread that reads the debug adapter's messages still never waits on that lock: the run states are an atomic swap.
- **Callers:** `DAPValueModifier` (Set Value), `DAPExpressionModifier` (Set Value on an Evaluate result) and `DAPLocations` (Jump to Source, Jump to Value Source) now pass their frame.
- **The epoch still ends for every thread** on:
  - every Resume or step that LSP4IJ sends, including a `singleThread: true` one, which GDB needs;
  - any `stopped` event, including `allThreadsStopped: true`, which adapters that renumber at every stop need;
  - a `continued` event of all threads;
  - Reset Frame.
- **Compatibility:** the existing `sendInExecutionEpoch(int, …)` overloads and the public `DAPStackFrame` constructors are unchanged.
- **Docs:** one sentence in the Set Value section of `docs/dap/UserGuide.md`.

Not in this PR:
- A `continue` response with `allThreadsContinued: false`, to a request sent without `singleThread`, still ends the epoch for all threads. IntelliJ resumes the session before Resume is sent, so no value of that stop is left to set. Undoing the run states set before the request fits with #2183's refused-resume handling.
- A value of a thread that exited while the session stays suspended now refuses as out of date. Before, `setVariable` was sent.

## Tests

New `DAPSetValueInAStoppedThreadSessionTest`, 5 session tests with an in-process debug adapter of two threads. Every wait is bounded and has a message.
- **The worker continues alone:** a local and an Evaluate result of `main` get `setVariable` and `setExpression` and show their new values. The worker's values refuse and send nothing.
- **A single-thread step:** Step Over with `singleThread: true` makes both threads' values refuse.
- **A stop of all threads:** the worker continues alone, then stops with `allThreadsStopped: true`. Both threads' earlier values refuse, and `main`'s local at the new stop can be set.
- **A continue of all threads:** both threads' values refuse.
- **Resume:** both threads' values refuse.

`DAPExecutionEpochTest` gets one unit test for the new `send`.

Red-green: without the change, the first test fails (`The local of 'main' is set`). The other four pass either way: they guard behaviour that already worked. With the change, all pass.

On main at 4e15453, the two classes pass headless on IC 2024.2, 2025.3 and IU 2026.3: 19 tests each. The `dap.*` tests pass on all three: 551 tests each, with 0 failures or skipped.

## Behaviour change

| Before | After |
|---|---|
| After another thread continues alone, Set Value, Jump to Source and Jump to Value Source on a value of the thread that's still stopped refuse: "The program has run since this value was shown" | They work in the stopped thread. Values of the thread that continued alone, or exited, still refuse. A single-thread step, any stop, and a continue or Resume of all threads still make every thread's values refuse |
lagergren added a commit that referenced this pull request Nov 25, 2026
Retakes the DAP Mappings screenshots without the Language Id column that #2173 removed, and the Terminate Thread screenshots with the run state of each thread (#2181). Adds a screenshot of Terminate Thread in the Frames view (#2217).

Fixes #2187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAP: Terminate Thread in the context menu of the Frames view

1 participant