xref: /llvm-project/lldb/test/API/functionalities/breakpoint/inlined_breakpoints/TestInlinedBreakpoints.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTest that inlined breakpoints (breakpoint set on a file/line included from
399451b44SJordan Rupprechtanother source file) works correctly.
499451b44SJordan Rupprecht"""
599451b44SJordan Rupprecht
699451b44SJordan Rupprecht
799451b44SJordan Rupprechtimport lldb
899451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
999451b44SJordan Rupprechtimport lldbsuite.test.lldbutil as lldbutil
1099451b44SJordan Rupprecht
1199451b44SJordan Rupprecht
1299451b44SJordan Rupprechtclass InlinedBreakpointsTestCase(TestBase):
1399451b44SJordan Rupprecht    """Bug fixed: rdar://problem/8464339"""
1499451b44SJordan Rupprecht
1599451b44SJordan Rupprecht    def test_with_run_command(self):
1699451b44SJordan Rupprecht        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
1799451b44SJordan Rupprecht        self.build()
1899451b44SJordan Rupprecht        self.inlined_breakpoints()
1999451b44SJordan Rupprecht
2099451b44SJordan Rupprecht    def setUp(self):
2199451b44SJordan Rupprecht        # Call super's setUp().
2299451b44SJordan Rupprecht        TestBase.setUp(self)
2399451b44SJordan Rupprecht        # Find the line number to break inside basic_type.cpp.
24*2238dcc3SJonas Devlieghere        self.line = line_number("basic_type.cpp", "// Set break point at this line.")
2599451b44SJordan Rupprecht
2699451b44SJordan Rupprecht    def inlined_breakpoints(self):
2799451b44SJordan Rupprecht        """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp)."""
2899451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
2999451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
3099451b44SJordan Rupprecht
3199451b44SJordan Rupprecht        # With the inline-breakpoint-strategy, our file+line breakpoint should
3299451b44SJordan Rupprecht        # not resolve to a location.
33*2238dcc3SJonas Devlieghere        self.runCmd("settings set target.inline-breakpoint-strategy headers")
3499451b44SJordan Rupprecht
3599451b44SJordan Rupprecht        # Set a breakpoint and fail because it is in an inlined source
3699451b44SJordan Rupprecht        # implemenation file
3799451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
38*2238dcc3SJonas Devlieghere            self, "basic_type.cpp", self.line, num_expected_locations=0
39*2238dcc3SJonas Devlieghere        )
4099451b44SJordan Rupprecht
4199451b44SJordan Rupprecht        # Now enable breakpoints in implementation files and see the breakpoint
4299451b44SJordan Rupprecht        # set succeed
43*2238dcc3SJonas Devlieghere        self.runCmd("settings set target.inline-breakpoint-strategy always")
4499451b44SJordan Rupprecht        # And add hooks to restore the settings during tearDown().
45*2238dcc3SJonas Devlieghere        self.addTearDownHook(
46*2238dcc3SJonas Devlieghere            lambda: self.runCmd("settings set target.inline-breakpoint-strategy always")
47*2238dcc3SJonas Devlieghere        )
4899451b44SJordan Rupprecht
4999451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
50*2238dcc3SJonas Devlieghere            self, "basic_type.cpp", self.line, num_expected_locations=1, loc_exact=True
51*2238dcc3SJonas Devlieghere        )
5299451b44SJordan Rupprecht
5399451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
5499451b44SJordan Rupprecht
5599451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
5699451b44SJordan Rupprecht        # And it should break at basic_type.cpp:176.
57*2238dcc3SJonas Devlieghere        self.expect(
58*2238dcc3SJonas Devlieghere            "thread list",
59*2238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
60*2238dcc3SJonas Devlieghere            substrs=[
61*2238dcc3SJonas Devlieghere                "stopped",
62*2238dcc3SJonas Devlieghere                "basic_type.cpp:%d" % self.line,
63*2238dcc3SJonas Devlieghere                "stop reason = breakpoint",
64*2238dcc3SJonas Devlieghere            ],
65*2238dcc3SJonas Devlieghere        )
66