From fd2f356f24b3876ce4f25cbbe97eadb2aa433a01 Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Thu, 16 Oct 2025 17:40:21 +0100 Subject: [PATCH 1/2] [lldb-dap] Fix mutex acquisition order for modules event. The modules event requires the `APIMutex` to create the module load address. this may happen at the same time the `module request` is handled. The modules request also requires the `APIMutex` and the `modules_mutex, set the order to acquire the mutexes. --- lldb/tools/lldb-dap/DAP.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index 52c8c6b9092b9..b5f77294ca520 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -1452,7 +1452,10 @@ void DAP::EventThread() { const bool remove_module = event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded; - std::lock_guard guard(modules_mutex); + // NOTE: Both mutexes must be acquired to prevent deadlock when + // handling `modules_request`, which also requires both locks. + lldb::SBMutex api_mutex = GetAPIMutex(); + const std::scoped_lock guard(api_mutex, modules_mutex); for (uint32_t i = 0; i < num_modules; ++i) { lldb::SBModule module = lldb::SBTarget::GetModuleAtIndexFromEvent(i, event); From b9153c23b144f7fb9ac5e14d37c08e28f42fafba Mon Sep 17 00:00:00 2001 From: Ebuka Ezike Date: Wed, 22 Oct 2025 16:38:34 +0100 Subject: [PATCH 2/2] [lldb-dap] add scoped_lock template params --- lldb/tools/lldb-dap/DAP.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp index b5f77294ca520..3c4f2253d1ad5 100644 --- a/lldb/tools/lldb-dap/DAP.cpp +++ b/lldb/tools/lldb-dap/DAP.cpp @@ -26,6 +26,7 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBLanguageRuntime.h" #include "lldb/API/SBListener.h" +#include "lldb/API/SBMutex.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" #include "lldb/Host/JSONTransport.h" @@ -1455,7 +1456,8 @@ void DAP::EventThread() { // NOTE: Both mutexes must be acquired to prevent deadlock when // handling `modules_request`, which also requires both locks. lldb::SBMutex api_mutex = GetAPIMutex(); - const std::scoped_lock guard(api_mutex, modules_mutex); + const std::scoped_lock guard( + api_mutex, modules_mutex); for (uint32_t i = 0; i < num_modules; ++i) { lldb::SBModule module = lldb::SBTarget::GetModuleAtIndexFromEvent(i, event);