xref: /llvm-project/lldb/test/API/lang/cpp/this/TestCPPThis.py (revision 2238dcc39358353cac21df75c3c3286ab20b8f53)
199451b44SJordan Rupprecht"""
299451b44SJordan RupprechtTests that C++ member and static variables are available where they should be.
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 CPPThisTestCase(TestBase):
1199451b44SJordan Rupprecht    # rdar://problem/9962849
1299451b44SJordan Rupprecht    @expectedFailureAll(
1399451b44SJordan Rupprecht        compiler="gcc",
14*2238dcc3SJonas Devlieghere        bugnumber="llvm.org/pr15439 The 'this' pointer isn't available during expression evaluation when stopped in an inlined member function",
15*2238dcc3SJonas Devlieghere    )
1699451b44SJordan Rupprecht    @expectedFailureAll(
1799451b44SJordan Rupprecht        compiler="icc",
18*2238dcc3SJonas Devlieghere        bugnumber="ICC doesn't emit correct DWARF inline debug info for inlined member functions.",
19*2238dcc3SJonas Devlieghere    )
2099451b44SJordan Rupprecht    @expectedFailureAll(
2199451b44SJordan Rupprecht        oslist=["windows"],
22*2238dcc3SJonas Devlieghere        bugnumber="llvm.org/pr24489: Name lookup not working correctly on Windows",
23*2238dcc3SJonas Devlieghere    )
2499451b44SJordan Rupprecht    def test_with_run_command(self):
2599451b44SJordan Rupprecht        """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
2699451b44SJordan Rupprecht        self.build()
2799451b44SJordan Rupprecht        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
2899451b44SJordan Rupprecht
29*2238dcc3SJonas Devlieghere        self.set_breakpoint(line_number("main.cpp", "// breakpoint 1"))
30*2238dcc3SJonas Devlieghere        self.set_breakpoint(line_number("main.cpp", "// breakpoint 2"))
31*2238dcc3SJonas Devlieghere        self.set_breakpoint(line_number("main.cpp", "// breakpoint 3"))
32*2238dcc3SJonas Devlieghere        self.set_breakpoint(line_number("main.cpp", "// breakpoint 4"))
3399451b44SJordan Rupprecht
3499451b44SJordan Rupprecht        self.runCmd("process launch", RUN_SUCCEEDED)
3599451b44SJordan Rupprecht
36*2238dcc3SJonas Devlieghere        self.expect("expression -- m_a = 2", startstr="(int) $0 = 2")
3799451b44SJordan Rupprecht
3899451b44SJordan Rupprecht        self.runCmd("process continue")
3999451b44SJordan Rupprecht
4099451b44SJordan Rupprecht        # This would be disallowed if we enforced const.  But we don't.
41*2238dcc3SJonas Devlieghere        self.expect("expression -- m_a = 2", startstr="(int) $1 = 2")
4299451b44SJordan Rupprecht
43*2238dcc3SJonas Devlieghere        self.expect("expression -- (int)getpid(); m_a", startstr="(int) $2 = 2")
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht        self.runCmd("process continue")
4699451b44SJordan Rupprecht
47*2238dcc3SJonas Devlieghere        self.expect("expression -- s_a", startstr="(int) $3 = 5")
4899451b44SJordan Rupprecht
4999451b44SJordan Rupprecht        self.runCmd("process continue")
5099451b44SJordan Rupprecht
51*2238dcc3SJonas Devlieghere        self.expect("expression -- m_a", startstr="(int) $4 = 2")
5299451b44SJordan Rupprecht
5399451b44SJordan Rupprecht    def set_breakpoint(self, line):
5499451b44SJordan Rupprecht        lldbutil.run_break_set_by_file_and_line(
55*2238dcc3SJonas Devlieghere            self, "main.cpp", line, num_expected_locations=1, loc_exact=False
56*2238dcc3SJonas Devlieghere        )
57