blob: 0850b9a6db07bcd6a9d0586f8a553854b755124f [file] [log] [blame]
Johnny Chen3d57ee72010-11-11 23:29:54 +00001"""
2Test the printing of anonymous and named namespace variables.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
9
10class NamespaceTestCase(TestBase):
11
Johnny Chen30a6a1e2011-06-25 20:21:10 +000012 mydir = os.path.join("lang", "cpp", "namespace")
Johnny Chen3d57ee72010-11-11 23:29:54 +000013
Johnny Chend71ffbc2010-12-23 23:26:05 +000014 # rdar://problem/8668674
Johnny Chen3d57ee72010-11-11 23:29:54 +000015 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
16 def test_with_dsym_and_run_command(self):
17 """Test that anonymous and named namespace variables display correctly."""
18 self.buildDsym()
19 self.namespace_variable_commands()
20
Johnny Chend71ffbc2010-12-23 23:26:05 +000021 # rdar://problem/8668674
Johnny Chen3d57ee72010-11-11 23:29:54 +000022 def test_with_dwarf_and_run_command(self):
23 """Test that anonymous and named namespace variables display correctly."""
24 self.buildDwarf()
25 self.namespace_variable_commands()
26
27 def setUp(self):
28 # Call super's setUp().
29 TestBase.setUp(self)
30 # Find the line numbers for declarations of namespace variables i and j.
31 self.line_var_i = line_number('main.cpp',
32 '// Find the line number for anonymous namespace variable i.')
33 self.line_var_j = line_number('main.cpp',
34 '// Find the line number for named namespace variable j.')
35 # And the line number to break at.
36 self.line_break = line_number('main.cpp',
37 '// Set break point at this line.')
38
39 def namespace_variable_commands(self):
40 """Test that anonymous and named namespace variables display correctly."""
41 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
42
43 self.expect("breakpoint set -f main.cpp -l %d" % self.line_break,
44 BREAKPOINT_CREATED,
45 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
46 self.line_break)
47
48 self.runCmd("run", RUN_SUCCEEDED)
49
50 # The stop reason of the thread should be breakpoint.
51 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
Greg Clayton7260f622011-04-18 08:33:37 +000052 substrs = ['stopped',
Johnny Chen3d57ee72010-11-11 23:29:54 +000053 'stop reason = breakpoint'])
54
Johnny Chen80e6db92010-11-17 00:52:41 +000055 # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
56 slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
57 if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']:
58 slist = ['(int) a = 12',
59 '(my_uint_t) anon_uint = 0',
60 '(A::uint_t) a_uint = 1',
61 '(A::B::uint_t) b_uint = 2',
Johnny Chenb4d59f42010-11-18 20:20:18 +000062 '(Y::uint_t) y_uint = 3']
63
Johnny Chen80e6db92010-11-17 00:52:41 +000064 # 'frame variable' displays the local variables with type information.
Johnny Chen13e64a72010-11-15 19:10:53 +000065 self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen80e6db92010-11-17 00:52:41 +000066 substrs = slist)
Johnny Chen13e64a72010-11-15 19:10:53 +000067
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000068 # 'frame variable' with basename 'i' should work.
Johnny Chen1d3e8802011-07-11 23:38:23 +000069 self.expect("frame variable -c -g i",
Johnny Chen3d57ee72010-11-11 23:29:54 +000070 startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
71 # main.cpp:12: (int) (anonymous namespace)::i = 3
72
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000073 # 'frame variable' with basename 'j' should work, too.
Johnny Chen1d3e8802011-07-11 23:38:23 +000074 self.expect("frame variable -c -g j",
Johnny Chen3d57ee72010-11-11 23:29:54 +000075 startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
76 # main.cpp:19: (int) A::B::j = 4
77
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000078 # 'frame variable' should support address-of operator.
79 self.runCmd("frame variable &i")
80
81 # 'frame variable' with fully qualified name 'A::B::j' should work.
Johnny Chend71ffbc2010-12-23 23:26:05 +000082 self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen8a815152011-07-28 00:52:23 +000083 startstr = '(int) A::B::j = 4',
84 patterns = [' = 4$'])
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000085
Johnny Chen913af512010-11-15 18:40:06 +000086 # So should the anonymous namespace case.
Johnny Chend71ffbc2010-12-23 23:26:05 +000087 self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen8a815152011-07-28 00:52:23 +000088 startstr = '(int) (anonymous namespace)::i = 3',
89 patterns = [' = 3$'])
Johnny Chen913af512010-11-15 18:40:06 +000090
Johnny Chen6df2cd32010-11-12 01:00:56 +000091 # rdar://problem/8660275
92 # test/namespace: 'expression -- i+j' not working
Johnny Chend71ffbc2010-12-23 23:26:05 +000093 # This has been fixed.
Johnny Chendeac5232010-11-15 17:42:22 +000094 self.expect("expression -- i + j",
95 startstr = "(int) $0 = 7")
Johnny Chen064d7f52010-11-12 00:50:45 +000096 # (int) $0 = 7
Johnny Chen3d57ee72010-11-11 23:29:54 +000097
Johnny Chend71ffbc2010-12-23 23:26:05 +000098 self.runCmd("expression -- i")
99 self.runCmd("expression -- j")
100
Johnny Chen8ed80e62010-11-15 18:49:03 +0000101 # rdar://problem/8668674
102 # expression command with fully qualified namespace for a variable does not work
Johnny Chen098781b2011-08-01 21:30:30 +0000103 self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen8a815152011-07-28 00:52:23 +0000104 patterns = [' = 3$'])
Johnny Chen098781b2011-08-01 21:30:30 +0000105 self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen8a815152011-07-28 00:52:23 +0000106 patterns = [' = 4$'])
Johnny Chen913af512010-11-15 18:40:06 +0000107
108
Johnny Chen3d57ee72010-11-11 23:29:54 +0000109if __name__ == '__main__':
110 import atexit
111 lldb.SBDebugger.Initialize()
112 atexit.register(lambda: lldb.SBDebugger.Terminate())
113 unittest2.main()