[Lldb-commits] [lldb] r220358 - The breakpoint location hit counts were getting incremented in

Jim Ingham jingham at apple.com
Tue Oct 21 18:54:17 PDT 2014


Author: jingham
Date: Tue Oct 21 20:54:17 2014
New Revision: 220358

URL: http://llvm.org/viewvc/llvm-project?rev=220358&view=rev
Log:
The breakpoint location hit counts were getting incremented in
BreakpointLocation::ShouldStop.  That worked but wasn't really right,
since there's nothing to guarantee that won't get called more than
once.  So this change moves that responsibility to the StopInfoBreakpoint
directly, and then it uses the BreakpointSite to actually do the bumping.

Also fix a test case that was assuming if you had many threads running some 
code with a breakpoint in it, the hit count when you stopped would always be
1.  Many of the threads could have hit it at the same time...

<rdar://problem/18577603>

Modified:
    lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h
    lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h
    lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
    lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp
    lldb/trunk/source/Breakpoint/BreakpointSite.cpp
    lldb/trunk/source/Target/StopInfo.cpp
    lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Tue Oct 21 20:54:17 2014
@@ -387,6 +387,7 @@ public:
     bool EquivalentToLocation(BreakpointLocation &location);
     
 protected:
+    friend class BreakpointSite;
     friend class BreakpointLocationList;
     friend class Process;
 
@@ -413,6 +414,9 @@ private:
     void
     SwapLocation (lldb::BreakpointLocationSP swap_from);
 
+    void
+    BumpHitCount();
+
 
     //------------------------------------------------------------------
     // Constructors and Destructors

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointSite.h Tue Oct 21 20:54:17 2014
@@ -259,6 +259,12 @@ public:
 private:
     friend class Process;
     friend class BreakpointLocation;
+    // The StopInfoBreakpoint knows when it is processing a hit for a thread for a site, so let it be the
+    // one to manage setting the location hit count once and only once.
+    friend class StopInfoBreakpoint;
+
+    void
+    BumpHitCounts();
 
     //------------------------------------------------------------------
     /// The method removes the owner at \a break_loc_id from this breakpoint list.

Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Tue Oct 21 20:54:17 2014
@@ -449,8 +449,7 @@ BreakpointLocation::ShouldStop (Stoppoin
     bool should_stop = true;
     Log *log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS);
 
-    IncrementHitCount();
-
+    // Do this first, if a location is disabled, it shouldn't increment its hit count.
     if (!IsEnabled())
         return false;
 
@@ -474,6 +473,13 @@ BreakpointLocation::ShouldStop (Stoppoin
     return should_stop;
 }
 
+void
+BreakpointLocation::BumpHitCount()
+{
+    if (IsEnabled())
+        IncrementHitCount();
+}
+
 bool
 BreakpointLocation::IsResolved () const
 {

Modified: lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocationCollection.cpp Tue Oct 21 20:54:17 2014
@@ -196,3 +196,4 @@ BreakpointLocationCollection::GetDescrip
         (*pos)->GetDescription(s, level);
     }
 }
+

Modified: lldb/trunk/source/Breakpoint/BreakpointSite.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointSite.cpp?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointSite.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointSite.cpp Tue Oct 21 20:54:17 2014
@@ -199,6 +199,15 @@ BreakpointSite::ValidForThisThread (Thre
     return m_owners.ValidForThisThread(thread);
 }
 
+void
+BreakpointSite::BumpHitCounts()
+{
+    for (BreakpointLocationSP loc_sp : m_owners.BreakpointLocations())
+    {
+        loc_sp->BumpHitCount();
+    }
+}
+
 bool
 BreakpointSite::IntersectsRange(lldb::addr_t addr, size_t size, lldb::addr_t *intersect_addr, size_t *intersect_size, size_t *opcode_offset) const
 {

Modified: lldb/trunk/source/Target/StopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/source/Target/StopInfo.cpp (original)
+++ lldb/trunk/source/Target/StopInfo.cpp Tue Oct 21 20:54:17 2014
@@ -182,6 +182,7 @@ public:
                 {
                     ExecutionContext exe_ctx (thread_sp->GetStackFrameAtIndex(0));
                     StoppointCallbackContext context (event_ptr, exe_ctx, true);
+                    bp_site_sp->BumpHitCounts();
                     m_should_stop = bp_site_sp->ShouldStop (&context);
                 }
                 else
@@ -403,10 +404,21 @@ protected:
 
                     // Let's copy the breakpoint locations out of the site and store them in a local list.  That way if
                     // one of the breakpoint actions changes the site, then we won't be operating on a bad list.
+                    // For safety's sake let's also grab an extra reference to the breakpoint owners of the locations we're
+                    // going to examine, since the locations are going to have to get back to their breakpoints, and the
+                    // locations don't keep their owners alive.  I'm just sticking the BreakpointSP's in a vector since
+                    // I'm only really using it to locally increment their retain counts.
 
                     BreakpointLocationCollection site_locations;
+                    std::vector<lldb::BreakpointSP> location_owners;
+
                     for (size_t j = 0; j < num_owners; j++)
-                        site_locations.Add(bp_site_sp->GetOwnerAtIndex(j));
+                    {
+                        BreakpointLocationSP loc(bp_site_sp->GetOwnerAtIndex(j));
+                        site_locations.Add(loc);
+                        location_owners.push_back(loc->GetBreakpoint().shared_from_this());
+
+                    }
 
                     for (size_t j = 0; j < num_owners; j++)
                     {

Modified: lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py?rev=220358&r1=220357&r2=220358&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py (original)
+++ lldb/trunk/test/functionalities/attach_resume/TestAttachResume.py Tue Oct 21 20:54:17 2014
@@ -80,8 +80,12 @@ class AttachResumeTestCase(TestBase):
 
         self.assertTrue(wait_for_state(lldb.eStateStopped),
             'Process not stopped after breakpoint')
+        # This test runs a bunch of threads in the same little function with this
+        # breakpoint.  We want to make sure the breakpoint got hit at least once,
+        # but more than one thread may hit it at a time.  So we really only care
+        # that is isn't 0 times, not how many times it is.
         self.expect('br list', 'Breakpoint not hit',
-            patterns = ['hit count = 1'])
+            patterns = ['hit count = [1-9]'])
 
         self.runCmd("c")
         self.assertTrue(wait_for_state(lldb.eStateRunning),





More information about the lldb-commits mailing list