Add locking around the m_owners collection in the breakpoint site. If we are in...
authorJim Ingham <jingham@apple.com>
Wed, 18 Jun 2014 01:04:40 +0000 (01:04 +0000)
committerJim Ingham <jingham@apple.com>
Wed, 18 Jun 2014 01:04:40 +0000 (01:04 +0000)
want other commands (like "break disable") to mutate the owners of this breakpoint out from under us.

<rdar://problem/17255589>

llvm-svn: 211136

lldb/include/lldb/Breakpoint/BreakpointSite.h
lldb/source/Breakpoint/BreakpointSite.cpp

index 6292b30..204206f 100644 (file)
@@ -19,6 +19,7 @@
 
 // Project includes
 #include "lldb/lldb-private.h"
+#include "lldb/Host/Mutex.h"
 #include "lldb/Core/UserID.h"
 #include "lldb/Breakpoint/StoppointLocation.h"
 #include "lldb/Breakpoint/BreakpointLocationCollection.h"
@@ -277,6 +278,7 @@ private:
     // Consider adding an optimization where if there is only one
     // owner, we don't store a list.  The usual case will be only one owner...
     BreakpointLocationCollection m_owners; ///< This has the BreakpointLocations that share this breakpoint site.
+    Mutex m_owners_mutex;      ///< This mutex protects the owners collection. 
 
     static lldb::break_id_t
     GetNextID();
index fa5d8c1..8290341 100644 (file)
@@ -32,7 +32,8 @@ BreakpointSite::BreakpointSite
     m_saved_opcode(),
     m_trap_opcode(),
     m_enabled(false), // Need to create it disabled, so the first enable turns it on.
-    m_owners()
+    m_owners(),
+    m_owners_mutex(Mutex::eMutexTypeRecursive)
 {
     m_owners.Add(owner);
 }
@@ -60,6 +61,7 @@ BreakpointSite::GetNextID()
 bool
 BreakpointSite::ShouldStop (StoppointCallbackContext *context)
 {
+    Mutex::Locker(m_owners_mutex);
     IncrementHitCount();
     return m_owners.ShouldStop (context);
 }
@@ -67,6 +69,7 @@ BreakpointSite::ShouldStop (StoppointCallbackContext *context)
 bool
 BreakpointSite::IsBreakpointAtThisSite (lldb::break_id_t bp_id)
 {
+    Mutex::Locker(m_owners_mutex);
     const size_t owner_count = m_owners.GetSize();
     for (size_t i = 0; i < owner_count; i++)
     {
@@ -93,6 +96,7 @@ BreakpointSite::Dump(Stream *s) const
 void
 BreakpointSite::GetDescription (Stream *s, lldb::DescriptionLevel level)
 {
+    Mutex::Locker(m_owners_mutex);
     if (level != lldb::eDescriptionLevelBrief)
         s->Printf ("breakpoint site: %d at 0x%8.8" PRIx64, GetID(), GetLoadAddress());
     m_owners.GetDescription (s, level);
@@ -101,6 +105,7 @@ BreakpointSite::GetDescription (Stream *s, lldb::DescriptionLevel level)
 bool
 BreakpointSite::IsInternal() const
 {
+    Mutex::Locker(m_owners_mutex);
     return m_owners.IsInternal();
 }
 
@@ -162,12 +167,14 @@ BreakpointSite::SetEnabled (bool enabled)
 void
 BreakpointSite::AddOwner (const BreakpointLocationSP &owner)
 {
+    Mutex::Locker(m_owners_mutex);
     m_owners.Add(owner);
 }
 
 size_t
 BreakpointSite::RemoveOwner (lldb::break_id_t break_id, lldb::break_id_t break_loc_id)
 {
+    Mutex::Locker(m_owners_mutex);
     m_owners.Remove(break_id, break_loc_id);
     return m_owners.GetSize();
 }
@@ -175,18 +182,21 @@ BreakpointSite::RemoveOwner (lldb::break_id_t break_id, lldb::break_id_t break_l
 size_t
 BreakpointSite::GetNumberOfOwners ()
 {
+    Mutex::Locker(m_owners_mutex);
     return m_owners.GetSize();
 }
 
 BreakpointLocationSP
 BreakpointSite::GetOwnerAtIndex (size_t index)
 {
+    Mutex::Locker(m_owners_mutex);
     return m_owners.GetByIndex (index);
 }
 
 bool
 BreakpointSite::ValidForThisThread (Thread *thread)
 {
+    Mutex::Locker(m_owners_mutex);
     return m_owners.ValidForThisThread(thread);
 }