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

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Mon Oct 20 13:41:22 PDT 2025


https://github.com/da-viper updated https://github.com/llvm/llvm-project/pull/163821

>From b1ae0f72c8ba40c93dec9c421c1da772d295e7a2 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Thu, 16 Oct 2025 17:40:21 +0100
Subject: [PATCH] [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 f76656e98ca01..ac8735eb4b5c0 100644
--- a/lldb/tools/lldb-dap/DAP.cpp
+++ b/lldb/tools/lldb-dap/DAP.cpp
@@ -1437,7 +1437,10 @@ 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 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);



More information about the lldb-commits mailing list