1 # Copyright (C) 1992, 1994, 1995, 1997 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Fred Fish. (fnf@cygnus.com)
30 # Check to see if we have an executable to test. If not, then either we
31 # haven't tried to compile one, or the compilation failed for some reason.
32 # In either case, just notify the user and skip the tests in this file.
35 set srcfile ${testfile}.cc
36 set binfile ${objdir}/${subdir}/${testfile}
38 # Create and source the file that provides information about the compiler
39 # used to compile the test case.
41 if [get_compiler_info ${binfile} "c++"] {
45 # if we are on HPUX and we are not compiled with gcc, then skip these tests.
47 if [istarget hppa*-*-hpux*] {
53 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
54 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
58 # Test ptype of class objects.
61 proc test_ptype_class_objects {} {
66 # Note that struct members are public by default, so we don't print
67 # "public:" for the public members of structs.
68 # Accept it as an expected failure if gdb just fails to distinguish between
69 # class and struct, and everything else is OK.
71 send_gdb "ptype struct default_public_struct\n"
73 -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
74 pass "ptype struct default_public_struct"
76 -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
78 fail "ptype struct default_public_struct"
80 -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
81 timeout { fail "ptype struct default_public_struct (timeout)" ; return }
84 # Note that struct members are public by default, so we don't print
85 # "public:" for the public members of structs.
86 # Accept it as an expected failure if gdb just fails to distinguish between
87 # class and struct, and everything else is OK.
89 send_gdb "ptype struct explicit_public_struct\n"
91 -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
92 pass "ptype struct explicit_public_struct"
94 -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
96 fail "ptype struct explicit_public_struct"
98 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
99 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
102 # Accept it as an expected failure if gdb just fails to distinguish between
103 # class and struct, and everything else is OK.
105 setup_xfail_format "DWARF 1"
106 send_gdb "ptype struct protected_struct\n"
108 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
109 pass "ptype struct protected_struct (FIXME)"
111 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
113 fail "ptype struct protected_struct (FIXME)"
115 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
116 timeout { fail "ptype struct protected_struct (timeout)" ; return }
119 # Accept it as an expected failure if gdb just fails to distinguish between
120 # class and struct, and everything else is OK.
122 setup_xfail_format "DWARF 1"
123 send_gdb "ptype struct private_struct\n"
125 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
126 pass "ptype struct private_struct (FIXME)"
128 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
130 fail "ptype struct private_struct (FIXME)"
132 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
133 timeout { fail "ptype struct private_struct (timeout)" ; return }
136 # Accept it as an expected failure if gdb just fails to distinguish between
137 # class and struct, and everything else is OK.
139 setup_xfail_format "DWARF 1"
140 send_gdb "ptype struct mixed_protection_struct\n"
142 -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 $" {
143 pass "ptype struct mixed_protection_struct (FIXME)"
145 -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 $" {
147 fail "ptype struct mixed_protection_struct (FIXME)"
149 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
150 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
153 # Accept it as an expected failure if gdb just fails to distinguish between
154 # class and struct, and everything else is OK.
156 send_gdb "ptype class public_class\n"
158 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
159 pass "ptype class public_class (FIXME)"
161 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
163 fail "ptype class public_class (FIXME)"
165 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
166 timeout { fail "ptype class public_class (timeout)" ; return }
169 send_gdb "ptype class protected_class\n"
171 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
172 pass "ptype class protected_class"
174 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
176 fail "ptype class protected_class"
178 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
179 timeout { fail "ptype class protected_class (timeout)" ; return }
182 # Accept it as an expected failure if gdb just emits a superflous "private:"
183 # attribute, since classes default to private and for consistency with
184 # structs (where we don't print the "public:" attribute) we don't print
185 # the "private:" attribute.
187 setup_xfail_format "DWARF 1"
188 send_gdb "ptype class default_private_class\n"
190 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
191 pass "ptype class default_private_class (FIXME)"
193 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
195 fail "ptype class default_private_class (FIXME)"
197 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
198 timeout { fail "ptype class default_private_class (timeout)" ; return }
201 send_gdb "ptype class explicit_private_class\n"
203 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
204 pass "ptype class explicit_private_class"
206 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
208 fail "ptype class explicit_private_class"
210 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
211 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
214 send_gdb "ptype class mixed_protection_class\n"
216 -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 $" {
217 pass "ptype class mixed_protection_class"
219 -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 $" {
221 fail "ptype class mixed_protection_class"
223 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
224 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
227 # This class does not use any C++-specific features, so it's fine for
228 # it to print as "struct".
229 send_gdb "ptype class A\n"
231 -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 $" {
234 -re ".*$gdb_prompt $" {
238 fail "ptype class A (timeout)"
243 setup_xfail_format "DWARF 1"
244 send_gdb "ptype class B\n"
246 -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 $" {
249 -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 $" {
250 pass "ptype class B (obsolescent gcc or gdb)"
252 -re ".*$gdb_prompt $" {
256 fail "ptype class B (timeout)"
261 setup_xfail_format "DWARF 1"
262 send_gdb "ptype class C\n"
264 -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 $" {
267 -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 $" {
268 pass "ptype class C (obsolescent gcc or gdb)"
270 -re ".*$gdb_prompt $" {
274 fail "ptype class C (timeout)"
279 setup_xfail_format "DWARF 1"
280 send_gdb "ptype class D\n"
282 -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 $" {
285 -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 $" {
286 pass "ptype class D (obsolescent gcc or gdb)"
288 -re ".*$gdb_prompt $" {
292 fail "ptype class D (timeout)"
297 setup_xfail_format "DWARF 1"
298 send_gdb "ptype class E\n"
300 -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 $" {
303 -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 $" {
306 -re ".*$gdb_prompt $" {
310 fail "ptype class E (timeout)"
315 send_gdb "ptype class vA\n"
317 -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 $" {
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 setup_xfail_format "DWARF 1"
337 send_gdb "ptype class vB\n"
339 -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 $" {
341 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
343 -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 $" {
345 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
347 -re ".*$gdb_prompt $" {
348 fail "ptype class vB"
351 fail "ptype class vB (timeout)"
356 # Accept the form with embedded GNU style mangled virtual table constructs
357 # for now, but with a FIXME. At some future point, gdb should use a
358 # portable representation for the virtual table constructs.
360 setup_xfail_format "DWARF 1"
361 send_gdb "ptype class vC\n"
363 -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 $" {
365 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
367 -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 $" {
369 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
371 -re ".*$gdb_prompt $" {
372 fail "ptype class vC"
375 fail "ptype class vC (timeout)"
380 # Accept the form with embedded GNU style mangled virtual table constructs
381 # for now, but with a FIXME. At some future point, gdb should use a
382 # portable representation for the virtual table constructs.
384 setup_xfail_format "DWARF 1"
385 send_gdb "ptype class vD\n"
387 -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 $" {
389 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
391 -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 $" {
393 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
395 -re ".*$gdb_prompt $" {
396 fail "ptype class vD"
399 fail "ptype class vD (timeout)"
404 # Accept the form with embedded GNU style mangled virtual table constructs
405 # for now, but with a FIXME. At some future point, gdb should use a
406 # portable representation for the virtual table constructs.
408 setup_xfail_format "DWARF 1"
409 send_gdb "ptype class vE\n"
411 -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 $" {
413 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
415 -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 $" {
417 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
419 -re ".*$gdb_prompt $" {
420 fail "ptype class vE"
423 fail "ptype class vE (timeout)"
428 setup_xfail_format "DWARF 1"
429 send_gdb "ptype class Base1\n"
431 -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 $" {
432 pass "ptype class Base1"
434 -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 $" {
435 pass "ptype class Base1 (obsolescent gcc or gdb)"
437 -re ".*$gdb_prompt $" {
438 fail "ptype class Base1"
441 fail "ptype class Base1 (timeout)"
446 setup_xfail_format "DWARF 1"
447 send_gdb "ptype class Foo\n"
449 -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 $" {
450 pass "ptype class Foo"
452 -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 $" {
453 pass "ptype class Foo (obsolescent gcc or gdb)"
455 -re ".*$gdb_prompt $" {
456 fail "ptype class Foo"
459 fail "ptype class Foo (timeout)"
464 setup_xfail_format "DWARF 1"
465 send_gdb "ptype class Bar\n"
467 -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 $" {
468 pass "ptype class Bar"
470 -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 $" {
471 pass "ptype class Bar (obsolescent gcc or gdb)"
473 -re ".*$gdb_prompt $" {
474 fail "ptype class Bar"
477 fail "ptype class Bar (timeout)"
484 # Test simple access to class members.
487 proc test_non_inherited_member_access {} {
490 # Print non-inherited members of g_A.
492 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
494 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
496 # Print non-inherited members of g_B.
498 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
500 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
502 # Print non-inherited members of g_C.
504 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
506 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
508 # Print non-inherited members of g_D.
510 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
512 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
514 # Print non-inherited members of g_E.
516 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
518 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
522 # Try access to non-members that are members of another class.
523 # Should give errors.
526 proc test_wrong_class_members {} {
529 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
531 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
533 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
535 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
537 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
539 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
543 # Try access to non-members that are not members of any class.
544 # Should give errors.
547 proc test_nonexistant_members {} {
550 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
552 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
554 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
556 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
560 # Pointers to class members
563 proc test_pointers_to_class_members {} {
568 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
570 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
572 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
574 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
576 -re ".* = true$nl$gdb_prompt $" {
577 pass "print (int)&Bar::y == 2*sizeof(int)"
579 -re "There is no field named y.*$gdb_prompt $" {
581 fail "print (int)&Bar::y == 2*sizeof(int)"
583 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
584 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
590 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
591 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
595 setup_xfail_format "DWARF 1"
596 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
600 # Test static members.
603 proc test_static_members {} {
608 send_gdb "print Foo::st\n"
610 -re ".* = 100$nl$gdb_prompt $" {
613 -re "There is no field named st.*$gdb_prompt $" {
617 -re ".*$gdb_prompt $" { fail "print Foo::st" }
618 timeout { fail "print Foo::st (timeout)" ; return }
621 send_gdb "set foo.st = 200\n"
623 -re ".*$gdb_prompt $" {}
626 send_gdb "print bar.st\n"
628 -re ".* = 200$nl$gdb_prompt $" {
631 -re "There is no member( or method|) named st.*$gdb_prompt $" {
635 -re ".*$gdb_prompt $" { fail "print bar.st" }
636 timeout { fail "print bar.st (timeout)" ; return }
639 send_gdb "print &foo.st\n"
641 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
644 -re "There is no member( or method|) named st.*$gdb_prompt $" {
648 -re ".*$gdb_prompt $" { fail "print &foo.st" }
649 timeout { fail "print &foo.st (timeout)" ; return }
653 send_gdb "print &Bar::st\n"
655 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
656 pass "print &Bar::st"
659 -re "There is no field named st.*$gdb_prompt $" {
661 fail "print &Bar::st"
663 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
664 timeout { fail "print &Bar::st (timeout)" ; return }
667 if $got_bar_st then {
668 gdb_test "print *\$" ".* = 200" "print *\$"
671 gdb_test "set print static-members off" ""
672 gdb_test "print csi" \
674 "print csi without static members"
675 gdb_test "print cnsi" \
677 "print cnsi without static members"
679 gdb_test "set print static-members on" ""
680 setup_xfail_format "DWARF 1"
681 gdb_test "print csi" \
682 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
683 "print csi with static members"
684 setup_xfail_format "DWARF 1"
685 gdb_test "print cnsi" \
686 "{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>}" \
687 "print cnsi with static members"
702 # Start with a fresh gdb.
706 gdb_reinitialize_dir $srcdir/$subdir
709 send_gdb "set language c++\n"
710 gdb_expect -re "$gdb_prompt $"
711 send_gdb "set width 0\n"
712 gdb_expect -re "$gdb_prompt $"
714 # Get the debug format for the compiled test case.
716 if [ runto_main ] then {
720 test_ptype_class_objects
722 if [ runto 'inheritance2(void)' ] then {
723 test_non_inherited_member_access
724 test_wrong_class_members
725 test_nonexistant_members
728 if [istarget "mips-idt-*"] then {
729 # Restart because IDT/SIM runs out of file descriptors.
732 gdb_reinitialize_dir $srcdir/$subdir
736 if [ runto_main ] then {
737 test_pointers_to_class_members
741 if [istarget "mips-idt-*"] then {
742 # Restart because IDT/SIM runs out of file descriptors.
745 gdb_reinitialize_dir $srcdir/$subdir
749 if [ runto marker_reg1 ] then {
751 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
753 send_gdb "print v.method ()\n"
755 -re "= 82.*$gdb_prompt $" {
756 pass "calling method for small class"
758 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
759 setup_xfail "*-*-*" 2972
760 fail "calling method for small class"
762 -re ".*$gdb_prompt $" { fail "calling method for small class" }
763 timeout { fail "calling method for small class (timeout)" }
764 eof { fail "calling method for small class (eof)" }
773 # Some additional tests for enums inside classes
776 # set a breakpoint and go there
777 send_gdb "break 503\n"
779 -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 503" }
780 -re "$gdb_prompt $" { fail "set break 503" }
781 timeout { fail "(timeout) set break 503" }
783 send_gdb "continue\n"
785 -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at.*misc\\.cc:503\r\n503.*\r\n$gdb_prompt $" { pass "continue" }
786 -re "$gdb_prompt $" { fail "continue" }
787 timeout { fail "(timeout) continue" }
791 send_gdb "print obj_with_enum\n"
793 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
794 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
795 timeout { fail "(timeout) print obj_with_enum (1)" }
800 -re "$gdb_prompt $" { pass "next" }
801 timeout { fail "(timeout) next" }
804 # print the object again
805 send_gdb "print obj_with_enum\n"
807 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
808 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
809 timeout { fail "(timeout) print obj_with_enum (2)" }
812 # print out the enum member
813 send_gdb "print obj_with_enum.priv_enum\n"
815 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
816 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
817 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
820 # ptype on the enum member
821 # The second success case is a little dubious, but it's not clear what
822 # ought to be required of a ptype on a private enum... -sts 19990324
823 send_gdb "ptype obj_with_enum.priv_enum\n"
825 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
826 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
827 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
828 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
831 # ptype on the object
832 send_gdb "ptype obj_with_enum\n"
834 -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" }
835 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
836 timeout { fail "(timeout) ptype obj_with_enum" }
839 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
841 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
842 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
843 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
847 send_gdb "maint demangle inheritance1__Fv\n"
849 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
850 -re ".*$gdb_prompt $" { fail "demangle" }
851 timeout { fail "(timeout) demangle" }