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++"] {
46 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
47 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 # Test ptype of class objects.
54 proc test_ptype_class_objects {} {
59 # Note that struct members are public by default, so we don't print
60 # "public:" for the public members of structs.
61 # Accept it as an expected failure if gdb just fails to distinguish between
62 # class and struct, and everything else is OK.
64 send_gdb "ptype struct default_public_struct\n"
66 -re "type = struct default_public_struct \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
67 pass "ptype struct default_public_struct"
69 -re "type = class default_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
71 fail "ptype struct default_public_struct"
73 -re ".*$gdb_prompt $" { fail "ptype struct default_public_struct" }
74 timeout { fail "ptype struct default_public_struct (timeout)" ; return }
77 # Note that struct members are public by default, so we don't print
78 # "public:" for the public members of structs.
79 # Accept it as an expected failure if gdb just fails to distinguish between
80 # class and struct, and everything else is OK.
82 send_gdb "ptype struct explicit_public_struct\n"
84 -re "type = struct explicit_public_struct \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
85 pass "ptype struct explicit_public_struct"
87 -re "type = class explicit_public_struct \{$nl.*int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
89 fail "ptype struct explicit_public_struct"
91 -re ".*$gdb_prompt $" { fail "ptype struct explicit_public_struct" }
92 timeout { fail "ptype struct explicit_public_struct (timeout)" ; return }
95 # Accept it as an expected failure if gdb just fails to distinguish between
96 # class and struct, and everything else is OK.
98 setup_xfail_format "DWARF 1"
99 send_gdb "ptype struct protected_struct\n"
101 -re "type = struct protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
102 pass "ptype struct protected_struct (FIXME)"
104 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
106 fail "ptype struct protected_struct (FIXME)"
108 -re ".*$gdb_prompt $" { fail "ptype struct protected_struct" }
109 timeout { fail "ptype struct protected_struct (timeout)" ; return }
112 # Accept it as an expected failure if gdb just fails to distinguish between
113 # class and struct, and everything else is OK.
115 setup_xfail_format "DWARF 1"
116 send_gdb "ptype struct private_struct\n"
118 -re "type = struct private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
119 pass "ptype struct private_struct (FIXME)"
121 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
123 fail "ptype struct private_struct (FIXME)"
125 -re ".*$gdb_prompt $" { fail "ptype struct private_struct" }
126 timeout { fail "ptype struct private_struct (timeout)" ; return }
129 # Accept it as an expected failure if gdb just fails to distinguish between
130 # class and struct, and everything else is OK.
132 setup_xfail_format "DWARF 1"
133 send_gdb "ptype struct mixed_protection_struct\n"
135 -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 $" {
136 pass "ptype struct mixed_protection_struct (FIXME)"
138 -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 $" {
139 pass "ptype struct mixed_protection_struct (extra public)"
141 -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 $" {
143 fail "ptype struct mixed_protection_struct (FIXME)"
145 -re ".*$gdb_prompt $" { fail "ptype struct mixed_protection_struct" }
146 timeout { fail "ptype struct mixed_protection_struct (timeout)" ; return }
149 # Accept it as an expected failure if gdb just fails to distinguish between
150 # class and struct, and everything else is OK.
152 send_gdb "ptype class public_class\n"
154 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
155 pass "ptype class public_class (FIXME)"
157 -re "type = struct public_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
159 fail "ptype class public_class (FIXME)"
161 -re ".*$gdb_prompt $" { fail "ptype class public_class" }
162 timeout { fail "ptype class public_class (timeout)" ; return }
165 send_gdb "ptype class protected_class\n"
167 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
168 pass "ptype class protected_class"
170 -re "type = struct protected_class \{${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
172 fail "ptype class protected_class"
174 -re ".*$gdb_prompt $" { fail "ptype class protected_class" }
175 timeout { fail "ptype class protected_class (timeout)" ; return }
178 # Accept it as an expected failure if gdb just emits a superflous "private:"
179 # attribute, since classes default to private and for consistency with
180 # structs (where we don't print the "public:" attribute) we don't print
181 # the "private:" attribute.
183 setup_xfail_format "DWARF 1"
184 send_gdb "ptype class default_private_class\n"
186 -re "type = class default_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
187 pass "ptype class default_private_class (FIXME)"
189 -re "type = class default_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
191 fail "ptype class default_private_class (FIXME)"
193 -re ".*$gdb_prompt $" { fail "ptype class default_private_class" }
194 timeout { fail "ptype class default_private_class (timeout)" ; return }
197 send_gdb "ptype class explicit_private_class\n"
199 -re "type = class explicit_private_class \{${ws}private:${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
200 pass "ptype class explicit_private_class"
202 -re "type = class explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
203 pass "ptype class explicit_private_class (OK for HP aCC)"
205 -re "type = struct explicit_private_class \{${ws}int a;${ws}int b;$nl.*\}$nl$gdb_prompt $" {
207 fail "ptype class explicit_private_class"
209 -re ".*$gdb_prompt $" { fail "ptype class explicit_private_class" }
210 timeout { fail "ptype class explicit_private_class (timeout)" ; return }
213 send_gdb "ptype class mixed_protection_class\n"
215 -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 $" {
216 pass "ptype class mixed_protection_class"
218 -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 $" {
220 fail "ptype class mixed_protection_class"
222 -re ".*$gdb_prompt $" { fail "ptype class mixed_protection_class" }
223 timeout { fail "ptype class mixed_protection_class (timeout)" ; return }
226 # This class does not use any C++-specific features, so it's fine for
227 # it to print as "struct".
228 send_gdb "ptype class A\n"
230 -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 $" {
233 -re ".*$gdb_prompt $" {
237 fail "ptype class A (timeout)"
242 setup_xfail_format "DWARF 1"
243 send_gdb "ptype class B\n"
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 $" {
248 -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 pass "ptype class B (obsolescent gcc or gdb)"
251 -re ".*$gdb_prompt $" {
255 fail "ptype class B (timeout)"
260 setup_xfail_format "DWARF 1"
261 send_gdb "ptype class C\n"
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 $" {
266 -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 pass "ptype class C (obsolescent gcc or gdb)"
269 -re ".*$gdb_prompt $" {
273 fail "ptype class C (timeout)"
278 setup_xfail_format "DWARF 1"
279 send_gdb "ptype class D\n"
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 $" {
284 -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 pass "ptype class D (obsolescent gcc or gdb)"
287 -re ".*$gdb_prompt $" {
291 fail "ptype class D (timeout)"
296 setup_xfail_format "DWARF 1"
297 send_gdb "ptype class E\n"
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 "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 $" {
305 -re ".*$gdb_prompt $" {
309 fail "ptype class E (timeout)"
314 send_gdb "ptype class vA\n"
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"
319 -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 $" {
320 pass "ptype class vA (obsolescent gcc or gdb)"
322 -re ".*$gdb_prompt $" {
323 fail "ptype class vA"
326 fail "ptype class vA (timeout)"
331 # Accept the form with embedded GNU style mangled virtual table constructs
332 # for now, but with a FIXME. At some future point, gdb should use a
333 # portable representation for the virtual table constructs.
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 \\*_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 $" {
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 \\*_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 $" {
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 \\*_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 $" {
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 \\*_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 $" {
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}int 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_nonexistant_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 # Pointers to class members
577 proc test_pointers_to_class_members {} {
582 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
584 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
586 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
588 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
590 -re ".* = true$nl$gdb_prompt $" {
591 pass "print (int)&Bar::y == 2*sizeof(int)"
593 -re "There is no field named y.*$gdb_prompt $" {
595 fail "print (int)&Bar::y == 2*sizeof(int)"
597 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
598 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
604 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;$nl$gdb_prompt $" {}
605 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
609 setup_xfail_format "DWARF 1"
610 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
614 # Test static members.
617 proc test_static_members {} {
622 send_gdb "print Foo::st\n"
624 -re ".* = 100$nl$gdb_prompt $" {
627 -re "There is no field named st.*$gdb_prompt $" {
631 -re ".*$gdb_prompt $" { fail "print Foo::st" }
632 timeout { fail "print Foo::st (timeout)" ; return }
635 send_gdb "set foo.st = 200\n"
637 -re ".*$gdb_prompt $" {}
640 send_gdb "print bar.st\n"
642 -re ".* = 200$nl$gdb_prompt $" {
645 -re "There is no member( or method|) named st.*$gdb_prompt $" {
649 -re ".*$gdb_prompt $" { fail "print bar.st" }
650 timeout { fail "print bar.st (timeout)" ; return }
653 send_gdb "print &foo.st\n"
655 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
658 -re "There is no member( or method|) named st.*$gdb_prompt $" {
662 -re ".*$gdb_prompt $" { fail "print &foo.st" }
663 timeout { fail "print &foo.st (timeout)" ; return }
667 send_gdb "print &Bar::st\n"
669 -re ".* = .int \[*)\]+ $hex$nl$gdb_prompt $" {
670 pass "print &Bar::st"
673 -re "There is no field named st.*$gdb_prompt $" {
675 fail "print &Bar::st"
677 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
678 timeout { fail "print &Bar::st (timeout)" ; return }
681 if $got_bar_st then {
682 gdb_test "print *\$" ".* = 200" "print *\$"
685 gdb_test "set print static-members off" ""
686 gdb_test "print csi" \
688 "print csi without static members"
689 gdb_test "print cnsi" \
691 "print cnsi without static members"
693 gdb_test "set print static-members on" ""
694 setup_xfail_format "DWARF 1"
695 gdb_test "print csi" \
696 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
697 "print csi with static members"
698 setup_xfail_format "DWARF 1"
699 gdb_test "print cnsi" \
700 "{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>}" \
701 "print cnsi with static members"
716 # Start with a fresh gdb.
720 gdb_reinitialize_dir $srcdir/$subdir
723 send_gdb "set language c++\n"
724 gdb_expect -re "$gdb_prompt $"
725 send_gdb "set width 0\n"
726 gdb_expect -re "$gdb_prompt $"
728 # Get the debug format for the compiled test case.
730 if [ runto_main ] then {
734 test_ptype_class_objects
736 if [ runto 'inheritance2(void)' ] then {
737 test_non_inherited_member_access
738 test_wrong_class_members
739 test_nonexistant_members
742 if [istarget "mips-idt-*"] then {
743 # Restart because IDT/SIM runs out of file descriptors.
746 gdb_reinitialize_dir $srcdir/$subdir
750 if [ runto_main ] then {
751 test_pointers_to_class_members
755 if [istarget "mips-idt-*"] then {
756 # Restart because IDT/SIM runs out of file descriptors.
759 gdb_reinitialize_dir $srcdir/$subdir
763 if [ runto marker_reg1 ] then {
765 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
767 send_gdb "print v.method ()\n"
769 -re "= 82.*$gdb_prompt $" {
770 pass "calling method for small class"
772 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
773 setup_xfail "*-*-*" 2972
774 fail "calling method for small class"
776 -re ".*$gdb_prompt $" { fail "calling method for small class" }
777 timeout { fail "calling method for small class (timeout)" }
778 eof { fail "calling method for small class (eof)" }
787 # Some additional tests for enums inside classes
790 # set a breakpoint and go there
791 send_gdb "break 516\n"
793 -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 516" }
794 -re "$gdb_prompt $" { fail "set break 516" }
795 timeout { fail "(timeout) set break 516" }
797 send_gdb "continue\n"
799 -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at.*misc\\.cc:516\r\n516.*\r\n$gdb_prompt $" { pass "continue" }
800 -re "$gdb_prompt $" { fail "continue" }
801 timeout { fail "(timeout) continue" }
805 send_gdb "print obj_with_enum\n"
807 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
808 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
809 timeout { fail "(timeout) print obj_with_enum (1)" }
814 -re "$gdb_prompt $" { pass "next" }
815 timeout { fail "(timeout) next" }
818 # print the object again
819 send_gdb "print obj_with_enum\n"
821 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
822 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
823 timeout { fail "(timeout) print obj_with_enum (2)" }
826 # print out the enum member
827 send_gdb "print obj_with_enum.priv_enum\n"
829 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
830 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
831 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
834 # ptype on the enum member
835 # The second success case is a little dubious, but it's not clear what
836 # ought to be required of a ptype on a private enum... -sts 19990324
837 send_gdb "ptype obj_with_enum.priv_enum\n"
839 -re "type = enum ClassWithEnum::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" }