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