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>


git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@157668 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Breakpoint/Breakpoint.cpp b/source/Breakpoint/Breakpoint.cpp
index 5d0cbd4..789118b 100644
--- a/source/Breakpoint/Breakpoint.cpp
+++ b/source/Breakpoint/Breakpoint.cpp
@@ -317,6 +317,7 @@
 void
 Breakpoint::ModulesChanged (ModuleList &module_list, bool load, bool delete_locations)
 {
+    Mutex::Locker modules_mutex(module_list.GetMutex());
     if (load)
     {
         // The logic for handling new modules is:
@@ -332,11 +333,11 @@
                                  // resolving breakpoints will add new locations potentially.
 
         const size_t num_locs = m_locations.GetSize();
-
-        for (size_t i = 0; i < module_list.GetSize(); i++)
+        size_t num_modules = module_list.GetSize();
+        for (size_t i = 0; i < num_modules; i++)
         {
             bool seen = false;
-            ModuleSP module_sp (module_list.GetModuleAtIndex (i));
+            ModuleSP module_sp (module_list.GetModuleAtIndexUnlocked (i));
             if (!m_filter_sp->ModulePasses (module_sp))
                 continue;
 
@@ -403,10 +404,11 @@
                                                                shared_from_this());
         else
             removed_locations_event = NULL;
-                    
-        for (size_t i = 0; i < module_list.GetSize(); i++)
+        
+        size_t num_modules = module_list.GetSize();
+        for (size_t i = 0; i < num_modules; i++)
         {
-            ModuleSP module_sp (module_list.GetModuleAtIndex (i));
+            ModuleSP module_sp (module_list.GetModuleAtIndexUnlocked (i));
             if (m_filter_sp->ModulePasses (module_sp))
             {
                 size_t loc_idx = 0;