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 as an expected failure 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 $" {
68 fail "ptype struct default_public_struct"
70 -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
71 timeout { fail "ptype struct default_public_struct (timeout)" ; return }
74 # Note that struct members are public by default, so we don't print
75 # "public:" for the public members of structs.
76 # Accept it as an expected failure if gdb just fails to distinguish between
77 # class and struct, and everything else is OK.
79 send_gdb "ptype struct explicit_public_struct\n"
81 -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
82 pass "ptype struct explicit_public_struct"
84 -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
86 fail "ptype struct explicit_public_struct"
88 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
89 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
92 # Accept it as an expected failure if gdb just fails to distinguish between
93 # class and struct, and everything else is OK.
95 send_gdb "ptype struct protected_struct\n"
97 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
98 pass "ptype struct protected_struct (FIXME)"
100 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
102 fail "ptype struct protected_struct (FIXME)"
104 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
105 timeout { fail "ptype struct protected_struct (timeout)" ; return }
108 # Accept it as an expected failure if gdb just fails to distinguish between
109 # class and struct, and everything else is OK.
111 send_gdb "ptype struct private_struct\n"
113 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
114 pass "ptype struct private_struct (FIXME)"
116 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
118 fail "ptype struct private_struct (FIXME)"
120 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
121 timeout { fail "ptype struct private_struct (timeout)" ; return }
124 # Accept it as an expected failure if gdb just fails to distinguish between
125 # class and struct, and everything else is OK.
127 send_gdb "ptype struct mixed_protection_struct\n"
129 -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 $" {
130 pass "ptype struct mixed_protection_struct (FIXME)"
132 -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 $" {
133 pass "ptype struct mixed_protection_struct (extra public)"
135 -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 $" {
137 fail "ptype struct mixed_protection_struct (FIXME)"
139 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
140 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
143 # Accept it as an expected failure if gdb just fails to distinguish between
144 # class and struct, and everything else is OK.
146 send_gdb "ptype class public_class\n"
148 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
149 pass "ptype class public_class (FIXME)"
151 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
153 fail "ptype class public_class (FIXME)"
155 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
156 timeout { fail "ptype class public_class (timeout)" ; return }
159 send_gdb "ptype class protected_class\n"
161 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
162 pass "ptype class protected_class"
164 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
166 fail "ptype class protected_class"
168 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
169 timeout { fail "ptype class protected_class (timeout)" ; return }
172 # Accept it as an expected failure if gdb just emits a superflous "private:"
173 # attribute, since classes default to private and for consistency with
174 # structs (where we don't print the "public:" attribute) we don't print
175 # the "private:" attribute.
177 send_gdb "ptype class default_private_class\n"
179 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
180 pass "ptype class default_private_class (FIXME)"
182 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
184 fail "ptype class default_private_class (FIXME)"
186 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
187 timeout { fail "ptype class default_private_class (timeout)" ; return }
190 send_gdb "ptype class explicit_private_class\n"
192 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
193 pass "ptype class explicit_private_class"
195 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
196 pass "ptype class explicit_private_class (OK for HP aCC)"
198 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
200 fail "ptype class explicit_private_class"
202 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
203 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
206 send_gdb "ptype class mixed_protection_class\n"
208 -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 $" {
209 pass "ptype class mixed_protection_class"
211 -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 $" {
213 fail "ptype class mixed_protection_class"
215 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
216 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
219 # This class does not use any C++-specific features, so it's fine for
220 # it to print as "struct".
221 send_gdb "ptype class A\n"
223 -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 $" {
226 -re ".*$gdb_prompt $" {
230 fail "ptype class A (timeout)"
235 send_gdb "ptype class B\n"
237 -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 $" {
240 -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 $" {
241 pass "ptype class B (obsolescent gcc or gdb)"
243 -re ".*$gdb_prompt $" {
247 fail "ptype class B (timeout)"
252 send_gdb "ptype class C\n"
254 -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 $" {
257 -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 $" {
258 pass "ptype class C (obsolescent gcc or gdb)"
260 -re ".*$gdb_prompt $" {
264 fail "ptype class C (timeout)"
269 send_gdb "ptype class D\n"
271 -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 $" {
274 -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 $" {
275 pass "ptype class D (obsolescent gcc or gdb)"
277 -re ".*$gdb_prompt $" {
281 fail "ptype class D (timeout)"
286 send_gdb "ptype class E\n"
288 -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 $" {
291 -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 $" {
294 -re ".*$gdb_prompt $" {
298 fail "ptype class E (timeout)"
303 # With g++ 2.x and stabs debug info, we misinterpret static methods
304 # whose name matches their argument mangling.
305 send_gdb "ptype class Static\n"
307 -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 $" {
308 pass "ptype class Static"
310 -re "type = (class|struct) Static \{(${ws}public:|)${ws}static void ii\\(int, int\\);${ws}\}$nl$gdb_prompt $" {
311 pass "ptype class Static"
313 -re ".*$gdb_prompt $" {
314 fail "ptype class Static"
317 fail "ptype class Static (timeout)"
322 send_gdb "ptype class vA\n"
324 -re "type = (class|struct) vA \{(${ws}public:|)${ws}int va;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
325 pass "ptype class vA"
327 -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 $" {
328 pass "ptype class vA"
330 -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 $" {
331 pass "ptype class vA (obsolescent gcc or gdb)"
333 -re ".*$gdb_prompt $" {
334 fail "ptype class vA"
337 fail "ptype class vA (timeout)"
342 # Accept the form with embedded GNU style mangled virtual table constructs
343 # for now, but with a FIXME. At some future point, gdb should use a
344 # portable representation for the virtual table constructs.
346 # The format of a g++ virtual base pointer.
347 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
349 send_gdb "ptype class vB\n"
351 -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 $" {
352 pass "ptype class vB"
354 -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 $" {
356 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
358 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
359 pass "ptype class vB"
361 -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 $" {
363 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
365 -re ".*$gdb_prompt $" {
366 fail "ptype class vB"
369 fail "ptype class vB (timeout)"
374 # Accept the form with embedded GNU style mangled virtual table constructs
375 # for now, but with a FIXME. At some future point, gdb should use a
376 # portable representation for the virtual table constructs.
378 send_gdb "ptype class vC\n"
380 -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 $" {
381 pass "ptype class vC"
383 -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 $" {
385 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
387 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
388 pass "ptype class vC"
390 -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 $" {
392 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
394 -re ".*$gdb_prompt $" {
395 fail "ptype class vC"
398 fail "ptype class vC (timeout)"
403 # Accept the form with embedded GNU style mangled virtual table constructs
404 # for now, but with a FIXME. At some future point, gdb should use a
405 # portable representation for the virtual table constructs.
407 send_gdb "ptype class vD\n"
409 -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 $" {
410 pass "ptype class vD"
412 -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 $" {
414 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
416 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
417 pass "ptype class vD"
419 -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 $" {
421 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
423 -re ".*$gdb_prompt $" {
424 fail "ptype class vD"
427 fail "ptype class vD (timeout)"
432 # Accept the form with embedded GNU style mangled virtual table constructs
433 # for now, but with a FIXME. At some future point, gdb should use a
434 # portable representation for the virtual table constructs.
436 send_gdb "ptype class vE\n"
438 -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 $" {
439 pass "ptype class vE"
441 -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 $" {
443 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
445 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
446 pass "ptype class vE"
448 -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 $" {
450 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
452 -re ".*$gdb_prompt $" {
453 fail "ptype class vE"
456 fail "ptype class vE (timeout)"
461 send_gdb "ptype class Base1\n"
463 -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 $" {
464 pass "ptype class Base1"
466 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}\}$nl$gdb_prompt $" {
467 pass "ptype class Base1"
469 -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 $" {
470 pass "ptype class Base1 (obsolescent gcc or gdb)"
472 -re ".*$gdb_prompt $" {
473 fail "ptype class Base1"
476 fail "ptype class Base1 (timeout)"
481 send_gdb "ptype class Foo\n"
483 -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 $" {
484 pass "ptype class Foo"
486 -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 $" {
487 pass "ptype class Foo"
489 -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 $" {
490 pass "ptype class Foo (obsolescent gcc or gdb)"
492 -re ".*$gdb_prompt $" {
493 fail "ptype class Foo"
496 fail "ptype class Foo (timeout)"
501 send_gdb "ptype class Bar\n"
503 -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 $" {
504 pass "ptype class Bar"
506 -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 $" {
507 pass "ptype class Bar (obsolescent gcc or gdb)"
509 -re ".*$gdb_prompt $" {
510 fail "ptype class Bar"
513 fail "ptype class Bar (timeout)"
520 # Test simple access to class members.
523 proc test_non_inherited_member_access {} {
526 # Print non-inherited members of g_A.
528 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
530 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
532 # Print non-inherited members of g_B.
534 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
536 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
538 # Print non-inherited members of g_C.
540 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
542 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
544 # Print non-inherited members of g_D.
546 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
548 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
550 # Print non-inherited members of g_E.
552 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
554 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
558 # Try access to non-members that are members of another class.
559 # Should give errors.
562 proc test_wrong_class_members {} {
565 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
567 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
569 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
571 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
573 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
575 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
579 # Try access to non-members that are not members of any class.
580 # Should give errors.
583 proc test_nonexistent_members {} {
586 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
588 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
590 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
592 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
596 # Call a method that expects a base class parameter with base, inherited,
597 # and unrelated class arguments.
600 proc test_method_param_class {} {
601 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
602 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
603 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
604 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
605 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a"
606 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
607 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
608 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x"
609 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
610 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
611 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
612 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
614 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
615 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m"
616 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
620 # Examine a class with an enum field.
625 global hp_aCC_compiler
628 send_gdb "print obj_with_enum\n"
630 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
631 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
632 timeout { fail "(timeout) print obj_with_enum (1)" }
637 -re "$gdb_prompt $" { pass "next" }
638 timeout { fail "(timeout) next" }
641 # print the object again
642 send_gdb "print obj_with_enum\n"
644 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
645 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
646 timeout { fail "(timeout) print obj_with_enum (2)" }
649 # print out the enum member
650 send_gdb "print obj_with_enum.priv_enum\n"
652 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
653 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
654 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
657 # ptype on the enum member
658 # The third success case is a little dubious, but it's not clear what
659 # ought to be required of a ptype on a private enum... -sts 19990324
660 send_gdb "ptype obj_with_enum.priv_enum\n"
662 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
663 -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
664 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
665 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
666 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
669 # ptype on the object
670 # g++ is putting out the wrong debug info. This works with aCC
671 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
672 send_gdb "ptype obj_with_enum\n"
674 -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" }
675 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
676 timeout { fail "(timeout) ptype obj_with_enum" }
679 # g++ is putting out the wrong debug info. This works with aCC
680 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
681 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
683 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
684 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
685 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
690 # Pointers to class members
693 proc test_pointers_to_class_members {} {
698 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
700 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
702 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
704 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
706 -re ".* = true$nl$gdb_prompt $" {
707 pass "print (int)&Bar::y == 2*sizeof(int)"
709 -re "There is no field named y.*$gdb_prompt $" {
711 fail "print (int)&Bar::y == 2*sizeof(int)"
713 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
714 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
720 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
721 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
725 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
729 # Test static members.
732 proc test_static_members {} {
737 send_gdb "print Foo::st\n"
739 -re ".* = 100$nl$gdb_prompt $" {
742 -re "There is no field named st.*$gdb_prompt $" {
746 -re ".*$gdb_prompt $" { fail "print Foo::st" }
747 timeout { fail "print Foo::st (timeout)" ; return }
750 send_gdb "set foo.st = 200\n"
752 -re ".*$gdb_prompt $" {}
755 send_gdb "print bar.st\n"
757 -re ".* = 200$nl$gdb_prompt $" {
760 -re "There is no member( or method|) named st.*$gdb_prompt $" {
764 -re ".*$gdb_prompt $" { fail "print bar.st" }
765 timeout { fail "print bar.st (timeout)" ; return }
768 send_gdb "print &foo.st\n"
770 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
773 -re "There is no member( or method|) named st.*$gdb_prompt $" {
777 -re ".*$gdb_prompt $" { fail "print &foo.st" }
778 timeout { fail "print &foo.st (timeout)" ; return }
782 send_gdb "print &Bar::st\n"
784 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
785 pass "print &Bar::st"
788 -re "There is no field named st.*$gdb_prompt $" {
790 fail "print &Bar::st"
792 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
793 timeout { fail "print &Bar::st (timeout)" ; return }
796 if $got_bar_st then {
797 gdb_test "print *\$" ".* = 200" "print *\$"
800 gdb_test "set print static-members off" ""
801 gdb_test "print csi" \
803 "print csi without static members"
804 gdb_test "print cnsi" \
806 "print cnsi without static members"
808 gdb_test "set print static-members on" ""
809 gdb_test "print csi" \
810 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
811 "print csi with static members"
812 gdb_test "print cnsi" \
813 "{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>}" \
814 "print cnsi with static members"
829 # Start with a fresh gdb.
833 gdb_reinitialize_dir $srcdir/$subdir
836 send_gdb "set language c++\n"
837 gdb_expect -re "$gdb_prompt $"
838 send_gdb "set width 0\n"
839 gdb_expect -re "$gdb_prompt $"
842 test_ptype_class_objects
844 if [ runto 'inheritance2' ] then {
845 test_non_inherited_member_access
846 test_wrong_class_members
847 test_nonexistent_members
848 test_method_param_class
851 gdb_breakpoint enums2
852 if [ gdb_continue "enums2(\\(\\)|)" ]==0 then {
853 gdb_test "finish" "" ""
857 if [istarget "mips-idt-*"] then {
858 # Restart because IDT/SIM runs out of file descriptors.
861 gdb_reinitialize_dir $srcdir/$subdir
865 if [ runto_main ] then {
866 test_pointers_to_class_members
870 if [istarget "mips-idt-*"] then {
871 # Restart because IDT/SIM runs out of file descriptors.
874 gdb_reinitialize_dir $srcdir/$subdir
878 if [ runto marker_reg1 ] then {
880 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
882 send_gdb "print v.method ()\n"
884 -re "= 82.*$gdb_prompt $" {
885 pass "calling method for small class"
887 -re "Address requested for identifier .v. which is in register.*$gdb_prompt $" {
888 setup_xfail "*-*-*" 2972
889 fail "calling method for small class"
891 -re ".*$gdb_prompt $" { fail "calling method for small class" }
892 timeout { fail "calling method for small class (timeout)" }
893 eof { fail "calling method for small class (eof)" }
901 send_gdb "maint demangle inheritance1__Fv\n"
903 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
904 -re ".*$gdb_prompt $" { fail "demangle" }
905 timeout { fail "(timeout) demangle" }