[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 15:50:29 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 we still receive more than a 100 stopped requests. https://gist.github.com/barsolo2000/616a087166aaafc9d27041c7ad16358d
https://github.com/llvm/llvm-project/pull/176273
More information about the lldb-commits
mailing list