1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
28 if { [skip_cplus_tests] } { continue }
30 set testfile "classes"
31 set srcfile ${testfile}.cc
32 set binfile ${objdir}/${subdir}/${testfile}
34 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
35 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
38 # Test ptype of class objects.
40 # This code accepts the output of gcc v2 and v3, dwarf-2 and stabs+.
41 # It could use some expansion with other compilers such as hp-ux ac++.
43 # There are lots of variations in the output:
45 # . older gcc -gstabs+ emits debug info for implicit member functions:
46 # operator=, copy ctor, ctor. newer gcc -gstabs+ sometimes emits
47 # this debug info. gcc -gdwarf-2 also emits this debug info,
48 # but gdb does not print implicit members in ptype output.
50 # . gcc with abi version 1 puts the implicit member functions
51 # at the beginning of the member function list; with abi version 2,
52 # the implicit member functions are at the end of the member function
53 # list. This appears as an output difference with -gstabs+.
54 # gcc 3.3.X defaults to abi version 1, and gcc 3.4 will default
57 # . gcc v2 shows data members for virtual base pointers.
60 # . ptype can print either "class ... { public:" or "struct ... {".
61 # this depends on the debug info format; on whether the struct/class
62 # has any c++ features such as non-public data members, base classes,
63 # or member functions; and on other factors. I accept any form that
64 # is semantically the same as the original.
66 proc test_ptype_class_objects {} {
73 set re_class "((struct|class) default_public_struct \{${ws}public:|struct default_public_struct \{)"
75 gdb_test_multiple "ptype struct default_public_struct" "ptype struct default_public_struct" {
76 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
77 # gcc 2.95.3 -gdwarf-2
80 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
81 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
82 pass "ptype struct default_public_struct"
84 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}default_public_struct ?& ?operator ?=\\(default_public_struct const ?&\\);${ws}default_public_struct\\(default_public_struct const ?&\\);${ws}default_public_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" {
88 pass "ptype struct default_public_struct"
92 # Same test, slightly different type.
94 set re_class "((struct|class) explicit_public_struct \{${ws}public:|struct explicit_public_struct \{)"
96 gdb_test_multiple "ptype struct explicit_public_struct" "ptype struct explicit_public_struct" {
97 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
98 # gcc 2.95.3 -gdwarf-2
100 # gcc 3.4.1 -gdwarf-2
101 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
102 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
103 pass "ptype struct explicit_public_struct"
105 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}explicit_public_struct ?& ?operator ?=\\(explicit_public_struct const ?&\\);${ws}explicit_public_struct\\(explicit_public_struct const ?&\\);${ws}explicit_public_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" {
106 # gcc 2.95.3 -gstabs+
109 pass "ptype struct explicit_public_struct"
113 # Same test, slightly different type.
115 set re_class "((struct|class) protected_struct \{${ws}protected:)"
117 gdb_test_multiple "ptype struct protected_struct" "ptype struct protected_struct" {
118 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
119 # gcc 2.95.3 -gdwarf-2
120 # gcc 3.3.2 -gdwarf-2
121 # gcc 3.4.1 -gdwarf-2
122 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
123 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
124 pass "ptype struct protected_struct"
126 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public:${ws}protected_struct ?& ?operator ?=\\(protected_struct const ?&\\);${ws}protected_struct\\(protected_struct const ?&\\);${ws}protected_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" {
127 # gcc 2.95.3 -gstabs+
130 pass "ptype struct protected_struct"
134 # Same test, slightly different type.
136 set re_class "((struct|class) private_struct \{${ws}private:|class private_struct \{)"
138 gdb_test_multiple "ptype struct private_struct" "ptype struct private_struct" {
139 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
140 # gcc 2.95.3 -gdwarf-2
141 # gcc 3.3.2 -gdwarf-2
142 # gcc 3.4.1 -gdwarf-2
143 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
144 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
145 pass "ptype struct private_struct"
147 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public:${ws}private_struct ?& ?operator ?=\\(private_struct const ?&\\);${ws}private_struct\\(private_struct const ?&\\);${ws}private_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" {
148 # gcc 2.95.3 -gstabs+
151 pass "ptype struct private_struct"
155 # Similar test, bigger type.
157 set re_class "((struct|class) mixed_protection_struct \{${ws}public:|struct mixed_protection_struct \{)"
159 gdb_test_multiple "ptype struct mixed_protection_struct" "ptype struct mixed_protection_struct" {
160 -re "type = ${re_class}${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 $" {
161 # gcc 2.95.3 -gdwarf-2
162 # gcc 3.3.2 -gdwarf-2
163 # gcc 3.4.1 -gdwarf-2
164 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
165 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
166 pass "ptype struct mixed_protection_struct"
168 -re "type = ${re_class}${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;${ws}public:${ws}mixed_protection_struct ?& ?operator ?=\\(mixed_protection_struct const ?&\\);${ws}mixed_protection_struct\\(mixed_protection_struct const ?&\\);${ws}mixed_protection_struct\\((void|)\\);$nl\}$nl$gdb_prompt $" {
169 # gcc 2.95.3 -gstabs+
172 pass "ptype struct mixed_protection_struct"
176 # All that again with "class" instead of "struct".
177 # gdb does not care about the difference anyways.
179 set re_class "((struct|class) public_class \{${ws}public:|struct public_class \{)"
181 gdb_test_multiple "ptype class public_class" "ptype class public_class" {
182 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
183 # gcc 2.95.3 -gdwarf-2
184 # gcc 3.3.2 -gdwarf-2
185 # gcc 3.4.1 -gdwarf-2
186 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
187 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
188 pass "ptype class public_class"
190 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public_class ?& ?operator ?=\\(public_class const ?&\\);${ws}public_class\\(public_class const ?&\\);${ws}public_class\\((void|)\\);$nl\}$nl$gdb_prompt $" {
191 # gcc 2.95.3 -gstabs+
194 pass "ptype class public_class"
198 # Same test, slightly different type.
200 set re_class "((struct|class) protected_class \{${ws}protected:)"
202 gdb_test_multiple "ptype class protected_class" "ptype class protected_class" {
203 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
204 # gcc 2.95.3 -gdwarf-2
205 # gcc 3.3.2 -gdwarf-2
206 # gcc 3.4.1 -gdwarf-2
207 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
208 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
209 pass "ptype class protected_class"
211 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public:${ws}protected_class ?& ?operator ?=\\(protected_class const ?&\\);${ws}protected_class\\(protected_class const ?&\\);${ws}protected_class\\((void|)\\);$nl\}$nl$gdb_prompt $" {
212 # gcc 2.95.3 -gstabs+
215 pass "ptype class protected_class"
219 # Same test, slightly different type.
221 set re_class "((struct|class) default_private_class \{${ws}private:|class default_private_class \{)"
223 gdb_test_multiple "ptype class default_private_class" "ptype class default_private_class" {
224 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
225 # gcc 2.95.3 -gdwarf-2
226 # gcc 3.3.2 -gdwarf-2
227 # gcc 3.4.1 -gdwarf-2
228 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
229 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
230 pass "ptype class default_private_class"
232 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public:${ws}default_private_class ?& ?operator ?=\\(default_private_class const ?&\\);${ws}default_private_class\\(default_private_class const ?&\\);${ws}default_private_class\\((void|)\\);$nl\}$nl$gdb_prompt $" {
233 # gcc 2.95.3 -gstabs+
236 pass "ptype class default_private_class"
240 # Same test, slightly different type.
242 set re_class "((struct|class) explicit_private_class \{${ws}private:|class explicit_private_class \{)"
244 gdb_test_multiple "ptype class explicit_private_class" "ptype class explicit_private_class" {
245 -re "type = ${re_class}${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
246 # gcc 2.95.3 -gdwarf-2
247 # gcc 3.3.2 -gdwarf-2
248 # gcc 3.4.1 -gdwarf-2
249 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
250 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
251 pass "ptype class explicit_private_class"
253 -re "type = ${re_class}${ws}int a;${ws}int b;${ws}public:${ws}explicit_private_class ?& ?operator ?=\\(explicit_private_class const ?&\\);${ws}explicit_private_class\\(explicit_private_class const ?&\\);${ws}explicit_private_class\\((void|)\\);$nl\}$nl$gdb_prompt $" {
254 # gcc 2.95.3 -gstabs+
257 pass "ptype class explicit_private_class"
261 # Similar test, bigger type.
263 set re_class "((struct|class) mixed_protection_class \{${ws}public:|struct mixed_protection_class \{)"
265 gdb_test_multiple "ptype class mixed_protection_class" "ptype struct mixed_protection_class" {
266 -re "type = ${re_class}${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 $" {
267 # gcc 2.95.3 -gdwarf-2
268 # gcc 3.3.2 -gdwarf-2
269 # gcc 3.4.1 -gdwarf-2
270 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
271 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
272 pass "ptype class mixed_protection_class"
274 -re "type = ${re_class}${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;${ws}public:${ws}mixed_protection_class ?& ?operator ?=\\(mixed_protection_class const ?&\\);${ws}mixed_protection_class\\(mixed_protection_class const ?&\\);${ws}mixed_protection_class\\((void|)\\);$nl\}$nl$gdb_prompt $" {
275 # gcc 2.95.3 -gstabs+
278 pass "ptype class mixed_protection_class"
282 # Here are some classes with inheritance.
286 set re_class "((struct|class) A \{${ws}public:|struct A \{)"
288 gdb_test_multiple "ptype class A" "ptype class A" {
289 -re "type = ${re_class}${ws}int a;${ws}int x;$nl\}$nl$gdb_prompt $" {
290 # gcc 2.95.3 -gdwarf-2
291 # gcc 3.3.2 -gdwarf-2
292 # gcc 3.4.1 -gdwarf-2
293 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
294 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
297 -re "type = ${re_class}${ws}int a;${ws}int x;${ws}A ?& ?operator ?=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);$nl\}$nl$gdb_prompt $" {
298 # gcc 2.95.3 -gstabs+
307 set re_class "((struct|class) B : public A \{${ws}public:|struct B : public A \{)"
309 gdb_test_multiple "ptype class B" "ptype class B" {
310 -re "type = ${re_class}${ws}int b;${ws}int x;$nl\}$nl$gdb_prompt $" {
311 # gcc 2.95.3 -gdwarf-2
312 # gcc 3.3.2 -gdwarf-2
313 # gcc 3.4.1 -gdwarf-2
314 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
315 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
318 -re "type = ${re_class}${ws}int b;${ws}int x;${ws}B ?& ?operator ?=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\((void|)\\);$nl\}$nl$gdb_prompt $" {
319 # gcc 2.95.3 -gstabs+
328 set re_class "((struct|class) C : public A \{${ws}public:|struct C : public A \{)"
330 gdb_test_multiple "ptype class C" "ptype class C" {
331 -re "${re_class}${ws}int c;${ws}int x;$nl\}$nl$gdb_prompt $" {
332 # gcc 2.95.3 -gdwarf-2
333 # gcc 3.3.2 -gdwarf-2
334 # gcc 3.4.1 -gdwarf-2
335 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
336 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
339 -re "${re_class}${ws}int c;${ws}int x;${ws}C ?& ?operator ?=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\((void|)\\);$nl\}$nl$gdb_prompt $" {
340 # gcc 2.95.3 -gstabs+
347 # Derived class, multiple inheritance.
349 set re_class "((struct|class) D : public B, public C \{${ws}public:|struct D : public B, public C \{)"
351 gdb_test_multiple "ptype class D" "ptype class D" {
352 -re "type = ${re_class}${ws}int d;${ws}int x;$nl\}$nl$gdb_prompt $" {
353 # gcc 2.95.3 -gdwarf-2
354 # gcc 3.3.2 -gdwarf-2
355 # gcc 3.4.1 -gdwarf-2
356 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
357 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
360 -re "type = ${re_class}${ws}int d;${ws}int x;${ws}D ?& ?operator ?=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\((void|)\\);$nl\}$nl$gdb_prompt $" {
361 # gcc 2.95.3 -gstabs+
370 set re_class "((struct|class) E : public D \{${ws}public:|struct E : public D \{)"
372 gdb_test_multiple "ptype class E" "ptype class E" {
373 -re "type = ${re_class}${ws}int e;${ws}int x;$nl\}$nl$gdb_prompt $" {
374 # gcc 2.95.3 -gdwarf-2
375 # gcc 3.3.2 -gdwarf-2
376 # gcc 3.4.1 -gdwarf-2
377 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
378 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
381 -re "type = ${re_class}${ws}int e;${ws}int x;${ws}E ?& ?operator ?=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\((void|)\\);$nl\}$nl$gdb_prompt $" {
382 # gcc 2.95.3 -gstabs+
389 # This is a break from inheritance tests.
391 # gcc 2.X with stabs (stabs or stabs+?) used to have a problem with
392 # static methods whose name is the same as their argument mangling.
394 set re_class "((struct|class) Static \{${ws}public:|struct Static \{)"
396 gdb_test_multiple "ptype class Static" "ptype class Static" {
397 -re "type = ${re_class}${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" {
398 # gcc 2.95.3 -gdwarf-2
399 # gcc 3.3.2 -gdwarf-2
400 # gcc 3.4.1 -gdwarf-2
401 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
402 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
403 pass "ptype class Static"
405 -re "type = ${re_class}${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" {
406 # gcc 2.95.3 -gstabs+
408 pass "ptype class Static"
410 -re "type = ${re_class}${ws}static void ii\\(int, int\\);${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);$nl\}$nl$gdb_prompt $" {
412 pass "ptype class Static"
416 # Here are some virtual inheritance tests.
418 set re_class "((struct|class) vA \{${ws}public:|struct vA \{)"
420 gdb_test_multiple "ptype class vA" "ptype class vA" {
421 -re "type = ${re_class}${ws}int va;${ws}int vx;$nl\}$nl$gdb_prompt $" {
422 # gcc 2.95.3 -gdwarf-2
423 # gcc 3.3.2 -gdwarf-2
424 # gcc 3.4.1 -gdwarf-2
425 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
426 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
427 pass "ptype class vA"
429 -re "type = ${re_class}${ws}int va;${ws}int vx;${ws}vA ?& ?operator ?=\\(vA const ?&\\);${ws}vA\\(vA const ?&\\);${ws}vA\\((void|)\\);$nl\}$nl$gdb_prompt $" {
430 # gcc 2.95.3 -gstabs+
433 pass "ptype class vA"
437 # With gcc 2, gdb prints the virtual base pointer.
438 # With gcc 3, gdb does not print the virtual base pointer.
439 # drow considers it a gdb bug if gdb prints the vbptr.
441 set re_class_private "((struct|class) vB : public virtual vA \{${ws}private:|class vB : public virtual vA \{)"
442 set re_class_public "((struct|class) vB : public virtual vA \{${ws}public:|struct vB : public virtual vA \{)"
444 gdb_test_multiple "ptype class vB" "ptype class vB" {
445 -re "type = ${re_class_private}${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" {
446 # gcc 2.95.3 -gdwarf-2
448 fail "ptype class vB"
450 -re "type = ${re_class_public}${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" {
451 # gcc 3.3.4 -gdwarf-2
452 # gcc 3.4.1 -gdwarf-2
453 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
454 pass "ptype class vB"
456 -re "type = ${re_class_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\\);$nl\}$nl$gdb_prompt $" {
457 # gcc 2.95.3 -gstabs+
458 # See the hidden "in-charge" ctor parameter!
461 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
463 -re "type = ${re_class_public}${ws}int vb;${ws}int vx;${ws}vB ?& ?operator ?=\\(vB const ?&\\);${ws}vB\\(vB const ?&\\);${ws}vB\\((void|)\\);$nl\}$nl$gdb_prompt $" {
466 pass "ptype class vB"
468 -re "type = ${re_class_public}${ws}int vb;${ws}int vx;${ws}vB\\(vB const ?&\\);${ws}vB\\((void|)\\);$nl\}$nl$gdb_prompt $" {
469 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
470 pass "ptype class vB"
474 # Another class with a virtual base.
476 set re_class_private "((struct|class) vC : public virtual vA \{${ws}private:|class vC : public virtual vA \{)"
477 set re_class_public "((struct|class) vC : public virtual vA \{${ws}public:|struct vC : public virtual vA \{)"
479 gdb_test_multiple "ptype class vC" "ptype class vC" {
480 -re "type = ${re_class_private}${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" {
481 # gcc 2.95.3 -gdwarf-2
483 fail "ptype class vC"
485 -re "type = ${re_class_public}${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" {
486 # gcc 3.3.4 -gdwarf-2
487 # gcc 3.4.1 -gdwarf-2
488 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
489 pass "ptype class vC"
491 -re "type = ${re_class_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\\);$nl\}$nl$gdb_prompt $" {
492 # gcc 2.95.3 -gstabs+
493 # See the hidden "in-charge" ctor parameter!
496 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
498 -re "type = ${re_class_public}${ws}int vc;${ws}int vx;${ws}vC ?& ?operator ?=\\(vC const ?&\\);${ws}vC\\(vC const ?&\\);${ws}vC\\((void|)\\);$nl\}$nl$gdb_prompt $" {
501 pass "ptype class vC"
503 -re "type = ${re_class_public}${ws}int vc;${ws}int vx;${ws}vC\\(vC const ?&\\);${ws}vC\\((void|)\\);$nl\}$nl$gdb_prompt $" {
504 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
505 pass "ptype class vC"
509 # The classic diamond inheritance.
511 set re_class_private "((struct|class) vD : public virtual vB, public virtual vC \{${ws}private:|class vD : public virtual vB, public virtual vC \{)"
512 set re_class_public "((struct|class) vD : public virtual vB, public virtual vC \{${ws}public:|struct vD : public virtual vB, public virtual vC \{)"
514 gdb_test_multiple "ptype class vD" "ptype class vD" {
515 -re "type = ${re_class_private}${ws}vC ?\\* ?_vb.2vC;${ws}vB ?\\* ?_vb.2vB;${ws}public:${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" {
516 # gcc 2.95.3 -gdwarf-2
518 fail "ptype class vD"
520 -re "type = ${re_class_public}${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" {
521 # gcc 3.3.2 -gdwarf-2
522 # gcc 3.4.1 -gdwarf-2
523 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
524 pass "ptype class vD"
526 -re "type = ${re_class_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\\);$nl\}$nl$gdb_prompt $" {
527 # gcc 2.95.3 -gstabs+
528 # See the hidden "in-charge" ctor parameter!
531 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
533 -re "type = ${re_class_public}${ws}int vd;${ws}int vx;${ws}vD ?& ?operator ?=\\(vD const ?&\\);${ws}vD\\(vD const ?&\\);${ws}vD\\((void|)\\);$nl\}$nl$gdb_prompt $" {
536 pass "ptype class vD"
538 -re "type = ${re_class_public}${ws}int vd;${ws}int vx;${ws}vD\\(vD const ?&\\);${ws}vD\\((void|)\\);$nl\}$nl$gdb_prompt $" {
539 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
540 pass "ptype class vD"
544 # One more case of virtual derivation.
546 set re_class_private "((struct|class) vE : public virtual vD \{${ws}private:|class vE : public virtual vD \{)"
547 set re_class_public "((struct|class) vE : public virtual vD \{${ws}public:|struct vE : public virtual vD \{)"
549 gdb_test_multiple "ptype class vE" "ptype class vE" {
550 -re "type = ${re_class_private}${ws}vD ?\\* ?_vb.2vD;${ws}public:${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" {
551 # gcc 2.95.3 -gdwarf-2
553 fail "ptype class vE"
555 -re "type = ${re_class_public}${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" {
556 # gcc 3.3.2 -gdwarf-2
557 # gcc 3.4.1 -gdwarf-2
558 # gcc HEAD 2004-07-31 00:45:52 UTC -gdwarf-2
559 pass "ptype class vE"
561 -re "type = ${re_class_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\\);$nl\}$nl$gdb_prompt $" {
562 # gcc 2.95.3 -gstabs+
563 # See the hidden "in-charge" ctor parameter!
566 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
568 -re "type = ${re_class_public}${ws}int ve;${ws}int vx;${ws}vE ?& ?operator ?=\\(vE const ?&\\);${ws}vE\\(vE const ?&\\);${ws}vE\\((void|)\\);$nl\}$nl$gdb_prompt $" {
571 pass "ptype class vE"
573 -re "type = ${re_class_public}${ws}int ve;${ws}int vx;${ws}vE\\(vE const ?&\\);${ws}vE\\((void|)\\);$nl\}$nl$gdb_prompt $" {
574 # gcc HEAD 2004-07-31 00:45:52 UTC -gstabs+
575 pass "ptype class vE"
579 # Another inheritance series.
581 gdb_test_multiple "ptype class Base1" "ptype class Base1" {
582 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);$nl\}$nl$gdb_prompt $" {
583 # gcc 2.95.3 -gdwarf-2
584 # gcc 3.3.2 -gdwarf-2
585 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
586 pass "ptype class Base1"
588 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1 ?& ?operator ?=\\(Base1 const ?&\\);${ws}Base1\\(Base1 const ?&\\);${ws}Base1\\(int\\);$nl\}$nl$gdb_prompt $" {
589 # gcc 2.95.3 -gstabs+
591 pass "ptype class Base1"
593 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);${ws}Base1 ?& ?operator ?=\\(Base1 const ?&\\);${ws}Base1\\(Base1 const ?&\\);$nl\}$nl$gdb_prompt $" {
594 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
595 pass "ptype class Base1"
599 # The second base class.
601 gdb_test_multiple "ptype class Foo" "ptype class Foo" {
602 -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo\\(int, int\\);${ws}int operator ?!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);$nl\}$nl$gdb_prompt $" {
603 # gcc 2.95.3 -gdwarf-2
604 # gcc 3.3.2 -gdwarf-2
605 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
606 pass "ptype class Foo"
608 -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\\);$nl\}$nl$gdb_prompt $" {
609 # gcc 2.95.3 -gstabs+
610 # TODO: "int operator int()" is a bug
611 # kfail "gdb/1497" "ptype class Foo"
612 pass "ptype class Foo"
614 -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\\);$nl\}$nl$gdb_prompt $" {
616 pass "ptype class Foo"
618 -re "type = class Foo \{${ws}public:${ws}int x;${ws}int y;${ws}static int st;${ws}Foo\\(int, int\\);${ws}int operator ?!\\((void|)\\);${ws}operator int\\((void|)\\);${ws}int times\\(int\\);${ws}Foo ?& ?operator ?=\\(Foo const ?&\\);${ws}Foo\\(Foo const ?&\\);$nl\}$nl$gdb_prompt $" {
619 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
620 pass "ptype class Foo"
624 # A multiple inheritance derived class.
626 gdb_test_multiple "ptype class Bar" "ptype class Bar" {
627 -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar\\(int, int, int\\);$nl\}$nl$gdb_prompt $" {
628 # gcc 2.95.3 -gdwarf-2
629 # gcc 3.3.2 -gdwarf-2
630 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
631 pass "ptype class Bar"
633 -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\\);$nl\}$nl$gdb_prompt $" {
634 # gcc 2.95.3 -gstabs+
636 pass "ptype class Bar"
638 -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar\\(int, int, int\\);${ws}Bar ?& ?operator ?=\\(Bar const ?&\\);${ws}Bar\\(Bar const ?&\\);$nl\}$nl$gdb_prompt $" {
639 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
640 pass "ptype class Bar"
645 # Test simple access to class members.
646 # TODO: these test names are gross!
647 # Just let the test name default.
649 proc test_non_inherited_member_access {} {
652 # Print non-inherited members of g_A.
653 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
654 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
656 # Print non-inherited members of g_B.
657 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
658 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
660 # Print non-inherited members of g_C.
661 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
662 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
664 # Print non-inherited members of g_D.
665 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
666 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
668 # Print non-inherited members of g_E.
669 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
670 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
673 # Test access to members of other classes.
674 # gdb should refuse to print them.
675 # (I feel old -- I remember when this was legal in C -- chastain).
676 # TODO: Again, change the silly test names.
678 proc test_wrong_class_members {} {
681 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
682 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
683 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
684 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
685 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
686 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
689 # Test access to names that are not members of any class.
690 # TODO: test names again.
692 proc test_nonexistent_members {} {
695 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
696 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
697 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
698 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
701 # Call a method that expects a base class parameter with base, inherited,
702 # and unrelated class arguments.
704 proc test_method_param_class {} {
705 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
706 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
707 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
708 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
709 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a"
710 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
711 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
712 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x"
713 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
714 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
715 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
716 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
718 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
719 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m"
720 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
723 # Examine a class with an enum field.
732 gdb_test "print obj_with_enum" \
733 "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \
734 "print obj_with_enum (1)"
740 # print the object again
742 gdb_test "print obj_with_enum" \
743 "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \
744 "print obj_with_enum (2)"
746 # print the enum member
748 gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green"
750 # ptype on the enum member
752 gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" {
753 -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
754 pass "ptype obj_with_enum.priv_enum"
756 -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
757 # gcc 2.95.3 -gdwarf-2
758 # gcc 3.3.2 -gdwarf-2
759 pass "ptype obj_with_enum.priv_enum"
761 -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
762 # This case case is a little dubious, but it's not clear what
763 # ought to be required of a ptype on a private enum...
766 # It bugs me that this happens with gcc 3.
767 # -- chastain 2003-12-30
769 # gcc 2.95.3 -gstabs+
771 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
772 pass "ptype obj_with_enum.priv_enum"
776 # ptype on the object
778 set re_class "((struct|class) ClassWithEnum \{${ws}public:|struct ClassWithEnum \{)"
780 gdb_test_multiple "ptype obj_with_enum" "ptype obj_with_enum" {
781 -re "type = ${re_class}${ws}(enum |)ClassWithEnum::PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" {
782 pass "ptype obj_with_enum"
784 -re "type = ${re_class}${ws}(enum |)PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" {
785 # NOTE: carlton/2003-02-28: One could certainly argue that
786 # this output is acceptable: PrivEnum is a member of
787 # ClassWithEnum, so there's no need to explicitly qualify
788 # its name with "ClassWithEnum::". The truth, though, is
789 # that GDB is simply forgetting that PrivEnum is a member
790 # of ClassWithEnum, so we do that output for a bad reason
791 # instead of a good reason. Under stabs, we probably
792 # can't get this right; under DWARF-2, we can.
794 # gcc 2.95.3 -gdwarf-2
795 # gcc 3.3.2 -gdwarf-2
796 kfail "gdb/57" "ptype obj_with_enum"
798 -re "type = ${re_class}${ws}(enum |)PrivEnum priv_enum;${ws}int x;${ws}ClassWithEnum ?& ?operator ?=\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\((void|)\\);$nl\}$nl$gdb_prompt $" {
799 # gcc 2.95.3 -gstabs+
800 kfail "gdb/57" "ptype obj_with_enum"
802 -re "type = ${re_class}${ws}(enum |)ClassWithEnum::PrivEnum priv_enum;${ws}int x;${ws}ClassWithEnum ?& ?operator ?=\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\((void|)\\);$nl\}$nl$gdb_prompt $" {
803 # I think this is a PASS, but only carlton knows for sure.
804 # -- chastain 2003-12-30
807 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
808 fail "ptype obj_with_enum"
812 # I'll do this test two different ways, because of a parser bug.
815 gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" {
816 -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
817 pass "print (ClassWithEnum::PrivEnum) 42"
819 -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" {
820 # "parse error" is bison 1.35.
821 # "syntax error" is bison 1.875.
822 kfail "gdb/1588" "print (ClassWithEnum::PrivEnum) 42"
826 gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
827 -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
829 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
830 pass "print ('ClassWithEnum::PrivEnum') 42"
832 -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" {
833 # gcc 2.95.3 -gdwarf-2
834 # gcc 3.3.2 -gdwarf-2
835 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
836 # gcc 2.95.3 -gstabs+
837 kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42"
842 # Pointers to class members
844 proc test_pointers_to_class_members {} {
847 gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z"
848 gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x"
849 gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0"
850 gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true"
852 # TODO: this is a bogus test. It's looking at a variable that
853 # has not even been declared yet, so it's accessing random junk
854 # on the stack and comparing that it's NOT equal to a specific
855 # value. It's been like this since gdb 4.10 in 1993!
856 # -- chastain 2004-01-01
857 gdb_test "print (int)pmi == sizeof(int)" ".* = false"
860 # Test static members.
862 proc test_static_members {} {
866 gdb_test "print Foo::st" "\\$\[0-9\]+ = 100"
867 gdb_test "set foo.st = 200" "" ""
868 gdb_test "print bar.st" "\\$\[0-9\]+ = 200"
869 gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
870 gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
871 gdb_test "print *\$" "\\$\[0-9\]+ = 200"
873 gdb_test "set print static-members off" ""
874 gdb_test "print csi" \
876 "print csi without static members"
877 gdb_test "print cnsi" \
879 "print cnsi without static members"
881 gdb_test "set print static-members on" ""
882 gdb_test "print csi" \
883 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
884 "print csi with static members"
885 gdb_test "print cnsi" \
886 "{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>}" \
887 "print cnsi with static members"
903 # Start with a fresh gdb.
907 gdb_reinitialize_dir $srcdir/$subdir
910 gdb_test "set language c++" "" ""
911 gdb_test "set width 0" "" ""
913 if ![runto_main ] then {
914 perror "couldn't run to breakpoint"
918 gdb_breakpoint inheritance2
919 gdb_test "continue" ".*Breakpoint .* inheritance2.*" ""
921 test_ptype_class_objects
922 test_non_inherited_member_access
923 test_wrong_class_members
924 test_nonexistent_members
925 test_method_param_class
927 gdb_breakpoint enums2
928 gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)"
929 gdb_test "finish" "" ""
932 gdb_test "finish" "" ""
933 test_pointers_to_class_members
936 # Now some random tests that were just thrown in here.
938 gdb_breakpoint marker_reg1
939 gdb_test "continue" ".*Breakpoint .* marker_reg1.*" ""
940 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
942 # This class is so small that an instance of it can fit in a register.
943 # When gdb tries to call a method, it gets embarrassed about taking
944 # the address of a register.
946 # TODO: I think that message should be a PASS, not an XFAIL.
947 # gdb prints an informative message and declines to do something
950 # The method call actually succeeds if the compiler allocates very
951 # small classes in memory instead of registers. So this test does
952 # not tell us anything interesting if the call succeeds.
954 # -- chastain 2003-12-31
955 gdb_test_multiple "print v.method ()" "calling method for small class" {
956 -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" {
957 # gcc 3.3.2 -gdwarf-2
958 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
960 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
961 pass "calling method for small class"
963 -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" {
964 # gcc 2.95.3 -gdwarf-2
965 # gcc 2.95.3 -gstabs+
966 setup_xfail "*-*-*" 2972
967 fail "calling method for small class"
971 # This is a random v2 demangling test.
972 # This is redundant with existing tests in demangle.exp.
973 # TODO: Just remove this.
974 gdb_test "maint demangle inheritance1__Fv" "inheritance1\\(void\\)" "demangle"