aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Devlieghere <jonas@devlieghere.com>2025-06-26 18:44:19 -0500
committerGitHub <noreply@github.com>2025-06-26 16:44:19 -0700
commit76f3cc9e045330466acc7bea852c3b8e71343397 (patch)
tree4db3e31a86af55b8b590a45faac29ce75bc396f6
parent018548ddffeaa0bd878aabe2ebcc8d4946774aa9 (diff)
downloadllvm-76f3cc9e045330466acc7bea852c3b8e71343397.zip
llvm-76f3cc9e045330466acc7bea852c3b8e71343397.tar.gz
llvm-76f3cc9e045330466acc7bea852c3b8e71343397.tar.bz2
[lldb] Fix another race condition in Target::GetExecutableModule (#145991)
c72c0b298c13 fixed a race condition in Target::GetExecutableModule. The patch originally added the lock_guard but I suggested using the locking ModuleList::Modules() helper instead. That didn't consider that the fallback would still access the ModuleList without holding the lock. This patch fixes the remaining issue.
-rw-r--r--lldb/source/Target/Target.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp
index 8f8d2ef..7f56917 100644
--- a/lldb/source/Target/Target.cpp
+++ b/lldb/source/Target/Target.cpp
@@ -1510,15 +1510,18 @@ bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id,
}
ModuleSP Target::GetExecutableModule() {
- // search for the first executable in the module list
- for (ModuleSP module_sp : m_images.Modules()) {
+ std::lock_guard<std::recursive_mutex> lock(m_images.GetMutex());
+
+ // Search for the first executable in the module list.
+ for (ModuleSP module_sp : m_images.ModulesNoLocking()) {
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
if (obj == nullptr)
continue;
if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
return module_sp;
}
- // as fall back return the first module loaded
+
+ // If there is none, fall back return the first module loaded.
return m_images.GetModuleAtIndex(0);
}