Skip to content

Commit a71784e

Browse files
committed
[lldb] Fix another race condition in Target::GetExecutableModule (llvm#145991)
c72c0b2 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. (cherry picked from commit 76f3cc9)
1 parent 8c0c768 commit a71784e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lldb/source/Target/Target.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,15 +1451,18 @@ bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id,
14511451
}
14521452

14531453
ModuleSP Target::GetExecutableModule() {
1454-
// search for the first executable in the module list
1455-
for (ModuleSP module_sp : m_images.Modules()) {
1454+
std::lock_guard<std::recursive_mutex> lock(m_images.GetMutex());
1455+
1456+
// Search for the first executable in the module list.
1457+
for (ModuleSP module_sp : m_images.ModulesNoLocking()) {
14561458
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
14571459
if (obj == nullptr)
14581460
continue;
14591461
if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
14601462
return module_sp;
14611463
}
1462-
// as fall back return the first module loaded
1464+
1465+
// If there is none, fall back return the first module loaded.
14631466
return m_images.GetModuleAtIndex(0);
14641467
}
14651468

0 commit comments

Comments
 (0)