[Lldb-commits] [lldb] [lldb-dap] Always return the up-to-date thread if possible. (PR #226140)

via lldb-commits lldb-commits at lists.llvm.org
Thu Sep 24 05:11:59 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Ebuka Ezike (da-viper)

<details>
<summary>Changes</summary>

Only send the initial thread list if the process is not stopped and only the first time.

Remove the workaround in tests. This should not affect tests since we mostly get the `threadId` from a stopped event.

---
Full diff: https://github.com/llvm/llvm-project/pull/226140.diff


2 Files Affected:

- (modified) lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session_helpers.py (-7) 
- (modified) lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp (+18-16) 


``````````diff
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session_helpers.py b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session_helpers.py
index 6665d2698933e..704e04073dd4f 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session_helpers.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb_dap/session_helpers.py
@@ -683,13 +683,6 @@ def verify_configuration_done(self, expected_success: bool = True):
                 response.success, True, f"got error response: {response}."
             )
             self.test_case.assertIsInstance(response, EmptyBodyResponse)
-
-            # In VSCode, immediately following 'configurationDone', a
-            # 'threads' request is made to get the initial set of threads,
-            # specifically the main threads id and name.
-            # We issue the threads request to mimic this pattern and prevent
-            # tests that use threads to have the wrong result.
-            self.send_request(ThreadsArgs()).result()
         else:
             self.test_case.assertEqual(response.success, False)
             self.test_case.assertIsInstance(response, ErrorResponse)
diff --git a/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp b/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp
index 8b328d8348e3c..95c4f35276dbf 100644
--- a/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp
+++ b/lldb/tools/lldb-dap/Handler/ThreadsRequestHandler.cpp
@@ -15,6 +15,7 @@
 #include "lldb/API/SBDefines.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/raw_ostream.h"
+#include <utility>
 
 using namespace llvm;
 using namespace lldb_dap::protocol;
@@ -27,26 +28,27 @@ ThreadsRequestHandler::Run(const ThreadsArguments &) const {
   lldb::SBProcess process = dap.target.GetProcess();
   std::vector<Thread> threads;
 
-  // Client requests the baseline of currently existing threads after
-  // a successful launch or attach by sending a 'threads' request
-  // right after receiving the configurationDone response.
-  // If no thread has reported to the client, it prevents something
-  // like the pause request from working in the running state.
-  // Return the cache of initial threads as the process might have resumed
-  if (!dap.initial_thread_list.empty()) {
-    threads = dap.initial_thread_list;
-    dap.initial_thread_list.clear();
-  } else {
-    if (!lldb::SBDebugger::StateIsStoppedState(process.GetState()))
-      return make_error<NotStoppedError>();
-
-    threads = GetThreads(process, dap.thread_format);
+  if (!lldb::SBDebugger::StateIsStoppedState(process.GetState())) {
+    // Client requests the baseline of currently existing threads after
+    // a successful launch or attach by sending a 'threads' request
+    // right after receiving the configurationDone response.
+    // If no thread has reported to the client, it prevents something
+    // like the pause request from working in the running state.
+    // Return the cache of initial threads as the process might have resumed
+    if (!dap.initial_thread_list.empty()) {
+      DAP_LOG(dap.log, "Using the initial thread list.");
+      std::swap(threads, dap.initial_thread_list);
+      assert(dap.initial_thread_list.empty());
+      return ThreadsResponseBody{std::move(threads)};
+    }
+    return make_error<NotStoppedError>();
   }
 
-  if (threads.size() == 0)
+  threads = GetThreads(process, dap.thread_format);
+  if (threads.empty())
     return make_error<DAPError>("failed to retrieve threads from process");
 
-  return ThreadsResponseBody{threads};
+  return ThreadsResponseBody{std::move(threads)};
 }
 
 } // namespace lldb_dap

``````````

</details>


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


More information about the lldb-commits mailing list