1""" 2Test breakpoint commands set before we have a target 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class BreakpointInDummyTarget (TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 def test(self): 17 """Test breakpoint set before we have a target. """ 18 self.build() 19 self.dummy_breakpoint_test() 20 21 def setUp(self): 22 # Call super's setUp(). 23 TestBase.setUp(self) 24 # Find the line number to break inside main(). 25 self.line = line_number('main.c', 'Set a breakpoint on this line.') 26 self.line2 = line_number('main.c', 'Set another on this line.') 27 28 def dummy_breakpoint_test(self): 29 """Test breakpoint set before we have a target. """ 30 31 # This should create a breakpoint with 3 locations. 32 lldbutil.run_break_set_by_file_and_line( 33 self, "main.c", self.line, num_expected_locations=0) 34 lldbutil.run_break_set_by_file_and_line( 35 self, "main.c", self.line2, num_expected_locations=0) 36 37 # This is the function to remove breakpoints from the dummy target 38 # to get a clean slate for the next test case. 39 def cleanup(): 40 self.runCmd('breakpoint delete -D -f', check=False) 41 self.runCmd('breakpoint list', check=False) 42 43 # Execute the cleanup function during test case tear down. 44 self.addTearDownHook(cleanup) 45 46 exe = self.getBuildArtifact("a.out") 47 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 48 49 # The breakpoint list should show 3 locations. 50 self.expect( 51 "breakpoint list -f", 52 "Breakpoint locations shown correctly", 53 substrs=[ 54 "1: file = 'main.c', line = %d, exact_match = 0, locations = 1" % 55 self.line, 56 "2: file = 'main.c', line = %d, exact_match = 0, locations = 1" % 57 self.line2]) 58 59 # Run the program. 60 self.runCmd("run", RUN_SUCCEEDED) 61 62 # Stopped once. 63 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 64 substrs=["stop reason = breakpoint 1."]) 65 66 # Continue the program, there should be another stop. 67 self.runCmd("process continue") 68 69 # Stopped again. 70 self.expect("thread backtrace", STOPPED_DUE_TO_BREAKPOINT, 71 substrs=["stop reason = breakpoint 2."]) 72