diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 45a9e1196a049..a1556d892fd43 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 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); }