1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
2 # 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 setup_xfail_format "DWARF 1"
96 send_gdb "ptype struct protected_struct\n"
98 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
99 pass "ptype struct protected_struct (FIXME)"
101 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
103 fail "ptype struct protected_struct (FIXME)"
105 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
106 timeout { fail "ptype struct protected_struct (timeout)" ; return }
109 # Accept it as an expected failure if gdb just fails to distinguish between
110 # class and struct, and everything else is OK.
112 setup_xfail_format "DWARF 1"
113 send_gdb "ptype struct private_struct\n"
115 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
116 pass "ptype struct private_struct (FIXME)"
118 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
120 fail "ptype struct private_struct (FIXME)"
122 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
123 timeout { fail "ptype struct private_struct (timeout)" ; return }
126 # Accept it as an expected failure if gdb just fails to distinguish between
127 # class and struct, and everything else is OK.
129 setup_xfail_format "DWARF 1"
130 send_gdb "ptype struct mixed_protection_struct\n"
132 -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 $" {
133 pass "ptype struct mixed_protection_struct (FIXME)"
135 -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 $" {
136 pass "ptype struct mixed_protection_struct (extra public)"
138 -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 $" {
140 fail "ptype struct mixed_protection_struct (FIXME)"
142 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
143 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
146 # Accept it as an expected failure if gdb just fails to distinguish between
147 # class and struct, and everything else is OK.
149 send_gdb "ptype class public_class\n"
151 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
152 pass "ptype class public_class (FIXME)"
154 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
156 fail "ptype class public_class (FIXME)"
158 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
159 timeout { fail "ptype class public_class (timeout)" ; return }
162 send_gdb "ptype class protected_class\n"
164 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
165 pass "ptype class protected_class"
167 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
169 fail "ptype class protected_class"
171 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
172 timeout { fail "ptype class protected_class (timeout)" ; return }
175 # Accept it as an expected failure if gdb just emits a superflous "private:"
176 # attribute, since classes default to private and for consistency with
177 # structs (where we don't print the "public:" attribute) we don't print
178 # the "private:" attribute.
180 setup_xfail_format "DWARF 1"
181 send_gdb "ptype class default_private_class\n"
183 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
184 pass "ptype class default_private_class (FIXME)"
186 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
188 fail "ptype class default_private_class (FIXME)"
190 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
191 timeout { fail "ptype class default_private_class (timeout)" ; return }
194 send_gdb "ptype class explicit_private_class\n"
196 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
197 pass "ptype class explicit_private_class"
199 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
200 pass "ptype class explicit_private_class (OK for HP aCC)"
202 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
204 fail "ptype class explicit_private_class"
206 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
207 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
210 send_gdb "ptype class mixed_protection_class\n"
212 -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 $" {
213 pass "ptype class mixed_protection_class"
215 -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 $" {
217 fail "ptype class mixed_protection_class"
219 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
220 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
223 # This class does not use any C++-specific features, so it's fine for
224 # it to print as "struct".
225 send_gdb "ptype class A\n"
227 -re "type = (class|struct) A \{(${ws}public:|)${ws}int a;${ws}int x;((${ws}A & operator=\\(A const ?&\\);)|(${ws}A\\(A const ?&\\);)|(${ws}A\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
230 -re ".*$gdb_prompt $" {
234 fail "ptype class A (timeout)"
239 setup_xfail_format "DWARF 1"
240 send_gdb "ptype class B\n"
242 -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 $" {
245 -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 $" {
246 pass "ptype class B (obsolescent gcc or gdb)"
248 -re ".*$gdb_prompt $" {
252 fail "ptype class B (timeout)"
257 setup_xfail_format "DWARF 1"
258 send_gdb "ptype class C\n"
260 -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 $" {
263 -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 $" {
264 pass "ptype class C (obsolescent gcc or gdb)"
266 -re ".*$gdb_prompt $" {
270 fail "ptype class C (timeout)"
275 setup_xfail_format "DWARF 1"
276 send_gdb "ptype class D\n"
278 -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 $" {
281 -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 $" {
282 pass "ptype class D (obsolescent gcc or gdb)"
284 -re ".*$gdb_prompt $" {
288 fail "ptype class D (timeout)"
293 setup_xfail_format "DWARF 1"
294 send_gdb "ptype class E\n"
296 -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;${ws}E & operator=\\(E const &\\);${ws}E\\(E const &\\);${ws}E\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
299 -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;((${ws}E & operator=\\(E const &\\);)|(${ws}E\\(E const &\\);)|(${ws}E\\((void|)\\);))*${ws}\}$nl$gdb_prompt $" {
302 -re ".*$gdb_prompt $" {
306 fail "ptype class E (timeout)"
311 send_gdb "ptype class vA\n"
313 -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 $" {
314 pass "ptype class vA"
316 -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 $" {
317 pass "ptype class vA (obsolescent gcc or gdb)"
319 -re ".*$gdb_prompt $" {
320 fail "ptype class vA"
323 fail "ptype class vA (timeout)"
328 # Accept the form with embedded GNU style mangled virtual table constructs
329 # for now, but with a FIXME. At some future point, gdb should use a
330 # portable representation for the virtual table constructs.
332 # The format of a g++ virtual base pointer.
333 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
335 setup_xfail_format "DWARF 1"
336 send_gdb "ptype class vB\n"
338 -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 $" {
340 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
342 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
343 pass "ptype class vB (aCC)"
345 -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 $" {
347 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
349 -re ".*$gdb_prompt $" {
350 fail "ptype class vB"
353 fail "ptype class vB (timeout)"
358 # Accept the form with embedded GNU style mangled virtual table constructs
359 # for now, but with a FIXME. At some future point, gdb should use a
360 # portable representation for the virtual table constructs.
362 setup_xfail_format "DWARF 1"
363 send_gdb "ptype class vC\n"
365 -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 $" {
367 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
369 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
370 pass "ptype class vC (aCC)"
372 -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 $" {
374 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
376 -re ".*$gdb_prompt $" {
377 fail "ptype class vC"
380 fail "ptype class vC (timeout)"
385 # Accept the form with embedded GNU style mangled virtual table constructs
386 # for now, but with a FIXME. At some future point, gdb should use a
387 # portable representation for the virtual table constructs.
389 setup_xfail_format "DWARF 1"
390 send_gdb "ptype class vD\n"
392 -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 $" {
394 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
396 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
397 pass "ptype class vD (aCC)"
399 -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 $" {
401 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
403 -re ".*$gdb_prompt $" {
404 fail "ptype class vD"
407 fail "ptype class vD (timeout)"
412 # Accept the form with embedded GNU style mangled virtual table constructs
413 # for now, but with a FIXME. At some future point, gdb should use a
414 # portable representation for the virtual table constructs.
416 setup_xfail_format "DWARF 1"
417 send_gdb "ptype class vE\n"
419 -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 $" {
421 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
423 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
424 pass "ptype class vE (aCC)"
426 -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 $" {
428 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
430 -re ".*$gdb_prompt $" {
431 fail "ptype class vE"
434 fail "ptype class vE (timeout)"
439 setup_xfail_format "DWARF 1"
440 send_gdb "ptype class Base1\n"
442 -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 $" {
443 pass "ptype class Base1"
445 -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 $" {
446 pass "ptype class Base1 (obsolescent gcc or gdb)"
448 -re ".*$gdb_prompt $" {
449 fail "ptype class Base1"
452 fail "ptype class Base1 (timeout)"
457 setup_xfail_format "DWARF 1"
458 send_gdb "ptype class Foo\n"
460 -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 $" {
461 pass "ptype class Foo(aCC)"
463 -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}operator int\\((void|)\\);${ws}int times\\(int\\);${ws}\}$nl$gdb_prompt $" {
464 pass "ptype class Foo"
466 -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 $" {
467 pass "ptype class Foo (obsolescent gcc or gdb)"
469 -re ".*$gdb_prompt $" {
470 fail "ptype class Foo"
473 fail "ptype class Foo (timeout)"
478 setup_xfail_format "DWARF 1"
479 send_gdb "ptype class Bar\n"
481 -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 $" {
482 pass "ptype class Bar"
484 -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 $" {
485 pass "ptype class Bar (obsolescent gcc or gdb)"
487 -re ".*$gdb_prompt $" {
488 fail "ptype class Bar"
491 fail "ptype class Bar (timeout)"
498 # Test simple access to class members.
501 proc test_non_inherited_member_access {} {
504 # Print non-inherited members of g_A.
506 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
508 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
510 # Print non-inherited members of g_B.
512 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
514 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
516 # Print non-inherited members of g_C.
518 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
520 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
522 # Print non-inherited members of g_D.
524 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
526 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
528 # Print non-inherited members of g_E.
530 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
532 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
536 # Try access to non-members that are members of another class.
537 # Should give errors.
540 proc test_wrong_class_members {} {
543 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
545 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
547 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
549 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
551 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
553 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
557 # Try access to non-members that are not members of any class.
558 # Should give errors.
561 proc test_nonexistent_members {} {
564 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
566 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
568 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
570 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
574 # Call a method that expects a base class parameter with base, inherited,
575 # and unrelated class arguments.
578 proc test_method_param_class {} {
579 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
580 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
581 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
582 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
583 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a"
584 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
585 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
586 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x"
587 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
588 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
589 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
590 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
592 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
593 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m"
594 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
598 # Examine a class with an enum field.
603 global hp_aCC_compiler
606 send_gdb "print obj_with_enum\n"
608 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
609 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
610 timeout { fail "(timeout) print obj_with_enum (1)" }
615 -re "$gdb_prompt $" { pass "next" }
616 timeout { fail "(timeout) next" }
619 # print the object again
620 send_gdb "print obj_with_enum\n"
622 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
623 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
624 timeout { fail "(timeout) print obj_with_enum (2)" }
627 # print out the enum member
628 send_gdb "print obj_with_enum.priv_enum\n"
630 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
631 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
632 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
635 # ptype on the enum member
636 # The third success case is a little dubious, but it's not clear what
637 # ought to be required of a ptype on a private enum... -sts 19990324
638 send_gdb "ptype obj_with_enum.priv_enum\n"
640 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
641 -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
642 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
643 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
644 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
647 # ptype on the object
648 # g++ is putting out the wrong debug info. This works with aCC
649 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
650 send_gdb "ptype obj_with_enum\n"
652 -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" }
653 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
654 timeout { fail "(timeout) ptype obj_with_enum" }
657 # g++ is putting out the wrong debug info. This works with aCC
658 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
659 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
661 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
662 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
663 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
668 # Pointers to class members
671 proc test_pointers_to_class_members {} {
676 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
678 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
680 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
682 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
684 -re ".* = true$nl$gdb_prompt $" {
685 pass "print (int)&Bar::y == 2*sizeof(int)"
687 -re "There is no field named y.*$gdb_prompt $" {
689 fail "print (int)&Bar::y == 2*sizeof(int)"
691 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
692 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
698 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
699 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
703 setup_xfail_format "DWARF 1"
704 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
708 # Test static members.
711 proc test_static_members {} {
716 send_gdb "print Foo::st\n"
718 -re ".* = 100$nl$gdb_prompt $" {
721 -re "There is no field named st.*$gdb_prompt $" {
725 -re ".*$gdb_prompt $" { fail "print Foo::st" }
726 timeout { fail "print Foo::st (timeout)" ; return }
729 send_gdb "set foo.st = 200\n"
731 -re ".*$gdb_prompt $" {}
734 send_gdb "print bar.st\n"
736 -re ".* = 200$nl$gdb_prompt $" {
739 -re "There is no member( or method|) named st.*$gdb_prompt $" {
743 -re ".*$gdb_prompt $" { fail "print bar.st" }
744 timeout { fail "print bar.st (timeout)" ; return }
747 send_gdb "print &foo.st\n"
749 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
752 -re "There is no member( or method|) named st.*$gdb_prompt $" {
756 -re ".*$gdb_prompt $" { fail "print &foo.st" }
757 timeout { fail "print &foo.st (timeout)" ; return }
761 send_gdb "print &Bar::st\n"
763 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
764 pass "print &Bar::st"
767 -re "There is no field named st.*$gdb_prompt $" {
769 fail "print &Bar::st"
771 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
772 timeout { fail "print &Bar::st (timeout)" ; return }
775 if $got_bar_st then {
776 gdb_test "print *\$" ".* = 200" "print *\$"
779 gdb_test "set print static-members off" ""
780 gdb_test "print csi" \
782 "print csi without static members"
783 gdb_test "print cnsi" \
785 "print cnsi without static members"
787 gdb_test "set print static-members on" ""
788 setup_xfail_format "DWARF 1"
789 gdb_test "print csi" \
790 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
791 "print csi with static members"
792 setup_xfail_format "DWARF 1"
793 gdb_test "print cnsi" \
794 "{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>}" \
795 "print cnsi with static members"
810 # Start with a fresh gdb.
814 gdb_reinitialize_dir $srcdir/$subdir
817 send_gdb "set language c++\n"
818 gdb_expect -re "$gdb_prompt $"
819 send_gdb "set width 0\n"
820 gdb_expect -re "$gdb_prompt $"
822 # Get the debug format for the compiled test case.
824 if [ runto_main ] then {
828 test_ptype_class_objects
830 if [ runto 'inheritance2' ] then {
831 test_non_inherited_member_access
832 test_wrong_class_members
833 test_nonexistent_members
834 test_method_param_class
837 gdb_breakpoint enums2
838 if [ gdb_continue enums2 ]==0 then {
839 gdb_test "finish" "" ""
843 if [istarget "mips-idt-*"] then {
844 # Restart because IDT/SIM runs out of file descriptors.
847 gdb_reinitialize_dir $srcdir/$subdir
851 if [ runto_main ] then {
852 test_pointers_to_class_members
856 if [istarget "mips-idt-*"] then {
857 # Restart because IDT/SIM runs out of file descriptors.
860 gdb_reinitialize_dir $srcdir/$subdir
864 if [ runto marker_reg1 ] then {
866 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
868 send_gdb "print v.method ()\n"
870 -re "= 82.*$gdb_prompt $" {
871 pass "calling method for small class"
873 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
874 setup_xfail "*-*-*" 2972
875 fail "calling method for small class"
877 -re ".*$gdb_prompt $" { fail "calling method for small class" }
878 timeout { fail "calling method for small class (timeout)" }
879 eof { fail "calling method for small class (eof)" }
887 send_gdb "maint demangle inheritance1__Fv\n"
889 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
890 -re ".*$gdb_prompt $" { fail "demangle" }
891 timeout { fail "(timeout) demangle" }