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