2010-03-29 Sami Wagiaalla <swagiaal@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / shadow.exp
1 # Copyright 2008 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 # Test that when multiple variables have the same
17 # name the one from the correct scope is printed.
18
19 if $tracelevel then {
20 strace $tracelevel
21 }
22
23 set prms_id 0
24 set bug_id 0
25
26 set testfile shadow
27 set srcfile ${testfile}.cc
28 set binfile ${objdir}/${subdir}/${testfile}
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
30 untested "Couldn't compile test program"
31 return -1
32 }
33
34 if [get_compiler_info ${binfile}] {
35 return -1
36 }
37
38 # Get things started.
39
40 gdb_exit
41 gdb_start
42 gdb_reinitialize_dir $srcdir/$subdir
43 gdb_load ${binfile}
44
45 if ![runto_main] then {
46 perror "couldn't run to breakpoint main"
47 continue
48 }
49
50 ############################################
51 # Test printing of class variable is not shadowed
52 # by global variable
53
54 gdb_breakpoint [gdb_get_line_number "marker1"]
55 gdb_continue_to_breakpoint "marker1"
56
57 gdb_test "print x" "= 33" "Print class x shadowing global x"
58
59
60 ############################################
61 # Test printing local variable is not shadowed
62 # by class variable
63
64 gdb_breakpoint [gdb_get_line_number "marker2"]
65 gdb_continue_to_breakpoint "marker2"
66
67 gdb_test "print x" "= 44" "Print local x shadowing class x"
68
69 ############################################
70 # Test inner scope x is printed not outer scope
71
72 gdb_breakpoint [gdb_get_line_number "marker3"]
73 gdb_continue_to_breakpoint "marker3"
74
75 gdb_test "print x" "= 55" "Print inner scope x"
76
77 ############################################
78 # Test printing local variable is not shadowed
79 # by namespace variable
80
81 gdb_breakpoint [gdb_get_line_number "marker4"]
82 gdb_continue_to_breakpoint "marker4"
83
84 gdb_test "print x" "= 55" "Print local x not namespace x"
85
86 ############################################
87 # Test imported namespace element is printed
88
89 gdb_breakpoint [gdb_get_line_number "marker5"]
90 gdb_continue_to_breakpoint "marker5"
91
92 if { [test_compiler_info {gcc-[0-3]-*}] ||
93 [test_compiler_info {gcc-4-[0-3]-*}]} {
94 setup_xfail *-*-*
95 }
96
97 gdb_test "print x" "= 11" "Print imported namespace x"
This page took 0.032636 seconds and 5 git commands to generate.