blob: 072ffbb663f9ea3db4cf4afa1212765c955b98b8 [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
12 mydir = "namespace"
13
14 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
15 def test_with_dsym_and_run_command(self):
16 """Test that anonymous and named namespace variables display correctly."""
17 self.buildDsym()
18 self.namespace_variable_commands()
19
Johnny Chen064d7f52010-11-12 00:50:45 +000020 # rdar://problem/8659840
Johnny Chen6df2cd32010-11-12 01:00:56 +000021 # runCmd: frame variable -c -G i
22 # runCmd failed!
23 # error: can't find global variable 'i'
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,
54 substrs = ['state is stopped',
55 'stop reason = breakpoint'])
56
57 self.expect("frame variable -c -G i",
58 startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
59 # main.cpp:12: (int) (anonymous namespace)::i = 3
60
61 self.expect("frame variable -c -G j",
62 startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
63 # main.cpp:19: (int) A::B::j = 4
64
Johnny Chen6df2cd32010-11-12 01:00:56 +000065 # rdar://problem/8660275
66 # test/namespace: 'expression -- i+j' not working
Johnny Chendeac5232010-11-15 17:42:22 +000067 self.expect("expression -- i + j",
68 startstr = "(int) $0 = 7")
Johnny Chen064d7f52010-11-12 00:50:45 +000069 # (int) $0 = 7
Johnny Chen3d57ee72010-11-11 23:29:54 +000070
71if __name__ == '__main__':
72 import atexit
73 lldb.SBDebugger.Initialize()
74 atexit.register(lambda: lldb.SBDebugger.Terminate())
75 unittest2.main()