2010-02-05 Sami Wagiaalla <swagiaal@redhat.com>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / nsusing.exp
CommitLineData
4c38e0a4 1# Copyright 2008, 2010 Free Software Foundation, Inc.
27aa8d6a
SW
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
16if $tracelevel then {
17 strace $tracelevel
18}
19
20set prms_id 0
21set bug_id 0
22
de958931 23set testfile nsusing
27aa8d6a
SW
24set srcfile ${testfile}.cc
25set binfile ${objdir}/${subdir}/${testfile}
df83a9bf
SW
26if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
27 {debug c++}] != "" } {
27aa8d6a
SW
28 untested "Couldn't compile test program"
29 return -1
30}
31
8540c487
SW
32if [get_compiler_info ${binfile}] {
33 return -1
34}
35
36
27aa8d6a
SW
37# Get things started.
38
39gdb_exit
40gdb_start
41gdb_reinitialize_dir $srcdir/$subdir
42gdb_load ${binfile}
43
44############################################
45# test printing of namespace imported within
46# the function.
47
48if ![runto_main] then {
49 perror "couldn't run to breakpoint main"
50 continue
51}
52
53gdb_test "print _a" "= 1"
54
df83a9bf
SW
55# Test that names are not printed when they
56# are not imported
57
58gdb_breakpoint marker3
59gdb_continue_to_breakpoint "marker3"
60
61#send_gdb "break marker3\n"
62#send_gdb "continue\n"
63
64gdb_test "print _a" "No symbol \"_a\" in current context." \
65 "Print _a without import"
66
67gdb_exit
68gdb_start
69gdb_reinitialize_dir $srcdir/$subdir
70gdb_load ${binfile}
71
72
27aa8d6a 73############################################
df83a9bf 74# test printing of namespace imported into
27aa8d6a
SW
75# a scope containing the pc.
76
df83a9bf
SW
77if ![runto_main] then {
78 perror "couldn't run to breakpoint main"
79 continue
80}
81
27aa8d6a
SW
82gdb_breakpoint [gdb_get_line_number "marker1 stop"]
83gdb_continue_to_breakpoint "marker1 stop"
84
85gdb_test "print _a" "= 1" "print _a in a nested scope"
86
df83a9bf
SW
87
88gdb_exit
89gdb_start
90gdb_reinitialize_dir $srcdir/$subdir
91gdb_load ${binfile}
92
93############################################
94# test printing of namespace imported into
95# file scope.
96
97
98if ![runto marker5] then {
99 perror "couldn't run to breakpoint marker5"
100 continue
101}
102
103gdb_test "print cc" "= 3"
104
105gdb_exit
106gdb_start
107gdb_reinitialize_dir $srcdir/$subdir
108gdb_load ${binfile}
109
110
27aa8d6a
SW
111############################################
112# Test printing of namespace aliases
113
27aa8d6a
SW
114if ![runto marker2] then {
115 perror "couldn't run to breakpoint marker2"
116 continue
117}
118
df83a9bf
SW
119gdb_test "print B::_a" "= 1"
120
df83a9bf
SW
121gdb_test "print _a" "No symbol \"_a\" in current context." \
122 "print _a in namespace alias scope"
123
df83a9bf
SW
124gdb_test "print x" "No symbol \"x\" in current context." \
125 "print x in namespace alias scope"
126
127gdb_exit
128gdb_start
129gdb_reinitialize_dir $srcdir/$subdir
130gdb_load ${binfile}
131
27aa8d6a
SW
132
133############################################
df83a9bf 134# Test that names are not printed when they
27aa8d6a
SW
135# are not imported
136
df83a9bf
SW
137if {![runto marker3]} {
138 perror "couldn't run to breakpoint marker3"
139}
27aa8d6a 140
8540c487
SW
141# gcc-4-3 puts import statements for aliases in
142# the global scope instead of the corresponding
143# function scope. These wrong import statements throw
144# this test off. This is fixed in gcc-4-4.
145if [test_compiler_info gcc-4-3-*] then { setup_xfail *-*-* }
146
df83a9bf
SW
147gdb_test "print _a" "No symbol \"_a\" in current context." \
148 "Print _a without import"
27aa8d6a
SW
149
150############################################
151# Test printing of individually imported elements
152
27aa8d6a
SW
153if ![runto marker4] then {
154 perror "couldn't run to breakpoint marker4"
155 continue
156}
df83a9bf
SW
157setup_kfail "gdb/7936" "*-*-*"
158gdb_test "print dx" "= 4"
8540c487
SW
159
160############################################
df83a9bf 161# Test printing of namespace aliases
8540c487
SW
162
163if ![runto marker5] then {
164 perror "couldn't run to marker5"
165 continue
166}
167
df83a9bf 168gdb_test "print efx" "= 5"
8540c487
SW
169
170############################################
df83a9bf
SW
171# Test printing of variables imported from
172# nested namespaces
173
174if ![runto I::marker7] then {
175 perror "couldn't run to breakpoint I::marker7"
176 continue
177}
178
179gdb_test "print ghx" "= 6"
180
181############################################
182# Test that variables are not printed in a namespace
183# that is sibling to the namespace containing an import
184
185if ![runto L::marker8] then {
186 perror "couldn't run to breakpoint L::marker8"
187 continue
188}
189
190gdb_test "print jx" "= 44"
191
192gdb_breakpoint "K::marker9"
193gdb_continue_to_breakpoint "K::marker9"
194
195gdb_test "print jx" "No symbol \"jx\" in current context."
8540c487 196
df83a9bf
SW
197############################################
198# Test that variables are only printed after the line
199# containing the import
200
201if ![runto_main] then {
202 perror "couldn't run to breakpoint main"
8540c487
SW
203 continue
204}
205
df83a9bf
SW
206gdb_breakpoint [gdb_get_line_number "marker10 stop"]
207gdb_continue_to_breakpoint "marker10 stop"
208
209# Assert that M::x is printed and not N::x
210gdb_test "print x" "= 911" "print x (from M::x)"
This page took 0.100219 seconds and 4 git commands to generate.