diff options
author | Sami Wagiaalla <swagiaal@redhat.com> | 2010-01-26 15:48:25 +0000 |
---|---|---|
committer | Sami Wagiaalla <swagiaal@redhat.com> | 2010-01-26 15:48:25 +0000 |
commit | 8540c487c665cd07366b3d1fa199af33fa5b3691 (patch) | |
tree | 021ae94532f49f553d59058b8a51fd6cfa36c809 /gdb/testsuite/gdb.cp | |
parent | 8f95b6e44955bda4aa330449215785aa987155bb (diff) | |
download | gdb-8540c487c665cd07366b3d1fa199af33fa5b3691.zip gdb-8540c487c665cd07366b3d1fa199af33fa5b3691.tar.gz gdb-8540c487c665cd07366b3d1fa199af33fa5b3691.tar.bz2 |
2010-01-26 Sami Wagiaalla <swagiaal@redhat.com>
* gdb.cp/namespace-using.exp: Add test for printing of namespaces
imported into file scope.
Marked test as xfail.
* gdb.cp/namespace-using.cc (marker5): New function.
* gdb.cp/shadow.exp: New test.
* gdb.cp/shadow.cc: New test program.
* gdb.cp/nsimport.exp: New test.
* gdb.cp/nsimport.cc: New test program.
2010-01-26 Sami Wagiaalla <swagiaal@redhat.com>
PR gdb/10929:
* dwarf2read.c (read_lexical_block_scope): Create blocks for
scopes which contain using directives even if they contain no
declarations.
* symtab.c (lookup_symbol_aux): Pass lowest level block to
la_lookup_symbol_nonlocal.
* cp-namespace.c (cp_lookup_symbol_nonlocal): call
cp_lookup_symbol_namespace.
(cp_lookup_symbol_namespace): Perform an import lookup at every
block level.
(cp_lookup_symbol_imports): New function.
(cp_lookup_symbol_in_namespace): New function.
Diffstat (limited to 'gdb/testsuite/gdb.cp')
-rw-r--r-- | gdb/testsuite/gdb.cp/namespace-using.cc | 36 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/namespace-using.exp | 35 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/nsimport.cc | 20 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/nsimport.exp | 52 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/shadow.cc | 45 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/shadow.exp | 89 |
6 files changed, 274 insertions, 3 deletions
diff --git a/gdb/testsuite/gdb.cp/namespace-using.cc b/gdb/testsuite/gdb.cp/namespace-using.cc index 4786fd5..b1f0ce4 100644 --- a/gdb/testsuite/gdb.cp/namespace-using.cc +++ b/gdb/testsuite/gdb.cp/namespace-using.cc @@ -1,3 +1,35 @@ +namespace O +{ + int ox = 4; +} + +namespace PQ +{ + int marker6 () + { + return 0; + } +} + +namespace P +{ + using namespace O; +} + +//-------------- +namespace C +{ + int cc = 3; +} + +using namespace C; +int marker5 () +{ + cc; + return PQ::marker6 (); +} + + namespace A { int _a = 1; @@ -6,7 +38,7 @@ namespace A int marker4(){ using A::x; - return 0; + return marker5 (); } int marker3(){ @@ -34,7 +66,7 @@ int marker1() } } } - return total; + return marker2() + total; } int main() diff --git a/gdb/testsuite/gdb.cp/namespace-using.exp b/gdb/testsuite/gdb.cp/namespace-using.exp index 319552b..38d65a3 100644 --- a/gdb/testsuite/gdb.cp/namespace-using.exp +++ b/gdb/testsuite/gdb.cp/namespace-using.exp @@ -28,6 +28,11 @@ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {deb return -1 } +if [get_compiler_info ${binfile}] { + return -1 +} + + # Get things started. gdb_exit @@ -73,7 +78,13 @@ gdb_test "print B::a" "= 1" gdb_breakpoint "marker3" gdb_continue_to_breakpoint "marker3" -gdb_test "print _a" "No symbol \"_a\" in current context." "Print a without import" +# gcc-4-3 puts import statements for aliases in +# the global scope instead of the corresponding +# function scope. These wrong import statements throw +# this test off. This is fixed in gcc-4-4. +if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* } + +gdb_test "print _a" "No symbol \"_a\" in current context." "Print _a without import" ############################################ # Test printing of individually imported elements @@ -85,3 +96,25 @@ if ![runto marker4] then { } gdb_test "print x" "= 2" + +############################################ +# test printing of namespace imported into +# file scope. + +if ![runto marker5] then { + perror "couldn't run to marker5" + continue +} + +gdb_test "print cc" "= 3" + +############################################ +# test printing of namespace imported into +# file scope. + +if ![runto PQ::marker6] then { + perror "couldn't run to PQ::marker6" + continue +} + +gdb_test "print ox" "No symbol \"ox\" in current context." diff --git a/gdb/testsuite/gdb.cp/nsimport.cc b/gdb/testsuite/gdb.cp/nsimport.cc new file mode 100644 index 0000000..6b180d6 --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsimport.cc @@ -0,0 +1,20 @@ +namespace A { + int x = 11; + namespace{ + int xx = 22; + } +} + +using namespace A; + +namespace{ + int xxx = 33; +}; + +int main() +{ + x; + xx; + xxx; + return 0; +} diff --git a/gdb/testsuite/gdb.cp/nsimport.exp b/gdb/testsuite/gdb.cp/nsimport.exp new file mode 100644 index 0000000..e61e2ee --- /dev/null +++ b/gdb/testsuite/gdb.cp/nsimport.exp @@ -0,0 +1,52 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test printing from multiple namespace +# imported into the same scope. + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile nsimport +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +############################################ +# test printing of namespace imported within +# the function. + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +gdb_test "print x" "\\$\[0-9\].* = 11" +gdb_test "print xx" "\\$\[0-9\].* = 22" +gdb_test "print xxx" "\\$\[0-9\].* = 33" diff --git a/gdb/testsuite/gdb.cp/shadow.cc b/gdb/testsuite/gdb.cp/shadow.cc new file mode 100644 index 0000000..1651510 --- /dev/null +++ b/gdb/testsuite/gdb.cp/shadow.cc @@ -0,0 +1,45 @@ +namespace A +{ + int x = 11; +} + +int x = 22; +int y = 0; + +class B +{ +public: + int x; + + int + func() + { + x = 33; + y++; // marker1 + + { + int x = 44; + y++; // marker2 + + { + int x = 55; + y++; // marker3 + + { + using namespace A; + y++; // marker4 + + using A::x; + y++; // marker5 + } + } + } + } +}; + +int +main() +{ + B theB; + return theB.func(); +} diff --git a/gdb/testsuite/gdb.cp/shadow.exp b/gdb/testsuite/gdb.cp/shadow.exp new file mode 100644 index 0000000..1e5e80b --- /dev/null +++ b/gdb/testsuite/gdb.cp/shadow.exp @@ -0,0 +1,89 @@ +# Copyright 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test that when multiple variables have the same +# name the one from the correct scope is printed. + +if $tracelevel then { + strace $tracelevel +} + +set prms_id 0 +set bug_id 0 + +set testfile shadow +set srcfile ${testfile}.cc +set binfile ${objdir}/${subdir}/${testfile} +if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } { + untested "Couldn't compile test program" + return -1 +} + +# Get things started. + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +if ![runto_main] then { + perror "couldn't run to breakpoint main" + continue +} + +############################################ +# Test printing of class variable is not shadowed +# by global variable + +gdb_breakpoint [gdb_get_line_number "marker1"] +gdb_continue_to_breakpoint "marker1" + +gdb_test "print x" "= 33" "Print class x shadowing global x" + + +############################################ +# Test printing local variable is not shadowed +# by class variable + +gdb_breakpoint [gdb_get_line_number "marker2"] +gdb_continue_to_breakpoint "marker2" + +gdb_test "print x" "= 44" "Print local x shadowing class x" + +############################################ +# Test inner scope x is printed not outer scope + +gdb_breakpoint [gdb_get_line_number "marker3"] +gdb_continue_to_breakpoint "marker3" + +gdb_test "print x" "= 55" "Print inner scope x" + +############################################ +# Test printing local variable is not shadowed +# by namespace variable + +gdb_breakpoint [gdb_get_line_number "marker4"] +gdb_continue_to_breakpoint "marker4" + +gdb_test "print x" "= 55" "Print local x not namespace x" + +############################################ +# Test imported namespace element is printed + +gdb_breakpoint [gdb_get_line_number "marker5"] +gdb_continue_to_breakpoint "marker5" + +setup_kfail "gdb/7936" "*-*-*" +gdb_test "print x" "= 11" "Print imported namespace x" |