blob: 004ec286156b4392d14a18b31941eff31211c675 [file] [log] [blame]
Daniel Malea9e84eb42013-03-01 18:25:42 +00001"""
2Tests that C++ member and static variables have correct layout and scope.
3"""
Zachary Turner77db4a82015-10-22 20:06:20 +00004
Zachary Turner35d017f2015-10-23 17:04:29 +00005from __future__ import print_function
6
Zachary Turner0a0490b2015-10-27 20:12:05 +00007import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +00008
9import unittest2
Daniel Malea9e84eb42013-03-01 18:25:42 +000010import lldb
11from lldbtest import *
12import lldbutil
13
14class CPPStaticMembersTestCase(TestBase):
15
Greg Clayton4570d3e2013-12-10 23:19:29 +000016 mydir = TestBase.compute_mydir(__file__)
Daniel Malea9e84eb42013-03-01 18:25:42 +000017
Daniel Malea9e84eb42013-03-01 18:25:42 +000018 @unittest2.expectedFailure # llvm.org/pr15401
Zachary Turner18442842015-08-20 22:09:35 +000019 @expectedFailureWindows("llvm.org/pr21765")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000020 def test_with_run_command(self):
Daniel Malea9e84eb42013-03-01 18:25:42 +000021 """Test that member variables have the correct layout, scope and qualifiers when stopped inside and outside C++ methods"""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000022 self.build()
Daniel Malea9e84eb42013-03-01 18:25:42 +000023 self.runCmd("file 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
Sean Callanan05834cd2015-07-01 23:56:30 +000028 self.runCmd("process launch", RUN_SUCCEEDED)
Daniel Malea9e84eb42013-03-01 18:25:42 +000029 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 AddFieldToRecordType, consistent with clang's AST layout.
36 self.expect("expression my_a.s_d",
37 startstr = "(int) $2 = 4")
38
39 self.expect("expression my_a.s_b",
40 startstr = "(long) $3 = 2")
41
42 self.expect("expression A::s_b",
43 startstr = "(long) $4 = 2")
44
45 # should not be available in global scope
46 self.expect("expression s_d",
47 startstr = "error: use of undeclared identifier 's_d'")
48
49 self.runCmd("process continue")
50 self.expect("expression m_c",
51 startstr = "(char) $5 = \'\\x03\'")
52
53 self.expect("expression s_b",
54 startstr = "(long) $6 = 2")
55
56 self.runCmd("process continue")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000057
58 def set_breakpoint(self, line):
59 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=1, loc_exact=False)