-
Couldn't load subscription status.
- Fork 15k
[lldb-dap] Fix mutex acquisition order for modules event. #163821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-lldb Author: Ebuka Ezike (da-viper) ChangesThe modules event requires the The modules request also requires the Full diff: https://github.com/llvm/llvm-project/pull/163821.diff 1 Files Affected:
diff --git a/lldb/tools/lldb-dap/DAP.cpp b/lldb/tools/lldb-dap/DAP.cpp
index f76656e98ca01..003b55fa31610 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1437,7 +1437,12 @@ void DAP::EventThread() {
const bool remove_module =
event_mask & lldb::SBTarget::eBroadcastBitModulesUnloaded;
- std::lock_guard<std::mutex> guard(modules_mutex);
+ // NOTE: Both mutexes must be acquired (API mutex first, then modules
+ // mutex) to prevent deadlock when handling `modules_request`, which
+ // also requires both locks.
+ lldb::SBMutex api_mutex = GetAPIMutex();
+ std::lock_guard api_guard(api_mutex);
+ std::lock_guard modules_guard(modules_mutex);
for (uint32_t i = 0; i < num_modules; ++i) {
lldb::SBModule module =
lldb::SBTarget::GetModuleAtIndexFromEvent(i, event);
|
b10c3b8 to
b1ae0f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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.
d6c4a77 to
fd2f356
Compare
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.
The modules event requires the
APIMutexto create the module load address. this may happen at the same time themodule requestis handled.The modules request also requires the
APIMutexand the `modules_mutex, set the order to acquire the mutexes.