xref: /llvm-project/lldb/test/API/lang/cpp/this/TestCPPThis.py (revision 99451b4453688a94c6014cac233d371ab4cc342d)
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    @expectedFailureNetBSD
25    def test_with_run_command(self):
26        """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
27        self.build()
28        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
29
30        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
31        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
32        self.set_breakpoint(line_number('main.cpp', '// breakpoint 3'))
33        self.set_breakpoint(line_number('main.cpp', '// breakpoint 4'))
34
35        self.runCmd("process launch", RUN_SUCCEEDED)
36
37        self.expect("expression -- m_a = 2",
38                    startstr="(int) $0 = 2")
39
40        self.runCmd("process continue")
41
42        # This would be disallowed if we enforced const.  But we don't.
43        self.expect("expression -- m_a = 2",
44                    startstr="(int) $1 = 2")
45
46        self.expect("expression -- (int)getpid(); m_a",
47                    startstr="(int) $2 = 2")
48
49        self.runCmd("process continue")
50
51        self.expect("expression -- s_a",
52                    startstr="(int) $3 = 5")
53
54        self.runCmd("process continue")
55
56        self.expect("expression -- m_a",
57                    startstr="(int) $4 = 2")
58
59    def set_breakpoint(self, line):
60        lldbutil.run_break_set_by_file_and_line(
61            self, "main.cpp", line, num_expected_locations=1, loc_exact=False)
62