1""" 2Tests that C++ member and static variables have correct layout and scope. 3""" 4import lldb 5from lldbtest import * 6import lldbutil 7 8class CPPStaticMembersTestCase(TestBase): 9 10 mydir = os.path.join("lang", "cpp", "static_members") 11 12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 13 @unittest2.expectedFailure # llvm.org/pr15401 14 @dsym_test 15 def test_with_dsym_and_run_command(self): 16 """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods""" 17 self.buildDsym() 18 self.static_member_commands() 19 20 @unittest2.expectedFailure # llvm.org/pr15401 21 @dwarf_test 22 def test_with_dwarf_and_run_command(self): 23 """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods""" 24 self.buildDwarf() 25 self.static_member_commands() 26 27 def setUp(self): 28 TestBase.setUp(self) 29 30 def set_breakpoint(self, line): 31 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=1, loc_exact=False) 32 33 def static_member_commands(self): 34 """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods""" 35 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 36 37 self.set_breakpoint(line_number('main.cpp', '// breakpoint 1')) 38 self.set_breakpoint(line_number('main.cpp', '// breakpoint 2')) 39 40 self.runCmd("process launch", RUN_SUCCEEDED) 41 self.expect("expression my_a.access()", 42 startstr = "(long) $0 = 10") 43 44 self.expect("expression my_a.m_a", 45 startstr = "(short) $1 = 1") 46 47 # Note: SymbolFileDWARF::ParseChildMembers doesn't call AddFieldToRecordType, consistent with clang's AST layout. 48 self.expect("expression my_a.s_d", 49 startstr = "(int) $2 = 4") 50 51 self.expect("expression my_a.s_b", 52 startstr = "(long) $3 = 2") 53 54 self.expect("expression A::s_b", 55 startstr = "(long) $4 = 2") 56 57 # should not be available in global scope 58 self.expect("expression s_d", 59 startstr = "error: use of undeclared identifier 's_d'") 60 61 self.runCmd("process continue") 62 self.expect("expression m_c", 63 startstr = "(char) $5 = \'\\x03\'") 64 65 self.expect("expression s_b", 66 startstr = "(long) $6 = 2") 67 68 self.runCmd("process continue") 69 70 71if __name__ == '__main__': 72 import atexit 73 lldb.SBDebugger.Initialize() 74 atexit.register(lambda: lldb.SBDebugger.Terminate()) 75 unittest2.main() 76