Skip to content

Commit 76f3cc9

Browse files
authored
[lldb] Fix another race condition in Target::GetExecutableModule (#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.
1 parent 018548d commit 76f3cc9

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
@@ -1510,15 +1510,18 @@ bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id,
15101510
}
15111511

15121512
ModuleSP Target::GetExecutableModule() {
1513-
// search for the first executable in the module list
1514-
for (ModuleSP module_sp : m_images.Modules()) {
1513+
std::lock_guard<std::recursive_mutex> lock(m_images.GetMutex());
1514+
1515+
// Search for the first executable in the module list.
1516+
for (ModuleSP module_sp : m_images.ModulesNoLocking()) {
15151517
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
15161518
if (obj == nullptr)
15171519
continue;
15181520
if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
15191521
return module_sp;
15201522
}
1521-
// as fall back return the first module loaded
1523+
1524+
// If there is none, fall back return the first module loaded.
15221525
return m_images.GetModuleAtIndex(0);
15231526
}
15241527

0 commit comments

Comments
 (0)