2 Test breakpoint hit count features.
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class BreakpointHitCountTestCase(TestBase):
14 NO_DEBUG_INFO_TESTCASE = True
16 mydir = TestBase.compute_mydir(__file__)
18 @add_test_categories(['pyapi'])
19 def test_breakpoint_location_hit_count(self):
20 """Use Python APIs to check breakpoint hit count."""
22 self.do_test_breakpoint_location_hit_count()
24 def test_breakpoint_one_shot(self):
25 """Check that one-shot breakpoints trigger only once."""
28 exe = self.getBuildArtifact("a.out")
29 target = self.dbg.CreateTarget(exe)
30 self.assertTrue(target, VALID_TARGET)
33 process = target.LaunchSimple(
34 None, None, self.get_process_working_directory())
35 self.assertTrue(process, PROCESS_IS_VALID)
37 from lldbsuite.test.lldbutil import get_stopped_thread
38 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
41 "There should be a thread stopped due to breakpoint")
43 frame0 = thread.GetFrameAtIndex(0)
44 self.assertTrue(frame0.GetFunctionName() == "a(int)" or frame0.GetFunctionName() == "int a(int)");
47 self.assertEqual(process.GetState(), lldb.eStateExited)
50 # Call super's setUp().
52 self.a_int_body_line_no = line_number(
53 'main.cpp', '// Breakpoint Location 1')
54 self.a_float_body_line_no = line_number(
55 'main.cpp', '// Breakpoint Location 2')
57 def do_test_breakpoint_location_hit_count(self):
58 """Use Python APIs to check breakpoint hit count."""
59 exe = self.getBuildArtifact("a.out")
61 target = self.dbg.CreateTarget(exe)
62 self.assertTrue(target, VALID_TARGET)
64 # Create a breakpoint in main.cpp by name 'a',
65 # there should be two locations.
66 breakpoint = target.BreakpointCreateByName('a', 'a.out')
67 self.assertTrue(breakpoint and
68 breakpoint.GetNumLocations() == 2,
71 # Verify all breakpoint locations are enabled.
72 location1 = breakpoint.GetLocationAtIndex(0)
73 self.assertTrue(location1 and
74 location1.IsEnabled(),
75 VALID_BREAKPOINT_LOCATION)
77 location2 = breakpoint.GetLocationAtIndex(1)
78 self.assertTrue(location2 and
79 location2.IsEnabled(),
80 VALID_BREAKPOINT_LOCATION)
82 # Launch the process, and do not stop at entry point.
83 process = target.LaunchSimple(
84 None, None, self.get_process_working_directory())
85 self.assertTrue(process, PROCESS_IS_VALID)
87 # Verify 1st breakpoint location is hit.
88 from lldbsuite.test.lldbutil import get_stopped_thread
89 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
92 "There should be a thread stopped due to breakpoint")
94 frame0 = thread.GetFrameAtIndex(0)
95 location1 = breakpoint.FindLocationByAddress(frame0.GetPC())
97 frame0.GetLineEntry().GetLine() == self.a_int_body_line_no,
98 "Stopped in int a(int)")
99 self.assertTrue(location1)
100 self.assertEqual(location1.GetHitCount(), 1)
101 self.assertEqual(breakpoint.GetHitCount(), 1)
105 # Verify 2nd breakpoint location is hit.
106 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
109 "There should be a thread stopped due to breakpoint")
111 frame0 = thread.GetFrameAtIndex(0)
112 location2 = breakpoint.FindLocationByAddress(frame0.GetPC())
114 frame0.GetLineEntry().GetLine() == self.a_float_body_line_no,
115 "Stopped in float a(float)")
116 self.assertTrue(location2)
117 self.assertEqual(location2.GetHitCount(), 1)
118 self.assertEqual(location1.GetHitCount(), 1)
119 self.assertEqual(breakpoint.GetHitCount(), 2)
123 # Verify 2nd breakpoint location is hit again.
124 thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint)
127 "There should be a thread stopped due to breakpoint")
129 self.assertEqual(location2.GetHitCount(), 2)
130 self.assertEqual(location1.GetHitCount(), 1)
131 self.assertEqual(breakpoint.GetHitCount(), 3)