]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/namespace.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / namespace.exp
1 # Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2007
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # tests for namespaces
19 # Originally written by Satish Pai <pai@apollo.hp.com> 1997-07-23
20
21 # This file is part of the gdb testsuite
22
23 # Note: The original tests were geared to the HP aCC compiler,
24 # which has an idiosyncratic way of emitting debug info
25 # for namespaces.
26 # Note: As of 2000-06-03, they passed under g++ - djb
27
28
29 if $tracelevel then {
30 strace $tracelevel
31 }
32
33 set prms_id 0
34 set bug_id 0
35
36 if { [skip_cplus_tests] } { continue }
37
38 set testfile "namespace"
39 set srcfile ${testfile}.cc
40 set objfile ${objdir}/${subdir}/${testfile}.o
41 set srcfile1 ${testfile}1.cc
42 set objfile1 ${objdir}/${subdir}/${testfile}1.o
43 set binfile ${objdir}/${subdir}/${testfile}
44
45 if [get_compiler_info ${binfile} c++] {
46 return -1;
47 }
48
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${objfile}" object {debug c++}] != "" } {
50 untested namespace.exp
51 return -1
52 }
53
54 if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${objfile1}" object {debug c++}] != "" } {
55 untested namespace.exp
56 return -1
57 }
58
59 if { [gdb_compile "${objfile} ${objfile1}" "${binfile}" executable {debug c++}] != "" } {
60 untested namespace.exp
61 return -1
62 }
63
64 gdb_exit
65 gdb_start
66 gdb_reinitialize_dir $srcdir/$subdir
67 gdb_load ${binfile}
68
69
70 #
71 # set it up at a breakpoint so we can play with the variable values
72 #
73 if ![runto_main] then {
74 perror "couldn't run to breakpoint"
75 continue
76 }
77
78 if ![runto 'marker1'] then {
79 perror "couldn't run to marker1"
80 continue
81 }
82
83 gdb_test "up" ".*main.*" "up from marker1"
84
85 # Access a data item inside a namespace using colons and
86 # single quotes. :-(
87
88 # NOTE: carlton/2003-09-24: the quotes are becoming less necessary (or
89 # even desirable.) For tests where it should still work with quotes,
90 # I'm including versions both with and without quotes; for tests that
91 # shouldn't work with quotes, I'm only including one version.
92
93 send_gdb "print 'AAA::c'\n"
94 gdb_expect {
95 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print 'AAA::c'" }
96 -re ".*$gdb_prompt $" { fail "print 'AAA::c'" }
97 timeout { fail "(timeout) print 'AAA::c'" }
98 }
99
100 send_gdb "print AAA::c\n"
101 gdb_expect {
102 -re "\\$\[0-9\]* = 0 '\\\\(0|000)'\r\n$gdb_prompt $" { pass "print AAA::c" }
103 -re ".*$gdb_prompt $" { fail "print AAA::c" }
104 timeout { fail "(timeout) print AAA::c" }
105 }
106
107 # An object declared using "using".
108
109 send_gdb "print ina\n"
110 gdb_expect {
111 -re "\\$\[0-9\]+ = {xx = 33}.*$gdb_prompt $" {
112 pass "print ina"
113 }
114 -re ".*$gdb_prompt $" { fail "print ina" }
115 timeout { fail "(timeout) print ina" }
116 }
117
118 send_gdb "ptype ina\n"
119 gdb_expect {
120 -re "type = class (AAA::|)inA \{\r\n\[ \]*public:\r\n\[ \]*int xx;\r\n\[ \]*\r\n\[ \]*.*int fum\\(int\\);\r\n\}\r\n$gdb_prompt $" {
121 pass "ptype ina"
122 }
123 -re "type = class (AAA::|)inA \{\r\n\[ \]*public:\r\n\[ \]*int xx;\r\n\[ \]*\r\n\[ \]*int fum\\(int\\);\r\n.*\}\r\n$gdb_prompt $" {
124 pass "ptype ina"
125 }
126 -re ".*$gdb_prompt $" { fail "ptype ina" }
127 timeout { fail "(timeout) ptype ina" }
128 }
129
130 # Check all functions are known to GDB
131
132 setup_xfail hppa*-*-*11* CLLbs14869
133 send_gdb "info func xyzq\n"
134 gdb_expect {
135 -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\n$gdb_prompt $" {
136 pass "info func xyzq"
137 }
138 -re "All functions.*File.*namespace.cc:\r\nint AAA::A_xyzq\\(int\\);\r\nchar AAA::xyzq\\(char\\);\r\nint BBB::B_xyzq\\(int\\);\r\nchar BBB::CCC::xyzq\\(char\\);\r\nchar BBB::Class::xyzq\\(char\\);\r\nchar BBB::xyzq\\(char\\);\r\n$gdb_prompt $" {
139 pass "info func xyzq"
140 }
141 -re ".*$gdb_prompt $" { fail "info func xyzq" }
142 timeout { fail "(timeout) info func xyzq" }
143 }
144
145 # Call a function in a namespace
146
147 send_gdb "print 'AAA::xyzq'('x')\n"
148 gdb_expect {
149 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
150 pass "print 'AAA::xyzq'('x')"
151 }
152 -re ".*$gdb_prompt $" { fail "print 'AAA::xyzq'('x')" }
153 timeout { fail "(timeout) print 'AAA::xyzq'('x')" }
154 }
155
156 send_gdb "print AAA::xyzq('x')\n"
157 gdb_expect {
158 -re "\\$\[0-9\]* = 97 'a'\r\n$gdb_prompt $" {
159 pass "print AAA::xyzq('x')"
160 }
161 -re ".*$gdb_prompt $" { fail "print AAA::xyzq('x')" }
162 timeout { fail "(timeout) print AAA::xyzq('x')" }
163 }
164
165 # Break on a function in a namespace
166
167 send_gdb "break AAA::xyzq\n"
168 gdb_expect {
169 -re "Breakpoint.*at $hex: file.*namespace.cc, line 42\\.\r\n$gdb_prompt $" {
170 pass "break AAA::xyzq"
171 }
172 -re ".*$gdb_prompt $" { fail "break AAA::xyzq" }
173 timeout { fail "(timeout) break AAA::xyzq" }
174 }
175
176 # Call a function in a nested namespace
177
178 send_gdb "print 'BBB::CCC::xyzq'('x')\n"
179 gdb_expect {
180 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
181 pass "print 'BBB::CCC::xyzq'('x')"
182 }
183 -re ".*$gdb_prompt $" { fail "print 'BBB::CCC::xyzq'('x')" }
184 timeout { fail "(timeout) print 'BBB::CCC::xyzq'('x')" }
185 }
186
187 send_gdb "print BBB::CCC::xyzq('x')\n"
188 gdb_expect {
189 -re "\\$\[0-9\]* = 122 'z'\r\n$gdb_prompt $" {
190 pass "print BBB::CCC::xyzq('x')"
191 }
192 -re ".*$gdb_prompt $" { fail "print BBB::CCC::xyzq('x')" }
193 timeout { fail "(timeout) print BBB::CCC::xyzq('x')" }
194 }
195
196 # Break on a function in a nested namespace
197
198 send_gdb "break BBB::CCC::xyzq\n"
199 gdb_expect {
200 -re "Breakpoint.*at $hex: file.*namespace.cc, line 58\\.\r\n$gdb_prompt $" {
201 pass "break BBB::CCC::xyzq"
202 }
203 -re ".*$gdb_prompt $" { fail "break BBB::CCC::xyzq" }
204 timeout { fail "(timeout) break BBB::CCC::xyzq" }
205 }
206
207 # Print address of a function in a class in a namespace
208
209 send_gdb "print 'BBB::Class::xyzq'\n"
210 gdb_expect {
211 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
212 pass "print 'BBB::Class::xyzq'"
213 }
214 -re ".*$gdb_prompt $" { fail "print 'BBB::Class::xyzq'" }
215 timeout { fail "(timeout) print 'BBB::Class::xyzq'" }
216 }
217
218 send_gdb "print BBB::Class::xyzq\n"
219 gdb_expect {
220 -re "\\$\[0-9\]* = \{char \\((BBB::|)Class \\*( const|), (char|int)\\)\} $hex <BBB::Class::xyzq\\(char\\)>\r\n$gdb_prompt $" {
221 pass "print BBB::Class::xyzq"
222 }
223 -re ".*$gdb_prompt $" { fail "print BBB::Class::xyzq" }
224 timeout { fail "(timeout) print BBB::Class::xyzq" }
225 }
226
227 # Break on a function in a class in a namespace
228
229 send_gdb "break BBB::Class::xyzq\n"
230 gdb_expect {
231 -re "Breakpoint.*at $hex: file.*namespace.cc, line 63\\.\r\n$gdb_prompt $" {
232 pass "break BBB::Class::xyzq"
233 }
234 -re ".*$gdb_prompt $" { fail "break BBB::Class::xyzq" }
235 timeout { fail "(timeout) break BBB::Class::xyzq" }
236 }
237
238 # Test to see if the appropriate namespaces are in scope when trying
239 # to print out stuff from within a function defined within a
240 # namespace.
241
242 if ![runto "C::D::marker2"] then {
243 perror "couldn't run to marker2"
244 continue
245 }
246
247 gdb_test "print c" "\\$\[0-9\].* = 1"
248 gdb_test "print cc" "No symbol \"cc\" in current context."
249 gdb_test "print 'C::cc'" "\\$\[0-9\].* = 2"
250 gdb_test "print C::cc" "\\$\[0-9\].* = 2"
251 gdb_test "print cd" "\\$\[0-9\].* = 3"
252 gdb_test "print C::D::cd" "No type \"D\" within class or namespace \"C::C\"."
253 gdb_test "print 'E::cde'" "\\$\[0-9\].* = 5"
254 gdb_test "print E::cde" "\\$\[0-9\].* = 5"
255 gdb_test "print shadow" "\\$\[0-9\].* = 13"
256 gdb_test "print E::ce" "No symbol \"ce\" in namespace \"C::D::E\"."
257 gdb_test "ptype C" "type = namespace C::C"
258 gdb_test "ptype E" "type = namespace C::D::E"
259
260 gdb_test "ptype CClass" "type = (class C::CClass \{\r\n public:|struct C::CClass \{)\r\n int x;\r\n\}"
261 gdb_test "ptype CClass::NestedClass" "type = (class C::CClass::NestedClass \{\r\n public:|struct C::CClass::NestedClass \{)\r\n int y;\r\n\}"
262 gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context."
263 setup_kfail "gdb/1448" "*-*-*"
264 gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n public:\r\n int x;\r\n\}"
265 setup_kfail "gdb/1448" "*-*-*"
266 gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n public:\r\n int y;\r\n\}"
267 setup_kfail "gdb/1448" "*-*-*"
268 gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"."
269 gdb_test "ptype C::CClass" "No symbol \"CClass\" in namespace \"C::C\"."
270 gdb_test "ptype C::CClass::NestedClass" "No type \"CClass\" within class or namespace \"C::C\"."
271 gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"."
272
273 # Tests involving multiple files
274
275 gdb_test "print cOtherFile" "\\$\[0-9\].* = 316"
276 gdb_test "ptype OtherFileClass" "type = (class C::OtherFileClass \{\r\n public:|struct C::OtherFileClass \{)\r\n int z;\r\n\}"
277 setup_kfail "gdb/1448" "*-*-*"
278 gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n public:\r\n int z;\r\n\}"
279 gdb_test "ptype C::OtherFileClass" "No symbol \"OtherFileClass\" in namespace \"C::C\"."
280
281 # Some anonymous namespace tests.
282
283 gdb_test "print cX" "\\$\[0-9\].* = 6"
284 gdb_test "print 'F::cXf'" "\\$\[0-9\].* = 7"
285 gdb_test "print F::cXf" "\\$\[0-9\].* = 7"
286 gdb_test "print F::cXfX" "\\$\[0-9\].* = 8"
287 gdb_test "print X" "\\$\[0-9\].* = 9"
288 gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10"
289 gdb_test "print G::Xg" "\\$\[0-9\].* = 10"
290 gdb_test "print G::XgX" "\\$\[0-9\].* = 11"
291 gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context."
292 gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context."