[Lldb-commits] [lldb] r270939 - Lock the access to the BreakpointLocationCollection.

Jim Ingham via lldb-commits lldb-commits at lists.llvm.org
Thu May 26 16:55:05 PDT 2016


Author: jingham
Date: Thu May 26 18:55:04 2016
New Revision: 270939

URL: http://llvm.org/viewvc/llvm-project?rev=270939&view=rev
Log:
Lock the access to the BreakpointLocationCollection.

I was investigating an odd crash in lldb when the breakpoint site
goes to bump the hit counts of the locations it implements.  I noticed
that the BreakpointLocationCollection wasn't locking itself for access and
modification.  I don't see how that can cause the crash I'm seeing, but still
this is the right thing to do...

<rdar://problem/25178205>

Modified:
    lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h
    lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h?rev=270939&r1=270938&r2=270939&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocationCollection.h Thu May 26 18:55:04 2016
@@ -13,6 +13,8 @@
 // C Includes
 // C++ Includes
 #include <vector>
+#include <mutex>
+
 // Other libraries and framework includes
 // Project includes
 #include "lldb/lldb-private.h"
@@ -201,7 +203,8 @@ private:
     collection::const_iterator
     GetIDPairConstIterator(lldb::break_id_t break_id, lldb::break_id_t break_loc_id) const;
 
-    collection m_break_loc_collection;
+    collection     m_break_loc_collection;
+    mutable std::mutex  m_collection_mutex;
 
 public:
     typedef AdaptedIterable<collection, lldb::BreakpointLocationSP, vector_adapter> BreakpointLocationCollectionIterable;

Modified: lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp?rev=270939&r1=270938&r2=270939&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp Thu May 26 18:55:04 2016
@@ -26,7 +26,8 @@ using namespace lldb_private;
 // BreakpointLocationCollection constructor
 //----------------------------------------------------------------------
 BreakpointLocationCollection::BreakpointLocationCollection() :
-    m_break_loc_collection()
+    m_break_loc_collection(),
+    m_collection_mutex()
 {
 }
 
@@ -40,6 +41,7 @@ BreakpointLocationCollection::~Breakpoin
 void
 BreakpointLocationCollection::Add(const BreakpointLocationSP &bp_loc)
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     BreakpointLocationSP old_bp_loc = FindByIDPair (bp_loc->GetBreakpoint().GetID(), bp_loc->GetID());
     if (!old_bp_loc.get())
         m_break_loc_collection.push_back(bp_loc);
@@ -48,6 +50,7 @@ BreakpointLocationCollection::Add(const
 bool
 BreakpointLocationCollection::Remove (lldb::break_id_t bp_id, lldb::break_id_t bp_loc_id)
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     collection::iterator pos = GetIDPairIterator(bp_id, bp_loc_id);    // Predicate
     if (pos != m_break_loc_collection.end())
     {
@@ -117,6 +120,7 @@ BreakpointLocationCollection::FindByIDPa
 BreakpointLocationSP
 BreakpointLocationCollection::GetByIndex (size_t i)
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     BreakpointLocationSP stop_sp;
     if (i < m_break_loc_collection.size())
         stop_sp = m_break_loc_collection[i];
@@ -127,6 +131,7 @@ BreakpointLocationCollection::GetByIndex
 const BreakpointLocationSP
 BreakpointLocationCollection::GetByIndex (size_t i) const
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     BreakpointLocationSP stop_sp;
     if (i < m_break_loc_collection.size())
         stop_sp = m_break_loc_collection[i];
@@ -156,6 +161,7 @@ BreakpointLocationCollection::ShouldStop
 bool 
 BreakpointLocationCollection::ValidForThisThread (Thread *thread)
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     collection::iterator pos,
         begin = m_break_loc_collection.begin(),
         end = m_break_loc_collection.end();
@@ -171,6 +177,7 @@ BreakpointLocationCollection::ValidForTh
 bool 
 BreakpointLocationCollection::IsInternal () const
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     collection::const_iterator pos,
         begin = m_break_loc_collection.begin(),
         end = m_break_loc_collection.end();
@@ -191,6 +198,7 @@ BreakpointLocationCollection::IsInternal
 void
 BreakpointLocationCollection::GetDescription (Stream *s, lldb::DescriptionLevel level)
 {
+    std::lock_guard<std::mutex> guard(m_collection_mutex);
     collection::iterator pos,
         begin = m_break_loc_collection.begin(),
         end = m_break_loc_collection.end();




More information about the lldb-commits mailing list