54 lines · python
1"""2When using C++11 in place member initialization, show that we3can set and hit breakpoints on initialization lines. This is a4little bit tricky because we try not to move file and line breakpoints 5across function boundaries but these lines are outside the source range6of the constructor.7"""8 9 10import lldb11import lldbsuite.test.lldbutil as lldbutil12from lldbsuite.test.lldbtest import *13 14 15class TestCase(TestBase):16 def test_breakpoints_on_initializers(self):17 """Show we can set breakpoints on initializers appearing both before18 and after the constructor body, and hit them."""19 self.build()20 self.main_source_file = lldb.SBFileSpec("main.cpp")21 self.first_initializer_line = line_number(22 "main.cpp", "Set the before constructor breakpoint here"23 )24 self.second_initializer_line = line_number(25 "main.cpp", "Set the after constructor breakpoint here"26 )27 28 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(29 self, " Set a breakpoint here to get started", self.main_source_file30 )31 32 # Now set breakpoints on the two initializer lines we found in the test startup:33 bkpt1 = target.BreakpointCreateByLocation(34 self.main_source_file, self.first_initializer_line35 )36 self.assertEqual(bkpt1.GetNumLocations(), 1)37 bkpt2 = target.BreakpointCreateByLocation(38 self.main_source_file, self.second_initializer_line39 )40 self.assertEqual(bkpt2.GetNumLocations(), 1)41 42 # Now continue, we should stop at the two breakpoints above, first the one before, then43 # the one after.44 self.assertEqual(45 len(lldbutil.continue_to_breakpoint(process, bkpt1)),46 1,47 "Hit first breakpoint",48 )49 self.assertEqual(50 len(lldbutil.continue_to_breakpoint(process, bkpt2)),51 1,52 "Hit second breakpoint",53 )54