[Lldb-commits] [lldb] [lldb-dap] Migrating 'stopped' event to structured types. (PR #176273)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Feb 6 12:55:21 PST 2026
================
@@ -188,63 +265,38 @@ llvm::Error SendThreadStoppedEvent(DAP &dap, bool on_entry) {
llvm::DenseSet<lldb::tid_t> old_thread_ids;
old_thread_ids.swap(dap.thread_ids);
- uint32_t stop_id = on_entry ? 0 : process.GetStopID();
- const uint32_t num_threads = process.GetNumThreads();
-
- // First make a pass through the threads to see if the focused thread
- // has a stop reason. In case the focus thread doesn't have a stop
- // reason, remember the first thread that has a stop reason so we can
- // set it as the focus thread if below if needed.
- lldb::tid_t first_tid_with_reason = LLDB_INVALID_THREAD_ID;
- uint32_t num_threads_with_reason = 0;
- bool focus_thread_exists = false;
- for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
- lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
- const lldb::tid_t tid = thread.GetThreadID();
- const bool has_reason = ThreadHasStopReason(thread);
- // If the focus thread doesn't have a stop reason, clear the thread ID
- if (tid == dap.focus_tid) {
- focus_thread_exists = true;
- if (!has_reason)
- dap.focus_tid = LLDB_INVALID_THREAD_ID;
- }
- if (has_reason) {
- ++num_threads_with_reason;
- if (first_tid_with_reason == LLDB_INVALID_THREAD_ID)
- first_tid_with_reason = tid;
- }
- }
- // We will have cleared dap.focus_tid if the focus thread doesn't have
- // a stop reason, so if it was cleared, or wasn't set, or doesn't exist,
- // then set the focus thread to the first thread with a stop reason.
- if (!focus_thread_exists || dap.focus_tid == LLDB_INVALID_THREAD_ID)
- dap.focus_tid = first_tid_with_reason;
-
- // If no threads stopped with a reason, then report the first one so
- // we at least let the UI know we stopped.
- if (num_threads_with_reason == 0) {
- lldb::SBThread thread = process.GetThreadAtIndex(0);
- dap.focus_tid = thread.GetThreadID();
- dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
- } else {
- for (uint32_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
- lldb::SBThread thread = process.GetThreadAtIndex(thread_idx);
- dap.thread_ids.insert(thread.GetThreadID());
- if (ThreadHasStopReason(thread)) {
- dap.SendJSON(CreateThreadStopped(dap, thread, stop_id));
- }
- }
+ lldb::tid_t focused_tid = LLDB_INVALID_THREAD_ID;
+ for (auto thread : process) {
+ // Collect all known thread ids for sending thread events.
+ dap.thread_ids.insert(thread.GetThreadID());
+
+ if (!ThreadHasStopReason(thread))
+ continue;
+
+ // When we stop, report allThreadsStopped for the *first* stopped thread to
+ // ensure the list of stopped threads is up to date.
+ bool first_stop = focused_tid == LLDB_INVALID_THREAD_ID;
+ SendStoppedEvent(dap, thread, on_entry, /*all_threads_stopped=*/first_stop,
----------------
barsolo2000 wrote:
@ashgti It seems like when we have multiply threads stopped on the same breakpoint, we still send a stop reply for every thread when we step over the breakpoint which confused the lldb-dap.
The problem is that preserveFocusHint only tells VSCode "don't change focus to this thread". It does NOT tell VSCode "don't highlight this thread as stopped."
VSCode sees each stopped event and highlights that thread's current location in the editor, regardless of preserveFocusHint. So you get multiple line highlights.
We need to fix it by not sending multiple stopped events at all. Send only ONE stopped event with allThreadsStopped=true. VSCode will then query thread states via the threads request if it needs more info.
In a multi thread example, I stopped all the threads on one bp:
<img width="866" height="529" alt="Image" src="https://github.com/user-attachments/assets/d07352b9-14a1-4790-95d0-96a03fdde098" />
when I press step-over:
<img width="549" height="137" alt="Image" src="https://github.com/user-attachments/assets/1c98ebf6-753c-48eb-9b89-78c6d9958fe9" />
https://github.com/llvm/llvm-project/pull/176273
More information about the lldb-commits
mailing list