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)
29 # Check to see if we have an executable to test. If not, then either we
30 # haven't tried to compile one, or the compilation failed for some reason.
31 # In either case, just notify the user and skip the tests in this file.
33 set testfile "misc-hp"
34 set srcfile ${testfile}.cc
35 set binfile ${objdir}/${subdir}/${testfile}
37 if [get_compiler_info ${binfile} "c++"] {
42 if {[skip_hp_tests $gcc_compiled]} then { continue }
44 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
45 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
49 # Test ptype of class objects.
52 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;\r\n\}\r\n$gdb_prompt $" {
64 pass "ptype struct default_public_struct"
66 -re "type = class default_public_struct \{\r\n.*int a;${ws}int b;\r\n.*\}\r\n$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;\r\n.*\}\r\n$gdb_prompt $" {
82 pass "ptype struct explicit_public_struct"
84 -re "type = class explicit_public_struct \{\r\n.*int a;${ws}int b;\r\n.*\}\r\n$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;\r\n\}\r\n$gdb_prompt $" {
99 pass "ptype struct protected_struct (FIXME)"
101 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;\r\n.*\}\r\n$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;\r\n\}\r\n$gdb_prompt $" {
116 pass "ptype struct private_struct (FIXME)"
118 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;\r\n.*\}\r\n$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;\[\r\n\]+\}\[\r\n\]+$gdb_prompt $" {
133 pass "ptype struct mixed_protection_struct (FIXME)"
135 -re "type = struct mixed_protection_struct \{\r\n\[ \]*public:\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n\[ \]*private:\r\n\[ \]*int c;\r\n\[ \]*int d;\r\n\[ \]*protected:\r\n\[ \]*int e;\r\n\[ \]*int f;\r\n\[ \]*public:\r\n\[ \]*int g;\r\n\[ \]*private:\r\n\[ \]*int h;\r\n\[ \]*protected:\r\n\[ \]*int i;\r\n.*\}\r\n$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;\r\n.*\}\r\n$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;\r\n.*\}\r\n$gdb_prompt $" {
152 pass "ptype class public_class (FIXME)"
154 -re "type = struct public_class \{${ws}int a;${ws}int b;\r\n\}\r\n$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;\r\n.*\}\r\n$gdb_prompt $" {
165 pass "ptype class protected_class"
167 -re "type = struct protected_class \{${ws}int a;${ws}int b;\r\n\}\r\n$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;\r\n.*\}\r\n$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;\r\n.*\}\r\n$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;\r\n.*\}\r\n$gdb_prompt $" {
197 pass "ptype class explicit_private_class"
199 -re "type = class explicit_private_class \{\r\n\[ \]*int a;\r\n\[ \]*int b;\r\n.*\}\r\n$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;\r\n.*\}\r\n$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;\r\n.*\}\r\n$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;\r\n.*\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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}\}\r\n$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 setup_xfail_format "DWARF 1"
333 send_gdb "ptype class vB\n"
335 -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}\}\r\n$gdb_prompt $" {
337 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
339 -re "type = class vB : public virtual vA \{\r\n\[ \]*public:\r\n\[ \]*int vb;\r\n\[ \]*int vx;\[\r\n\t \]+\}\r\n$gdb_prompt $" {
340 pass "ptype class vB (aCC)"
342 -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}\}\r\n$gdb_prompt $" {
344 fail "ptype class vB (FIXME) (obsolescent gcc or gdb)"
346 -re ".*$gdb_prompt $" {
347 fail "ptype class vB"
350 fail "ptype class vB (timeout)"
355 # Accept the form with embedded GNU style mangled virtual table constructs
356 # for now, but with a FIXME. At some future point, gdb should use a
357 # portable representation for the virtual table constructs.
359 setup_xfail_format "DWARF 1"
360 send_gdb "ptype class vC\n"
362 -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}\}\r\n$gdb_prompt $" {
364 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
366 -re "type = class vC : public virtual vA \{\r\n\[ \]*public:\r\n\[ \]*int vc;\r\n\[ \]*int vx;\[\r\n\t \]+\}\r\n$gdb_prompt $" {
367 pass "ptype class vC (aCC)"
369 -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}\}\r\n$gdb_prompt $" {
371 fail "ptype class vC (FIXME) (obsolescent gcc or gdb)"
373 -re ".*$gdb_prompt $" {
374 fail "ptype class vC"
377 fail "ptype class vC (timeout)"
382 # Accept the form with embedded GNU style mangled virtual table constructs
383 # for now, but with a FIXME. At some future point, gdb should use a
384 # portable representation for the virtual table constructs.
386 setup_xfail_format "DWARF 1"
387 send_gdb "ptype class vD\n"
389 -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}\}\r\n$gdb_prompt $" {
391 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
393 -re "type = class vD : public virtual vB, public virtual vC \{\r\n\[ \]*public:\r\n\[ \]*int vd;\r\n\[ \]*int vx;\[\r\n\t \]+\}\r\n$gdb_prompt $" {
394 pass "ptype class vD (aCC)"
396 -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}\}\r\n$gdb_prompt $" {
398 fail "ptype class vD (FIXME) (obsolescent gcc or gdb)"
400 -re ".*$gdb_prompt $" {
401 fail "ptype class vD"
404 fail "ptype class vD (timeout)"
409 # Accept the form with embedded GNU style mangled virtual table constructs
410 # for now, but with a FIXME. At some future point, gdb should use a
411 # portable representation for the virtual table constructs.
413 setup_xfail_format "DWARF 1"
414 send_gdb "ptype class vE\n"
416 -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}\}\r\n$gdb_prompt $" {
418 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
420 -re "type = class vE : public virtual vD \{\r\n\[ \]*public:\r\n\[ \]*int ve;\r\n\[ \]*int vx;\[\r\n\t \]+\}\r\n$gdb_prompt $" {
421 pass "ptype class vE (aCC)"
423 -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}\}\r\n$gdb_prompt $" {
425 fail "ptype class vE (FIXME) (obsolescent gcc or gdb)"
427 -re ".*$gdb_prompt $" {
428 fail "ptype class vE"
431 fail "ptype class vE (timeout)"
436 setup_xfail_format "DWARF 1"
437 send_gdb "ptype class Base1\n"
439 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 & operator=\\(Base1 const &\\);${ws}Base1\\(Base1 const &\\);${ws}Base1\\(int\\);${ws}\}\r\n$gdb_prompt $" {
440 pass "ptype class Base1"
442 -re "type = class Base1 \{${ws}public:${ws}int x;((${ws}Base1 & operator=\\(Base1 const &\\);)|(${ws}Base1\\(Base1 const &\\);)|(${ws}Base1\\(int\\);))*${ws}\}\r\n$gdb_prompt $" {
443 pass "ptype class Base1 (obsolescent gcc or gdb)"
445 -re ".*$gdb_prompt $" {
446 fail "ptype class Base1"
449 fail "ptype class Base1 (timeout)"
454 setup_xfail_format "DWARF 1"
455 send_gdb "ptype class Foo\n"
457 -re "type = class Foo \{\r\n\[ \]*public:\r\n\[ \]*int x;\r\n\[ \]*int y;\r\n\[ \]*static int st;\r\n\r\n\[ \]*Foo\\(int, int\\);\r\n\[ \]*int operator!.void.;\r\n\[ \]*operator int.void.;\r\n\[ \]*int times.int.;\r\n\}\r\n$gdb_prompt $" {
458 pass "ptype class Foo(aCC)"
460 -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}\}\r\n$gdb_prompt $" {
461 pass "ptype class Foo"
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}\}\r\n$gdb_prompt $" {
464 pass "ptype class Foo (obsolescent gcc or gdb)"
466 -re ".*$gdb_prompt $" {
467 fail "ptype class Foo"
470 fail "ptype class Foo (timeout)"
475 setup_xfail_format "DWARF 1"
476 send_gdb "ptype class Bar\n"
478 -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}\}\r\n$gdb_prompt $" {
479 pass "ptype class Bar"
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}\}\r\n$gdb_prompt $" {
482 pass "ptype class Bar (obsolescent gcc or gdb)"
484 -re ".*$gdb_prompt $" {
485 fail "ptype class Bar"
488 fail "ptype class Bar (timeout)"
495 # Test simple access to class members.
498 proc test_non_inherited_member_access {} {
501 # Print non-inherited members of g_A.
503 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
505 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
507 # Print non-inherited members of g_B.
509 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
511 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
513 # Print non-inherited members of g_C.
515 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
517 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
519 # Print non-inherited members of g_D.
521 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
523 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
525 # Print non-inherited members of g_E.
527 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
529 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
533 # Try access to non-members that are members of another class.
534 # Should give errors.
537 proc test_wrong_class_members {} {
540 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
542 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
544 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
546 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
548 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
550 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
554 # Try access to non-members that are not members of any class.
555 # Should give errors.
558 proc test_nonexistant_members {} {
561 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
563 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
565 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
567 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
571 # Pointers to class members
574 proc test_pointers_to_class_members {} {
578 gdb_test "print Bar::z" ".* = .int\[ \]*\[( \]*Bar::&\[)\]+\[ \]*Bar::z" "print Bar::z"
580 gdb_test "print &Foo::x" ".* = .int\[ \]*\[( \]*Foo::\[*)\]+\[ \]*&Foo::x" "print &Foo::x"
582 gdb_test "print (int)&Foo::x" ".* = 0" "print (int)&Foo::x"
584 send_gdb "print (int)&Bar::y == 2*sizeof(int)\n"
586 -re ".* = true\r\n$gdb_prompt $" {
587 pass "print (int)&Bar::y == 2*sizeof(int)"
589 -re "There is no field named y.*$gdb_prompt $" {
591 fail "print (int)&Bar::y == 2*sizeof(int)"
593 -re ".*$gdb_prompt $" { fail "print (int)&Bar::y == 2*sizeof(int)" }
594 timeout { fail "print (int)&Bar::y == 2*sizeof(int) (timeout)" ; return }
600 -re "$decimal\[ \t\]+inheritance3 \[)(\]+;\r\n$gdb_prompt $" {}
601 -re ".*$gdb_prompt $" { fail "next to inheritance3" ; return }
605 setup_xfail_format "DWARF 1"
606 gdb_test "print (int)pmi == sizeof(int)" ".* = false" "print (int)pmi == sizeof(int)"
610 # Test static members.
613 proc test_static_members {} {
617 send_gdb "print Foo::st\n"
619 -re ".* = 100\r\n$gdb_prompt $" {
622 -re "There is no field named st.*$gdb_prompt $" {
626 -re ".*$gdb_prompt $" { fail "print Foo::st" }
627 timeout { fail "print Foo::st (timeout)" ; return }
630 send_gdb "set foo.st = 200\n"
632 -re ".*$gdb_prompt $" {}
635 send_gdb "print bar.st\n"
637 -re ".* = 200\r\n$gdb_prompt $" {
640 -re "There is no member( or method|) named st.*$gdb_prompt $" {
644 -re ".*$gdb_prompt $" { fail "print bar.st" }
645 timeout { fail "print bar.st (timeout)" ; return }
648 send_gdb "print &foo.st\n"
650 -re ".* = .int \[*)\]+ $hex\r\n$gdb_prompt $" {
653 -re "There is no member( or method|) named st.*$gdb_prompt $" {
657 -re ".*$gdb_prompt $" { fail "print &foo.st" }
658 timeout { fail "print &foo.st (timeout)" ; return }
662 send_gdb "print &Bar::st\n"
664 -re ".* = .int \[*)\]+ $hex\r\n$gdb_prompt $" {
665 pass "print &Bar::st"
668 -re "There is no field named st.*$gdb_prompt $" {
670 fail "print &Bar::st"
672 -re ".*$gdb_prompt $" { fail "print &Bar::st" }
673 timeout { fail "print &Bar::st (timeout)" ; return }
676 if $got_bar_st then {
677 gdb_test "print *\$" ".* = 200" "print *\$"
680 gdb_test "set print static-members off" ""
681 gdb_test "print csi" \
683 "print csi without static members"
684 gdb_test "print cnsi" \
686 "print cnsi without static members"
688 gdb_test "set print static-members on" ""
689 setup_xfail_format "DWARF 1"
690 gdb_test "print csi" \
691 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
692 "print csi with static members"
693 setup_xfail_format "DWARF 1"
694 gdb_test "print cnsi" \
695 "{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>}" \
696 "print cnsi with static members"
711 # Start with a fresh gdb.
715 gdb_reinitialize_dir $srcdir/$subdir
718 send_gdb "set language c++\n"
719 gdb_expect -re "$gdb_prompt $"
720 send_gdb "set width 0\n"
721 gdb_expect -re "$gdb_prompt $"
723 # Get the debug format for the compiled test case.
725 if [ runto_main ] then {
729 test_ptype_class_objects
731 if [ runto 'inheritance2(void)' ] then {
732 test_non_inherited_member_access
733 test_wrong_class_members
734 test_nonexistant_members
737 if [istarget "mips-idt-*"] then {
738 # Restart because IDT/SIM runs out of file descriptors.
741 gdb_reinitialize_dir $srcdir/$subdir
745 if [ runto_main ] then {
746 test_pointers_to_class_members
750 if [istarget "mips-idt-*"] then {
751 # Restart because IDT/SIM runs out of file descriptors.
754 gdb_reinitialize_dir $srcdir/$subdir
758 if [ runto marker_reg1 ] then {
760 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
762 send_gdb "print v.method ()\n"
764 -re "= 82.*$gdb_prompt $" {
765 pass "calling method for small class"
767 -re "Address requested for identifier .v. which is in a register.*$gdb_prompt $" {
768 setup_xfail "*-*-*" 2972
769 fail "calling method for small class"
771 -re ".*$gdb_prompt $" { fail "calling method for small class" }
772 timeout { fail "calling method for small class (timeout)" }
773 eof { fail "calling method for small class (eof)" }
782 # Some additional tests for enums inside classes
785 # set a breakpoint and go there
786 send_gdb "break 498\n"
788 -re "Breakpoint \[0-9\] at.*$gdb_prompt $" { pass "set break 498" }
789 -re "$gdb_prompt $" { fail "set break 498" }
790 timeout { fail "(timeout) set break 498" }
792 send_gdb "continue\n"
794 -re "Continuing\\.\r\n\r\nBreakpoint \[0-9\]*, main....at ${srcdir}/${subdir}/${srcfile}:498\r\n498.*\r\n$gdb_prompt $" { pass "continue" }
795 -re "$gdb_prompt $" { fail "continue" }
796 timeout { fail "(timeout) continue" }
800 send_gdb "print obj_with_enum\n"
802 -re "\\$\[0-9\]* = \\{priv_enum = red, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (1)" }
803 -re "$gdb_prompt $" { fail "print obj_with_enum (1)" }
804 timeout { fail "(timeout) print obj_with_enum (1)" }
809 -re "$gdb_prompt $" { pass "next" }
810 timeout { fail "(timeout) next" }
813 # print the object again
814 send_gdb "print obj_with_enum\n"
816 -re "\\$\[0-9\]* = \\{priv_enum = green, x = 0\\}.*$gdb_prompt $" { pass "print obj_with_enum (2)" }
817 -re "$gdb_prompt $" { fail "print obj_with_enum (2)" }
818 timeout { fail "(timeout) print obj_with_enum (2)" }
821 # print out the enum member
822 send_gdb "print obj_with_enum.priv_enum\n"
824 -re "\\$\[0-9\]* = green.*$gdb_prompt $" { pass "print obj_with_enum.priv_enum" }
825 -re "$gdb_prompt $" { fail "print obj_with_enum.priv_enum" }
826 timeout { fail "(timeout) print obj_with_enum.priv_enum" }
829 # ptype on the enum member
830 send_gdb "ptype obj_with_enum.priv_enum\n"
832 -re "type = enum ClassWithEnum::PrivEnum \\{red, green, blue, yellow = 42\\}.*$gdb_prompt $" { pass "ptype obj_with_enum.priv_enum" }
833 -re "$gdb_prompt $" { fail "ptype obj_with_enum.priv_enum" }
834 timeout { fail "(timeout) ptype obj_with_enum.priv_enum" }
837 # ptype on the object
838 send_gdb "ptype obj_with_enum\n"
840 -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" }
841 -re "$gdb_prompt $" { fail "ptype obj_with_enum" }
842 timeout { fail "(timeout) ptype obj_with_enum" }
845 send_gdb "print (ClassWithEnum::PrivEnum) 42\n"
847 -re "\\$\[0-9\]* = yellow.*$gdb_prompt $" { pass "print (ClassWithEnum::PrivEnum) 42" }
848 -re "$gdb_prompt $" { fail "print (ClassWithEnum::PrivEnum) 42" }
849 timeout { fail "(timeout) print (ClassWithEnum::PrivEnum) 42" }
853 send_gdb "maint demangle inheritance1__Fv\n"
855 -re "inheritance1\\(void\\).*$gdb_prompt $" { pass "demangle" }
856 -re ".*$gdb_prompt $" { fail "demangle" }
857 timeout { fail "(timeout) demangle" }