[Lldb-commits] [lldb] Don't hold the Target's ModuleListLock over running LoadScriptingResourceInTarget (PR #138216)
via lldb-commits
lldb-commits at lists.llvm.org
Fri May 2 11:51:15 PDT 2025
https://github.com/jimingham updated https://github.com/llvm/llvm-project/pull/138216
>From 656fe559f84526fd3edc91b1c0d12fd56d838085 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Thu, 1 May 2025 16:27:37 -0700
Subject: [PATCH 1/2] Don't hold the Target's ModuleListLock over running
LoadScriptingResourceInTarget. That calls an unknown amount of Python code,
and can do quite a bit of work - especially if people do things like launch
scripted processes in this script affordance. Doing that while holding a
major lock like the ModuleList lock is asking for trouble.
I tried to make a test that would actually stall without this, but I couldn't
come up with anything that reliably failed. You always have to get pretty
unlucky.
---
lldb/source/Core/ModuleList.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 6052cc151744d..9724039decf0d 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1046,8 +1046,14 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
bool continue_on_error) {
if (!target)
return false;
- std::lock_guard<std::recursive_mutex> guard(m_modules_mutex);
- for (auto module : m_modules) {
+ m_modules_mutex.lock();
+ // Don't hold the module list mutex while loading the scripting resources,
+ // The initializer might do any amount of work, and having that happen while
+ // the module list is held is asking for A/B locking problems.
+ const ModuleList tmp_module_list(*this);
+ m_modules_mutex.unlock();
+
+ for (auto module : tmp_module_list.ModulesNoLocking()) {
if (module) {
Status error;
if (!module->LoadScriptingResourceInTarget(target, error,
>From 21b3c847236c239e07cbf14220ea6516181e3d13 Mon Sep 17 00:00:00 2001
From: Jim Ingham <jingham at apple.com>
Date: Fri, 2 May 2025 11:50:57 -0700
Subject: [PATCH 2/2] formatting
---
lldb/source/Core/ModuleList.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lldb/source/Core/ModuleList.cpp b/lldb/source/Core/ModuleList.cpp
index 9724039decf0d..d5ddf6e846112 100644
--- a/lldb/source/Core/ModuleList.cpp
+++ b/lldb/source/Core/ModuleList.cpp
@@ -1052,7 +1052,7 @@ bool ModuleList::LoadScriptingResourcesInTarget(Target *target,
// the module list is held is asking for A/B locking problems.
const ModuleList tmp_module_list(*this);
m_modules_mutex.unlock();
-
+
for (auto module : tmp_module_list.ModulesNoLocking()) {
if (module) {
Status error;
More information about the lldb-commits
mailing list