OSDN Git Service

74f328e0f5c234e028b760a972bb010065193fa9
[pf3gnuchains/pf3gnuchains3x.git] / gdb / testsuite / gdb.cp / classes.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2 # 2003, 2004 Free Software Foundation, Inc.
3
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.
8
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.
13
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.  
17
18 # This file was written by Fred Fish. (fnf@cygnus.com)
19 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
20
21 set ws "\[\r\n\t \]+"
22 set nl "\[\r\n\]+"
23
24 if $tracelevel then {
25     strace $tracelevel
26 }
27
28 if { [skip_cplus_tests] } { continue }
29
30 set testfile "classes"
31 set srcfile ${testfile}.cc
32 set binfile ${objdir}/${subdir}/${testfile}
33
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."
36 }
37
38 # Test ptype of class objects.
39 #
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++.
42 #
43 # There are lots of variations in the output:
44 #
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.
49 #
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
55 #   to abi version 2.
56 #
57 # . gcc v2 shows data members for virtual base pointers.
58 #   gcc v3 does not.
59 #
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.
65
66 proc test_ptype_class_objects {} {
67     global gdb_prompt
68     global ws
69     global nl
70
71     # Simple type.
72
73     set re_class "((struct|class) default_public_struct \{${ws}public:|struct default_public_struct \{)"
74
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
78             # gcc 3.3.2 -gdwarf-2
79             # gcc 3.4.1 -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"
83         }
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 $" {
85             # gcc 2.95.3 -gstabs+
86             # gcc 3.3.2 -gstabs+
87             # gcc 3.4.1 -gstabs+
88             pass "ptype struct default_public_struct"
89         }
90     }
91
92     # Same test, slightly different type.
93
94     set re_class "((struct|class) explicit_public_struct \{${ws}public:|struct explicit_public_struct \{)"
95
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
99             # gcc 3.3.2 -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"
104         }
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+
107             # gcc 3.3.2 -gstabs+
108             # gcc 3.4.1 -gstabs+
109             pass "ptype struct explicit_public_struct"
110         }
111     }
112
113     # Same test, slightly different type.
114
115     set re_class "((struct|class) protected_struct \{${ws}protected:)"
116
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"
125         }
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+
128             # gcc 3.3.2 -gstabs+
129             # gcc 3.4.1 -gstabs+
130             pass "ptype struct protected_struct"
131         }
132     }
133
134     # Same test, slightly different type.
135
136     set re_class "((struct|class) private_struct \{${ws}private:|class private_struct \{)"
137
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"
146         }
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+
149             # gcc 3.3.2 -gstabs+
150             # gcc 3.4.1 -gstabs+
151             pass "ptype struct private_struct"
152         }
153     }
154
155     # Similar test, bigger type.
156
157     set re_class "((struct|class) mixed_protection_struct \{${ws}public:|struct mixed_protection_struct \{)"
158
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"
167         }
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+
170             # gcc 3.3.2 -gstabs+
171             # gcc 3.4.1 -gstabs+
172             pass "ptype struct mixed_protection_struct"
173         }
174     }
175
176     # All that again with "class" instead of "struct".
177     # gdb does not care about the difference anyways.
178
179     set re_class "((struct|class) public_class \{${ws}public:|struct public_class \{)"
180
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"
189         }
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+
192             # gcc 3.3.2 -gstabs+
193             # gcc 3.4.1 -gstabs+
194             pass "ptype class public_class"
195         }
196     }
197
198     # Same test, slightly different type.
199
200     set re_class "((struct|class) protected_class \{${ws}protected:)"
201
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"
210         }
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+
213             # gcc 3.3.2 -gstabs+
214             # gcc 3.4.1 -gstabs+
215             pass "ptype class protected_class"
216         }
217     }
218
219     # Same test, slightly different type.
220
221     set re_class "((struct|class) default_private_class \{${ws}private:|class default_private_class \{)"
222
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"
231         }
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+
234             # gcc 3.3.2 -gstabs+
235             # gcc 3.4.1 -gstabs+
236             pass "ptype class default_private_class"
237         }
238     }
239
240     # Same test, slightly different type.
241
242     set re_class "((struct|class) explicit_private_class \{${ws}private:|class explicit_private_class \{)"
243
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"
252         }
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+
255             # gcc 3.3.2 -gstabs+
256             # gcc 3.4.1 -gstabs+
257             pass "ptype class explicit_private_class"
258         }
259     }
260
261     # Similar test, bigger type.
262
263     set re_class "((struct|class) mixed_protection_class \{${ws}public:|struct mixed_protection_class \{)"
264
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"
273         }
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+
276             # gcc 3.3.2 -gstabs+
277             # gcc 3.4.1 -gstabs+
278             pass "ptype class mixed_protection_class"
279         }
280     }
281
282     # Here are some classes with inheritance.
283
284     # Base class.
285
286     set re_class "((struct|class) A \{${ws}public:|struct A \{)"
287
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+
295             pass "ptype class A"
296         }
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+
299             # gcc 3.3.2 -gstabs+
300             # gcc 3.4.1 -gstabs+
301             pass "ptype class A"
302         }
303     }
304
305     # Derived class.
306
307     set re_class "((struct|class) B : public A \{${ws}public:|struct B : public A \{)"
308
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+
316             pass "ptype class B"
317         }
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+
320             # gcc 3.3.2 -gstabs+
321             # gcc 3.4.1 -gstabs+
322             pass "ptype class B"
323         }
324     }
325
326     # Derived class.
327
328     set re_class "((struct|class) C : public A \{${ws}public:|struct C : public A \{)"
329
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+
337             pass "ptype class C"
338         }
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+
341             # gcc 3.3.2 -gstabs+
342             # gcc 3.4.1 -gstabs+
343             pass "ptype class C"
344         }
345     }
346
347     # Derived class, multiple inheritance.
348
349     set re_class "((struct|class) D : public B, public C \{${ws}public:|struct D : public B, public C \{)"
350
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+
358             pass "ptype class D"
359         }
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+
362             # gcc 3.3.2 -gstabs+
363             # gcc 3.4.1 -gstabs+
364             pass "ptype class D"
365         }
366     }
367
368     # Derived class.
369
370     set re_class "((struct|class) E : public D \{${ws}public:|struct E : public D \{)"
371
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+
379             pass "ptype class E"
380         }
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+
383             # gcc 3.3.2 -gstabs+
384             # gcc 3.4.1 -gstabs+
385             pass "ptype class E"
386         }
387     }
388
389     # This is a break from inheritance tests.
390     #
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.
393  
394     set re_class "((struct|class) Static \{${ws}public:|struct Static \{)"
395
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"
404         }
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+
407             # gcc 3.3.2 -gstabs+
408             pass "ptype class Static"
409         }
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 $" {
411             # gcc 3.4.1 -gstabs+
412             pass "ptype class Static"
413         }
414     }
415
416     # Here are some virtual inheritance tests.
417
418     set re_class "((struct|class) vA \{${ws}public:|struct vA \{)"
419
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"
428         }
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+
431             # gcc 3.3.2 -gstabs+
432             # gcc 3.4.1 -gstabs+
433             pass "ptype class vA"
434         }
435     }
436
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.
440
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 \{)"
443
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
447             # TODO: kfail this
448             fail "ptype class vB"
449         }
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"
455         }
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!
459             # TODO: kfail this
460             setup_xfail "*-*-*"
461             fail "ptype class vB (FIXME: non-portable virtual table constructs)"
462         }
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 $" {
464             # gcc 3.3.4 -gstabs+
465             # gcc 3.4.1 -gstabs+
466             pass "ptype class vB"
467         }
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"
471         }
472     }
473
474     # Another class with a virtual base.
475
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 \{)"
478
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
482             # TODO: kfail this
483             fail "ptype class vC"
484         }
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"
490         }
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!
494             # TODO: kfail this
495             setup_xfail "*-*-*"
496             fail "ptype class vC (FIXME: non-portable virtual table constructs)"
497         }
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 $" {
499             # gcc 3.3.4 -gstabs+
500             # gcc 3.4.1 -gstabs+
501             pass "ptype class vC"
502         }
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"
506         }
507     }
508
509     # The classic diamond inheritance.
510
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 \{)"
513
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
517             # TODO: kfail
518             fail "ptype class vD"
519         }
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"
525         }
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!
529             # TODO: kfail
530             setup_xfail "*-*-*"
531             fail "ptype class vD (FIXME: non-portable virtual table constructs)"
532         }
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 $" {
534             # gcc 3.3.2 -gstabs+
535             # gcc 3.4.1 -gstabs+
536             pass "ptype class vD"
537         }
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"
541         }
542     }
543
544     # One more case of virtual derivation.
545
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 \{)"
548
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
552             # TODO: kfail
553             fail "ptype class vE"
554         }
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"
560         }
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!
564             # TODO: kfail
565             setup_xfail "*-*-*"
566             fail "ptype class vE (FIXME: non-portable virtual table constructs)"
567         }
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 $" {
569             # gcc 3.3.2 -gstabs+
570             # gcc 3.4.1 -gstabs+
571             pass "ptype class vE"
572         }
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"
576         }
577     }
578
579     # Another inheritance series.
580
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"
587         }
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+
590             # gcc 3.3.2 -gstabs+
591             pass "ptype class Base1"
592         }
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"
596         }
597     }
598
599     # The second base class.
600
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"
607         }
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"
613         }
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 $" {
615             # gcc 3.3.2 -gstabs+
616             pass "ptype class Foo"
617         }
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"
621         }
622     }
623
624     # A multiple inheritance derived class.
625
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"
632         }
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+
635             # gcc 3.3.2 -gstabs+
636             pass "ptype class Bar"
637         }
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"
641         }
642     }
643 }
644
645 # Test simple access to class members.
646 # TODO: these test names are gross!
647 # Just let the test name default.
648
649 proc test_non_inherited_member_access {} {
650     global gdb_prompt
651     
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"
655
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"
659
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"
663
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"
667
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"
671 }
672
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.
677
678 proc test_wrong_class_members {} {
679     global gdb_prompt
680
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"
687 }
688
689 # Test access to names that are not members of any class.
690 # TODO: test names again.
691
692 proc test_nonexistent_members {} {
693     global gdb_prompt
694
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"
699 }
700
701 # Call a method that expects a base class parameter with base, inherited,
702 # and unrelated class arguments.
703
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 (&param)->a"
710     gdb_test "call class_param.Aref_x (g_A)" ".* = 2" "base class (&param)->x"
711     gdb_test "call class_param.Aref_a (g_B)" ".* = 3" "inherited class (&param)->a"
712     gdb_test "call class_param.Aref_x (g_B)" ".* = 4" "inherited class (&param)->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"
717
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 &param"
720     gdb_test "call class_param.Aval_a (foo)" "Cannot resolve .*" "unrelated class param"
721 }
722
723 # Examine a class with an enum field.
724
725 proc test_enums {} {
726     global gdb_prompt
727     global nl
728     global ws
729
730     # print the object
731
732     gdb_test "print obj_with_enum" \
733         "\\$\[0-9\]+ = \{priv_enum = red, x = 0\}" \
734         "print obj_with_enum (1)"
735
736     # advance one line
737
738     gdb_test "next" ""
739
740     # print the object again
741
742     gdb_test "print obj_with_enum" \
743         "\\$\[0-9\]+ = \{priv_enum = green, x = 0\}" \
744         "print obj_with_enum (2)"
745
746     # print the enum member
747
748     gdb_test "print obj_with_enum.priv_enum" "\\$\[0-9\]+ = green"
749
750     # ptype on the enum member
751
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"
755         }
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"
760         }
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...
764             # -sts 19990324
765             #
766             # It bugs me that this happens with gcc 3.
767             # -- chastain 2003-12-30
768             #
769             # gcc 2.95.3 -gstabs+
770             # gcc 3.3.2 -gstabs+
771             # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
772             pass "ptype obj_with_enum.priv_enum"
773         }
774     }
775
776     # ptype on the object
777
778     set re_class "((struct|class) ClassWithEnum \{${ws}public:|struct ClassWithEnum \{)"
779
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"
783         }
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.
793             #
794             # gcc 2.95.3 -gdwarf-2
795             # gcc 3.3.2 -gdwarf-2
796             kfail "gdb/57" "ptype obj_with_enum"
797         }
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"
801         }
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
805             #
806             # gcc 3.3.2 -gstabs+
807             # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
808             fail "ptype obj_with_enum"
809         }
810     }
811
812     # I'll do this test two different ways, because of a parser bug.
813     # See PR gdb/1588.
814
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"
818         }
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"
823         }
824     }
825
826     gdb_test_multiple "print ('ClassWithEnum::PrivEnum') 42" "print ('ClassWithEnum::PrivEnum') 42" {
827         -re "\\$\[0-9\]+ = yellow$nl$gdb_prompt $" {
828             # gcc 3.3.2 -gstabs+
829             # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
830             pass "print ('ClassWithEnum::PrivEnum') 42"
831         }
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"
838         }
839     }
840 }
841
842 # Pointers to class members
843
844 proc test_pointers_to_class_members {} {
845     global gdb_prompt
846
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"
851
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"
858 }
859
860 # Test static members.
861
862 proc test_static_members {} {
863     global gdb_prompt
864     global hex
865
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"
872
873     gdb_test "set print static-members off" ""
874     gdb_test "print csi" \
875         "{x = 10, y = 20}" \
876         "print csi without static members"
877     gdb_test "print cnsi" \
878         "{x = 30, y = 40}" \
879         "print cnsi without static members"
880
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"
888 }
889
890 proc do_tests {} {
891     global prms_id
892     global bug_id
893     global subdir
894     global objdir
895     global srcdir
896     global binfile
897     global gdb_prompt
898     global nl
899
900     set prms_id 0
901     set bug_id 0
902
903     # Start with a fresh gdb.
904
905     gdb_exit
906     gdb_start
907     gdb_reinitialize_dir $srcdir/$subdir
908     gdb_load $binfile
909
910     gdb_test "set language c++" "" ""
911     gdb_test "set width 0" "" ""
912
913     if ![runto_main ] then {
914         perror "couldn't run to breakpoint"
915         return
916     }
917
918     gdb_breakpoint inheritance2
919     gdb_test "continue" ".*Breakpoint .* inheritance2.*" ""
920
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
926
927     gdb_breakpoint enums2
928     gdb_test "continue" ".*Breakpoint .* enums2.*" "continue to enums2(\\(\\)|)"
929     gdb_test "finish" "" ""
930     test_enums
931
932     gdb_test "finish" "" ""
933     test_pointers_to_class_members
934     test_static_members
935
936     # Now some random tests that were just thrown in here.
937
938     gdb_breakpoint marker_reg1
939     gdb_test "continue" ".*Breakpoint .* marker_reg1.*" ""
940     gdb_test "finish" "Run till exit from.*" "finish from marker_reg1"
941
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.
945     #
946     # TODO: I think that message should be a PASS, not an XFAIL.
947     # gdb prints an informative message and declines to do something
948     # impossible.
949     #
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.
953     #
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
959             # gcc 3.3.2 -gstabs+
960             # gcc HEAD 2003-12-28 21:08:30 UTC -gstabs+
961             pass "calling method for small class"
962         }
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"
968         }
969     }
970
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"
975 }
976
977 do_tests