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