1 # Copyright 2008, 2011-2012 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Test that when multiple variables have the same
17 # name the one from the correct scope is printed.
21 set srcfile ${testfile}.cc
22 set binfile ${objdir}/${subdir}/${testfile}
23 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
24 untested "Couldn't compile test program"
28 if [get_compiler_info] {
36 gdb_reinitialize_dir $srcdir/$subdir
39 if ![runto_main] then {
40 perror "couldn't run to breakpoint main"
44 ############################################
45 # Test printing of class variable is not shadowed
48 gdb_breakpoint [gdb_get_line_number "marker1"]
49 gdb_continue_to_breakpoint "marker1"
51 gdb_test "print x" "= 33" "Print class x shadowing global x"
54 ############################################
55 # Test printing local variable is not shadowed
58 gdb_breakpoint [gdb_get_line_number "marker2"]
59 gdb_continue_to_breakpoint "marker2"
61 gdb_test "print x" "= 44" "Print local x shadowing class x"
63 ############################################
64 # Test inner scope x is printed not outer scope
66 gdb_breakpoint [gdb_get_line_number "marker3"]
67 gdb_continue_to_breakpoint "marker3"
69 gdb_test "print x" "= 55" "Print inner scope x"
71 ############################################
72 # Test printing local variable is not shadowed
73 # by namespace variable
75 gdb_breakpoint [gdb_get_line_number "marker4"]
76 gdb_continue_to_breakpoint "marker4"
78 gdb_test "print x" "= 55" "Print local x not namespace x"
80 ############################################
81 # Test imported namespace element is printed
83 gdb_breakpoint [gdb_get_line_number "marker5"]
84 gdb_continue_to_breakpoint "marker5"
86 if { [test_compiler_info {gcc-[0-3]-*}] ||
87 [test_compiler_info {gcc-4-[0-3]-*}]} {
91 gdb_test "print x" "= 11" "Print imported namespace x"