xref: /llvm-project/lldb/test/API/lang/cpp/inlines/TestInlines.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""Test variable lookup when stopped in inline functions."""
299451b44SJordan Rupprecht
399451b44SJordan Rupprecht
499451b44SJordan Rupprechtimport lldb
599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import *
699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil
899451b44SJordan Rupprecht
999451b44SJordan Rupprecht
1099451b44SJordan Rupprechtclass InlinesTestCase(TestBase):
1199451b44SJordan Rupprecht    def setUp(self):
1299451b44SJordan Rupprecht        # Call super's setUp().
1399451b44SJordan Rupprecht        TestBase.setUp(self)
1499451b44SJordan Rupprecht        # Find the line number to break inside main().
15*2238dcc3SJonas Devlieghere        self.line = line_number("inlines.cpp", "// Set break point at this line.")
1699451b44SJordan Rupprecht
1799451b44SJordan Rupprecht    def test(self):
1899451b44SJordan Rupprecht        """Test that local variables are visible in expressions."""
1999451b44SJordan Rupprecht        self.build()
2099451b44SJordan Rupprecht        self.runToBreakpoint()
2199451b44SJordan Rupprecht
2299451b44SJordan Rupprecht        # Check that 'frame variable' finds a variable
2399451b44SJordan Rupprecht        self.expect(
2499451b44SJordan Rupprecht            "frame variable inner_input",
2599451b44SJordan Rupprecht            VARIABLES_DISPLAYED_CORRECTLY,
26*2238dcc3SJonas Devlieghere            startstr="(int) inner_input =",
27*2238dcc3SJonas Devlieghere        )
2899451b44SJordan Rupprecht
2999451b44SJordan Rupprecht        # Check that 'expr' finds a variable
30*2238dcc3SJonas Devlieghere        self.expect(
31*2238dcc3SJonas Devlieghere            "expr inner_input", VARIABLES_DISPLAYED_CORRECTLY, startstr="(int) $0 ="
32*2238dcc3SJonas Devlieghere        )
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht    def runToBreakpoint(self):
3599451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
3699451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
3799451b44SJordan Rupprecht
3899451b44SJordan Rupprecht        # Break inside the main.
3999451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
40*2238dcc3SJonas Devlieghere            self, "inlines.cpp", self.line, num_expected_locations=2, loc_exact=True
41*2238dcc3SJonas Devlieghere        )
4299451b44SJordan Rupprecht
4399451b44SJordan Rupprecht        self.runCmd("run", RUN_SUCCEEDED)
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht        # The stop reason of the thread should be breakpoint.
46*2238dcc3SJonas Devlieghere        self.expect(
47*2238dcc3SJonas Devlieghere            "thread list",
48*2238dcc3SJonas Devlieghere            STOPPED_DUE_TO_BREAKPOINT,
49*2238dcc3SJonas Devlieghere            substrs=["stopped", "stop reason = breakpoint"],
50*2238dcc3SJonas Devlieghere        )
5199451b44SJordan Rupprecht
5299451b44SJordan Rupprecht        # The breakpoint should have a hit count of 1.
539f0b5f9aSSYNOPSYS\georgiev        lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1)
54