blob: bab85be562051e48e20f8147b08f41db8f1b38ba [file] [log] [blame]
Sean Callanan72e49402011-08-05 23:43:37 +00001"""
2Tests that C++ member and static variables are available where they should be.
3"""
Jim Ingham63dfc722012-09-22 00:05:11 +00004import lldb
Sean Callanan72e49402011-08-05 23:43:37 +00005from lldbtest import *
Jim Ingham63dfc722012-09-22 00:05:11 +00006import lldbutil
Sean Callanan72e49402011-08-05 23:43:37 +00007
8class CPPThisTestCase(TestBase):
9
10 mydir = os.path.join("lang", "cpp", "this")
11
12 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
Johnny Chen49996272011-08-23 01:00:14 +000013 #rdar://problem/9962849
Johnny Chen1e4cd1f2011-12-12 22:07:36 +000014 #@expectedFailureClang
Johnny Chen24086bc2012-04-06 19:54:10 +000015 @dsym_test
Sean Callanan72e49402011-08-05 23:43:37 +000016 def test_with_dsym_and_run_command(self):
17 """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
18 self.buildDsym()
19 self.static_method_commands()
20
Johnny Chen49996272011-08-23 01:00:14 +000021 #rdar://problem/9962849
Daniel Malea658fd572013-03-04 23:15:08 +000022 @expectedFailureGcc # llvm.org/pr15439 The 'this' pointer isn't available during expression evaluation when stopped in an inlined member function.
Johnny Chen24086bc2012-04-06 19:54:10 +000023 @dwarf_test
Sean Callanan72e49402011-08-05 23:43:37 +000024 def test_with_dwarf_and_run_command(self):
25 """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
26 self.buildDwarf()
27 self.static_method_commands()
28
29 def setUp(self):
30 TestBase.setUp(self)
31
32 def set_breakpoint(self, line):
Jim Ingham63dfc722012-09-22 00:05:11 +000033 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line, num_expected_locations=1, loc_exact=False)
34
Sean Callanan72e49402011-08-05 23:43:37 +000035 def static_method_commands(self):
36 """Test that the appropriate member variables are available when stopped in C++ static, inline, and const methods"""
37 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
38
39 self.set_breakpoint(line_number('main.cpp', '// breakpoint 1'))
40 self.set_breakpoint(line_number('main.cpp', '// breakpoint 2'))
41 self.set_breakpoint(line_number('main.cpp', '// breakpoint 3'))
42 self.set_breakpoint(line_number('main.cpp', '// breakpoint 4'))
43
44 self.runCmd("process launch", RUN_SUCCEEDED)
45
46 self.expect("expression -- m_a = 2",
47 startstr = "(int) $0 = 2")
48
49 self.runCmd("process continue")
50
51 # This would be disallowed if we enforced const. But we don't.
52 self.expect("expression -- m_a = 2",
53 startstr = "(int) $1 = 2")
54
Sean Callanan0259e512012-05-21 21:29:52 +000055 self.expect("expression -- (int)getpid(); m_a",
Sean Callanan72e49402011-08-05 23:43:37 +000056 startstr = "(int) $2 = 2")
57
58 self.runCmd("process continue")
59
60 self.expect("expression -- s_a",
61 startstr = "(int) $3 = 5")
62
63 self.runCmd("process continue")
64
65 self.expect("expression -- m_a",
66 startstr = "(int) $4 = 2")
67
68if __name__ == '__main__':
69 import atexit
70 lldb.SBDebugger.Initialize()
71 atexit.register(lambda: lldb.SBDebugger.Terminate())
72 unittest2.main()