[Lldb-commits] [lldb] [lldb-dap] Always return the up-to-date thread if possible. (PR #226140)
Ebuka Ezike via lldb-commits
lldb-commits at lists.llvm.org
Thu Sep 24 05:10:56 PDT 2026
https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/226140
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.
>From 96cbee89af3c1218a22f60564338277f4a35df36 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 24 Sep 2026 12:45:10 +0100
Subject: [PATCH] [lldb-dap] Always return the up-to-date thread if possible.
only send the initial thread list if the process is not stopped
and only the first time.
This should not affect tests since we mostly get the theadId from
a stopped event.
---
.../test/tools/lldb_dap/session_helpers.py | 7 ----
.../Handler/ThreadsRequestHandler.cpp | 34 ++++++++++---------
2 files changed, 18 insertions(+), 23 deletions(-)
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 6665d2698933ee..704e04073dd4fa 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 8b328d8348e3cf..95c4f35276dbf4 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
More information about the lldb-commits
mailing list