xref: /llvm-project/lldb/test/API/lang/cpp/inlines/TestInlines.py (revision 9f0b5f9a39ea6e70c98c69a720d7e4f5d3800bf6)
1"""Test variable lookup when stopped in inline functions."""
2
3
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class InlinesTestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    def setUp(self):
15        # Call super's setUp().
16        TestBase.setUp(self)
17        # Find the line number to break inside main().
18        self.line = line_number(
19            'inlines.cpp',
20            '// Set break point at this line.')
21
22    def test(self):
23        """Test that local variables are visible in expressions."""
24        self.build()
25        self.runToBreakpoint()
26
27        # Check that 'frame variable' finds a variable
28        self.expect(
29            "frame variable inner_input",
30            VARIABLES_DISPLAYED_CORRECTLY,
31            startstr='(int) inner_input =')
32
33        # Check that 'expr' finds a variable
34        self.expect("expr inner_input", VARIABLES_DISPLAYED_CORRECTLY,
35                    startstr='(int) $0 =')
36
37    def runToBreakpoint(self):
38        exe = self.getBuildArtifact("a.out")
39        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
40
41        # Break inside the main.
42        lldbutil.run_break_set_by_file_and_line(
43            self,
44            "inlines.cpp",
45            self.line,
46            num_expected_locations=2,
47            loc_exact=True)
48
49        self.runCmd("run", RUN_SUCCEEDED)
50
51        # The stop reason of the thread should be breakpoint.
52        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
53                    substrs=['stopped',
54                             'stop reason = breakpoint'])
55
56        # The breakpoint should have a hit count of 1.
57        lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1)
58