Skip to content

Commit 3d8aa19

Browse files
authored
Merge pull request #10906 from swiftlang/cherrypick-swift/release/6.2-c72c0b298c13
Fix race condition during iteration through modules (llvm#139283) (llvm#139862)
2 parents ac66248 + a71784e commit 3d8aa19

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lldb/source/Target/Target.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,16 +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 (size_t i = 0; i < m_images.GetSize(); ++i) {
1456-
ModuleSP module_sp = m_images.GetModuleAtIndex(i);
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()) {
14571458
lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
14581459
if (obj == nullptr)
14591460
continue;
14601461
if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
14611462
return module_sp;
14621463
}
1463-
// as fall back return the first module loaded
1464+
1465+
// If there is none, fall back return the first module loaded.
14641466
return m_images.GetModuleAtIndex(0);
14651467
}
14661468

0 commit comments

Comments
 (0)