[Lldb-commits] [lldb] r308480 - Expose hit count via SBBreakpointLocation.
Bruce Mitchener via lldb-commits
lldb-commits at lists.llvm.org
Wed Jul 19 07:31:20 PDT 2017
Author: brucem
Date: Wed Jul 19 07:31:19 2017
New Revision: 308480
URL: http://llvm.org/viewvc/llvm-project?rev=308480&view=rev
Log:
Expose hit count via SBBreakpointLocation.
Summary:
SBBreakpointLocation exposed the ignore count, but didn't expose
the hit count. Both values were exposed by SBBreakpoint and
SBWatchpoint, so this makes things a bit more consistent.
Reviewers: lldb-commits
Subscribers: lldb-commits
Differential Revision: https://reviews.llvm.org/D31283
Added:
lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/
lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile
lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp
Modified:
lldb/trunk/include/lldb/API/SBBreakpointLocation.h
lldb/trunk/scripts/interface/SBBreakpointLocation.i
lldb/trunk/source/API/SBBreakpointLocation.cpp
Modified: lldb/trunk/include/lldb/API/SBBreakpointLocation.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/API/SBBreakpointLocation.h?rev=308480&r1=308479&r2=308480&view=diff
==============================================================================
--- lldb/trunk/include/lldb/API/SBBreakpointLocation.h (original)
+++ lldb/trunk/include/lldb/API/SBBreakpointLocation.h Wed Jul 19 07:31:19 2017
@@ -38,6 +38,8 @@ public:
bool IsEnabled();
+ uint32_t GetHitCount();
+
uint32_t GetIgnoreCount();
void SetIgnoreCount(uint32_t n);
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile?rev=308480&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/Makefile Wed Jul 19 07:31:19 2017
@@ -0,0 +1,5 @@
+LEVEL = ../../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py?rev=308480&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/TestBreakpointHitCount.py Wed Jul 19 07:31:19 2017
@@ -0,0 +1,109 @@
+"""
+Test breakpoint hit count features.
+"""
+
+from __future__ import print_function
+
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+
+class BreakpointHitCountTestCase(TestBase):
+
+ NO_DEBUG_INFO_TESTCASE = True
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(['pyapi'])
+ def test_breakpoint_location_hit_count(self):
+ """Use Python APIs to check breakpoint hit count."""
+ self.build()
+ self.do_test_breakpoint_location_hit_count()
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ self.a_int_body_line_no = line_number(
+ 'main.cpp', '// Breakpoint Location 1')
+ self.a_float_body_line_no = line_number(
+ 'main.cpp', '// Breakpoint Location 2')
+
+ def do_test_breakpoint_location_hit_count(self):
+ """Use Python APIs to check breakpoint hit count."""
+ exe = os.path.join(os.getcwd(), "a.out")
+
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # Create a breakpoint in main.cpp by name 'a',
+ # there should be two locations.
+ breakpoint = target.BreakpointCreateByName('a', 'a.out')
+ self.assertTrue(breakpoint and
+ breakpoint.GetNumLocations() == 2,
+ VALID_BREAKPOINT)
+
+ # Verify all breakpoint locations are enabled.
+ location1 = breakpoint.GetLocationAtIndex(0)
+ self.assertTrue(location1 and
+ location1.IsEnabled(),
+ VALID_BREAKPOINT_LOCATION)
+
+ location2 = breakpoint.GetLocationAtIndex(1)
+ self.assertTrue(location2 and
+ location2.IsEnabled(),
+ VALID_BREAKPOINT_LOCATION)
+
+ # Launch the process, and do not stop at entry point.
+ process = target.LaunchSimple(
+ None, None, self.get_process_working_directory())
+ self.assertTrue(process, PROCESS_IS_VALID)
+
+ # Verify 1st breakpoint location is hit.
+ from lldbsuite.test.lldbutil import get_stopped_thread
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ frame0 = thread.GetFrameAtIndex(0)
+ location1 = breakpoint.FindLocationByAddress(frame0.GetPC())
+ self.assertTrue(
+ frame0.GetLineEntry().GetLine() == self.a_int_body_line_no,
+ "Stopped in int a(int)")
+ self.assertTrue(location1)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 1)
+
+ process.Continue()
+
+ # Verify 2nd breakpoint location is hit.
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ frame0 = thread.GetFrameAtIndex(0)
+ location2 = breakpoint.FindLocationByAddress(frame0.GetPC())
+ self.assertTrue(
+ frame0.GetLineEntry().GetLine() == self.a_float_body_line_no,
+ "Stopped in float a(float)")
+ self.assertTrue(location2)
+ self.assertEqual(location2.GetHitCount(), 1)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 2)
+
+ process.Continue()
+
+ # Verify 2nd breakpoint location is hit again.
+ thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
+ self.assertTrue(
+ thread.IsValid(),
+ "There should be a thread stopped due to breakpoint")
+
+ self.assertEqual(location2.GetHitCount(), 2)
+ self.assertEqual(location1.GetHitCount(), 1)
+ self.assertEqual(breakpoint.GetHitCount(), 3)
+
+ process.Continue()
Added: lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp?rev=308480&view=auto
==============================================================================
--- lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp (added)
+++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/breakpoint/breakpoint_hit_count/main.cpp Wed Jul 19 07:31:19 2017
@@ -0,0 +1,27 @@
+//===-- main.cpp ------------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+int a(int val)
+{
+ return val; // Breakpoint Location 1
+}
+
+float a(float val)
+{
+ return val; // Breakpoint Location 2
+}
+
+int main (int argc, char const *argv[])
+{
+ int A1 = a(1);
+ float A2 = a(2.0f);
+ float A3 = a(3.0f);
+
+ return 0;
+}
Modified: lldb/trunk/scripts/interface/SBBreakpointLocation.i
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/scripts/interface/SBBreakpointLocation.i?rev=308480&r1=308479&r2=308480&view=diff
==============================================================================
--- lldb/trunk/scripts/interface/SBBreakpointLocation.i (original)
+++ lldb/trunk/scripts/interface/SBBreakpointLocation.i Wed Jul 19 07:31:19 2017
@@ -48,6 +48,9 @@ public:
IsEnabled ();
uint32_t
+ GetHitCount ();
+
+ uint32_t
GetIgnoreCount ();
void
Modified: lldb/trunk/source/API/SBBreakpointLocation.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/API/SBBreakpointLocation.cpp?rev=308480&r1=308479&r2=308480&view=diff
==============================================================================
--- lldb/trunk/source/API/SBBreakpointLocation.cpp (original)
+++ lldb/trunk/source/API/SBBreakpointLocation.cpp Wed Jul 19 07:31:19 2017
@@ -100,6 +100,16 @@ bool SBBreakpointLocation::IsEnabled() {
return false;
}
+uint32_t SBBreakpointLocation::GetHitCount() {
+ BreakpointLocationSP loc_sp = GetSP();
+ if (loc_sp) {
+ std::lock_guard<std::recursive_mutex> guard(
+ loc_sp->GetTarget().GetAPIMutex());
+ return loc_sp->GetHitCount();
+ } else
+ return 0;
+}
+
uint32_t SBBreakpointLocation::GetIgnoreCount() {
BreakpointLocationSP loc_sp = GetSP();
if (loc_sp) {
More information about the lldb-commits
mailing list