1"""
2Test that inlined breakpoints (breakpoint set on a file/line included from
3another source file) works correctly.
4"""
5
6
7
8import lldb
9from lldbsuite.test.lldbtest import *
10import lldbsuite.test.lldbutil as lldbutil
11
12
13class InlinedBreakpointsTestCase(TestBase):
14    """Bug fixed: rdar://problem/8464339"""
15
16    def test_with_run_command(self):
17        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
18        self.build()
19        self.inlined_breakpoints()
20
21    def setUp(self):
22        # Call super's setUp().
23        TestBase.setUp(self)
24        # Find the line number to break inside basic_type.cpp.
25        self.line = line_number(
26            'basic_type.cpp',
27            '// Set break point at this line.')
28
29    def inlined_breakpoints(self):
30        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
31        exe = self.getBuildArtifact("a.out")
32        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
33
34        # With the inline-breakpoint-strategy, our file+line breakpoint should
35        # not resolve to a location.
36        self.runCmd('settings set target.inline-breakpoint-strategy headers')
37
38        # Set a breakpoint and fail because it is in an inlined source
39        # implemenation file
40        lldbutil.run_break_set_by_file_and_line(
41            self, "basic_type.cpp", self.line, num_expected_locations=0)
42
43        # Now enable breakpoints in implementation files and see the breakpoint
44        # set succeed
45        self.runCmd('settings set target.inline-breakpoint-strategy always')
46        # And add hooks to restore the settings during tearDown().
47        self.addTearDownHook(lambda: self.runCmd(
48            "settings set target.inline-breakpoint-strategy always"))
49
50        lldbutil.run_break_set_by_file_and_line(
51            self,
52            "basic_type.cpp",
53            self.line,
54            num_expected_locations=1,
55            loc_exact=True)
56
57        self.runCmd("run", RUN_SUCCEEDED)
58
59        # The stop reason of the thread should be breakpoint.
60        # And it should break at basic_type.cpp:176.
61        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
62                    substrs=['stopped',
63                             'basic_type.cpp:%d' % self.line,
64                             'stop reason = breakpoint',])
65