1 # Copyright (C) 1992, 1994, 1995, 1997, 1999 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)
29 if { [skip_cplus_tests] } { continue }
32 set srcfile ${testfile}.cc
33 set binfile ${objdir}/${subdir}/${testfile}
35 # Create and source the file that provides information about the compiler
36 # used to compile the test case.
38 if [get_compiler_info ${binfile} "c++"] {
42 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
43 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
47 # Test ptype of class objects.
50 proc test_ptype_class_objects {} {
55 # Note that struct members are public by default, so we don't print
56 # "public:" for the public members of structs.
57 # Accept it as an expected failure if gdb just fails to distinguish between
58 # class and struct, and everything else is OK.
60 send_gdb "ptype struct default_public_struct\n"
62 -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
63 pass "ptype struct default_public_struct"
65 -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
67 fail "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 as an expected failure 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 $" {
85 fail "ptype struct explicit_public_struct"
87 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
88 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
91 # Accept it as an expected failure if gdb just fails to distinguish between
92 # class and struct, and everything else is OK.
94 setup_xfail_format "DWARF 1"
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 setup_xfail_format "DWARF 1"
112 send_gdb "ptype struct private_struct\n"
114 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
115 pass "ptype struct private_struct (FIXME)"
117 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
119 fail "ptype struct private_struct (FIXME)"
121 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
122 timeout { fail "ptype struct private_struct (timeout)" ; return }
125 # Accept it as an expected failure if gdb just fails to distinguish between
126 # class and struct, and everything else is OK.
128 setup_xfail_format "DWARF 1"
129 send_gdb "ptype struct mixed_protection_struct\n"
131 -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 $" {
132 pass "ptype struct mixed_protection_struct (FIXME)"
134 -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 $" {
135 pass "ptype struct mixed_protection_struct (extra public)"
137 -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 $" {
139 fail "ptype struct mixed_protection_struct (FIXME)"
141 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
142 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
145 # Accept it as an expected failure if gdb just fails to distinguish between
146 # class and struct, and everything else is OK.
148 send_gdb "ptype class public_class\n"
150 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
151 pass "ptype class public_class (FIXME)"
153 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
155 fail "ptype class public_class (FIXME)"
157 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
158 timeout { fail "ptype class public_class (timeout)" ; return }
161 send_gdb "ptype class protected_class\n"
163 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
164 pass "ptype class protected_class"
166 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
168 fail "ptype class protected_class"
170 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
171 timeout { fail "ptype class protected_class (timeout)" ; return }
174 # Accept it as an expected failure if gdb just emits a superflous "private:"
175 # attribute, since classes default to private and for consistency with
176 # structs (where we don't print the "public:" attribute) we don't print
177 # the "private:" attribute.
179 setup_xfail_format "DWARF 1"
180 send_gdb "ptype class default_private_class\n"
182 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
183 pass "ptype class default_private_class (FIXME)"
185 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
187 fail "ptype class default_private_class (FIXME)"
189 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
190 timeout { fail "ptype class default_private_class (timeout)" ; return }
193 send_gdb "ptype class explicit_private_class\n"
195 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
196 pass "ptype class explicit_private_class"
198 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
199 pass "ptype class explicit_private_class (OK for HP aCC)"
201 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
203 fail "ptype class explicit_private_class"
205 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
206 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
209 send_gdb "ptype class mixed_protection_class\n"
211 -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 $" {
212 pass "ptype class mixed_protection_class"
214 -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 $" {
216 fail "ptype class mixed_protection_class"
218 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
219 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
222 # This class does not use any C++-specific features, so it's fine for
223 # it to print as "struct".
224 send_gdb "ptype class A\n"
226 -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 $" {
229 -re ".*$gdb_prompt $" {
233 fail "ptype class A (timeout)"
238 setup_xfail_format "DWARF 1"
239 send_gdb "ptype class B\n"
241 -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 $" {
244 -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 pass "ptype class B (obsolescent gcc or gdb)"
247 -re ".*$gdb_prompt $" {
251 fail "ptype class B (timeout)"
256 setup_xfail_format "DWARF 1"
257 send_gdb "ptype class C\n"
259 -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 $" {
262 -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 pass "ptype class C (obsolescent gcc or gdb)"
265 -re ".*$gdb_prompt $" {
269 fail "ptype class C (timeout)"
274 setup_xfail_format "DWARF 1"
275 send_gdb "ptype class D\n"
277 -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 $" {
280 -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 pass "ptype class D (obsolescent gcc or gdb)"
283 -re ".*$gdb_prompt $" {
287 fail "ptype class D (timeout)"
292 setup_xfail_format "DWARF 1"
293 send_gdb "ptype class E\n"
295 -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 $" {
298 -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 $" {
301 -re ".*$gdb_prompt $" {
305 fail "ptype class E (timeout)"
310 send_gdb "ptype class vA\n"
312 -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 $" {
313 pass "ptype class vA"
315 -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 $" {
316 pass "ptype class vA (obsolescent gcc or gdb)"
318 -re ".*$gdb_prompt $" {
319 fail "ptype class vA"
322 fail "ptype class vA (timeout)"
327 # Accept the form with embedded GNU style mangled virtual table constructs
328 # for now, but with a FIXME. At some future point, gdb should use a
329 # portable representation for the virtual table constructs.
331 # The format of a g++ virtual base pointer.
332 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
334 setup_xfail_format "DWARF 1"
335 send_gdb "ptype class vB\n"
337 -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 $" {
339 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
341 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
342 pass "ptype class vB (aCC)"
344 -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 $" {
346 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
348 -re ".*$gdb_prompt $" {
349 fail "ptype class vB"
352 fail "ptype class vB (timeout)"
357 # Accept the form with embedded GNU style mangled virtual table constructs
358 # for now, but with a FIXME. At some future point, gdb should use a
359 # portable representation for the virtual table constructs.
361 setup_xfail_format "DWARF 1"
362 send_gdb "ptype class vC\n"
364 -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 $" {
366 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
368 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
369 pass "ptype class vC (aCC)"
371 -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 $" {
373 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
375 -re ".*$gdb_prompt $" {
376 fail "ptype class vC"
379 fail "ptype class vC (timeout)"
384 # Accept the form with embedded GNU style mangled virtual table constructs
385 # for now, but with a FIXME. At some future point, gdb should use a
386 # portable representation for the virtual table constructs.
388 setup_xfail_format "DWARF 1"
389 send_gdb "ptype class vD\n"
391 -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 $" {
393 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
395 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
396 pass "ptype class vD (aCC)"
398 -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 $" {
400 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
402 -re ".*$gdb_prompt $" {
403 fail "ptype class vD"
406 fail "ptype class vD (timeout)"
411 # Accept the form with embedded GNU style mangled virtual table constructs
412 # for now, but with a FIXME. At some future point, gdb should use a
413 # portable representation for the virtual table constructs.
415 setup_xfail_format "DWARF 1"
416 send_gdb "ptype class vE\n"
418 -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 $" {
420 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
422 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}\}$nl$gdb_prompt $" {
423 pass "ptype class vE (aCC)"
425 -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 $" {
427 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
429 -re ".*$gdb_prompt $" {
430 fail "ptype class vE"
433 fail "ptype class vE (timeout)"
438 setup_xfail_format "DWARF 1"
439 send_gdb "ptype class Base1\n"
441 -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 $" {
442 pass "ptype class Base1"
444 -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 $" {
445 pass "ptype class Base1 (obsolescent gcc or gdb)"
447 -re ".*$gdb_prompt $" {
448 fail "ptype class Base1"
451 fail "ptype class Base1 (timeout)"
456 setup_xfail_format "DWARF 1"
457 send_gdb "ptype class Foo\n"
459 -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 $" {
460 pass "ptype class Foo(aCC)"
462 -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 $" {
463 pass "ptype class Foo"
465 -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 $" {
466 pass "ptype class Foo (obsolescent gcc or gdb)"
468 -re ".*$gdb_prompt $" {
469 fail "ptype class Foo"
472 fail "ptype class Foo (timeout)"
477 setup_xfail_format "DWARF 1"
478 send_gdb "ptype class Bar\n"
480 -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 $" {
481 pass "ptype class Bar"
483 -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 $" {
484 pass "ptype class Bar (obsolescent gcc or gdb)"
486 -re ".*$gdb_prompt $" {
487 fail "ptype class Bar"
490 fail "ptype class Bar (timeout)"
497 # Test simple access to class members.
500 proc test_non_inherited_member_access {} {
503 # Print non-inherited members of g_A.
505 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
507 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
509 # Print non-inherited members of g_B.
511 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
513 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
515 # Print non-inherited members of g_C.
517 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
519 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
521 # Print non-inherited members of g_D.
523 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
525 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
527 # Print non-inherited members of g_E.
529 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
531 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
535 # Try access to non-members that are members of another class.
536 # Should give errors.
539 proc test_wrong_class_members {} {
542 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
544 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
546 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
548 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
550 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
552 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
556 # Try access to non-members that are not members of any class.
557 # Should give errors.
560 proc test_nonexistant_members {} {
563 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
565 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
567 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
569 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
573 # Pointers to class members
576 proc test_pointers_to_class_members {} {
581 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
583 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
585 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
587 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
589 -re ".* = true$nl$gdb_prompt $" {
590 pass "print (int)&Bar::y == 2*sizeof(int)"
592 -re "There is no field named y.*$gdb_prompt $" {
594 fail "print (int)&Bar::y == 2*sizeof(int)"
596 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
597 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
603 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
604 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
608 setup_xfail_format "DWARF 1"
609 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
613 # Test static members.
616 proc test_static_members {} {
621 send_gdb "print Foo::st\n"
623 -re ".* = 100$nl$gdb_prompt $" {
626 -re "There is no field named st.*$gdb_prompt $" {
630 -re ".*$gdb_prompt $" { fail "print Foo::st" }
631 timeout { fail "print Foo::st (timeout)" ; return }
634 send_gdb "set foo.st = 200\n"
636 -re ".*$gdb_prompt $" {}
639 send_gdb "print bar.st\n"
641 -re ".* = 200$nl$gdb_prompt $" {
644 -re "There is no member( or method|) named st.*$gdb_prompt $" {
648 -re ".*$gdb_prompt $" { fail "print bar.st" }
649 timeout { fail "print bar.st (timeout)" ; return }
652 send_gdb "print &foo.st\n"
654 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
657 -re "There is no member( or method|) named st.*$gdb_prompt $" {
661 -re ".*$gdb_prompt $" { fail "print &foo.st" }
662 timeout { fail "print &foo.st (timeout)" ; return }
666 send_gdb "print &Bar::st\n"
668 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
669 pass "print &Bar::st"
672 -re "There is no field named st.*$gdb_prompt $" {
674 fail "print &Bar::st"
676 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
677 timeout { fail "print &Bar::st (timeout)" ; return }
680 if $got_bar_st then {
681 gdb_test "print *\$" ".* = 200" "print *\$"
684 gdb_test "set print static-members off" ""
685 gdb_test "print csi" \
687 "print csi without static members"
688 gdb_test "print cnsi" \
690 "print cnsi without static members"
692 gdb_test "set print static-members on" ""
693 setup_xfail_format "DWARF 1"
694 gdb_test "print csi" \
695 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
696 "print csi with static members"
697 setup_xfail_format "DWARF 1"
698 gdb_test "print cnsi" \
699 "{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>}" \
700 "print cnsi with static members"
715 # Start with a fresh gdb.
719 gdb_reinitialize_dir $srcdir/$subdir
722 send_gdb "set language c++\n"
723 gdb_expect -re "$gdb_prompt $"
724 send_gdb "set width 0\n"
725 gdb_expect -re "$gdb_prompt $"
727 # Get the debug format for the compiled test case.
729 if [ runto_main ] then {
733 test_ptype_class_objects
735 if [ runto 'inheritance2(void)' ] then {
736 test_non_inherited_member_access
737 test_wrong_class_members
738 test_nonexistant_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_main ] then {
750 test_pointers_to_class_members
754 if [istarget "mips-idt-*"] then {
755 # Restart because IDT/SIM runs out of file descriptors.
758 gdb_reinitialize_dir $srcdir/$subdir
762 if [ runto marker_reg1 ] then {
764 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
766 send_gdb "print v.method ()\n"
768 -re "= 82.*$gdb_prompt $" {
769 pass "calling method for small class"
771 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
772 setup_xfail "*-*-*" 2972
773 fail "calling method for small class"
775 -re ".*$gdb_prompt $" { fail "calling method for small class" }
776 timeout { fail "calling method for small class (timeout)" }
777 eof { fail "calling method for small class (eof)" }
786 # Some additional tests for enums inside classes
789 # set a breakpoint and go there
790 send_gdb "break 516\n"
792 -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 516" }
793 -re "$gdb_prompt $" { fail "set break 516" }
794 timeout { fail "(timeout) set break 516" }
796 send_gdb "continue\n"
798 -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at.*misc\\.cc:516\r\n516.*\r\n$gdb_prompt $" { pass "continue" }
799 -re "$gdb_prompt $" { fail "continue" }
800 timeout { fail "(timeout) continue" }
804 send_gdb "print obj_with_enum\n"
806 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
807 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
808 timeout { fail "(timeout) print obj_with_enum (1)" }
813 -re "$gdb_prompt $" { pass "next" }
814 timeout { fail "(timeout) next" }
817 # print the object again
818 send_gdb "print obj_with_enum\n"
820 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
821 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
822 timeout { fail "(timeout) print obj_with_enum (2)" }
825 # print out the enum member
826 send_gdb "print obj_with_enum.priv_enum\n"
828 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
829 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
830 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
833 # ptype on the enum member
834 # The third success case is a little dubious, but it's not clear what
835 # ought to be required of a ptype on a private enum... -sts 19990324
836 send_gdb "ptype obj_with_enum.priv_enum\n"
838 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
839 -re "type = enum PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
840 -re "type = enum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
841 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
842 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
845 # ptype on the object
846 # g++ is putting out the wrong debug info. This works with aCC
847 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
848 send_gdb "ptype obj_with_enum\n"
850 -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" }
851 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
852 timeout { fail "(timeout) ptype obj_with_enum" }
855 # g++ is putting out the wrong debug info. This works with aCC
856 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
857 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
859 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
860 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
861 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
865 send_gdb "maint demangle inheritance1__Fv\n"
867 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
868 -re ".*$gdb_prompt $" { fail "demangle" }
869 timeout { fail "(timeout) demangle" }