1"""
2When using C++11 in place member initialization, show that we
3can set and hit breakpoints on initialization lines.  This is a
4little bit tricky because we try not to move file and line breakpoints
5across function boundaries but these lines are outside the source range
6of the constructor.
7"""
8
9
10
11import lldb
12import lldbsuite.test.lldbutil as lldbutil
13from lldbsuite.test.lldbtest import *
14
15
16class TestCase(TestBase):
17
18    def test_breakpoints_on_initializers(self):
19        """Show we can set breakpoints on initializers appearing both before
20           and after the constructor body, and hit them."""
21        self.build()
22        self.main_source_file = lldb.SBFileSpec("main.cpp")
23        self.first_initializer_line = line_number("main.cpp", "Set the before constructor breakpoint here")
24        self.second_initializer_line = line_number("main.cpp", "Set the after constructor breakpoint here")
25
26        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
27                                   " Set a breakpoint here to get started", self.main_source_file)
28
29        # Now set breakpoints on the two initializer lines we found in the test startup:
30        bkpt1 = target.BreakpointCreateByLocation(self.main_source_file, self.first_initializer_line)
31        self.assertEqual(bkpt1.GetNumLocations(), 1)
32        bkpt2 = target.BreakpointCreateByLocation(self.main_source_file, self.second_initializer_line)
33        self.assertEqual(bkpt2.GetNumLocations(), 1)
34
35        # Now continue, we should stop at the two breakpoints above, first the one before, then
36        # the one after.
37        self.assertEqual(len(lldbutil.continue_to_breakpoint(process, bkpt1)), 1, "Hit first breakpoint")
38        self.assertEqual(len(lldbutil.continue_to_breakpoint(process, bkpt2)), 1, "Hit second breakpoint")
39
40
41