2003-09-07 Michael Chastain <mec@shout.net>
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / classes.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003 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 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Fred Fish. (fnf@cygnus.com)
22
23 set ws "\[\r\n\t \]+"
24 set nl "\[\r\n\]+"
25
26 if $tracelevel then {
27 strace $tracelevel
28 }
29
30 if { [skip_cplus_tests] } { continue }
31
32 set testfile "misc"
33 set srcfile ${testfile}.cc
34 set binfile ${objdir}/${subdir}/${testfile}
35
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
38
39 if [get_compiler_info ${binfile} "c++"] {
40 return -1
41 }
42
43 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
44 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
45 }
46
47 #
48 # Test ptype of class objects.
49 #
50
51 proc test_ptype_class_objects {} {
52 global gdb_prompt
53 global ws
54 global nl
55
56 # Note that struct members are public by default, so we don't print
57 # "public:" for the public members of structs.
58 # Accept it if gdb just fails to distinguish between
59 # class and struct, and everything else is OK.
60
61 send_gdb "ptype struct default_public_struct\n"
62 gdb_expect {
63 -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
64 pass "ptype struct default_public_struct"
65 }
66 -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
67 pass "ptype struct default_public_struct"
68 }
69 -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
70 timeout { fail "ptype struct default_public_struct (timeout)" ; return }
71 }
72
73 # Note that struct members are public by default, so we don't print
74 # "public:" for the public members of structs.
75 # Accept it if gdb just fails to distinguish between
76 # class and struct, and everything else is OK.
77
78 send_gdb "ptype struct explicit_public_struct\n"
79 gdb_expect {
80 -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
81 pass "ptype struct explicit_public_struct"
82 }
83 -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
84 pass "ptype struct explicit_public_struct"
85 }
86 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
87 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
88 }
89
90 # Accept it if gdb just fails to distinguish between
91 # class and struct, and everything else is OK.
92
93 send_gdb "ptype struct protected_struct\n"
94 gdb_expect {
95 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
96 pass "ptype struct protected_struct"
97 }
98 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
99 pass "ptype struct protected_struct"
100 }
101 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
102 timeout { fail "ptype struct protected_struct (timeout)" ; return }
103 }
104
105 # Accept it if gdb just fails to distinguish between
106 # class and struct, and everything else is OK.
107
108 send_gdb "ptype struct private_struct\n"
109 gdb_expect {
110 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
111 pass "ptype struct private_struct"
112 }
113 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
114 pass "ptype struct private_struct"
115 }
116 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
117 timeout { fail "ptype struct private_struct (timeout)" ; return }
118 }
119
120 # Accept it if gdb just fails to distinguish between
121 # class and struct, and everything else is OK.
122
123 send_gdb "ptype struct mixed_protection_struct\n"
124 gdb_expect {
125 -re "type = struct mixed_protection_struct \{${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl\}$nl$gdb_prompt $" {
126 pass "ptype struct mixed_protection_struct"
127 }
128 -re "type = struct mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
129 pass "ptype struct mixed_protection_struct (extra public)"
130 }
131 -re "type = class mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
132 pass "ptype struct mixed_protection_struct"
133 }
134 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
135 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
136 }
137
138 # Accept it if gdb just fails to distinguish between
139 # class and struct, and everything else is OK.
140
141 send_gdb "ptype class public_class\n"
142 gdb_expect {
143 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
144 pass "ptype class public_class"
145 }
146 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
147 pass "ptype class public_class"
148 }
149 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
150 timeout { fail "ptype class public_class (timeout)" ; return }
151 }
152
153 send_gdb "ptype class protected_class\n"
154 gdb_expect {
155 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
156 pass "ptype class protected_class"
157 }
158 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
159 fail "ptype class protected_class"
160 }
161 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
162 timeout { fail "ptype class protected_class (timeout)" ; return }
163 }
164
165 # Accept it if gdb just emits a superflous "private:"
166 # attribute, since classes default to private and for consistency with
167 # structs (where we don't print the "public:" attribute) we don't print
168 # the "private:" attribute.
169
170 send_gdb "ptype class default_private_class\n"
171 gdb_expect {
172 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
173 pass "ptype class default_private_class"
174 }
175 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
176 pass "ptype class default_private_class"
177 }
178 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
179 timeout { fail "ptype class default_private_class (timeout)" ; return }
180 }
181
182 send_gdb "ptype class explicit_private_class\n"
183 gdb_expect {
184 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
185 pass "ptype class explicit_private_class"
186 }
187 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
188 pass "ptype class explicit_private_class"
189 }
190 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
191 fail "ptype class explicit_private_class"
192 }
193 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
194 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
195 }
196
197 send_gdb "ptype class mixed_protection_class\n"
198 gdb_expect {
199 -re "type = class mixed_protection_class \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl.*\}$nl$gdb_prompt $" {
200 pass "ptype class mixed_protection_class"
201 }
202 -re "type = struct mixed_protection_class \{${ws}int a;${ws}int b;${ws}int c;${ws}int d;${ws}int e;${ws}int f;${ws}int g;${ws}int h;${ws}int i;$nl.*\}$nl$gdb_prompt $" {
203 fail "ptype class mixed_protection_class"
204 }
205 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
206 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
207 }
208
209 # This class does not use any C++-specific features, so it's fine for
210 # it to print as "struct".
211 send_gdb "ptype class A\n"
212 gdb_expect {
213 -re "type = (class|struct) A \{(${ws}public:|)${ws}int a;${ws}int x;((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\((A const|const A) ?&\\);)|(${ws}A\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
214 pass "ptype class A"
215 }
216 -re ".*$gdb_prompt $" {
217 fail "ptype class A"
218 }
219 timeout {
220 fail "ptype class A (timeout)"
221 return
222 }
223 }
224
225 send_gdb "ptype class B\n"
226 gdb_expect {
227 -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;${ws}B & operator=\\(B const ?&\\);${ws}B\\((B const|const B) ?&\\);${ws}B\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
228 pass "ptype class B"
229 }
230 -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;((${ws}B & operator=\\(B const ?&\\);)|(${ws}B\\(B const ?&\\);)|(${ws}B\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
231 pass "ptype class B (obsolescent gcc or gdb)"
232 }
233 -re ".*$gdb_prompt $" {
234 fail "ptype class B"
235 }
236 timeout {
237 fail "ptype class B (timeout)"
238 return
239 }
240 }
241
242 send_gdb "ptype class C\n"
243 gdb_expect {
244 -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;${ws}C & operator=\\(C const ?&\\);${ws}C\\((C const|const C) ?&\\);${ws}C\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
245 pass "ptype class C"
246 }
247 -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;((${ws}C & operator=\\(C const ?&\\);)|(${ws}C\\(C const ?&\\);)|(${ws}C\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
248 pass "ptype class C (obsolescent gcc or gdb)"
249 }
250 -re ".*$gdb_prompt $" {
251 fail "ptype class C"
252 }
253 timeout {
254 fail "ptype class C (timeout)"
255 return
256 }
257 }
258
259 send_gdb "ptype class D\n"
260 gdb_expect {
261 -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;${ws}D & operator=\\(D const ?&\\);${ws}D\\((D const|const D) ?&\\);${ws}D\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
262 pass "ptype class D"
263 }
264 -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;((${ws}D & operator=\\(D const ?&\\);)|(${ws}D\\(D const ?&\\);)|(${ws}D\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
265 pass "ptype class D (obsolescent gcc or gdb)"
266 }
267 -re ".*$gdb_prompt $" {
268 fail "ptype class D"
269 }
270 timeout {
271 fail "ptype class D (timeout)"
272 return
273 }
274 }
275
276 send_gdb "ptype class E\n"
277 gdb_expect {
278 -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;${ws}E & operator=\\(E const ?&\\);${ws}E\\((E const|const E) ?&\\);${ws}E\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
279 pass "ptype class E"
280 }
281 -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;((${ws}E & operator=\\(E const ?&\\);)|(${ws}E\\((E const|const E) ?&\\);)|(${ws}E\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
282 pass "ptype class E"
283 }
284 -re ".*$gdb_prompt $" {
285 fail "ptype class E"
286 }
287 timeout {
288 fail "ptype class E (timeout)"
289 return
290 }
291 }
292
293 # With g++ 2.x and stabs debug info, we misinterpret static methods
294 # whose name matches their argument mangling.
295 send_gdb "ptype class Static\n"
296 gdb_expect {
297 -re "type = (class|struct) Static \{(${ws}public:|)${ws}Static & operator=\\(Static const ?&\\);${ws}Static\\((Static const|const Static) ?&\\);${ws}Static\\((void|)\\);${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
298 pass "ptype class Static"
299 }
300 -re "type = (class|struct) Static \{(${ws}public:|)${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
301 pass "ptype class Static"
302 }
303 -re ".*$gdb_prompt $" {
304 fail "ptype class Static"
305 }
306 timeout {
307 fail "ptype class Static (timeout)"
308 return
309 }
310 }
311
312 send_gdb "ptype class vA\n"
313 gdb_expect {
314 -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
315 pass "ptype class vA"
316 }
317 -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}vA & operator=\\(vA const ?&\\);${ws}vA\\((vA const|const vA) ?&\\);${ws}vA\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
318 pass "ptype class vA"
319 }
320 -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;((${ws}vA & operator=\\(vA const ?&\\);)|(${ws}vA\\(vA const ?&\\);)|(${ws}vA\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
321 pass "ptype class vA (obsolescent gcc or gdb)"
322 }
323 -re ".*$gdb_prompt $" {
324 fail "ptype class vA"
325 }
326 timeout {
327 fail "ptype class vA (timeout)"
328 return
329 }
330 }
331
332 # Accept the form with embedded GNU style mangled virtual table constructs
333 # for now, but with a FIXME. At some future point, gdb should use a
334 # portable representation for the virtual table constructs.
335
336 # The format of a g++ virtual base pointer.
337 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
338
339 send_gdb "ptype class vB\n"
340 gdb_expect {
341 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}vB & operator=\\(vB const ?&\\);${ws}vB\\((vB const|const vB) ?&\\);${ws}vB\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
342 pass "ptype class vB"
343 }
344 -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*${vbptr}vA;${ws}public:${ws}int vb;${ws}int vx;${ws}vB & operator=\\(vB const ?&\\);${ws}vB\\(int, vB const ?&\\);${ws}vB\\(int\\);${ws}\}$nl$gdb_prompt $" {
345 setup_xfail "*-*-*"
346 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
347 }
348 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
349 pass "ptype class vB"
350 }
351 -re "type = class vB : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vb;${ws}int vx;((${ws}vB & operator=\\(vB const ?&\\);)|(${ws}vB\\(int, vB const ?&\\);)|(${ws}vB\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
352 setup_xfail "*-*-*"
353 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
354 }
355 -re ".*$gdb_prompt $" {
356 fail "ptype class vB"
357 }
358 timeout {
359 fail "ptype class vB (timeout)"
360 return
361 }
362 }
363
364 # Accept the form with embedded GNU style mangled virtual table constructs
365 # for now, but with a FIXME. At some future point, gdb should use a
366 # portable representation for the virtual table constructs.
367
368 send_gdb "ptype class vC\n"
369 gdb_expect {
370 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}vC & operator=\\(vC const ?&\\);${ws}vC\\((vC const|const vC) ?&\\);${ws}vC\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
371 pass "ptype class vC"
372 }
373 -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*${vbptr}vA;${ws}public:${ws}int vc;${ws}int vx;${ws}vC & operator=\\(vC const ?&\\);${ws}vC\\(int, vC const ?&\\);${ws}vC\\(int\\);${ws}\}$nl$gdb_prompt $" {
374 setup_xfail "*-*-*"
375 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
376 }
377 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
378 pass "ptype class vC"
379 }
380 -re "type = class vC : public virtual vA \{${ws}private:${ws}vA \\*_vb.vA;${ws}public:${ws}int vc;${ws}int vx;((${ws}vC & operator=\\(vC const ?&\\);)|(${ws}vC\\(int, vC const ?&\\);)|(${ws}vC\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
381 setup_xfail "*-*-*"
382 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
383 }
384 -re ".*$gdb_prompt $" {
385 fail "ptype class vC"
386 }
387 timeout {
388 fail "ptype class vC (timeout)"
389 return
390 }
391 }
392
393 # Accept the form with embedded GNU style mangled virtual table constructs
394 # for now, but with a FIXME. At some future point, gdb should use a
395 # portable representation for the virtual table constructs.
396
397 send_gdb "ptype class vD\n"
398 gdb_expect {
399 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}vD & operator=\\(vD const ?&\\);${ws}vD\\((vD const|const vD) ?&\\);${ws}vD\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
400 pass "ptype class vD"
401 }
402 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*${vbptr}vC;${ws}vB \\*${vbptr}vB;${ws}public:${ws}int vd;${ws}int vx;${ws}vD & operator=\\(vD const ?&\\);${ws}vD\\(int, vD const ?&\\);${ws}vD\\(int\\);${ws}\}$nl$gdb_prompt $" {
403 setup_xfail "*-*-*"
404 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
405 }
406 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
407 pass "ptype class vD"
408 }
409 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*_vb.vC;${ws}vB \\*_vb.vB;${ws}public:${ws}int vd;${ws}int vx;((${ws}vD & operator=\\(vD const ?&\\);)|(${ws}vD\\(int, vD const ?&\\);)|(${ws}vD\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
410 setup_xfail "*-*-*"
411 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
412 }
413 -re ".*$gdb_prompt $" {
414 fail "ptype class vD"
415 }
416 timeout {
417 fail "ptype class vD (timeout)"
418 return
419 }
420 }
421
422 # Accept the form with embedded GNU style mangled virtual table constructs
423 # for now, but with a FIXME. At some future point, gdb should use a
424 # portable representation for the virtual table constructs.
425
426 send_gdb "ptype class vE\n"
427 gdb_expect {
428 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}vE & operator=\\(vE const ?&\\);${ws}vE\\((vE const|const vE) ?&\\);${ws}vE\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
429 pass "ptype class vE"
430 }
431 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*${vbptr}vD;${ws}public:${ws}int ve;${ws}int vx;${ws}vE & operator=\\(vE const ?&\\);${ws}vE\\(int, vE const ?&\\);${ws}vE\\(int\\);${ws}\}$nl$gdb_prompt $" {
432 setup_xfail "*-*-*"
433 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
434 }
435 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
436 pass "ptype class vE"
437 }
438 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*_vb.vD;${ws}public:${ws}int ve;${ws}int vx;((${ws}vE & operator=\\(vE const ?&\\);)|(${ws}vE\\(int, vE const ?&\\);)|(${ws}vE\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
439 setup_xfail "*-*-*"
440 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
441 }
442 -re ".*$gdb_prompt $" {
443 fail "ptype class vE"
444 }
445 timeout {
446 fail "ptype class vE (timeout)"
447 return
448 }
449 }
450
451 send_gdb "ptype class Base1\n"
452 gdb_expect {
453 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 & operator=\\(Base1 const ?&\\);${ws}Base1\\(((Base1 const)|(const Base1)) ?&\\);${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
454 pass "ptype class Base1"
455 }
456 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
457 pass "ptype class Base1"
458 }
459 -re "type = class Base1 \{${ws}public:${ws}int x;((${ws}Base1 & operator=\\(Base1 const ?&\\);)|(${ws}Base1\\(Base1 const ?&\\);)|(${ws}Base1\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
460 pass "ptype class Base1 (obsolescent gcc or gdb)"
461 }
462 -re ".*$gdb_prompt $" {
463 fail "ptype class Base1"
464 }
465 timeout {
466 fail "ptype class Base1 (timeout)"
467 return
468 }
469 }
470
471 send_gdb "ptype class Foo\n"
472 gdb_expect {
473 -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;\r\n${ws}Foo\\(int, int\\);${ws}int operator!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);$nl\}$nl$gdb_prompt $" {
474 pass "ptype class Foo"
475 }
476 -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo & operator=\\(Foo const ?&\\);${ws}Foo\\((Foo const|const Foo) ?&\\);${ws}Foo\\(int, int\\);${ws}int operator!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);${ws}\}$nl$gdb_prompt $" {
477 pass "ptype class Foo"
478 }
479 -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;((${ws}Foo & operator=\\(Foo const ?&\\);)|(${ws}Foo\\(Foo const ?&\\);)|(${ws}Foo\\(int, int\\);)|(${ws}int operator!\\((void|)\\);)|(${ws}int operator int\\((void|)\\);)|(${ws}int times\\(int\\);))*${ws}\}$nl$gdb_prompt $" {
480 pass "ptype class Foo (obsolescent gcc or gdb)"
481 }
482 -re ".*$gdb_prompt $" {
483 fail "ptype class Foo"
484 }
485 timeout {
486 fail "ptype class Foo (timeout)"
487 return
488 }
489 }
490
491 send_gdb "ptype class Bar\n"
492 gdb_expect {
493 -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar & operator=\\(Bar const ?&\\);${ws}Bar\\((Bar const|const Bar) ?&\\);${ws}Bar\\(int, int, int\\);${ws}\}$nl$gdb_prompt $" {
494 pass "ptype class Bar"
495 }
496 -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;((${ws}Bar & operator=\\(Bar const ?&\\);)|(${ws}Bar\\(Bar const ?&\\);)|(${ws}Bar\\(int, int, int\\);))*${ws}\}$nl$gdb_prompt $" {
497 pass "ptype class Bar (obsolescent gcc or gdb)"
498 }
499 -re ".*$gdb_prompt $" {
500 fail "ptype class Bar"
501 }
502 timeout {
503 fail "ptype class Bar (timeout)"
504 return
505 }
506 }
507 }
508
509 #
510 # Test simple access to class members.
511 #
512
513 proc test_non_inherited_member_access {} {
514 global gdb_prompt
515
516 # Print non-inherited members of g_A.
517
518 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
519
520 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
521
522 # Print non-inherited members of g_B.
523
524 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
525
526 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
527
528 # Print non-inherited members of g_C.
529
530 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
531
532 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
533
534 # Print non-inherited members of g_D.
535
536 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
537
538 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
539
540 # Print non-inherited members of g_E.
541
542 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
543
544 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
545 }
546
547 #
548 # Try access to non-members that are members of another class.
549 # Should give errors.
550 #
551
552 proc test_wrong_class_members {} {
553 global gdb_prompt
554
555 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
556
557 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
558
559 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
560
561 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
562
563 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
564
565 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
566 }
567
568 #
569 # Try access to non-members that are not members of any class.
570 # Should give errors.
571 #
572
573 proc test_nonexistent_members {} {
574 global gdb_prompt
575
576 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
577
578 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
579
580 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
581
582 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
583 }
584
585 #
586 # Call a method that expects a base class parameter with base, inherited,
587 # and unrelated class arguments.
588 #
589
590 proc test_method_param_class {} {
591 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
592 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
593 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
594 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
595 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (&param)->a"
596 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (&param)->x"
597 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (&param)->a"
598 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (&param)->x"
599 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
600 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
601 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
602 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
603
604 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
605 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class &param"
606 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
607 }
608
609 #
610 # Examine a class with an enum field.
611 #
612
613 proc test_enums {} {
614 global gdb_prompt
615 global hp_aCC_compiler
616
617 # print the object
618 send_gdb "print obj_with_enum\n"
619 gdb_expect {
620 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
621 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
622 timeout { fail "(timeout) print obj_with_enum (1)" }
623 }
624
625 send_gdb "next\n"
626 gdb_expect {
627 -re "$gdb_prompt $" { pass "next" }
628 timeout { fail "(timeout) next" }
629 }
630
631 # print the object again
632 send_gdb "print obj_with_enum\n"
633 gdb_expect {
634 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
635 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
636 timeout { fail "(timeout) print obj_with_enum (2)" }
637 }
638
639 # print out the enum member
640 send_gdb "print obj_with_enum.priv_enum\n"
641 gdb_expect {
642 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
643 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
644 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
645 }
646
647 # ptype on the enum member
648 # The third success case is a little dubious, but it's not clear what
649 # ought to be required of a ptype on a private enum... -sts 19990324
650 send_gdb "ptype obj_with_enum.priv_enum\n"
651 gdb_expect {
652 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
653 -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
654 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
655 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
656 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
657 }
658
659 # ptype on the object
660 send_gdb "ptype obj_with_enum\n"
661 gdb_expect {
662 -re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)ClassWithEnum::PrivEnum priv_enum;\r\n\[ \t\]*int x;\r\n\\}\r\n$gdb_prompt $" { pass "ptype obj_with_enum" }
663 -re "type = class ClassWithEnum \\{\r\n\[ \t\]*public:\r\n\[ \t\]*(enum |)PrivEnum priv_enum;\r\n\[ \t\]*int x;.*\\}\r\n$gdb_prompt $"
664 {
665 # NOTE: carlton/2003-02-28: One could certainly argue that
666 # this output is acceptable: PrivEnum is a member of
667 # ClassWithEnum, so there's no need to explicitly qualify
668 # its name with "ClassWithEnum::". The truth, though, is
669 # that GDB is simply forgetting that PrivEnum is a member
670 # of ClassWithEnum, so we do that output for a bad reason
671 # instead of a good reason. Under stabs, we probably
672 # can't get this right; under DWARF-2, we can.
673 kfail "gdb/57" "ptype obj_with_enum"
674 }
675 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
676 timeout { fail "(timeout) ptype obj_with_enum" }
677 }
678
679 # We'll do this test twice, because of a parser bug: see
680 # PR gdb/826.
681
682 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
683 gdb_expect {
684 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
685 -re "A parse error in expression, near `42'.\r\n$gdb_prompt $" {
686 # bison 1.35
687 kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42"
688 }
689 -re "A syntax error in expression, near `42'.\r\n$gdb_prompt $" {
690 # bison 1.875
691 kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42"
692 }
693 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
694 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
695 }
696
697 send_gdb "print ('ClassWithEnum::PrivEnum') 42\n"
698 gdb_expect {
699 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print ('ClassWithEnum::PrivEnum') 42" }
700 -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.\r\n$gdb_prompt $"
701 { kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42" }
702 -re "$gdb_prompt $" { fail "print ('ClassWithEnum::PrivEnum') 42" }
703 timeout { fail "(timeout) print ('ClassWithEnum::PrivEnum') 42" }
704 }
705 }
706
707 #
708 # Pointers to class members
709 #
710
711 proc test_pointers_to_class_members {} {
712 global gdb_prompt
713 global decimal
714 global nl
715
716 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
717
718 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
719
720 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
721
722 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
723 gdb_expect {
724 -re ".* = true$nl$gdb_prompt $" {
725 pass "print (int)&Bar::y == 2*sizeof(int)"
726 }
727 -re "There is no field named y.*$gdb_prompt $" {
728 setup_xfail "*-*-*"
729 fail "print (int)&Bar::y == 2*sizeof(int)"
730 }
731 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
732 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
733 }
734
735 send_gdb "next 2\n"
736 setup_xfail "*-*-*"
737 gdb_expect {
738 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
739 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
740 }
741 clear_xfail "*-*-*"
742
743 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
744 }
745
746 #
747 # Test static members.
748 #
749
750 proc test_static_members {} {
751 global gdb_prompt
752 global hex
753 global nl
754
755 send_gdb "print Foo::st\n"
756 gdb_expect {
757 -re ".* = 100$nl$gdb_prompt $" {
758 pass "print Foo::st"
759 }
760 -re "There is no field named st.*$gdb_prompt $" {
761 setup_xfail "*-*-*"
762 fail "print Foo::st"
763 }
764 -re ".*$gdb_prompt $" { fail "print Foo::st" }
765 timeout { fail "print Foo::st (timeout)" ; return }
766 }
767
768 send_gdb "set foo.st = 200\n"
769 gdb_expect {
770 -re ".*$gdb_prompt $" {}
771 }
772
773 send_gdb "print bar.st\n"
774 gdb_expect {
775 -re ".* = 200$nl$gdb_prompt $" {
776 pass "print bar.st"
777 }
778 -re "There is no member( or method|) named st.*$gdb_prompt $" {
779 setup_xfail "*-*-*"
780 fail "print bar.st"
781 }
782 -re ".*$gdb_prompt $" { fail "print bar.st" }
783 timeout { fail "print bar.st (timeout)" ; return }
784 }
785
786 send_gdb "print &foo.st\n"
787 gdb_expect {
788 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
789 pass "print &foo.st"
790 }
791 -re "There is no member( or method|) named st.*$gdb_prompt $" {
792 setup_xfail "*-*-*"
793 fail "print &foo.st"
794 }
795 -re ".*$gdb_prompt $" { fail "print &foo.st" }
796 timeout { fail "print &foo.st (timeout)" ; return }
797 }
798
799 set got_bar_st 0
800 send_gdb "print &Bar::st\n"
801 gdb_expect {
802 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
803 pass "print &Bar::st"
804 set got_bar_st 1
805 }
806 -re "There is no field named st.*$gdb_prompt $" {
807 setup_xfail "*-*-*"
808 fail "print &Bar::st"
809 }
810 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
811 timeout { fail "print &Bar::st (timeout)" ; return }
812 }
813
814 if $got_bar_st then {
815 gdb_test "print *\$" ".* = 200" "print *\$"
816 }
817
818 gdb_test "set print static-members off" ""
819 gdb_test "print csi" \
820 "{x = 10, y = 20}" \
821 "print csi without static members"
822 gdb_test "print cnsi" \
823 "{x = 30, y = 40}" \
824 "print cnsi without static members"
825
826 gdb_test "set print static-members on" ""
827 gdb_test "print csi" \
828 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
829 "print csi with static members"
830 gdb_test "print cnsi" \
831 "{x = 30, y = 40, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>, static yy = {z = 5, static xx = {x = 1, y = 2, static null = <same as static member of an already seen type>, static yy = <same as static member of an already seen type>}}}, static yy = <same as static member of an already seen type>}" \
832 "print cnsi with static members"
833 }
834
835 proc do_tests {} {
836 global prms_id
837 global bug_id
838 global subdir
839 global objdir
840 global srcdir
841 global binfile
842 global gdb_prompt
843
844 set prms_id 0
845 set bug_id 0
846
847 # Start with a fresh gdb.
848
849 gdb_exit
850 gdb_start
851 gdb_reinitialize_dir $srcdir/$subdir
852 gdb_load $binfile
853
854 send_gdb "set language c++\n"
855 gdb_expect -re "$gdb_prompt $"
856 send_gdb "set width 0\n"
857 gdb_expect -re "$gdb_prompt $"
858
859 runto_main
860 test_ptype_class_objects
861
862 if [ runto 'inheritance2' ] then {
863 test_non_inherited_member_access
864 test_wrong_class_members
865 test_nonexistent_members
866 test_method_param_class
867 }
868
869 gdb_breakpoint enums2
870 if [ gdb_continue "enums2(\\(\\)|)" ]==0 then {
871 gdb_test "finish" "" ""
872 test_enums
873 }
874
875 if [istarget "mips-idt-*"] then {
876 # Restart because IDT/SIM runs out of file descriptors.
877 gdb_exit
878 gdb_start
879 gdb_reinitialize_dir $srcdir/$subdir
880 gdb_load $binfile
881 }
882
883 if [ runto_main ] then {
884 test_pointers_to_class_members
885 test_static_members
886 }
887
888 if [istarget "mips-idt-*"] then {
889 # Restart because IDT/SIM runs out of file descriptors.
890 gdb_exit
891 gdb_start
892 gdb_reinitialize_dir $srcdir/$subdir
893 gdb_load $binfile
894 }
895
896 if [ runto marker_reg1 ] then {
897
898 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
899
900 send_gdb "print v.method ()\n"
901 gdb_expect {
902 -re "= 82.*$gdb_prompt $" {
903 pass "calling method for small class"
904 }
905 -re "Address requested for identifier .v. which is in register.*$gdb_prompt $" {
906 setup_xfail "*-*-*" 2972
907 fail "calling method for small class"
908 }
909 -re ".*$gdb_prompt $" { fail "calling method for small class" }
910 timeout { fail "calling method for small class (timeout)" }
911 eof { fail "calling method for small class (eof)" }
912 }
913 }
914
915 }
916
917 do_tests
918
919 send_gdb "maint demangle inheritance1__Fv\n"
920 gdb_expect {
921 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
922 -re ".*$gdb_prompt $" { fail "demangle" }
923 timeout { fail "(timeout) demangle" }
924 }
This page took 0.078352 seconds and 5 git commands to generate.