[Lldb-commits] [lldb] Support single stopped event in lldb-dap (PR #98568)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 15 11:23:37 PDT 2024


================
@@ -255,45 +253,75 @@ void SendThreadStoppedEvent() {
       lldb::tid_t first_tid_with_reason = LLDB_INVALID_THREAD_ID;
       uint32_t num_threads_with_reason = 0;
       bool focus_thread_exists = false;
+      lldb::SBThread focus_thread, first_thread_with_reason;
       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 == g_dap.focus_tid) {
+          focus_thread = thread;
           focus_thread_exists = true;
           if (!has_reason)
             g_dap.focus_tid = LLDB_INVALID_THREAD_ID;
         }
         if (has_reason) {
           ++num_threads_with_reason;
-          if (first_tid_with_reason == LLDB_INVALID_THREAD_ID)
+          if (first_tid_with_reason == LLDB_INVALID_THREAD_ID) {
             first_tid_with_reason = tid;
+            first_thread_with_reason = thread;
+          }
         }
       }
 
       // We will have cleared g_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 || g_dap.focus_tid == LLDB_INVALID_THREAD_ID)
+      if (!focus_thread_exists || g_dap.focus_tid == LLDB_INVALID_THREAD_ID) {
         g_dap.focus_tid = first_tid_with_reason;
+        focus_thread = first_thread_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);
         g_dap.focus_tid = thread.GetThreadID();
         g_dap.SendJSON(CreateThreadStopped(thread, stop_id));
+      } else if (g_dap.single_stopped_event) {
+        // If single_stopped_event option is true only one stopped event will
+        // be sent during debugger stop. The focused thread's stopped event is
+        // preferred if it is stopped with a reason; otherwise, we simply use
+        // the first stopped thread.
+        //
+        // This option would be preferred for VSCode IDE because multiple
+        // stopped events would cause confusing UX.
+        //
+        // TODO: do we need to give priority to exception/signal stopped event
+        // over normal stepping complete/breakpoint?
----------------
clayborg wrote:

This would be important

https://github.com/llvm/llvm-project/pull/98568


More information about the lldb-commits mailing list