2 Test the printing of anonymous and named namespace variables.
5 from __future__ import print_function
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
14 class NamespaceTestCase(TestBase):
16 mydir = TestBase.compute_mydir(__file__)
19 # Call super's setUp().
21 # Find the line numbers for declarations of namespace variables i and j.
22 self.line_var_i = line_number('main.cpp',
23 '// Find the line number for anonymous namespace variable i.')
24 self.line_var_j = line_number('main.cpp',
25 '// Find the line number for named namespace variable j.')
26 # And the line number to break at.
27 self.line_break = line_number('main.cpp',
28 '// Set break point at this line.')
29 # Break inside do {} while and evaluate value
30 self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value')
31 self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value')
33 def runToBkpt(self, command):
34 self.runCmd(command, RUN_SUCCEEDED)
35 # The stop reason of the thread should be breakpoint.
36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38 'stop reason = breakpoint'])
40 # rdar://problem/8668674
41 @expectedFailureWindows("llvm.org/pr24764")
42 def test_with_run_command(self):
43 """Test that anonymous and named namespace variables display correctly."""
45 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
47 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns1, num_expected_locations=1, loc_exact=True)
48 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break_ns2, num_expected_locations=1, loc_exact=True)
49 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line_break, num_expected_locations=1, loc_exact=True)
53 self.expect("expression -- value", startstr = "(int) $0 = 100")
55 self.runToBkpt("continue")
57 self.expect("expression -- value", startstr = "(int) $1 = 200")
59 self.runToBkpt("continue")
60 # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to types.
61 slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
62 if self.platformIsDarwin() and self.getCompiler() in ['clang', 'llvm-gcc']:
63 slist = ['(int) a = 12',
64 '::my_uint_t', 'anon_uint = 0',
65 '(A::uint_t) a_uint = 1',
66 '(A::B::uint_t) b_uint = 2',
67 '(Y::uint_t) y_uint = 3']
69 # 'frame variable' displays the local variables with type information.
70 self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY,
73 # 'frame variable' with basename 'i' should work.
74 self.expect("frame variable --show-declaration --show-globals i",
75 startstr = "main.cpp:%d: (int) (anonymous namespace)::i = 3" % self.line_var_i)
76 # main.cpp:12: (int) (anonymous namespace)::i = 3
78 # 'frame variable' with basename 'j' should work, too.
79 self.expect("frame variable --show-declaration --show-globals j",
80 startstr = "main.cpp:%d: (int) A::B::j = 4" % self.line_var_j)
81 # main.cpp:19: (int) A::B::j = 4
83 # 'frame variable' should support address-of operator.
84 self.runCmd("frame variable &i")
86 # 'frame variable' with fully qualified name 'A::B::j' should work.
87 self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
88 startstr = '(int) A::B::j = 4',
91 # So should the anonymous namespace case.
92 self.expect("frame variable '(anonymous namespace)::i'", VARIABLES_DISPLAYED_CORRECTLY,
93 startstr = '(int) (anonymous namespace)::i = 3',
96 # rdar://problem/8660275
97 # test/namespace: 'expression -- i+j' not working
98 # This has been fixed.
99 self.expect("expression -- i + j",
100 startstr = "(int) $2 = 7")
103 self.runCmd("expression -- i")
104 self.runCmd("expression -- j")
106 # rdar://problem/8668674
107 # expression command with fully qualified namespace for a variable does not work
108 self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY,
110 self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
113 # expression command with function in anonymous namespace
114 self.expect("expression -- myanonfunc(3)",
117 # global namespace qualification with function in anonymous namespace
118 self.expect("expression -- ::myanonfunc(4)",
121 self.expect("p myanonfunc",
122 patterns = ['\(anonymous namespace\)::myanonfunc\(int\)'])
124 self.expect("p variadic_sum",
125 patterns = ['\(anonymous namespace\)::variadic_sum\(int, ...\)'])