Skip to content

Commit b1ae0f7

Browse files
committed
[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.
1 parent c3d905e commit b1ae0f7

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,10 @@ void DAP::EventThread() {
14371437
const bool remove_module =
14381438
event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded;
14391439

1440-
std::lock_guard<std::mutex> guard(modules_mutex);
1440+
// NOTE: Both mutexes must be acquired to prevent deadlock when
1441+
// handling `modules_request`, which also requires both locks.
1442+
lldb::SBMutex api_mutex = GetAPIMutex();
1443+
const std::scoped_lock guard(api_mutex, modules_mutex);
14411444
for (uint32_t i = 0; i < num_modules; ++i) {
14421445
lldb::SBModule module =
14431446
lldb::SBTarget::GetModuleAtIndexFromEvent(i, event);

0 commit comments

Comments
 (0)