xref: /llvm-project/lldb/test/API/lang/cpp/this/TestCPPThis.py (revision 99562332e3de19da9da1714a58b5cc2d24724ef5)
1"""
2Tests that C++ member and static variables are available where they should be.
3"""
4import lldb
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8
9
10class CPPThisTestCase(TestBase):
11
12    mydir = TestBase.compute_mydir(__file__)
13
14    # rdar://problem/9962849
15    @expectedFailureAll(
16        compiler="gcc",
17        bugnumber="llvm.org/pr15439 The 'this' pointer isn't available during expression evaluation when stopped in an inlined member function")
18    @expectedFailureAll(
19        compiler="icc",
20        bugnumber="ICC doesn't emit correct DWARF inline debug info for inlined member functions.")
21    @expectedFailureAll(
22        oslist=["windows"],
23        bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows")
24    def test_with_run_command(self):
25        """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
26        self.build()
27        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
28
29        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
30        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
31        self.set_breakpoint(line_number('main.cpp', '// breakpoint 3'))
32        self.set_breakpoint(line_number('main.cpp', '// breakpoint 4'))
33
34        self.runCmd("process launch", RUN_SUCCEEDED)
35
36        self.expect("expression -- m_a = 2",
37                    startstr="(int) $0 = 2")
38
39        self.runCmd("process continue")
40
41        # This would be disallowed if we enforced const.  But we don't.
42        self.expect("expression -- m_a = 2",
43                    startstr="(int) $1 = 2")
44
45        self.expect("expression -- (int)getpid(); m_a",
46                    startstr="(int) $2 = 2")
47
48        self.runCmd("process continue")
49
50        self.expect("expression -- s_a",
51                    startstr="(int) $3 = 5")
52
53        self.runCmd("process continue")
54
55        self.expect("expression -- m_a",
56                    startstr="(int) $4 = 2")
57
58    def set_breakpoint(self, line):
59        lldbutil.run_break_set_by_file_and_line(
60            self, "main.cpp", line, num_expected_locations=1, loc_exact=False)
61