2 Test the printing of anonymous and named namespace variables.
7 from lldbsuite
.test
.decorators
import *
8 from lldbsuite
.test
.lldbtest
import *
9 from lldbsuite
.test
import lldbutil
12 class NamespaceLookupTestCase(TestBase
):
14 # Call super's setUp().
16 # Break inside different scopes and evaluate value
17 self
.line_break_global_scope
= line_number("ns.cpp", "// BP_global_scope")
18 self
.line_break_file_scope
= line_number("ns2.cpp", "// BP_file_scope")
19 self
.line_break_ns_scope
= line_number("ns2.cpp", "// BP_ns_scope")
20 self
.line_break_nested_ns_scope
= line_number(
21 "ns2.cpp", "// BP_nested_ns_scope"
23 self
.line_break_nested_ns_scope_after_using
= line_number(
24 "ns2.cpp", "// BP_nested_ns_scope_after_using"
26 self
.line_break_before_using_directive
= line_number(
27 "ns3.cpp", "// BP_before_using_directive"
29 self
.line_break_after_using_directive
= line_number(
30 "ns3.cpp", "// BP_after_using_directive"
33 def runToBkpt(self
, command
):
34 self
.runCmd(command
, RUN_SUCCEEDED
)
35 # The stop reason of the thread should be breakpoint.
38 STOPPED_DUE_TO_BREAKPOINT
,
39 substrs
=["stopped", "stop reason = breakpoint"],
42 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
43 @expectedFailure("CU-local objects incorrectly scoped")
44 def test_scope_lookup_with_run_command_globals(self
):
45 """Test scope lookup of functions in lldb."""
48 lldbutil
.run_to_source_breakpoint(
49 self
, self
.line_break_global_scope
, lldb
.SBFileSpec("ns.cpp")
52 lldbutil
.run_break_set_by_file_and_line(
55 self
.line_break_before_using_directive
,
56 num_expected_locations
=1,
60 lldbutil
.run_break_set_by_file_and_line(
63 self
.line_break_after_using_directive
,
64 num_expected_locations
=1,
68 # Run to BP_global_scope at file scope
71 # FIXME: LLDB does not correctly scope CU-local objects.
72 # LLDB currently lumps functions from all files into
73 # a single AST and depending on the order with which
74 # functions are considered, LLDB can incorrectly call
75 # the static local ns.cpp::func() instead of the expected
78 # Evaluate func() - should call ::func()
79 self
.expect_expr("func()", expect_type
="int", expect_value
="1")
81 # Evaluate ::func() - should call A::func()
82 self
.expect_expr("::func()", result_type
="int", result_value
="1")
84 # Continue to BP_before_using_directive at file scope
85 self
.runToBkpt("continue")
87 # Evaluate func() - should call ::func()
88 self
.expect_expr("func()", result_type
="int", result_value
="1")
90 # Evaluate ::func() - should call ::func()
91 self
.expect_expr("::func()", result_type
="int", result_value
="1")
93 # Continue to BP_after_using_directive at file scope
94 self
.runToBkpt("continue")
96 # Evaluate ::func() - should call ::func()
97 self
.expect_expr("::func()", result_type
="int", result_value
="1")
99 @skipIfWindows # This is flakey on Windows: llvm.org/pr38373
100 def test_scope_lookup_with_run_command(self
):
101 """Test scope lookup of functions in lldb."""
103 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
105 lldbutil
.run_break_set_by_file_and_line(
108 self
.line_break_global_scope
,
109 num_expected_locations
=1,
112 lldbutil
.run_break_set_by_file_and_line(
115 self
.line_break_ns_scope
,
116 num_expected_locations
=1,
119 lldbutil
.run_break_set_by_file_and_line(
122 self
.line_break_nested_ns_scope
,
123 num_expected_locations
=1,
126 lldbutil
.run_break_set_by_file_and_line(
129 self
.line_break_nested_ns_scope_after_using
,
130 num_expected_locations
=1,
133 lldbutil
.run_break_set_by_file_and_line(
136 self
.line_break_file_scope
,
137 num_expected_locations
=1,
140 lldbutil
.run_break_set_by_file_and_line(
143 self
.line_break_before_using_directive
,
144 num_expected_locations
=1,
147 lldbutil
.run_break_set_by_file_and_line(
150 self
.line_break_after_using_directive
,
151 num_expected_locations
=1,
155 # Run to BP_global_scope at global scope
156 self
.runToBkpt("run")
158 # Evaluate A::B::func() - should call A::B::func()
159 self
.expect_expr("A::B::func()", result_type
="int", result_value
="4")
160 # Evaluate func(10) - should call ::func(int)
161 self
.expect_expr("func(10)", result_type
="int", result_value
="11")
162 # Evaluate A::foo() - should call A::foo()
163 self
.expect_expr("A::foo()", result_type
="int", result_value
="42")
165 # Continue to BP_file_scope at file scope
166 self
.runToBkpt("continue")
167 # FIXME: In DWARF 5 with dsyms, the ordering of functions is slightly
168 # different, which also hits the same issues mentioned previously.
169 if configuration
.dwarf_version
<= 4 or self
.getDebugInfo() == "dwarf":
170 self
.expect_expr("func()", result_type
="int", result_value
="2")
172 # Continue to BP_ns_scope at ns scope
173 self
.runToBkpt("continue")
174 # Evaluate func(10) - should call A::func(int)
175 self
.expect_expr("func(10)", result_type
="int", result_value
="13")
176 # Evaluate B::func() - should call B::func()
177 self
.expect_expr("B::func()", result_type
="int", result_value
="4")
178 # Evaluate func() - should call A::func()
179 self
.expect_expr("func()", result_type
="int", result_value
="3")
181 # Continue to BP_nested_ns_scope at nested ns scope
182 self
.runToBkpt("continue")
183 # Evaluate func() - should call A::B::func()
184 self
.expect_expr("func()", result_type
="int", result_value
="4")
185 # Evaluate A::func() - should call A::func()
186 self
.expect_expr("A::func()", result_type
="int", result_value
="3")
188 # Evaluate func(10) - should call A::func(10)
189 # NOTE: Under the rules of C++, this test would normally get an error
190 # because A::B::func() hides A::func(), but lldb intentionally
191 # disobeys these rules so that the intended overload can be found
192 # by only removing duplicates if they have the same type.
193 self
.expect_expr("func(10)", result_type
="int", result_value
="13")
195 # Continue to BP_nested_ns_scope_after_using at nested ns scope after
197 self
.runToBkpt("continue")
198 # Evaluate A::func(10) - should call A::func(int)
199 self
.expect_expr("A::func(10)", result_type
="int", result_value
="13")
201 # Continue to BP_before_using_directive at global scope before using
203 self
.runToBkpt("continue")
204 # Evaluate B::func() - should call B::func()
205 self
.expect_expr("B::func()", result_type
="int", result_value
="4")
207 # Continue to BP_after_using_directive at global scope after using
209 self
.runToBkpt("continue")
210 # Evaluate B::func() - should call B::func()
211 self
.expect_expr("B::func()", result_type
="int", result_value
="4")
213 @expectedFailure("lldb scope lookup of functions bugs")
214 def test_function_scope_lookup_with_run_command(self
):
215 """Test scope lookup of functions in lldb."""
217 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
219 lldbutil
.run_break_set_by_file_and_line(
222 self
.line_break_global_scope
,
223 num_expected_locations
=1,
226 lldbutil
.run_break_set_by_file_and_line(
229 self
.line_break_ns_scope
,
230 num_expected_locations
=1,
234 # Run to BP_global_scope at global scope
235 self
.runToBkpt("run")
236 # Evaluate foo() - should call ::foo()
237 # FIXME: lldb finds Y::foo because lookup for variables is done
239 self
.expect_expr("foo()", result_type
="int", result_value
="42")
240 # Evaluate ::foo() - should call ::foo()
241 # FIXME: lldb finds Y::foo because lookup for variables is done
242 # before functions and :: is ignored.
243 self
.expect_expr("::foo()", result_type
="int", result_value
="42")
245 # Continue to BP_ns_scope at ns scope
246 self
.runToBkpt("continue")
247 # Evaluate foo() - should call A::foo()
248 # FIXME: lldb finds Y::foo because lookup for variables is done
250 self
.expect_expr("foo()", result_type
="int", result_value
="42")
252 # NOTE: this test may fail on older systems that don't emit import
253 # entries in DWARF - may need to add checks for compiler versions here.
254 @skipIf(compiler
="gcc", oslist
=["linux"], debug_info
=["dwo"]) # Skip to avoid crash
255 def test_scope_after_using_directive_lookup_with_run_command(self
):
256 """Test scope lookup after using directive in lldb."""
258 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
260 lldbutil
.run_break_set_by_file_and_line(
263 self
.line_break_after_using_directive
,
264 num_expected_locations
=1,
268 # Run to BP_after_using_directive at global scope after using
270 self
.runToBkpt("run")
271 # Evaluate func2() - should call A::func2()
272 self
.expect_expr("func2()", result_type
="int", result_value
="3")
274 @expectedFailure("lldb scope lookup after using declaration bugs")
275 # NOTE: this test may fail on older systems that don't emit import
276 # emtries in DWARF - may need to add checks for compiler versions here.
277 def test_scope_after_using_declaration_lookup_with_run_command(self
):
278 """Test scope lookup after using declaration in lldb."""
280 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
282 lldbutil
.run_break_set_by_file_and_line(
285 self
.line_break_nested_ns_scope_after_using
,
286 num_expected_locations
=1,
290 # Run to BP_nested_ns_scope_after_using at nested ns scope after using
292 self
.runToBkpt("run")
293 # Evaluate func() - should call A::func()
294 self
.expect_expr("func()", result_type
="int", result_value
="3")
296 @expectedFailure("lldb scope lookup ambiguity after using bugs")
297 def test_scope_ambiguity_after_using_lookup_with_run_command(self
):
298 """Test scope lookup ambiguity after using in lldb."""
300 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
302 lldbutil
.run_break_set_by_file_and_line(
305 self
.line_break_after_using_directive
,
306 num_expected_locations
=1,
310 # Run to BP_after_using_directive at global scope after using
312 self
.runToBkpt("run")
313 # Evaluate func() - should get error: ambiguous
314 # FIXME: This test fails because lldb removes duplicates if they have
316 self
.expect("expr -- func()", startstr
="error")
318 def test_scope_lookup_shadowed_by_using_with_run_command(self
):
319 """Test scope lookup shadowed by using in lldb."""
321 self
.runCmd("file " + self
.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET
)
323 lldbutil
.run_break_set_by_file_and_line(
326 self
.line_break_nested_ns_scope
,
327 num_expected_locations
=1,
331 # Run to BP_nested_ns_scope at nested ns scope
332 self
.runToBkpt("run")
333 # Evaluate func(10) - should call A::func(10)
334 # NOTE: Under the rules of C++, this test would normally get an error
335 # because A::B::func() shadows A::func(), but lldb intentionally
336 # disobeys these rules so that the intended overload can be found
337 # by only removing duplicates if they have the same type.
338 self
.expect_expr("func(10)", result_type
="int", result_value
="13")