[Lldb-commits] [lldb] r226074 - Make sure that when a breakpoint is hit but its condition is not met,

Jim Ingham jingham at apple.com
Wed Jan 14 17:41:04 PST 2015


Author: jingham
Date: Wed Jan 14 19:41:04 2015
New Revision: 226074

URL: http://llvm.org/viewvc/llvm-project?rev=226074&view=rev
Log:
Make sure that when a breakpoint is hit but its condition is not met,
the hit count is not updated.
Also, keep the hit count for the breakpoint in the breakpoint.  We were
using just the sum of the location's hit counts, but that was wrong since if a shared library is
unloaded, and the location goes away, the breakpoint hit count should not suddenly drop
by the number of hits there were on that location.

Modified:
    lldb/trunk/include/lldb/Breakpoint/Breakpoint.h
    lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h
    lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h
    lldb/trunk/source/Breakpoint/Breakpoint.cpp
    lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
    lldb/trunk/source/Breakpoint/StoppointLocation.cpp
    lldb/trunk/source/Target/StopInfo.cpp
    lldb/trunk/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py

Modified: lldb/trunk/include/lldb/Breakpoint/Breakpoint.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/Breakpoint.h?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/Breakpoint.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/Breakpoint.h Wed Jan 14 19:41:04 2015
@@ -714,6 +714,19 @@ protected:
     bool
     IgnoreCountShouldStop ();
 
+    void
+    IncrementHitCount()
+    {
+        m_hit_count++;
+    }
+
+    void
+    DecrementHitCount()
+    {
+        assert (m_hit_count > 0);
+        m_hit_count--;
+    }
+
 private:
     // This one should only be used by Target to copy breakpoints from target to target - primarily from the dummy
     // target to prime new targets.
@@ -733,7 +746,10 @@ private:
     BreakpointLocationList m_locations;       // The list of locations currently found for this breakpoint.
     std::string m_kind_description;
     bool m_resolve_indirect_symbols;
-    
+    uint32_t    m_hit_count;                   // Number of times this breakpoint/watchpoint has been hit.  This is kept
+                                               // separately from the locations hit counts, since locations can go away when
+                                               // their backing library gets unloaded, and we would lose hit counts.
+
     void
     SendBreakpointChangedEvent (lldb::BreakpointEventType eventKind);
     

Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointLocation.h Wed Jan 14 19:41:04 2015
@@ -390,6 +390,7 @@ protected:
     friend class BreakpointSite;
     friend class BreakpointLocationList;
     friend class Process;
+    friend class StopInfoBreakpoint;
 
     //------------------------------------------------------------------
     /// Set the breakpoint site for this location to \a bp_site_sp.
@@ -417,6 +418,9 @@ private:
     void
     BumpHitCount();
 
+    void
+    UndoBumpHitCount();
+
 
     //------------------------------------------------------------------
     // Constructors and Destructors

Modified: lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/StoppointLocation.h Wed Jan 14 19:41:04 2015
@@ -134,6 +134,9 @@ protected:
         ++m_hit_count;
     }
 
+    void
+    DecrementHitCount ();
+
 private:
     //------------------------------------------------------------------
     // For StoppointLocation only

Modified: lldb/trunk/source/Breakpoint/Breakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Breakpoint.cpp?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/Breakpoint.cpp (original)
+++ lldb/trunk/source/Breakpoint/Breakpoint.cpp Wed Jan 14 19:41:04 2015
@@ -60,7 +60,8 @@ Breakpoint::Breakpoint(Target &target,
     m_resolver_sp (resolver_sp),
     m_options (),
     m_locations (*this),
-    m_resolve_indirect_symbols(resolve_indirect_symbols)
+    m_resolve_indirect_symbols(resolve_indirect_symbols),
+    m_hit_count(0)
 {
     m_being_created = false;
 }
@@ -72,7 +73,8 @@ Breakpoint::Breakpoint (Target &new_targ
     m_name_list (source_bp.m_name_list),
     m_options (source_bp.m_options),
     m_locations(*this),
-    m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols)
+    m_resolve_indirect_symbols(source_bp.m_resolve_indirect_symbols),
+    m_hit_count(0)
 {
     // Now go through and copy the filter & resolver:
     m_resolver_sp = source_bp.m_resolver_sp->CopyForBreakpoint(*this);
@@ -207,7 +209,7 @@ Breakpoint::IgnoreCountShouldStop ()
 uint32_t
 Breakpoint::GetHitCount () const
 {
-    return m_locations.GetHitCount();
+    return m_hit_count;
 }
 
 bool

Modified: lldb/trunk/source/Breakpoint/BreakpointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointLocation.cpp?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointLocation.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointLocation.cpp Wed Jan 14 19:41:04 2015
@@ -477,7 +477,22 @@ void
 BreakpointLocation::BumpHitCount()
 {
     if (IsEnabled())
+    {
+        // Step our hit count, and also step the hit count of the owner.
         IncrementHitCount();
+        m_owner.IncrementHitCount();
+    }
+}
+
+void
+BreakpointLocation::UndoBumpHitCount()
+{
+    if (IsEnabled())
+    {
+        // Step our hit count, and also step the hit count of the owner.
+        DecrementHitCount();
+        m_owner.DecrementHitCount();
+    }
 }
 
 bool

Modified: lldb/trunk/source/Breakpoint/StoppointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/StoppointLocation.cpp?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/StoppointLocation.cpp (original)
+++ lldb/trunk/source/Breakpoint/StoppointLocation.cpp Wed Jan 14 19:41:04 2015
@@ -46,3 +46,10 @@ StoppointLocation::StoppointLocation (br
 StoppointLocation::~StoppointLocation()
 {
 }
+
+void
+StoppointLocation::DecrementHitCount ()
+{
+    assert (m_hit_count > 0);
+    --m_hit_count;
+}

Modified: lldb/trunk/source/Target/StopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/StopInfo.cpp?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/source/Target/StopInfo.cpp (original)
+++ lldb/trunk/source/Target/StopInfo.cpp Wed Jan 14 19:41:04 2015
@@ -479,7 +479,12 @@ protected:
                                                  condition_says_stop);
                                 }
                                 if (!condition_says_stop)
+                                {
+                                    // We don't want to increment the hit count of breakpoints if the condition fails.
+                                    // We've already bumped it by the time we get here, so undo the bump:
+                                    bp_loc_sp->UndoBumpHitCount();
                                     continue;
+                                }
                             }
                         }
 

Modified: lldb/trunk/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py?rev=226074&r1=226073&r2=226074&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py (original)
+++ lldb/trunk/test/functionalities/breakpoint/breakpoint_conditions/TestBreakpointConditions.py Wed Jan 14 19:41:04 2015
@@ -90,10 +90,10 @@ class BreakpointConditionsTestCase(TestB
             startstr = '(int) val = 3')
 
         # Also check the hit count, which should be 3, by design.
-        self.expect("breakpoint list -f", BREAKPOINT_HIT_THRICE,
+        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
             substrs = ["resolved = 1",
                        "Condition: val == 3",
-                       "hit count = 3"])
+                       "hit count = 1"])
 
         # The frame #0 should correspond to main.c:36, the executable statement
         # in function name 'c'.  And the parent frame should point to main.c:24.
@@ -188,8 +188,8 @@ class BreakpointConditionsTestCase(TestB
         self.assertTrue(frame0.GetLineEntry().GetLine() == self.line1 and
                         var.GetValue() == '3')
 
-        # The hit count for the breakpoint should be 3.
-        self.assertTrue(breakpoint.GetHitCount() == 3)
+        # The hit count for the breakpoint should be 1.
+        self.assertTrue(breakpoint.GetHitCount() == 1)
 
         process.Continue()
 





More information about the lldb-commits mailing list