Skip to content

feat: when the selected thread of a DAP session continues alone, the session selects the thread where it stays suspended - #2218

Merged
lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:feat/dap-select-stopped-thread
Nov 24, 2026
Merged

lagergren merged 2 commits into
redhat-developer:mainfrom
lagergren:feat/dap-select-stopped-thread

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2184

What

Since #2181, when a thread other than the one where a DAP session is suspended continues alone (continued with allThreadsContinued: false), the session stays suspended and the Frames view says the thread is running. But if that thread was the selected one, the selection stayed on the frame of its stop:

  • the current frame, the Variables view and the execution point stayed stale;
  • Step and Resume, which take their thread from the context's active stack, sent their request for the thread that runs.

Change

  • DAPClient: when another thread continues alone, after the views are rebuilt, the new selectStoppedThread runs.
    • It notes the suspend context and the current frame, then goes to the EDT (invokeLater, with ModalityState.any(), expiring with the project). The 2024.2 Frames view asserts it's there.
    • It does nothing unless the session is still at the same suspend context with the same current frame, so a newer stop, or a frame the user selected meanwhile, wins.
    • It also does nothing unless the current frame belongs to the thread that continued.
    • Otherwise it makes the stopped thread's stack the context's active stack, which Step and Resume use, and calls session.setCurrentStackFrame(stoppedStack, topFrame, true), which moves the Variables view and the execution point. setCurrentStackFrame is public API; on 2026.3 the backend sends the change to the split debugger's frontend.
  • Helpers (package-private): DAPSuspendContext.getExecutionStack(threadId), and DAPExecutionStack.hasStackFrame(frame), which compares by identity.
  • Docs: one sentence in the Threads section of the DAP user guide.

Not in this PR:

  • If an invalidated event reloaded the continued thread's frames since it was selected, the frame objects differ and the selection isn't moved, as before.
  • DAPExecutionStack.computeStackFrames makes a stack the active one only when its frames were already loaded. The first time a thread whose frames aren't loaded is picked, its stack isn't made active after the load. Whether that shows up depends on how often the Frames view asks for the frames; I haven't confirmed that, so it isn't filed yet. The tests ask for the frames twice, as the view does.

Tests

DAPThreadRunStateSessionTest gets two tests. Its test server gives main a second frame and answers next.

  • The selected thread continues alone: main stops, the worker is selected, and the worker continues alone. A bounded wait requires the current frame to become a different object with main's frame id. It must be main's top frame, Step's thread must be main, and a step must send next for main.
  • A thread that isn't selected continues alone: main's caller frame is selected, and the worker continues alone. The same frame object stays current, and a step sends next for main.

Red-green: without the change, the first test fails ("the current frame moves to the top frame of 'main', but it is the frame 12"). The second passes both ways, as it guards against moving a selection that shouldn't move.

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

Behaviour change

Before After
When the selected thread continues alone while the session stays suspended at another thread, the selection stays on the frame of its stop: the Variables view and the execution point are stale, and Step and Resume send their request for the thread that runs The selection moves to the top frame of the thread where the session is suspended, and the Variables view, the execution point, Step and Resume follow it. A selected thread that's still stopped, a newer stop, or a frame the user selected meanwhile keeps the selection

…session selects the thread where it stays suspended

When a thread other than the one where the session is suspended continues
alone (a 'continued' event with allThreadsContinued: false) while one of its
frames is the current frame, the session now selects the top frame of the
thread where it stays suspended. The Variables view and the execution point
follow that thread, and so do Step and Resume, which act on the thread of the
active stack of the suspend context: before, they sent their request for the
thread which runs.

The selection moves on the EDT with XDebugSession.setCurrentStackFrame, which
also reaches the frontend of the split debugger, and only while the session is
still at the same stop with the same current frame: a newer stop, or a frame
selected meanwhile, stays. The selection of a thread which is still stopped
stays too.

Fixes redhat-developer#2184
… thread where it stays suspended, and steps it

DAPThreadRunStateSessionTest: 'main' stops and the worker is selected; once
the worker continues alone, the current frame becomes the top frame of 'main'
and a step sends 'next' for 'main'. When the worker continues alone while a
frame of 'main' is selected, that frame stays the current frame.
@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

  • Bug Fixes
    • When a running thread is selected while the session remains suspended, selection now moves to the suspended thread’s top frame. Variables, the execution point, stepping, and resuming follow the suspended thread.
    • If a different thread was selected, its selection remains unchanged; stepping still targets the suspended thread.
  • Documentation
    • Clarified thread selection behavior and noted that frames are unavailable for the running thread.

When a thread continues alone while the session remains suspended, the DAP client moves selection to the stopped thread’s top frame if the continued thread was selected. Tests check frame selection and step targets. The user guide describes how views and controls follow the selection.

Changes: Thread selection after continued events

Layer / File(s) Summary
Update selection to the stopped thread
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionStack.java, src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPSuspendContext.java
DAPClient now selects the stopped thread’s top frame when the selected frame belongs to the thread that continued. The client checks that the suspend context and current frame have not changed before updating the active execution stack and frame.
Test and document the selection behavior
src/test/java/com/redhat/devtools/lsp4ij/dap/threads/DAPThreadRunStateSessionTest.java, docs/dap/UserGuide.md
Session tests check that selection moves to main when selected worker continues, and that Step targets main. When worker was not selected, the test checks that the selected frame remains unchanged while Step targets main. The guide describes how Variables, the execution point, Step, and Resume follow the selection.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant DAPServer
  participant DAPClient
  participant DAPSuspendContext
  participant DAPExecutionStack
  participant DebugSession
  participant DAPDebugProcess
  DAPServer->>DAPClient: Send continued event for worker
  DAPClient->>DAPSuspendContext: Find stopped thread execution stack
  DAPSuspendContext-->>DAPClient: Return stopped thread stack
  DAPClient->>DAPExecutionStack: Check whether current frame belongs to worker
  DAPClient->>DebugSession: Activate stopped stack and select its top frame
  DebugSession->>DAPDebugProcess: Request Step
  DAPDebugProcess->>DAPServer: Send next for the active stack thread
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to a4223

When the selected thread continues alone while another thread stays suspended, the debugger now moves selection to the suspended thread's top frame, and Variables, the execution point, Step, and Resume follow it. The change is localized to DAP thread selection, is covered by new session tests, and is easy to revert. One minor caveat is that editing a variable value on the newly selected frame may be refused as stale after a partial continue. That comes from the existing epoch model rather than from this change.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main behavior change: when the selected thread continues alone while the DAP session stays suspended on another thread, the session selects the thread where it stays suspended. Th…
Description check Passed The description links issue #2184, explains the stale selection problem, and lists the DAPClient change, the helpers, the docs sentence, the tests, and the behavior change. It is directly related to t…
Linked Issues check Passed Issue #2184 requires that, when the selected thread continues alone while the session stays suspended, (1) selection moves to the stopped thread's top frame, (2) Variables and the execution point foll…
Out of Scope Changes check Passed The changed areas are DAPClient (selectStoppedThread and its call after continued handling), the package-private helpers DAPSuspendContext.getExecutionStack(threadId) and DAPExecutionStack.hasStackFra…
Full details: Title check

Explanation

The title states the main behavior change: when the selected thread continues alone while the DAP session stays suspended on another thread, the session selects the thread where it stays suspended. The raw summary, the description, and the objectives all describe selection moving to the suspended thread's top frame in DAPClient, supported by new helpers and a docs sentence. The title is concise and specific, though it is long (120 characters) and uses a 'feat:' prefix.

Full details: Description check

Explanation

The description links issue #2184, explains the stale selection problem, and lists the DAPClient change, the helpers, the docs sentence, the tests, and the behavior change. It is directly related to the changeset.

Full details: Linked Issues check

Explanation

Issue #2184 requires that, when the selected thread continues alone while the session stays suspended, (1) selection moves to the stopped thread's top frame, (2) Variables and the execution point follow it, (3) Step and Resume act on the stopped thread, and (4) a session test covers this. The PR summary and description state that DAPClient runs the new selectStoppedThread after the views are rebuilt. The helper makes the stopped thread's stack the context's active stack and calls session.setCurrentStackFrame(stoppedStack, topFrame, true) on the EDT. It acts only when the session is still at the same suspend context and the same current frame, and that frame belongs to the continued thread. DAPThreadRunStateSessionTest gains a test that matches the issue's proposed scenario: main stops, worker is selected and continues alone, the current frame becomes main's top frame, and a step sends next for main. A second test guards the unselected case. The description reports the test passing on IC 2024.2, 2025.3, and IU 2026.3. Limits: the changed-file diff was unavailable in this review, so the code evidence comes from the whole-PR summary and the PR description, not from reading the hunks. The PR also states two known gaps outside the issue's stated scenario: frame objects replaced by an invalidated event, and the first selection of a thread whose frames are not yet loaded.

Full details: Out of Scope Changes check

Explanation

The changed areas are DAPClient (selectStoppedThread and its call after continued handling), the package-private helpers DAPSuspendContext.getExecutionStack(threadId) and DAPExecutionStack.hasStackFrame(frame), the DAPThreadRunStateSessionTest tests, and one sentence in the DAP user guide Threads section. Each change supports the #2184 objective or its verification. The helpers are needed to find the stopped thread's stack and to check the current frame identity. The documentation sentence describes the new behavior. No unrelated change appears in the summary. The diff was unavailable in this review, so this verdict rests on the whole-PR summary and the PR description.

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: 67d53df0-0382-4395-af42-500c1d5276de
Commits

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

Files selected for processing: 5

  • docs/dap/UserGuide.md
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPExecutionStack.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPSuspendContext.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/threads/DAPThreadRunStateSessionTest.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 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.16667% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.97%. Comparing base (84b4ec3) to head (a42236e).

Files with missing lines Patch % Lines
...m/redhat/devtools/lsp4ij/dap/client/DAPClient.java 42.10% 5 Missing and 6 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2218      +/-   ##
==========================================
+ Coverage   54.95%   54.97%   +0.01%     
==========================================
  Files         836      836              
  Lines       35478    35502      +24     
  Branches     7317     7325       +8     
==========================================
+ Hits        19497    19517      +20     
+ Misses      13126    13123       -3     
- Partials     2855     2862       +7     

☔ 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 67f9884 into redhat-developer:main Nov 24, 2026
9 checks passed
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: when the selected thread continues alone, select the thread where the session stays suspended

1 participant