1"""
2Tests that C++ member and static variables have correct layout and scope.
3"""
4
5
6
7import unittest2
8import lldb
9from lldbsuite.test.decorators import *
10from lldbsuite.test.lldbtest import *
11from lldbsuite.test import lldbutil
12
13
14class CPPStaticMembersTestCase(TestBase):
15
16    mydir = TestBase.compute_mydir(__file__)
17
18    @expectedFailure  # llvm.org/pr15401
19    @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr21765")
20    def test_with_run_command(self):
21        """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""
22        self.build()
23        self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
24
25        self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
26        self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
27
28        self.runCmd("process launch", RUN_SUCCEEDED)
29        self.expect("expression my_a.access()",
30                    startstr="(long) $0 = 10")
31
32        self.expect("expression my_a.m_a",
33                    startstr="(short) $1 = 1")
34
35        # Note: SymbolFileDWARF::ParseChildMembers doesn't call
36        # AddFieldToRecordType, consistent with clang's AST layout.
37        self.expect("expression my_a.s_d",
38                    startstr="(int) $2 = 4")
39
40        self.expect("expression my_a.s_b",
41                    startstr="(long) $3 = 2")
42
43        self.expect("expression A::s_b",
44                    startstr="(long) $4 = 2")
45
46        # should not be available in global scope
47        self.expect("expression s_d",
48                    startstr="error: use of undeclared identifier 's_d'")
49
50        self.runCmd("process continue")
51        self.expect("expression m_c",
52                    startstr="(char) $5 = \'\\x03\'")
53
54        self.expect("expression s_b",
55                    startstr="(long) $6 = 2")
56
57        self.runCmd("process continue")
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