Skip to content

Commit 8f9c64d

Browse files
Merge pull request llvm#11914 from swiftlang/cherry-pick-#163821
[lldb-dap] Fix mutex acquisition order for modules event. (llvm#163821)
2 parents f3cf6da + 540e09d commit 8f9c64d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lldb/tools/lldb-dap/DAP.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "lldb/API/SBEvent.h"
2828
#include "lldb/API/SBLanguageRuntime.h"
2929
#include "lldb/API/SBListener.h"
30+
#include "lldb/API/SBMutex.h"
3031
#include "lldb/API/SBProcess.h"
3132
#include "lldb/API/SBStream.h"
3233
#include "lldb/Utility/IOObject.h"
@@ -1357,7 +1358,11 @@ void DAP::EventThread() {
13571358
const bool remove_module =
13581359
event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded;
13591360

1360-
std::lock_guard<std::mutex> guard(modules_mutex);
1361+
// NOTE: Both mutexes must be acquired to prevent deadlock when
1362+
// handling `modules_request`, which also requires both locks.
1363+
lldb::SBMutex api_mutex = GetAPIMutex();
1364+
const std::scoped_lock<lldb::SBMutex, std::mutex> guard(
1365+
api_mutex, modules_mutex);
13611366
for (uint32_t i = 0; i < num_modules; ++i) {
13621367
lldb::SBModule module =
13631368
lldb::SBTarget::GetModuleAtIndexFromEvent(i, event);

0 commit comments

Comments
 (0)