diff options
Diffstat (limited to 'gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace')
9 files changed, 834 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile new file mode 100644 index 00000000000..638974fafd6 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile @@ -0,0 +1,3 @@ +CXX_SOURCES := main.cpp ns.cpp ns2.cpp ns3.cpp + +include Makefile.rules diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py new file mode 100644 index 00000000000..2221755fad3 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py @@ -0,0 +1,236 @@ +""" +Test the printing of anonymous and named namespace variables. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NamespaceBreakpointTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc") + @expectedFailureAll(oslist=["windows"]) + def test_breakpoints_func_auto(self): + """Test that we can set breakpoints correctly by basename to find all functions whose basename is "func".""" + self.build() + + names = [ + "func()", + "func(int)", + "A::B::func()", + "A::func()", + "A::func(int)"] + + # Create a target by the debugger. + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + # Set a breakpoint by name "func" which should pick up all functions + # whose basename is "func" + bp = target.BreakpointCreateByName( + "func", lldb.eFunctionNameTypeAuto, module_list, cu_list) + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue( + name in names, + "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeAuto") + + @expectedFailureAll(bugnumber="llvm.org/pr28548", compiler="gcc") + def test_breakpoints_func_full(self): + """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "func" + (no namespaces).""" + self.build() + + names = ["func()", "func(int)"] + + # Create a target by the debugger. + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + + # Set a breakpoint by name "func" whose fullly qualified named matches "func" which + # should pick up only functions whose basename is "func" and has no + # containing context + bp = target.BreakpointCreateByName( + "func", lldb.eFunctionNameTypeFull, module_list, cu_list) + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue( + name in names, + "make sure breakpoint locations are correct for 'func' with eFunctionNameTypeFull") + + def test_breakpoints_a_func_full(self): + """Test that we can set breakpoints correctly by fullname to find all functions whose fully qualified name is "A::func".""" + self.build() + + names = ["A::func()", "A::func(int)"] + + # Create a target by the debugger. + exe = self.getBuildArtifact("a.out") + target = self.dbg.CreateTarget(exe) + self.assertTrue(target, VALID_TARGET) + module_list = lldb.SBFileSpecList() + module_list.Append(lldb.SBFileSpec(exe, False)) + cu_list = lldb.SBFileSpecList() + + # Set a breakpoint by name "A::func" whose fullly qualified named matches "A::func" which + # should pick up only functions whose basename is "func" and is + # contained in the "A" namespace + bp = target.BreakpointCreateByName( + "A::func", lldb.eFunctionNameTypeFull, module_list, cu_list) + for bp_loc in bp: + name = bp_loc.GetAddress().GetFunction().GetName() + self.assertTrue( + name in names, + "make sure breakpoint locations are correct for 'A::func' with eFunctionNameTypeFull") + + +class NamespaceTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Find the line numbers for declarations of namespace variables i and + # j. + self.line_var_i = line_number( + 'main.cpp', '// Find the line number for anonymous namespace variable i.') + self.line_var_j = line_number( + 'main.cpp', '// Find the line number for named namespace variable j.') + # And the line number to break at. + self.line_break = line_number('main.cpp', + '// Set break point at this line.') + # Break inside do {} while and evaluate value + self.line_break_ns1 = line_number('main.cpp', '// Evaluate ns1::value') + self.line_break_ns2 = line_number('main.cpp', '// Evaluate ns2::value') + + def runToBkpt(self, command): + self.runCmd(command, RUN_SUCCEEDED) + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + # rdar://problem/8668674 + @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764") + def test_with_run_command(self): + """Test that anonymous and named namespace variables display correctly.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.line_break_ns1, + num_expected_locations=1, + loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.line_break_ns2, + num_expected_locations=1, + loc_exact=True) + lldbutil.run_break_set_by_file_and_line( + self, + "main.cpp", + self.line_break, + num_expected_locations=1, + loc_exact=True) + + self.runToBkpt("run") + # Evaluate ns1::value + self.expect("expression -- value", startstr="(int) $0 = 100") + + self.runToBkpt("continue") + # Evaluate ns2::value + self.expect("expression -- value", startstr="(int) $1 = 200") + + self.runToBkpt("continue") + # On Mac OS X, gcc 4.2 emits the wrong debug info with respect to + # types. + slist = ['(int) a = 12', 'anon_uint', 'a_uint', 'b_uint', 'y_uint'] + if self.platformIsDarwin() and self.getCompiler() in [ + 'clang', 'llvm-gcc']: + slist = ['(int) a = 12', + '::my_uint_t', 'anon_uint = 0', + '(A::uint_t) a_uint = 1', + '(A::B::uint_t) b_uint = 2', + '(Y::uint_t) y_uint = 3'] + + # 'frame variable' displays the local variables with type information. + self.expect('frame variable', VARIABLES_DISPLAYED_CORRECTLY, + substrs=slist) + + # 'frame variable' with basename 'i' should work. + self.expect( + "frame variable --show-declaration --show-globals i", + startstr="main.cpp:%d: (int) (anonymous namespace)::i = 3" % + self.line_var_i) + # main.cpp:12: (int) (anonymous namespace)::i = 3 + + # 'frame variable' with basename 'j' should work, too. + self.expect( + "frame variable --show-declaration --show-globals j", + startstr="main.cpp:%d: (int) A::B::j = 4" % + self.line_var_j) + # main.cpp:19: (int) A::B::j = 4 + + # 'frame variable' should support address-of operator. + self.runCmd("frame variable &i") + + # 'frame variable' with fully qualified name 'A::B::j' should work. + self.expect("frame variable A::B::j", VARIABLES_DISPLAYED_CORRECTLY, + startstr='(int) A::B::j = 4', + patterns=[' = 4']) + + # So should the anonymous namespace case. + self.expect( + "frame variable '(anonymous namespace)::i'", + VARIABLES_DISPLAYED_CORRECTLY, + startstr='(int) (anonymous namespace)::i = 3', + patterns=[' = 3']) + + # rdar://problem/8660275 + # test/namespace: 'expression -- i+j' not working + # This has been fixed. + self.expect("expression -- i + j", + startstr="(int) $2 = 7") + # (int) $2 = 7 + + self.runCmd("expression -- i") + self.runCmd("expression -- j") + + # rdar://problem/8668674 + # expression command with fully qualified namespace for a variable does + # not work + self.expect("expression -- ::i", VARIABLES_DISPLAYED_CORRECTLY, + patterns=[' = 3']) + self.expect("expression -- A::B::j", VARIABLES_DISPLAYED_CORRECTLY, + patterns=[' = 4']) + + # expression command with function in anonymous namespace + self.expect("expression -- myanonfunc(3)", + patterns=[' = 6']) + + # global namespace qualification with function in anonymous namespace + self.expect("expression -- ::myanonfunc(4)", + patterns=[' = 8']) + + self.expect("p myanonfunc", + patterns=['\(anonymous namespace\)::myanonfunc\(int\)']) + + self.expect("p variadic_sum", patterns=[ + '\(anonymous namespace\)::variadic_sum\(int, ...\)']) diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py new file mode 100644 index 00000000000..5526a14f530 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py @@ -0,0 +1,314 @@ +""" +Test the printing of anonymous and named namespace variables. +""" + + + +import lldb +from lldbsuite.test.decorators import * +from lldbsuite.test.lldbtest import * +from lldbsuite.test import lldbutil + + +class NamespaceLookupTestCase(TestBase): + + mydir = TestBase.compute_mydir(__file__) + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + # Break inside different scopes and evaluate value + self.line_break_global_scope = line_number( + 'ns.cpp', '// BP_global_scope') + self.line_break_file_scope = line_number('ns2.cpp', '// BP_file_scope') + self.line_break_ns_scope = line_number('ns2.cpp', '// BP_ns_scope') + self.line_break_nested_ns_scope = line_number( + 'ns2.cpp', '// BP_nested_ns_scope') + self.line_break_nested_ns_scope_after_using = line_number( + 'ns2.cpp', '// BP_nested_ns_scope_after_using') + self.line_break_before_using_directive = line_number( + 'ns3.cpp', '// BP_before_using_directive') + self.line_break_after_using_directive = line_number( + 'ns3.cpp', '// BP_after_using_directive') + + def runToBkpt(self, command): + self.runCmd(command, RUN_SUCCEEDED) + # The stop reason of the thread should be breakpoint. + self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, + substrs=['stopped', + 'stop reason = breakpoint']) + + @expectedFailureAll( + oslist=["freebsd"], + bugnumber="llvm.org/pr25819") + @skipIfWindows # This is flakey on Windows: llvm.org/pr38373 + def test_scope_lookup_with_run_command(self): + """Test scope lookup of functions in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns.cpp", + self.line_break_global_scope, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_ns_scope, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_nested_ns_scope, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_nested_ns_scope_after_using, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns3.cpp", + self.line_break_before_using_directive, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns3.cpp", + self.line_break_after_using_directive, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_global_scope at global scope + self.runToBkpt("run") + # Evaluate func() - should call ::func() + self.expect("expr -- func()", startstr="(int) $0 = 1") + # Evaluate A::B::func() - should call A::B::func() + self.expect("expr -- A::B::func()", startstr="(int) $1 = 4") + # Evaluate func(10) - should call ::func(int) + self.expect("expr -- func(10)", startstr="(int) $2 = 11") + # Evaluate ::func() - should call A::func() + self.expect("expr -- ::func()", startstr="(int) $3 = 1") + # Evaluate A::foo() - should call A::foo() + self.expect("expr -- A::foo()", startstr="(int) $4 = 42") + + # Continue to BP_ns_scope at ns scope + self.runToBkpt("continue") + # Evaluate func(10) - should call A::func(int) + self.expect("expr -- func(10)", startstr="(int) $5 = 13") + # Evaluate B::func() - should call B::func() + self.expect("expr -- B::func()", startstr="(int) $6 = 4") + # Evaluate func() - should call A::func() + self.expect("expr -- func()", startstr="(int) $7 = 3") + + # Continue to BP_nested_ns_scope at nested ns scope + self.runToBkpt("continue") + # Evaluate func() - should call A::B::func() + self.expect("expr -- func()", startstr="(int) $8 = 4") + # Evaluate A::func() - should call A::func() + self.expect("expr -- A::func()", startstr="(int) $9 = 3") + + # Evaluate func(10) - should call A::func(10) + # NOTE: Under the rules of C++, this test would normally get an error + # because A::B::func() hides A::func(), but lldb intentionally + # disobeys these rules so that the intended overload can be found + # by only removing duplicates if they have the same type. + self.expect("expr -- func(10)", startstr="(int) $10 = 13") + + # Continue to BP_nested_ns_scope_after_using at nested ns scope after + # using declaration + self.runToBkpt("continue") + # Evaluate A::func(10) - should call A::func(int) + self.expect("expr -- A::func(10)", startstr="(int) $11 = 13") + + # Continue to BP_before_using_directive at global scope before using + # declaration + self.runToBkpt("continue") + # Evaluate ::func() - should call ::func() + self.expect("expr -- ::func()", startstr="(int) $12 = 1") + # Evaluate B::func() - should call B::func() + self.expect("expr -- B::func()", startstr="(int) $13 = 4") + + # Continue to BP_after_using_directive at global scope after using + # declaration + self.runToBkpt("continue") + # Evaluate ::func() - should call ::func() + self.expect("expr -- ::func()", startstr="(int) $14 = 1") + # Evaluate B::func() - should call B::func() + self.expect("expr -- B::func()", startstr="(int) $15 = 4") + + @unittest2.expectedFailure("lldb scope lookup of functions bugs") + def test_function_scope_lookup_with_run_command(self): + """Test scope lookup of functions in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns.cpp", + self.line_break_global_scope, + num_expected_locations=1, + loc_exact=False) + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_ns_scope, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_global_scope at global scope + self.runToBkpt("run") + # Evaluate foo() - should call ::foo() + # FIXME: lldb finds Y::foo because lookup for variables is done + # before functions. + self.expect("expr -- foo()", startstr="(int) $0 = 42") + # Evaluate ::foo() - should call ::foo() + # FIXME: lldb finds Y::foo because lookup for variables is done + # before functions and :: is ignored. + self.expect("expr -- ::foo()", startstr="(int) $1 = 42") + + # Continue to BP_ns_scope at ns scope + self.runToBkpt("continue") + # Evaluate foo() - should call A::foo() + # FIXME: lldb finds Y::foo because lookup for variables is done + # before functions. + self.expect("expr -- foo()", startstr="(int) $2 = 42") + + @unittest2.expectedFailure("lldb file scope lookup bugs") + @skipIfWindows # This is flakey on Windows: llvm.org/pr38373 + def test_file_scope_lookup_with_run_command(self): + """Test file scope lookup in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_file_scope, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_file_scope at file scope + self.runToBkpt("run") + # Evaluate func() - should call static ns2.cpp:func() + # FIXME: This test fails because lldb doesn't know about file scopes so + # finds the global ::func(). + self.expect("expr -- func()", startstr="(int) $0 = 2") + + @skipIfWindows # This is flakey on Windows: llvm.org/pr38373 + def test_scope_lookup_before_using_with_run_command(self): + """Test scope lookup before using in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns3.cpp", + self.line_break_before_using_directive, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_before_using_directive at global scope before using + # declaration + self.runToBkpt("run") + # Evaluate func() - should call ::func() + self.expect("expr -- func()", startstr="(int) $0 = 1") + + # NOTE: this test may fail on older systems that don't emit import + # entries in DWARF - may need to add checks for compiler versions here. + @skipIf( + compiler="gcc", + oslist=["linux"], + debug_info=["dwo"]) # Skip to avoid crash + @expectedFailureAll( + oslist=["freebsd"], + bugnumber="llvm.org/pr25819") + def test_scope_after_using_directive_lookup_with_run_command(self): + """Test scope lookup after using directive in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns3.cpp", + self.line_break_after_using_directive, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_after_using_directive at global scope after using + # declaration + self.runToBkpt("run") + # Evaluate func2() - should call A::func2() + self.expect("expr -- func2()", startstr="(int) $0 = 3") + + @unittest2.expectedFailure( + "lldb scope lookup after using declaration bugs") + # NOTE: this test may fail on older systems that don't emit import + # emtries in DWARF - may need to add checks for compiler versions here. + def test_scope_after_using_declaration_lookup_with_run_command(self): + """Test scope lookup after using declaration in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_nested_ns_scope_after_using, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_nested_ns_scope_after_using at nested ns scope after using + # declaration + self.runToBkpt("run") + # Evaluate func() - should call A::func() + self.expect("expr -- func()", startstr="(int) $0 = 3") + + @unittest2.expectedFailure("lldb scope lookup ambiguity after using bugs") + def test_scope_ambiguity_after_using_lookup_with_run_command(self): + """Test scope lookup ambiguity after using in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns3.cpp", + self.line_break_after_using_directive, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_after_using_directive at global scope after using + # declaration + self.runToBkpt("run") + # Evaluate func() - should get error: ambiguous + # FIXME: This test fails because lldb removes duplicates if they have + # the same type. + self.expect("expr -- func()", startstr="error") + + @expectedFailureAll( + oslist=["freebsd"], + bugnumber="llvm.org/pr25819") + def test_scope_lookup_shadowed_by_using_with_run_command(self): + """Test scope lookup shadowed by using in lldb.""" + self.build() + self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET) + + lldbutil.run_break_set_by_file_and_line( + self, + "ns2.cpp", + self.line_break_nested_ns_scope, + num_expected_locations=1, + loc_exact=False) + + # Run to BP_nested_ns_scope at nested ns scope + self.runToBkpt("run") + # Evaluate func(10) - should call A::func(10) + # NOTE: Under the rules of C++, this test would normally get an error + # because A::B::func() shadows A::func(), but lldb intentionally + # disobeys these rules so that the intended overload can be found + # by only removing duplicates if they have the same type. + self.expect("expr -- func(10)", startstr="(int) $0 = 13") diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt new file mode 100644 index 00000000000..76bb1bcba75 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt @@ -0,0 +1,3 @@ +b main.cpp:54 +c +var diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp new file mode 100644 index 00000000000..22c0309695c --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp @@ -0,0 +1,124 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <cstdarg> +#include <cstdlib> +#include "ns.h" + +namespace { + typedef unsigned int my_uint_t; + int i; // Find the line number for anonymous namespace variable i. + + int myanonfunc (int a) + { + return a + a; + } + + int + variadic_sum (int arg_count...) + { + int sum = 0; + std::va_list args; + va_start(args, arg_count); + + for (int i = 0; i < arg_count; i++) + sum += va_arg(args, int); + + va_end(args); + return sum; + } +} + +namespace A { + typedef unsigned int uint_t; + namespace B { + typedef unsigned int uint_t; + int j; // Find the line number for named namespace variable j. + int myfunc (int a); + int myfunc2(int a) + { + return a + 2; + } + float myfunc (float f) + { + return f - 2.0; + } + } +} + +namespace Y +{ + typedef unsigned int uint_t; + using A::B::j; + int foo; +} + +using A::B::j; // using declaration + +namespace Foo = A::B; // namespace alias + +using Foo::myfunc; // using declaration + +using namespace Foo; // using directive + +namespace A { + namespace B { + using namespace Y; + int k; + } +} + +namespace ns1 { + int value = 100; +} + +namespace ns2 { + int value = 200; +} + +void test_namespace_scopes() { + do { + using namespace ns1; + printf("ns1::value = %d\n", value); // Evaluate ns1::value + } while(0); + + do { + using namespace ns2; + printf("ns2::value = %d\n", value); // Evaluate ns2::value + } while(0); +} + +int Foo::myfunc(int a) +{ + test_namespace_scopes(); + + ::my_uint_t anon_uint = 0; + A::uint_t a_uint = 1; + B::uint_t b_uint = 2; + Y::uint_t y_uint = 3; + i = 3; + j = 4; + printf("::i=%d\n", ::i); + printf("A::B::j=%d\n", A::B::j); + printf("variadic_sum=%d\n", variadic_sum(3, 1, 2, 3)); + myanonfunc(3); + return myfunc2(3) + j + i + a + 2 + anon_uint + a_uint + b_uint + y_uint; // Set break point at this line. +} + +int +main (int argc, char const *argv[]) +{ + test_lookup_at_global_scope(); + test_lookup_at_file_scope(); + A::test_lookup_at_ns_scope(); + A::B::test_lookup_at_nested_ns_scope(); + A::B::test_lookup_at_nested_ns_scope_after_using(); + test_lookup_before_using_directive(); + test_lookup_after_using_directive(); + return Foo::myfunc(12); +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp new file mode 100644 index 00000000000..481a9866fcb --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp @@ -0,0 +1,31 @@ +//===-- ns.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +int foo() +{ + std::printf("global foo()\n"); + return 42; +} +int func() +{ + std::printf("global func()\n"); + return 1; +} +int func(int a) +{ + std::printf("global func(int)\n"); + return a + 1; +} +void test_lookup_at_global_scope() +{ + // BP_global_scope + std::printf("at global scope: foo() = %d\n", foo()); // eval foo(), exp: 42 + std::printf("at global scope: func() = %d\n", func()); // eval func(), exp: 1 +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h new file mode 100644 index 00000000000..d04b45a7d7a --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h @@ -0,0 +1,33 @@ +//===-- ns.h ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include <cstdio> + +void test_lookup_at_global_scope(); +void test_lookup_at_file_scope(); +void test_lookup_before_using_directive(); +void test_lookup_after_using_directive(); +int func(int a); +namespace A { +int foo(); +int func(int a); +inline int func() { + std::printf("A::func()\n"); + return 3; +} +inline int func2() { + std::printf("A::func2()\n"); + return 3; +} +void test_lookup_at_ns_scope(); +namespace B { +int func(); +void test_lookup_at_nested_ns_scope(); +void test_lookup_at_nested_ns_scope_after_using(); +} // namespace B +} // namespace A diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp new file mode 100644 index 00000000000..9aae5d0a495 --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp @@ -0,0 +1,64 @@ +//===-- ns2.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +static int func() +{ + std::printf("static m2.cpp func()\n"); + return 2; +} +void test_lookup_at_file_scope() +{ + // BP_file_scope + std::printf("at file scope: func() = %d\n", func()); // eval func(), exp: 2 + std::printf("at file scope: func(10) = %d\n", func(10)); // eval func(10), exp: 11 +} +namespace A { + namespace B { + int func() + { + std::printf("A::B::func()\n"); + return 4; + } + void test_lookup_at_nested_ns_scope() + { + // BP_nested_ns_scope + std::printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 4 + + //printf("func(10) = %d\n", func(10)); // eval func(10), exp: 13 + // NOTE: Under the rules of C++, this test would normally get an error + // because A::B::func() hides A::func(), but lldb intentionally + // disobeys these rules so that the intended overload can be found + // by only removing duplicates if they have the same type. + } + void test_lookup_at_nested_ns_scope_after_using() + { + // BP_nested_ns_scope_after_using + using A::func; + std::printf("at nested ns scope after using: func() = %d\n", func()); // eval func(), exp: 3 + } + } +} +int A::foo() +{ + std::printf("A::foo()\n"); + return 42; +} +int A::func(int a) +{ + std::printf("A::func(int)\n"); + return a + 3; +} +void A::test_lookup_at_ns_scope() +{ + // BP_ns_scope + std::printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 3 + std::printf("at nested ns scope: func(10) = %d\n", func(10)); // eval func(10), exp: 13 + std::printf("at nested ns scope: foo() = %d\n", foo()); // eval foo(), exp: 42 +} diff --git a/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp new file mode 100644 index 00000000000..0f7a5050fde --- /dev/null +++ b/gnu/llvm/lldb/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp @@ -0,0 +1,26 @@ +//===-- ns3.cpp ------------------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "ns.h" +extern int func(); + +// Note: the following function must be before the using. +void test_lookup_before_using_directive() +{ + // BP_before_using_directive + std::printf("before using directive: func() = %d\n", func()); // eval func(), exp: 1 +} +using namespace A; +void test_lookup_after_using_directive() +{ + // BP_after_using_directive + //printf("func() = %d\n", func()); // eval func(), exp: error, amiguous + std::printf("after using directive: func2() = %d\n", func2()); // eval func2(), exp: 3 + std::printf("after using directive: ::func() = %d\n", ::func()); // eval ::func(), exp: 1 + std::printf("after using directive: B::func() = %d\n", B::func()); // eval B::func(), exp: 4 +} |