diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 8f8d2ef21cc5..7f569173eba2 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); }