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 }
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 # . gcc -stabs+ emits debug info for implicit member functions:
46 # operator=, copy ctor, ctor. gcc -gdwarf-2 does not.
48 # . gcc with abi version 1 puts the implicit member functions
49 # at the beginning of the member function list; with abi version 2,
50 # the implicit member functions are at the end of the member function
51 # list. This appears as an output difference with -gstabs+.
52 # gcc 3.3.X defaults to abi version 1, and gcc 3.4 will default
55 # . gcc v2 shows data members for virtual base pointers.
58 # . gdb always prints "class" for both "class" and "struct".
59 # In the future, I should accept "struct" in case gdb improves.
61 proc test_ptype_class_objects {} {
68 gdb_test_multiple "ptype struct default_public_struct" "ptype struct default_public_struct" {
69 -re "type = class default_public_struct \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
70 # gcc 2.95.3 -gdwarf-2
72 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
73 pass "ptype struct default_public_struct"
75 -re "type = class default_public_struct \{${ws}public:${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 $" {
78 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
79 pass "ptype struct default_public_struct"
83 # Same test, slightly different type.
85 gdb_test_multiple "ptype struct explicit_public_struct" "ptype struct explicit_public_struct" {
86 -re "type = class explicit_public_struct \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
87 # gcc 2.95.3 -gdwarf-2
89 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
90 pass "ptype struct explicit_public_struct"
92 -re "type = class explicit_public_struct \{${ws}public:${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 $" {
95 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
96 pass "ptype struct explicit_public_struct"
100 # Same test, slightly different type.
102 gdb_test_multiple "ptype struct protected_struct" "ptype struct protected_struct" {
103 -re "type = class protected_struct \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
104 # gcc 2.95.3 -gdwarf-2
105 # gcc 3.3.2 -gdwarf-2
106 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
107 pass "ptype struct protected_struct"
109 -re "type = class protected_struct \{${ws}protected:${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 $" {
110 # gcc 2.95.3 -gstabs+
112 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
113 pass "ptype struct protected_struct"
117 # Same test, slightly different type.
119 gdb_test_multiple "ptype struct private_struct" "ptype struct private_struct" {
120 -re "type = class private_struct \{${ws}private:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
121 # gcc 2.95.3 -gdwarf-2
122 # gcc 3.3.2 -gdwarf-2
123 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
124 pass "ptype struct private_struct"
126 -re "type = class private_struct \{${ws}private:${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 $" {
127 # gcc 2.95.3 -gstabs+
129 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
130 pass "ptype struct private_struct"
134 # Similar test, bigger type.
136 gdb_test_multiple "ptype struct mixed_protection_struct" "ptype struct mixed_protection_struct" {
137 -re "type = class mixed_protection_struct \{${ws}public:${ws}int a;${ws}int b;${ws}private:${ws}int c;${ws}int d;${ws}protected:${ws}int e;${ws}int f;${ws}public:${ws}int g;${ws}private:${ws}int h;${ws}protected:${ws}int i;$nl\}$nl$gdb_prompt $" {
138 # gcc 2.95.3 -gdwarf-2
139 # gcc 3.3.2 -gdwarf-2
140 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
141 pass "ptype struct mixed_protection_struct"
143 -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;${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 $" {
144 # gcc 2.95.3 -gstabs+
146 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
147 pass "ptype struct mixed_protection_struct"
151 # All that again with "class" instead of "struct".
152 # gdb does not care about the difference anyways.
154 gdb_test_multiple "ptype class public_class" "ptype class public_class" {
155 -re "type = class public_class \{${ws}public:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
156 # gcc 2.95.3 -gdwarf-2
157 # gcc 3.3.2 -gdwarf-2
158 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
159 pass "ptype class public_class"
161 -re "type = class public_class \{${ws}public:${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 $" {
162 # gcc 2.95.3 -gstabs+
164 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
165 pass "ptype class public_class"
169 # Same test, slightly different type.
171 gdb_test_multiple "ptype class protected_class" "ptype class protected_class" {
172 -re "type = class protected_class \{${ws}protected:${ws}int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
173 # gcc 2.95.3 -gdwarf-2
174 # gcc 3.3.2 -gdwarf-2
175 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
176 pass "ptype class protected_class"
178 -re "type = class protected_class \{${ws}protected:${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 $" {
179 # gcc 2.95.3 -gstabs+
181 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
182 pass "ptype class protected_class"
186 # Same test, slightly different type.
187 # The 'private' is optional but gdb always prints it.
189 gdb_test_multiple "ptype class default_private_class" "ptype class default_private_class" {
190 -re "type = class default_private_class \{${ws}(private:${ws}|)int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
191 # gcc 2.95.3 -gdwarf-2
192 # gcc 3.3.2 -gdwarf-2
193 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
194 pass "ptype class default_private_class"
196 -re "type = class default_private_class \{${ws}(private:${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 $" {
197 # gcc 2.95.3 -gstabs+
199 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
200 pass "ptype class default_private_class"
204 # Same test, slightly different type.
206 gdb_test_multiple "ptype class explicit_private_class" "ptype class explicit_private_class" {
207 -re "type = class explicit_private_class \{${ws}(private:${ws}|)int a;${ws}int b;$nl\}$nl$gdb_prompt $" {
208 # gcc 2.95.3 -gdwarf-2
209 # gcc 3.3.2 -gdwarf-2
210 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
211 pass "ptype class explicit_private_class"
213 -re "type = class explicit_private_class \{${ws}(private:${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 $" {
214 # gcc 2.95.3 -gstabs+
216 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
217 pass "ptype class explicit_private_class"
221 # Similar test, bigger type.
223 gdb_test_multiple "ptype class mixed_protection_class" "ptype struct mixed_protection_class" {
224 -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 $" {
225 # gcc 2.95.3 -gdwarf-2
226 # gcc 3.3.2 -gdwarf-2
227 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
228 pass "ptype class mixed_protection_class"
230 -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;${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 $" {
231 # gcc 2.95.3 -gstabs+
233 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
234 pass "ptype class mixed_protection_class"
238 # Here are some classes with inheritance.
242 gdb_test_multiple "ptype class A" "ptype class A" {
243 -re "type = class A \{${ws}public:${ws}int a;${ws}int x;$nl\}$nl$gdb_prompt $" {
244 # gcc 2.95.3 -gdwarf-2
245 # gcc 3.3.2 -gdwarf-2
246 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
249 -re "type = class A \{${ws}public:${ws}int a;${ws}int x;${ws}A ?& ?operator ?=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\((void|)\\);$nl\}$nl$gdb_prompt $" {
250 # gcc 2.95.3 -gstabs+
252 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
259 gdb_test_multiple "ptype class B" "ptype class B" {
260 -re "type = class B : public A \{${ws}public:${ws}int b;${ws}int x;$nl\}$nl$gdb_prompt $" {
261 # gcc 2.95.3 -gdwarf-2
262 # gcc 3.3.2 -gdwarf-2
263 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
266 -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|)\\);$nl\}$nl$gdb_prompt $" {
267 # gcc 2.95.3 -gstabs+
269 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
276 gdb_test_multiple "ptype class C" "ptype class C" {
277 -re "type = class C : public A \{${ws}public:${ws}int c;${ws}int x;$nl\}$nl$gdb_prompt $" {
278 # gcc 2.95.3 -gdwarf-2
279 # gcc 3.3.2 -gdwarf-2
280 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
283 -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|)\\);$nl\}$nl$gdb_prompt $" {
284 # gcc 2.95.3 -gstabs+
286 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
291 # Derived class, multiple inheritance.
293 gdb_test_multiple "ptype class D" "ptype class D" {
294 -re "type = class D : public B, public C \{${ws}public:${ws}int d;${ws}int x;$nl\}$nl$gdb_prompt $" {
295 # gcc 2.95.3 -gdwarf-2
296 # gcc 3.3.2 -gdwarf-2
297 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
300 -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|)\\);$nl\}$nl$gdb_prompt $" {
301 # gcc 2.95.3 -gstabs+
303 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
310 gdb_test_multiple "ptype class E" "ptype class E" {
311 -re "type = class E : public D \{${ws}public:${ws}int e;${ws}int x;$nl\}$nl$gdb_prompt $" {
312 # gcc 2.95.3 -gdwarf-2
313 # gcc 3.3.2 -gdwarf-2
314 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
317 -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|)\\);$nl\}$nl$gdb_prompt $" {
318 # gcc 2.95.3 -gstabs+
320 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
325 # This is a break from inheritance tests.
327 # gcc 2.X with stabs (stabs or stabs+?) used to have a problem with
328 # static methods whose name is the same as their argument mangling.
330 gdb_test_multiple "ptype class Static" "ptype class Static" {
331 -re "type = class Static \{${ws}public:${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" {
332 # gcc 2.95.3 -gdwarf-2
333 # gcc 3.3.2 -gdwarf-2
334 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
335 pass "ptype class Static"
337 -re "type = class Static \{${ws}public:${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);${ws}static void ii\\(int, int\\);$nl\}$nl$gdb_prompt $" {
338 # gcc 2.95.3 -gstabs+
340 pass "ptype class Static"
342 -re "type = class Static \{${ws}public:${ws}static void ii\\(int, int\\);${ws}Static ?& ?operator ?=\\(Static const ?&\\);${ws}Static\\(Static const ?&\\);${ws}Static\\((void|)\\);$nl\}$nl$gdb_prompt $" {
343 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
344 pass "ptype class Static"
348 # Here are some virtual inheritance tests.
350 gdb_test_multiple "ptype class vA" "ptype class vA" {
351 -re "type = class vA \{${ws}public:${ws}int va;${ws}int vx;$nl\}$nl$gdb_prompt $" {
352 # gcc 2.95.3 -gdwarf-2
353 # gcc 3.3.2 -gdwarf-2
354 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
355 pass "ptype class vA"
357 -re "type = class vA \{${ws}public:${ws}int va;${ws}int vx;${ws}vA ?& ?operator ?=\\(vA const ?&\\);${ws}vA\\(vA const ?&\\);${ws}vA\\((void|)\\);$nl\}$nl$gdb_prompt $" {
358 # gcc 2.95.3 -gstabs+
360 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
361 pass "ptype class vA"
365 # With gcc 2, gdb prints the virtual base pointer.
366 # With gcc 3, gdb does not print the virtual base pointer.
367 # drow considers it a gdb bug if gdb prints the vbptr.
369 gdb_test_multiple "ptype class vB" "ptype class vB" {
370 -re "type = class vB : public virtual vA \{${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" {
371 # gcc 2.95.3 -gdwarf-2
373 fail "ptype class vB"
375 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;$nl\}$nl$gdb_prompt $" {
376 # gcc 3.3.2 -gdwarf-2
377 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
378 pass "ptype class vB"
380 -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\\);$nl\}$nl$gdb_prompt $" {
381 # gcc 2.95.3 -gstabs+
382 # See the hidden "in-charge" ctor parameter!
385 fail "ptype class vB (FIXME: non-portable virtual table constructs)"
387 -re "type = class vB : public virtual vA \{${ws}public:${ws}int vb;${ws}int vx;${ws}vB ?& ?operator ?=\\(vB const ?&\\);${ws}vB\\(vB const ?&\\);${ws}vB\\((void|)\\);$nl\}$nl$gdb_prompt $" {
389 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
390 pass "ptype class vB"
394 # Another class with a virtual base.
396 gdb_test_multiple "ptype class vC" "ptype class vC" {
397 -re "type = class vC : public virtual vA \{${ws}private:${ws}vA ?\\* ?_vb.2vA;${ws}public:${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" {
398 # gcc 2.95.3 -gdwarf-2
400 fail "ptype class vC"
402 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;$nl\}$nl$gdb_prompt $" {
403 # gcc 3.3.2 -gdwarf-2
404 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
405 pass "ptype class vC"
407 -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\\);$nl\}$nl$gdb_prompt $" {
408 # gcc 2.95.3 -gstabs+
409 # See the hidden "in-charge" ctor parameter!
412 fail "ptype class vC (FIXME: non-portable virtual table constructs)"
414 -re "type = class vC : public virtual vA \{${ws}public:${ws}int vc;${ws}int vx;${ws}vC ?& ?operator ?=\\(vC const ?&\\);${ws}vC\\(vC const ?&\\);${ws}vC\\((void|)\\);$nl\}$nl$gdb_prompt $" {
416 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
417 pass "ptype class vC"
421 # The classic diamond inheritance.
423 gdb_test_multiple "ptype class vD" "ptype class vD" {
424 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC ?\\* ?_vb.2vC;${ws}vB ?\\* ?_vb.2vB;${ws}public:${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" {
425 # gcc 2.95.3 -gdwarf-2
427 fail "ptype class vD"
429 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;$nl\}$nl$gdb_prompt $" {
430 # gcc 3.3.2 -gdwarf-2
431 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
432 pass "ptype class vD"
434 -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\\);$nl\}$nl$gdb_prompt $" {
435 # gcc 2.95.3 -gstabs+
436 # See the hidden "in-charge" ctor parameter!
439 fail "ptype class vD (FIXME: non-portable virtual table constructs)"
441 -re "type = class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;${ws}vD ?& ?operator ?=\\(vD const ?&\\);${ws}vD\\(vD const ?&\\);${ws}vD\\((void|)\\);$nl\}$nl$gdb_prompt $" {
443 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
444 pass "ptype class vD"
448 # One more case of virtual derivation.
450 gdb_test_multiple "ptype class vE" "ptype class vE" {
451 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD ?\\* ?_vb.2vD;${ws}public:${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" {
452 # gcc 2.95.3 -gdwarf-2
454 fail "ptype class vE"
456 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;$nl\}$nl$gdb_prompt $" {
457 # gcc 3.3.2 -gdwarf-2
458 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
459 pass "ptype class vE"
461 -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\\);$nl\}$nl$gdb_prompt $" {
462 # gcc 2.95.3 -gstabs+
463 # See the hidden "in-charge" ctor parameter!
466 fail "ptype class vE (FIXME: non-portable virtual table constructs)"
468 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;${ws}vE ?& ?operator ?=\\(vE const ?&\\);${ws}vE\\(vE const ?&\\);${ws}vE\\((void|)\\);$nl\}$nl$gdb_prompt $" {
470 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
471 pass "ptype class vE"
475 # Another inheritance series.
477 gdb_test_multiple "ptype class Base1" "ptype class Base1" {
478 -re "type = class Base1 \{${ws}public:${ws}int x;${ws}Base1\\(int\\);$nl\}$nl$gdb_prompt $" {
479 # gcc 2.95.3 -gdwarf-2
480 # gcc 3.3.2 -gdwarf-2
481 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
482 pass "ptype class Base1"
484 -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 $" {
485 # gcc 2.95.3 -gstabs+
487 pass "ptype class Base1"
489 -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 $" {
490 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
491 pass "ptype class Base1"
495 # The second base class.
497 gdb_test_multiple "ptype class Foo" "ptype class Foo" {
498 -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 $" {
499 # gcc 2.95.3 -gdwarf-2
500 # gcc 3.3.2 -gdwarf-2
501 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
502 pass "ptype class Foo"
504 -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 $" {
505 # gcc 2.95.3 -gstabs+
506 # TODO: "int operator int()" is a bug
507 # kfail "gdb/1497" "ptype class Foo"
508 pass "ptype class Foo"
510 -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 $" {
512 pass "ptype class Foo"
514 -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 $" {
515 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
516 pass "ptype class Foo"
520 # A multiple inheritance derived class.
522 gdb_test_multiple "ptype class Bar" "ptype class Bar" {
523 -re "type = class Bar : public Base1, public Foo \{${ws}public:${ws}int z;${ws}Bar\\(int, int, int\\);$nl\}$nl$gdb_prompt $" {
524 # gcc 2.95.3 -gdwarf-2
525 # gcc 3.3.2 -gdwarf-2
526 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
527 pass "ptype class Bar"
529 -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 $" {
530 # gcc 2.95.3 -gstabs+
532 pass "ptype class Bar"
534 -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 $" {
535 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
536 pass "ptype class Bar"
541 # Test simple access to class members.
542 # TODO: these test names are gross!
543 # Just let the test name default.
545 proc test_non_inherited_member_access {} {
548 # Print non-inherited members of g_A.
549 gdb_test "print g_A.a" ".* = 1" "g_A.a incorrect"
550 gdb_test "print g_A.x" ".* = 2" "g_A.x incorrect"
552 # Print non-inherited members of g_B.
553 gdb_test "print g_B.b" ".* = 5" "g_B.b incorrect"
554 gdb_test "print g_B.x" ".* = 6" "g_B.x incorrect"
556 # Print non-inherited members of g_C.
557 gdb_test "print g_C.c" ".* = 9" "g_C.c incorrect"
558 gdb_test "print g_C.x" ".* = 10" "g_C.x incorrect"
560 # Print non-inherited members of g_D.
561 gdb_test "print g_D.d" ".* = 19" "g_D.d incorrect"
562 gdb_test "print g_D.x" ".* = 20" "g_D.x incorrect"
564 # Print non-inherited members of g_E.
565 gdb_test "print g_E.e" ".* = 31" "g_E.e incorrect"
566 gdb_test "print g_E.x" ".* = 32" "g_E.x incorrect"
569 # Test access to members of other classes.
570 # gdb should refuse to print them.
571 # (I feel old -- I remember when this was legal in C -- chastain).
572 # TODO: Again, change the silly test names.
574 proc test_wrong_class_members {} {
577 gdb_test "print g_A.b" "There is no member( or method|) named b." "print g_A.b should be error"
578 gdb_test "print g_B.c" "There is no member( or method|) named c." "print g_B.c should be error"
579 gdb_test "print g_B.d" "There is no member( or method|) named d." "print g_B.d should be error"
580 gdb_test "print g_C.b" "There is no member( or method|) named b." "print g_C.b should be error"
581 gdb_test "print g_C.d" "There is no member( or method|) named d." "print g_C.d should be error"
582 gdb_test "print g_D.e" "There is no member( or method|) named e." "print g_D.e should be error"
585 # Test access to names that are not members of any class.
586 # TODO: test names again.
588 proc test_nonexistent_members {} {
591 gdb_test "print g_A.y" "There is no member( or method|) named y." "print g_A.y should be error"
592 gdb_test "print g_B.z" "There is no member( or method|) named z." "print g_B.z should be error"
593 gdb_test "print g_C.q" "There is no member( or method|) named q." "print g_C.q should be error"
594 gdb_test "print g_D.p" "There is no member( or method|) named p." "print g_D.p should be error"
597 # Call a method that expects a base class parameter with base, inherited,
598 # and unrelated class arguments.
600 proc test_method_param_class {} {
601 gdb_test "call class_param.Aptr_a (&g_A)" ".* = 1" "base class param->a"
602 gdb_test "call class_param.Aptr_x (&g_A)" ".* = 2" "base class param->x"
603 gdb_test "call class_param.Aptr_a (&g_B)" ".* = 3" "inherited class param->a"
604 gdb_test "call class_param.Aptr_x (&g_B)" ".* = 4" "inherited class param->x"
605 gdb_test "call class_param.Aref_a (g_A)" ".* = 1" "base class (¶m)->a"
606 gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (¶m)->x"
607 gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (¶m)->a"
608 gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (¶m)->x"
609 gdb_test "call class_param.Aval_a (g_A)" ".* = 1" "base class param.a"
610 gdb_test "call class_param.Aval_x (g_A)" ".* = 2" "base class param.x"
611 gdb_test "call class_param.Aval_a (g_B)" ".* = 3" "inherited class param.a"
612 gdb_test "call class_param.Aval_x (g_B)" ".* = 4" "inherited class param.x"
614 gdb_test "call class_param.Aptr_a (&foo)" "Cannot resolve .*" "unrelated class *param"
615 gdb_test "call class_param.Aref_a (foo)" "Cannot resolve .*" "unrelated class ¶m"
616 gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
619 # Examine a class with an enum field.
628 gdb_test "print obj_with_enum" \
629 "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \
630 "print obj_with_enum (1)"
636 # TODO: with gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2,
637 # gdb says that obj_with_enum is out of scope here and the
638 # tests after this FAIL. This needs investigation.
639 # -- chastain 2003-12-30
641 # print the object again
643 gdb_test "print obj_with_enum" \
644 "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \
645 "print obj_with_enum (2)"
647 # print the enum member
649 gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green"
651 # ptype on the enum member
653 gdb_test_multiple "ptype obj_with_enum.priv_enum" "ptype obj_with_enum.priv_enum" {
654 -re "type = enum ClassWithEnum::PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
655 pass "ptype obj_with_enum.priv_enum"
657 -re "type = enum PrivEnum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
658 # gcc 2.95.3 -gdwarf-2
659 # gcc 3.3.2 -gdwarf-2
660 pass "ptype obj_with_enum.priv_enum"
662 -re "type = enum \{ ?red, green, blue, yellow = 42 ?\}$nl$gdb_prompt $" {
663 # This case case is a little dubious, but it's not clear what
664 # ought to be required of a ptype on a private enum...
667 # It bugs me that this happens with gcc 3.
668 # -- chastain 2003-12-30
670 # gcc 2.95.3 -gstabs+
672 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
673 pass "ptype obj_with_enum.priv_enum"
677 # ptype on the object
678 gdb_test_multiple "ptype obj_with_enum" "ptype obj_with_enum" {
679 -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)ClassWithEnum::PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" {
680 pass "ptype obj_with_enum"
682 -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)PrivEnum priv_enum;${ws}int x;$nl\}$nl$gdb_prompt $" {
683 # NOTE: carlton/2003-02-28: One could certainly argue that
684 # this output is acceptable: PrivEnum is a member of
685 # ClassWithEnum, so there's no need to explicitly qualify
686 # its name with "ClassWithEnum::". The truth, though, is
687 # that GDB is simply forgetting that PrivEnum is a member
688 # of ClassWithEnum, so we do that output for a bad reason
689 # instead of a good reason. Under stabs, we probably
690 # can't get this right; under DWARF-2, we can.
692 # gcc 2.95.3 -gdwarf-2
693 # gcc 3.3.2 -gdwarf-2
694 kfail "gdb/57" "ptype obj_with_enum"
696 -re "type = class ClassWithEnum \{${ws}public:${ws}(enum |)PrivEnum priv_enum;${ws}int x;${ws}ClassWithEnum ?& ?operator ?=\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\(ClassWithEnum const ?&\\);${ws}ClassWithEnum\\((void|)\\);$nl\}$nl$gdb_prompt $" {
697 # gcc 2.95.3 -gstabs+
698 kfail "gdb/57" "ptype obj_with_enum"
700 -re "type = class ClassWithEnum \{${ws}public:${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 $" {
701 # I think this is a PASS, but only carlton knows for sure.
702 # -- chastain 2003-12-30
705 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
706 fail "ptype obj_with_enum"
710 # I'll do this test two different ways, because of a parser bug.
713 gdb_test_multiple "print (ClassWithEnum::PrivEnum) 42" "print (ClassWithEnum::PrivEnum) 42" {
714 -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
715 pass "print (ClassWithEnum::PrivEnum) 42"
717 -re "A (parse|syntax) error in expression, near `42'.$nl$gdb_prompt $" {
718 # "parse error" is bison 1.35.
719 # "syntax error" is bison 1.875.
720 kfail "gdb/826" "print (ClassWithEnum::PrivEnum) 42"
724 gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
725 -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
727 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
728 pass "print ('ClassWithEnum::PrivEnum') 42"
730 -re "No symbol \"ClassWithEnum::PrivEnum\" in current context.$nl$gdb_prompt $" {
731 # gcc 2.95.3 -gdwarf-2
732 # gcc 3.3.2 -gdwarf-2
733 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
734 # gcc 2.95.3 -gstabs+
735 kfail "gdb/57" "print ('ClassWithEnum::PrivEnum') 42"
740 # Pointers to class members
742 proc test_pointers_to_class_members {} {
745 gdb_test "print Bar::z" "\\$\[0-9\]+ = \\(int ?\\( ?Bar::& ?\\) ?\\) ?Bar::z"
746 gdb_test "print &Foo::x" "\\$\[0-9\]+ = \\(int ?\\( ?Foo::\\* ?\\) ?\\) ?&Foo::x"
747 gdb_test "print (int)&Foo::x" "\\$\[0-9\]+ = 0"
748 gdb_test "print (int)&Bar::y == 2*sizeof(int)" "\\$\[0-9\]+ = true"
750 # TODO: this is a bogus test. It's looking at a variable that
751 # has not even been declared yet, so it's accessing random junk
752 # on the stack and comparing that it's NOT equal to a specific
753 # value. It's been like this since gdb 4.10 in 1993!
754 # -- chastain 2004-01-01
755 gdb_test "print (int)pmi == sizeof(int)" ".* = false"
758 # Test static members.
760 proc test_static_members {} {
764 gdb_test "print Foo::st" "\\$\[0-9\]+ = 100"
765 gdb_test "set foo.st = 200" "" ""
766 gdb_test "print bar.st" "\\$\[0-9\]+ = 200"
767 gdb_test "print &foo.st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
768 gdb_test "print &Bar::st" "\\$\[0-9\]+ = \\(int ?\\*\\) $hex"
769 gdb_test "print *\$" "\\$\[0-9\]+ = 200"
771 gdb_test "set print static-members off" ""
772 gdb_test "print csi" \
774 "print csi without static members"
775 gdb_test "print cnsi" \
777 "print cnsi without static members"
779 gdb_test "set print static-members on" ""
780 gdb_test "print csi" \
781 "{x = 10, y = 20, static null = {x = 0, y = 0, static null = <same as static member of an already seen type>}}" \
782 "print csi with static members"
783 gdb_test "print cnsi" \
784 "{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>}" \
785 "print cnsi with static members"
801 # Start with a fresh gdb.
805 gdb_reinitialize_dir $srcdir/$subdir
808 gdb_test "set language c++" "" ""
809 gdb_test "set width 0" "" ""
811 if ![runto_main ] then {
812 perror "couldn't run to breakpoint"
816 gdb_breakpoint inheritance2
817 gdb_test "continue" ".*Breakpoint .* inheritance2.*" ""
819 test_ptype_class_objects
820 test_non_inherited_member_access
821 test_wrong_class_members
822 test_nonexistent_members
823 test_method_param_class
825 gdb_breakpoint enums2
826 gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)"
827 gdb_test "finish" "" ""
830 gdb_test "finish" "" ""
831 test_pointers_to_class_members
834 # Now some random tests that were just thrown in here.
836 gdb_breakpoint marker_reg1
837 gdb_test "continue" ".*Breakpoint .* marker_reg1.*" ""
838 gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
840 # This class is so small that an instance of it can fit in a register.
841 # When gdb tries to call a method, it gets embarrassed about taking
842 # the address of a register.
844 # TODO: I think that message should be a PASS, not an XFAIL.
845 # gdb prints an informative message and declines to do something
848 # The method call actually succeeds if the compiler allocates very
849 # small classes in memory instead of registers. So this test does
850 # not tell us anything interesting if the call succeeds.
852 # -- chastain 2003-12-31
853 gdb_test_multiple "print v.method ()" "calling method for small class" {
854 -re "\\$\[0-9\]+ = 82$nl$gdb_prompt $" {
855 # gcc 3.3.2 -gdwarf-2
856 # gcc HEAD 2003-12-28 21:08:30 UTC -gdwarf-2
858 # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
859 pass "calling method for small class"
861 -re "Address requested for identifier \"v\" which is in register .*$nl$gdb_prompt $" {
862 # gcc 2.95.3 -gdwarf-2
863 # gcc 2.95.3 -gstabs+
864 setup_xfail "*-*-*" 2972
865 fail "calling method for small class"
869 # This is a random v2 demangling test.
870 # This is redundant with existing tests in demangle.exp.
871 # TODO: Just remove this.
872 gdb_test "maint demangle inheritance1__Fv" "inheritance1\\(void\\)" "demangle"