[Lldb-commits] [lldb] [lldb-dap] Fix mutex acquisition order for modules event. (PR #163821)

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Sat Oct 18 11:11:12 PDT 2025


================
@@ -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);
----------------
JDevlieghere wrote:

We should, that fits well with the SBMutex design: https://github.com/llvm/llvm-project/pull/164109

https://github.com/llvm/llvm-project/pull/163821


More information about the lldb-commits mailing list