[Lldb-commits] [lldb] 3edde47 - [lldb][Windows] Hold the process and thread list locks in OnCreateThread and OnExitThread (#231489)
via lldb-commits
lldb-commits at lists.llvm.org
Wed Oct 14 04:12:41 PDT 2026
Author: Charles Zablit
Date: 2026-10-14T12:12:36+01:00
New Revision: 3edde475ce31f6874aae714df6329892ca8cdb37
URL: https://github.com/llvm/llvm-project/commit/3edde475ce31f6874aae714df6329892ca8cdb37
DIFF: https://github.com/llvm/llvm-project/commit/3edde475ce31f6874aae714df6329892ca8cdb37.diff
LOG: [lldb][Windows] Hold the process and thread list locks in OnCreateThread and OnExitThread (#231489)
`OnExitThread` modifies `m_threads` without holding `m_mutex`, unlike
the other debug event handlers.
This patch makes `OnCreateThread` hold `m_threads_mutex` for its whole
body, so the new thread is set up and added to the list under one lock.
Added:
Modified:
lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
index 09986d3d1f7cc0..9d2cdf9f58510c 100644
--- a/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/NativeProcessWindows.cpp
@@ -826,6 +826,8 @@ NativeProcessWindows::OnDebugException(bool first_chance,
void NativeProcessWindows::OnCreateThread(const HostThread &new_thread) {
llvm::sys::ScopedLock lock(m_mutex);
+ const StateType state = GetState();
+ std::lock_guard<std::recursive_mutex> threads_guard(m_threads_mutex);
auto thread = std::make_unique<NativeThreadWindows>(*this, new_thread);
thread->GetRegisterContext().ClearAllHardwareWatchpoints();
@@ -835,8 +837,7 @@ void NativeProcessWindows::OnCreateThread(const HostThread &new_thread) {
wp.m_hardware);
}
- if (StateType state = GetState();
- state == eStateStopped || state == eStateCrashed) {
+ if (state == eStateStopped || state == eStateCrashed) {
if (Status error = thread->DoStop(); error.Fail()) {
Log *log = GetLog(WindowsLog::Thread);
LLDB_LOG(log, "failed to suspend newly-created thread {0}: {1}",
@@ -847,12 +848,12 @@ void NativeProcessWindows::OnCreateThread(const HostThread &new_thread) {
thread->SetStopReason(stop_info, "");
}
- std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
m_threads.push_back(std::move(thread));
}
void NativeProcessWindows::OnExitThread(lldb::tid_t thread_id,
uint32_t exit_code) {
+ llvm::sys::ScopedLock lock(m_mutex);
std::lock_guard<std::recursive_mutex> guard(m_threads_mutex);
llvm::erase_if(m_threads, [thread_id](const auto &t) {
return t->GetID() == thread_id;
More information about the lldb-commits
mailing list