blob: d1418e53328907a16704e5c4056dca7ee4f5e73b [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
15 @unittest2.expectedFailure
Johnny Chen3d57ee72010-11-11 23:29:54 +000016 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
17 def test_with_dsym_and_run_command(self):
18 """Test that anonymous and named namespace variables display correctly."""
19 self.buildDsym()
20 self.namespace_variable_commands()
21
Johnny Chend71ffbc2010-12-23 23:26:05 +000022 # rdar://problem/8668674
23 @unittest2.expectedFailure
Johnny Chen3d57ee72010-11-11 23:29:54 +000024 def test_with_dwarf_and_run_command(self):
25 """Test that anonymous and named namespace variables display correctly."""
26 self.buildDwarf()
27 self.namespace_variable_commands()
28
29 def setUp(self):
30 # Call super's setUp().
31 TestBase.setUp(self)
32 # Find the line numbers for declarations of namespace variables i and j.
33 self.line_var_i = line_number('main.cpp',
34 '// Find the line number for anonymous namespace variable i.')
35 self.line_var_j = line_number('main.cpp',
36 '// Find the line number for named namespace variable j.')
37 # And the line number to break at.
38 self.line_break = line_number('main.cpp',
39 '// Set break point at this line.')
40
41 def namespace_variable_commands(self):
42 """Test that anonymous and named namespace variables display correctly."""
43 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
44
45 self.expect("breakpoint set -f main.cpp -l %d" % self.line_break,
46 BREAKPOINT_CREATED,
47 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
48 self.line_break)
49
50 self.runCmd("run", RUN_SUCCEEDED)
51
52 # The stop reason of the thread should be breakpoint.
53 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
Greg Clayton7260f622011-04-18 08:33:37 +000054 substrs = ['stopped',
Johnny Chen3d57ee72010-11-11 23:29:54 +000055 'stop reason = breakpoint'])
56
Johnny Chen80e6db92010-11-17 00:52:41 +000057 # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
58 slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
59 if sys.platform.startswith("darwin") and self.getCompiler() in ['clang', 'llvm-gcc']:
60 slist = ['(int) a = 12',
61 '(my_uint_t) anon_uint = 0',
62 '(A::uint_t) a_uint = 1',
63 '(A::B::uint_t) b_uint = 2',
Johnny Chenb4d59f42010-11-18 20:20:18 +000064 '(Y::uint_t) y_uint = 3']
65
Johnny Chen80e6db92010-11-17 00:52:41 +000066 # 'frame variable' displays the local variables with type information.
Johnny Chen13e64a72010-11-15 19:10:53 +000067 self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen80e6db92010-11-17 00:52:41 +000068 substrs = slist)
Johnny Chen13e64a72010-11-15 19:10:53 +000069
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000070 # 'frame variable' with basename 'i' should work.
Johnny Chen1d3e8802011-07-11 23:38:23 +000071 self.expect("frame variable -c -g i",
Johnny Chen3d57ee72010-11-11 23:29:54 +000072 startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
73 # main.cpp:12: (int) (anonymous namespace)::i = 3
74
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000075 # 'frame variable' with basename 'j' should work, too.
Johnny Chen1d3e8802011-07-11 23:38:23 +000076 self.expect("frame variable -c -g j",
Johnny Chen3d57ee72010-11-11 23:29:54 +000077 startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
78 # main.cpp:19: (int) A::B::j = 4
79
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000080 # 'frame variable' should support address-of operator.
81 self.runCmd("frame variable &i")
82
83 # 'frame variable' with fully qualified name 'A::B::j' should work.
Johnny Chend71ffbc2010-12-23 23:26:05 +000084 self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen6ba9d1f2010-11-15 18:27:57 +000085 startstr = '(int) A::B::j = 4')
86
Johnny Chen913af512010-11-15 18:40:06 +000087 # So should the anonymous namespace case.
Johnny Chend71ffbc2010-12-23 23:26:05 +000088 self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chen913af512010-11-15 18:40:06 +000089 startstr = '(int) (anonymous namespace)::i = 3')
90
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 Chen847f5112011-07-27 23:17:56 +0000103 self.expect("expression -- '::i'", VARIABLES_DISPLAYED_CORRECTLY,
Johnny Chend71ffbc2010-12-23 23:26:05 +0000104 substrs = [" = 3"])
105 self.expect("expression -- 'A::B::j'", VARIABLES_DISPLAYED_CORRECTLY,
106 substrs = [" = 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()