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 RenameThisSampleTestTestCase(TestBase):
17
18    mydir = TestBase.compute_mydir(__file__)
19
20    def test_breakpoints_on_initializers(self):
21        """Show we can set breakpoints on initializers appearing both before
22           and after the constructor body, and hit them."""
23        self.build()
24        self.main_source_file = lldb.SBFileSpec("main.cpp")
25        self.first_initializer_line = line_number("main.cpp", "Set the before constructor breakpoint here")
26        self.second_initializer_line = line_number("main.cpp", "Set the after constructor breakpoint here")
27        self.sample_test()
28
29    def setUp(self):
30        # Call super's setUp().
31        TestBase.setUp(self)
32        # Set up your test case here. If your test doesn't need any set up then
33        # remove this method from your TestCase class.
34
35    def sample_test(self):
36        """You might use the test implementation in several ways, say so here."""
37
38        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
39                                   " Set a breakpoint here to get started", self.main_source_file)
40
41        # Now set breakpoints on the two initializer lines we found in the test startup:
42        bkpt1 = target.BreakpointCreateByLocation(self.main_source_file, self.first_initializer_line)
43        self.assertEqual(bkpt1.GetNumLocations(), 1)
44        bkpt2 = target.BreakpointCreateByLocation(self.main_source_file, self.second_initializer_line)
45        self.assertEqual(bkpt2.GetNumLocations(), 1)
46
47        # Now continue, we should stop at the two breakpoints above, first the one before, then
48        # the one after.
49        self.assertEqual(len(lldbutil.continue_to_breakpoint(process, bkpt1)), 1, "Hit first breakpoint")
50        self.assertEqual(len(lldbutil.continue_to_breakpoint(process, bkpt2)), 1, "Hit second breakpoint")
51
52
53