We were accessing the ModuleList in the target without locking it for tasks like
setting breakpoints. That's dangerous, since while we are setting a breakpoint,
the target might hit the dyld load notification, and start removing modules from
the list. This change adds a GetMutex accessor to the ModuleList class, and
uses it whenever we are accessing the target's ModuleList (as returned by GetImages().)
<rdar://problem/11552372>
llvm-svn: 157668
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index c8e9cec..c42f469 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -1057,12 +1057,14 @@
// to an equivalent version. We don't want it to stay in the target's module list or it will confuse
// us, so unload it here.
Target &target = m_process->GetTarget();
- ModuleList &modules = target.GetImages();
+ ModuleList &target_modules = target.GetImages();
ModuleList not_loaded_modules;
- size_t num_modules = modules.GetSize();
+ Mutex::Locker modules_locker(target_modules.GetMutex());
+
+ size_t num_modules = target_modules.GetSize();
for (size_t i = 0; i < num_modules; i++)
{
- ModuleSP module_sp = modules.GetModuleAtIndex(i);
+ ModuleSP module_sp = target_modules.GetModuleAtIndexUnlocked (i);
if (!module_sp->IsLoadedInTarget (&target))
{
if (log)
diff --git a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
index a1d6442..abfbf1c 100644
--- a/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
+++ b/lldb/source/Plugins/DynamicLoader/Static/DynamicLoaderStatic.cpp
@@ -97,10 +97,12 @@
ModuleList loaded_module_list;
+ Mutex::Locker mutex_locker(module_list.GetMutex());
+
const size_t num_modules = module_list.GetSize();
for (uint32_t idx = 0; idx < num_modules; ++idx)
{
- ModuleSP module_sp (module_list.GetModuleAtIndex (idx));
+ ModuleSP module_sp (module_list.GetModuleAtIndexUnlocked (idx));
if (module_sp)
{
bool changed = false;