1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003 Free Software Foundation, Inc.
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.
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.
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.
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
21 # This file was written by Fred Fish. (fnf@cygnus.com)
30 if { [skip_cplus_tests] } { continue }
33 set srcfile ${testfile}.cc
34 set binfile ${objdir}/${subdir}/${testfile}
36 # Create and source the file that provides information about the compiler
37 # used to compile the test case.
39 if [get_compiler_info ${binfile} "c++"] {
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."
48 # Test ptype of class objects.
51 proc test_ptype_class_objects {} {
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.
61 send_gdb "ptype struct default_public_struct\n"
63 -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
64 pass "ptype struct default_public_struct"
66 -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
67 pass "ptype struct default_public_struct"
69 -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
70 timeout { fail "ptype struct default_public_struct (timeout)" ; return }
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.
78 send_gdb "ptype struct explicit_public_struct\n"
80 -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
81 pass "ptype struct explicit_public_struct"
83 -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
84 pass "ptype struct explicit_public_struct"
86 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
87 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
90 # Accept it if gdb just fails to distinguish between
91 # class and struct, and everything else is OK.
93 send_gdb "ptype struct protected_struct\n"
95 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
96 pass "ptype struct protected_struct"
98 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
99 pass "ptype struct protected_struct"
101 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
102 timeout { fail "ptype struct protected_struct (timeout)" ; return }
105 # Accept it if gdb just fails to distinguish between
106 # class and struct, and everything else is OK.
108 send_gdb "ptype struct private_struct\n"
110 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
111 pass "ptype struct private_struct"
113 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
114 pass "ptype struct private_struct"
116 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
117 timeout { fail "ptype struct private_struct (timeout)" ; return }
120 # Accept it if gdb just fails to distinguish between
121 # class and struct, and everything else is OK.
123 send_gdb "ptype struct mixed_protection_struct\n"
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"
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)"
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"
134 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
135 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
138 # Accept it if gdb just fails to distinguish between
139 # class and struct, and everything else is OK.
141 send_gdb "ptype class public_class\n"
143 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
144 pass "ptype class public_class"
146 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
147 pass "ptype class public_class"
149 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
150 timeout { fail "ptype class public_class (timeout)" ; return }
153 send_gdb "ptype class protected_class\n"
155 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
156 pass "ptype class protected_class"
158 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
159 fail "ptype class protected_class"
161 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
162 timeout { fail "ptype class protected_class (timeout)" ; return }
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.
170 send_gdb "ptype class default_private_class\n"
172 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
173 pass "ptype class default_private_class"
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"
178 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
179 timeout { fail "ptype class default_private_class (timeout)" ; return }
182 send_gdb "ptype class explicit_private_class\n"
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"
187 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
188 pass "ptype class explicit_private_class"
190 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
191 fail "ptype class explicit_private_class"
193 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
194 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
197 send_gdb "ptype class mixed_protection_class\n"
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"
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"
205 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
206 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
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"
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 $" {
216 -re ".*$gdb_prompt $" {
220 fail "ptype class A (timeout)"
225 send_gdb "ptype class B\n"
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 $" {
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)"
233 -re ".*$gdb_prompt $" {
237 fail "ptype class B (timeout)"
242 send_gdb "ptype class C\n"
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 $" {
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)"
250 -re ".*$gdb_prompt $" {
254 fail "ptype class C (timeout)"
259 send_gdb "ptype class D\n"
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 $" {
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)"
267 -re ".*$gdb_prompt $" {
271 fail "ptype class D (timeout)"
276 send_gdb "ptype class E\n"
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 $" {
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 $" {
284 -re ".*$gdb_prompt $" {
288 fail "ptype class E (timeout)"
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"
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"
300 -re "type = (class|struct) Static \{(${ws}public:|)${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
301 pass "ptype class Static"
303 -re ".*$gdb_prompt $" {
304 fail "ptype class Static"
307 fail "ptype class Static (timeout)"
312 send_gdb "ptype class vA\n"
314 -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
315 pass "ptype class vA"
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"
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)"
323 -re ".*$gdb_prompt $" {
324 fail "ptype class vA"
327 fail "ptype class vA (timeout)"
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.
336 # The format of a g++ virtual base pointer.
337 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
339 send_gdb "ptype class vB\n"
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"
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 $" {
346 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
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"
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 $" {
353 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
355 -re ".*$gdb_prompt $" {
356 fail "ptype class vB"
359 fail "ptype class vB (timeout)"
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.
368 send_gdb "ptype class vC\n"
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"
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 $" {
375 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
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"
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 $" {
382 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
384 -re ".*$gdb_prompt $" {
385 fail "ptype class vC"
388 fail "ptype class vC (timeout)"
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.
397 send_gdb "ptype class vD\n"
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"
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 $" {
404 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
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"
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 $" {
411 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
413 -re ".*$gdb_prompt $" {
414 fail "ptype class vD"
417 fail "ptype class vD (timeout)"
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.
426 send_gdb "ptype class vE\n"
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"
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 $" {
433 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
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"
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 $" {
440 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
442 -re ".*$gdb_prompt $" {
443 fail "ptype class vE"
446 fail "ptype class vE (timeout)"
451 send_gdb "ptype class Base1\n"
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"
456 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
457 pass "ptype class Base1"
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)"
462 -re ".*$gdb_prompt $" {
463 fail "ptype class Base1"
466 fail "ptype class Base1 (timeout)"
471 send_gdb "ptype class Foo\n"
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"
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"
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)"
482 -re ".*$gdb_prompt $" {
483 fail "ptype class Foo"
486 fail "ptype class Foo (timeout)"
491 send_gdb "ptype class Bar\n"
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"
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)"
499 -re ".*$gdb_prompt $" {
500 fail "ptype class Bar"
503 fail "ptype class Bar (timeout)"
510 # Test simple access to class members.
513 proc test_non_inherited_member_access {} {
516 # Print non-inherited members of g_A.
518 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
520 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
522 # Print non-inherited members of g_B.
524 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
526 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
528 # Print non-inherited members of g_C.
530 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
532 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
534 # Print non-inherited members of g_D.
536 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
538 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
540 # Print non-inherited members of g_E.
542 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
544 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
548 # Try access to non-members that are members of another class.
549 # Should give errors.
552 proc test_wrong_class_members {} {
555 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
557 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
559 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
561 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
563 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
565 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
569 # Try access to non-members that are not members of any class.
570 # Should give errors.
573 proc test_nonexistent_members {} {
576 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
578 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
580 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
582 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
586 # Call a method that expects a base class parameter with base, inherited,
587 # and unrelated class arguments.
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 (¶m)->a"
596 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
597 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
598 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->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"
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 ¶m"
606 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
610 # Examine a class with an enum field.
615 global hp_aCC_compiler
618 send_gdb "print obj_with_enum\n"
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)" }
627 -re "$gdb_prompt $" { pass "next" }
628 timeout { fail "(timeout) next" }
631 # print the object again
632 send_gdb "print obj_with_enum\n"
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)" }
639 # print out the enum member
640 send_gdb "print obj_with_enum.priv_enum\n"
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" }
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"
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" }
659 # ptype on the object
660 send_gdb "ptype obj_with_enum\n"
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 $"
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"
675 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
676 timeout { fail "(timeout) ptype obj_with_enum" }
679 # We'll do this test twice, because of a parser bug: see
682 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
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 $" {
687 kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42"
689 -re "A syntax error in expression, near `42'.\r\n$gdb_prompt $" {
691 kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42"
693 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
694 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
697 send_gdb "print ('ClassWithEnum::PrivEnum') 42\n"
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" }
708 # Pointers to class members
711 proc test_pointers_to_class_members {} {
716 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
718 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
720 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
722 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
724 -re ".* = true$nl$gdb_prompt $" {
725 pass "print (int)&Bar::y == 2*sizeof(int)"
727 -re "There is no field named y.*$gdb_prompt $" {
729 fail "print (int)&Bar::y == 2*sizeof(int)"
731 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
732 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
738 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
739 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
743 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
747 # Test static members.
750 proc test_static_members {} {
755 send_gdb "print Foo::st\n"
757 -re ".* = 100$nl$gdb_prompt $" {
760 -re "There is no field named st.*$gdb_prompt $" {
764 -re ".*$gdb_prompt $" { fail "print Foo::st" }
765 timeout { fail "print Foo::st (timeout)" ; return }
768 send_gdb "set foo.st = 200\n"
770 -re ".*$gdb_prompt $" {}
773 send_gdb "print bar.st\n"
775 -re ".* = 200$nl$gdb_prompt $" {
778 -re "There is no member( or method|) named st.*$gdb_prompt $" {
782 -re ".*$gdb_prompt $" { fail "print bar.st" }
783 timeout { fail "print bar.st (timeout)" ; return }
786 send_gdb "print &foo.st\n"
788 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
791 -re "There is no member( or method|) named st.*$gdb_prompt $" {
795 -re ".*$gdb_prompt $" { fail "print &foo.st" }
796 timeout { fail "print &foo.st (timeout)" ; return }
800 send_gdb "print &Bar::st\n"
802 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
803 pass "print &Bar::st"
806 -re "There is no field named st.*$gdb_prompt $" {
808 fail "print &Bar::st"
810 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
811 timeout { fail "print &Bar::st (timeout)" ; return }
814 if $got_bar_st then {
815 gdb_test "print *\$" ".* = 200" "print *\$"
818 gdb_test "set print static-members off" ""
819 gdb_test "print csi" \
821 "print csi without static members"
822 gdb_test "print cnsi" \
824 "print cnsi without static members"
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"
847 # Start with a fresh gdb.
851 gdb_reinitialize_dir $srcdir/$subdir
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 $"
860 test_ptype_class_objects
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
869 gdb_breakpoint enums2
870 if [ gdb_continue "enums2(\\(\\)|)" ]==0 then {
871 gdb_test "finish" "" ""
875 if [istarget "mips-idt-*"] then {
876 # Restart because IDT/SIM runs out of file descriptors.
879 gdb_reinitialize_dir $srcdir/$subdir
883 if [ runto_main ] then {
884 test_pointers_to_class_members
888 if [istarget "mips-idt-*"] then {
889 # Restart because IDT/SIM runs out of file descriptors.
892 gdb_reinitialize_dir $srcdir/$subdir
896 if [ runto marker_reg1 ] then {
898 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
900 send_gdb "print v.method ()\n"
902 -re "= 82.*$gdb_prompt $" {
903 pass "calling method for small class"
905 -re "Address requested for identifier .v. which is in register.*$gdb_prompt $" {
906 setup_xfail "*-*-*" 2972
907 fail "calling method for small class"
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)" }
919 send_gdb "maint demangle inheritance1__Fv\n"
921 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
922 -re ".*$gdb_prompt $" { fail "demangle" }
923 timeout { fail "(timeout) demangle" }