blob: c059acdf87ab19af472c55b1cf0d01a1cd3c8a09 [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 @unittest2.expectedFailure
21 # rdar://problem/8659840
Johnny Chen6df2cd32010-11-12 01:00:56 +000022 # runCmd: frame variable -c -G i
23 # runCmd failed!
24 # error: can't find global variable 'i'
Johnny Chen3d57ee72010-11-11 23:29:54 +000025 def test_with_dwarf_and_run_command(self):
26 """Test that anonymous and named namespace variables display correctly."""
27 self.buildDwarf()
28 self.namespace_variable_commands()
29
30 def setUp(self):
31 # Call super's setUp().
32 TestBase.setUp(self)
33 # Find the line numbers for declarations of namespace variables i and j.
34 self.line_var_i = line_number('main.cpp',
35 '// Find the line number for anonymous namespace variable i.')
36 self.line_var_j = line_number('main.cpp',
37 '// Find the line number for named namespace variable j.')
38 # And the line number to break at.
39 self.line_break = line_number('main.cpp',
40 '// Set break point at this line.')
41
42 def namespace_variable_commands(self):
43 """Test that anonymous and named namespace variables display correctly."""
44 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
45
46 self.expect("breakpoint set -f main.cpp -l %d" % self.line_break,
47 BREAKPOINT_CREATED,
48 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d, locations = 1" %
49 self.line_break)
50
51 self.runCmd("run", RUN_SUCCEEDED)
52
53 # The stop reason of the thread should be breakpoint.
54 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
55 substrs = ['state is stopped',
56 'stop reason = breakpoint'])
57
58 self.expect("frame variable -c -G i",
59 startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
60 # main.cpp:12: (int) (anonymous namespace)::i = 3
61
62 self.expect("frame variable -c -G j",
63 startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
64 # main.cpp:19: (int) A::B::j = 4
65
Johnny Chen6df2cd32010-11-12 01:00:56 +000066 # rdar://problem/8660275
67 # test/namespace: 'expression -- i+j' not working
Johnny Chen064d7f52010-11-12 00:50:45 +000068 #self.expect("expression -- i + j",
69 # startstr = "(int) $0 = 7")
70 # (int) $0 = 7
Johnny Chen3d57ee72010-11-11 23:29:54 +000071
72if __name__ == '__main__':
73 import atexit
74 lldb.SBDebugger.Initialize()
75 atexit.register(lambda: lldb.SBDebugger.Terminate())
76 unittest2.main()