2 Test the printing of anonymous and named namespace variables.
5 from __future__ import print_function
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
16 class NamespaceBreakpointTestCase(TestBase):
18 mydir = TestBase.compute_mydir(__file__)
20 @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc")
21 @expectedFailureAll(oslist=["windows"])
22 def test_breakpoints_func_auto(self):
23 """Test that we can set breakpoints correctly by basename to find all functions whose basename is "func"."""
33 # Create a target by the debugger.
34 exe = os.path.join(os.getcwd(), "a.out")
35 target = self.dbg.CreateTarget(exe)
36 self.assertTrue(target, VALID_TARGET)
37 module_list = lldb.SBFileSpecList()
38 module_list.Append(lldb.SBFileSpec(exe, False))
39 cu_list = lldb.SBFileSpecList()
40 # Set a breakpoint by name "func" which should pick up all functions
41 # whose basename is "func"
42 bp = target.BreakpointCreateByName(
43 "func", lldb.eFunctionNameTypeAuto, module_list, cu_list)
45 name = bp_loc.GetAddress().GetFunction().GetName()
48 "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeAuto")
50 @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc")
51 def test_breakpoints_func_full(self):
52 """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "func"
56 names = ["func()", "func(int)"]
58 # Create a target by the debugger.
59 exe = os.path.join(os.getcwd(), "a.out")
60 target = self.dbg.CreateTarget(exe)
61 self.assertTrue(target, VALID_TARGET)
62 module_list = lldb.SBFileSpecList()
63 module_list.Append(lldb.SBFileSpec(exe, False))
64 cu_list = lldb.SBFileSpecList()
66 # Set a breakpoint by name "func" whose fullly qualified named matches "func" which
67 # should pick up only functions whose basename is "func" and has no
69 bp = target.BreakpointCreateByName(
70 "func", lldb.eFunctionNameTypeFull, module_list, cu_list)
72 name = bp_loc.GetAddress().GetFunction().GetName()
75 "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeFull")
77 def test_breakpoints_a_func_full(self):
78 """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "A::func"."""
81 names = ["A::func()", "A::func(int)"]
83 # Create a target by the debugger.
84 exe = os.path.join(os.getcwd(), "a.out")
85 target = self.dbg.CreateTarget(exe)
86 self.assertTrue(target, VALID_TARGET)
87 module_list = lldb.SBFileSpecList()
88 module_list.Append(lldb.SBFileSpec(exe, False))
89 cu_list = lldb.SBFileSpecList()
91 # Set a breakpoint by name "A::func" whose fullly qualified named matches "A::func" which
92 # should pick up only functions whose basename is "func" and is
93 # contained in the "A" namespace
94 bp = target.BreakpointCreateByName(
95 "A::func", lldb.eFunctionNameTypeFull, module_list, cu_list)
97 name = bp_loc.GetAddress().GetFunction().GetName()
100 "make sure breakpoint locations are correct for 'A::func' with eFunctionNameTypeFull")
103 class NamespaceTestCase(TestBase):
105 mydir = TestBase.compute_mydir(__file__)
108 # Call super's setUp().
110 # Find the line numbers for declarations of namespace variables i and
112 self.line_var_i = line_number(
113 'main.cpp', '// Find the line number for anonymous namespace variable i.')
114 self.line_var_j = line_number(
115 'main.cpp', '// Find the line number for named namespace variable j.')
116 # And the line number to break at.
117 self.line_break = line_number('main.cpp',
118 '// Set break point at this line.')
119 # Break inside do {} while and evaluate value
120 self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value')
121 self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value')
123 def runToBkpt(self, command):
124 self.runCmd(command, RUN_SUCCEEDED)
125 # The stop reason of the thread should be breakpoint.
126 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
128 'stop reason = breakpoint'])
130 # rdar://problem/8668674
131 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
132 def test_with_run_command(self):
133 """Test that anonymous and named namespace variables display correctly."""
135 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
137 lldbutil.run_break_set_by_file_and_line(
141 num_expected_locations=1,
143 lldbutil.run_break_set_by_file_and_line(
147 num_expected_locations=1,
149 lldbutil.run_break_set_by_file_and_line(
153 num_expected_locations=1,
156 self.runToBkpt("run")
157 # Evaluate ns1::value
158 self.expect("expression -- value", startstr="(int) $0 = 100")
160 self.runToBkpt("continue")
161 # Evaluate ns2::value
162 self.expect("expression -- value", startstr="(int) $1 = 200")
164 self.runToBkpt("continue")
165 # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to
167 slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint']
168 if self.platformIsDarwin() and self.getCompiler() in [
169 'clang', 'llvm-gcc']:
170 slist = ['(int) a = 12',
171 '::my_uint_t', 'anon_uint = 0',
172 '(A::uint_t) a_uint = 1',
173 '(A::B::uint_t) b_uint = 2',
174 '(Y::uint_t) y_uint = 3']
176 # 'frame variable' displays the local variables with type information.
177 self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY,
180 # 'frame variable' with basename 'i' should work.
182 "frame variable --show-declaration --show-globals i",
183 startstr="main.cpp:%d: (int) (anonymous namespace)::i = 3" %
185 # main.cpp:12: (int) (anonymous namespace)::i = 3
187 # 'frame variable' with basename 'j' should work, too.
189 "frame variable --show-declaration --show-globals j",
190 startstr="main.cpp:%d: (int) A::B::j = 4" %
192 # main.cpp:19: (int) A::B::j = 4
194 # 'frame variable' should support address-of operator.
195 self.runCmd("frame variable &i")
197 # 'frame variable' with fully qualified name 'A::B::j' should work.
198 self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
199 startstr='(int) A::B::j = 4',
202 # So should the anonymous namespace case.
204 "frame variable '(anonymous namespace)::i'",
205 VARIABLES_DISPLAYED_CORRECTLY,
206 startstr='(int) (anonymous namespace)::i = 3',
209 # rdar://problem/8660275
210 # test/namespace: 'expression -- i+j' not working
211 # This has been fixed.
212 self.expect("expression -- i + j",
213 startstr="(int) $2 = 7")
216 self.runCmd("expression -- i")
217 self.runCmd("expression -- j")
219 # rdar://problem/8668674
220 # expression command with fully qualified namespace for a variable does
222 self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY,
224 self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY,
227 # expression command with function in anonymous namespace
228 self.expect("expression -- myanonfunc(3)",
231 # global namespace qualification with function in anonymous namespace
232 self.expect("expression -- ::myanonfunc(4)",
235 self.expect("p myanonfunc",
236 patterns=['\(anonymous namespace\)::myanonfunc\(int\)'])
238 self.expect("p variadic_sum", patterns=[
239 '\(anonymous namespace\)::variadic_sum\(int, ...\)'])