diff options
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/cpp/namespace')
9 files changed, 640 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile b/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile new file mode 100644 index 0000000..7dd5eb4 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/Makefile @@ -0,0 +1,5 @@ +LEVEL = ../../../make + +CXX_SOURCES := main.cpp ns.cpp ns2.cpp ns3.cpp + +include $(LEVEL)/Makefile.rules diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py new file mode 100644 index 0000000..a60d825 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespace.py @@ -0,0 +1,125 @@ +""" +Test the printing of anonymous and named namespace variables. +""" + +from __future__ import print_function + + + +import os, time +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as lldbutil + +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 + @expectedFailureWindows("llvm.org/pr24764") + def test_with_run_command(self): + """Test that anonymous and named namespace variables display correctly.""" + self.build() + self.runCmd("file 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/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py new file mode 100644 index 0000000..4cad455 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/TestNamespaceLookup.py @@ -0,0 +1,223 @@ +""" +Test the printing of anonymous and named namespace variables. +""" + +from __future__ import print_function + + +import os, time +import lldb +from lldbsuite.test.lldbtest import * +import lldbsuite.test.lldbutil as 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']) + + @expectedFailureFreeBSD("llvm.org/pr25819") + @expectedFailureLinux("llvm.org/pr25819") + def test_scope_lookup_with_run_command(self): + """Test scope lookup of functions in lldb.""" + self.build() + self.runCmd("file 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 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") + def test_file_scope_lookup_with_run_command(self): + """Test file scope lookup in lldb.""" + self.build() + self.runCmd("file 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") + + @expectedFailureLinux("llvm.org/pr25819") + def test_scope_lookup_before_using_with_run_command(self): + """Test scope lookup before using in lldb.""" + self.build() + self.runCmd("file 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 + # emtries in DWARF - may need to add checks for compiler versions here. + @expectedFailureFreeBSD("llvm.org/pr25819") + @expectedFailureLinux("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 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 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 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") + + @expectedFailureFreeBSD("llvm.org/pr25819") + @expectedFailureLinux("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 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/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt b/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt new file mode 100644 index 0000000..76bb1bc --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/cmds.txt @@ -0,0 +1,3 @@ +b main.cpp:54 +c +var diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp new file mode 100644 index 0000000..560ec40 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/main.cpp @@ -0,0 +1,124 @@ +//===-- main.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <cstdarg> +#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; + 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/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp new file mode 100644 index 0000000..9e5637d --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.cpp @@ -0,0 +1,32 @@ +//===-- ns.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +int foo() +{ + printf("global foo()\n"); + return 42; +} +int func() +{ + printf("global func()\n"); + return 1; +} +int func(int a) +{ + printf("global func(int)\n"); + return a + 1; +} +void test_lookup_at_global_scope() +{ + // BP_global_scope + printf("at global scope: foo() = %d\n", foo()); // eval foo(), exp: 42 + printf("at global scope: func() = %d\n", func()); // eval func(), exp: 1 +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h new file mode 100644 index 0000000..a07b600 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns.h @@ -0,0 +1,36 @@ +//===-- ns.h ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <stdio.h> + +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() + { + printf("A::func()\n"); + return 3; + } + inline int func2() + { + 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(); + } +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp new file mode 100644 index 0000000..04046ad --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns2.cpp @@ -0,0 +1,65 @@ +//===-- ns2.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "ns.h" + +static int func() +{ + printf("static m2.cpp func()\n"); + return 2; +} +void test_lookup_at_file_scope() +{ + // BP_file_scope + printf("at file scope: func() = %d\n", func()); // eval func(), exp: 2 + printf("at file scope: func(10) = %d\n", func(10)); // eval func(10), exp: 11 +} +namespace A { + namespace B { + int func() + { + printf("A::B::func()\n"); + return 4; + } + void test_lookup_at_nested_ns_scope() + { + // BP_nested_ns_scope + 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; + printf("at nested ns scope after using: func() = %d\n", func()); // eval func(), exp: 3 + } + } +} +int A::foo() +{ + printf("A::foo()\n"); + return 42; +} +int A::func(int a) +{ + printf("A::func(int)\n"); + return a + 3; +} +void A::test_lookup_at_ns_scope() +{ + // BP_ns_scope + printf("at nested ns scope: func() = %d\n", func()); // eval func(), exp: 3 + printf("at nested ns scope: func(10) = %d\n", func(10)); // eval func(10), exp: 13 + printf("at nested ns scope: foo() = %d\n", foo()); // eval foo(), exp: 42 +} diff --git a/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp new file mode 100644 index 0000000..10b0df7 --- /dev/null +++ b/packages/Python/lldbsuite/test/lang/cpp/namespace/ns3.cpp @@ -0,0 +1,27 @@ +//===-- ns3.cpp ------------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#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 + 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 + printf("after using directive: func2() = %d\n", func2()); // eval func2(), exp: 3 + printf("after using directive: ::func() = %d\n", ::func()); // eval ::func(), exp: 1 + printf("after using directive: B::func() = %d\n", B::func()); // eval B::func(), exp: 4 +} |