2004-01-08 Michael Chastain <mec.gnu@mindspring.com>
[external/binutils.git] / gdb / testsuite / gdb.cp / virtfunc.exp
1 # Copyright 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004
2 # 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 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Fred Fish. (fnf@cygnus.com)
22 # And rewritten by Michael Chastain <mec.gnu@mindspring.com>.
23
24 set wsopt       "\[\r\n\t \]*"
25 set ws          "\[\r\n\t \]+"
26 set nl          "\[\r\n\]+"
27
28 if $tracelevel then {
29     strace $tracelevel
30 }
31
32 if { [skip_cplus_tests] } { continue }
33
34 set testfile "virtfunc"
35 set srcfile ${testfile}.cc
36 set binfile ${objdir}/${subdir}/${testfile}
37
38 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {c++ debug}] != "" } {
39      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
40 }
41
42 # Test ptype of a class.
43 #
44 # Different C++ compilers produce different output.  I build up regular
45 # expressions piece by piece to accommodate all the compilers that I
46 # have seen: gcc 2.95.3, gcc 3.3.2 (ABI 1), gcc 3.4 prerelease (ABI 2);
47 # and all the debug formats I have seen: dwarf-2 and stabs+.
48 #
49 # A complicated class declaration looks like this:
50 #
51 #   class A : public virtual V {        // re_class
52 #     private:
53 #       V * _vb$V;                      // re_vbptr
54 #       int a;                          // re_fields
55 #
56 #     public:                           // re_access_methods
57 #       A & operator=(A const &);       // re_synth_gcc_2
58 #       A(int, A const &);              // ...
59 #       A(int);                         // ...
60 #       virtual int f(void);            // re_methods
61 #   }
62 #
63 # RE_CLASS matches the class declaration.  C++ allows multiple ways of
64 # expressing this.
65 #
66 #   struct ... { private: ... };
67 #   class ... { private: ... };
68 #   class ... { ... };
69 #
70 # RE_VBPTR matches the virtual base declarations.  gcc 2.95.3 sometimes
71 # emits these, but gcc 3.X.Y never emits these.  The name depends on the
72 # debug format.
73 #
74 # RE_FIELDS matches the data fields of the class.
75 # RE_METHODS matches the methods explicitly declared for the class.
76 #
77 # RE_SYNTH_GCC_2 and RE_SYNTH_GCC_3 match the optional synthetic methods
78 # of the class.  gcc -gstabs+ emits these methods, and gcc -gdwarf-2
79 # does not.
80 #
81 # RE_ACCESS_METHODS is an access specifier after RE_FIELDS and before
82 # the methods (explicit methods and/or synthetic methods).
83 # There is also an RE_ACCESS_FIELDS.
84 #
85 # When I get HP-UX aCC, I hope that I can just add RE_SYNTH_ACC_NNN.
86 #
87 # Yet another twist: with gcc v2, ctor and dtor methods have a hidden
88 # argument in front, the "in-charge" flag.  With gcc v3, there is no
89 # hidden argument; instead, there are multiple object functions for
90 # each ctor and dtor.
91 #
92 # -- chastain 2004-01-01
93
94 # compatibility kludges
95 set kk0 ""
96 set kk1 ""
97 set kk2 ""
98 set kk3 ""
99 set kk4 ""
100 set kk5 ""
101
102 proc kk_debug { } {
103     global kk0
104     global kk1
105     global kk2
106     global kk3
107     global kk4
108     global kk5
109     set kk0 " (0)"
110     set kk1 " (1)"
111     set kk2 " (2)"
112     set kk3 " (3)"
113     set kk4 " (4)"
114     set kk5 " (5)"
115 }
116
117 proc test_one_ptype { command testname re_class re_vbptr re_access_fields re_fields re_access_methods re_methods re_synth_gcc_2 re_synth_gcc_3 re_star } {
118     global gdb_prompt
119     global wsopt
120     global ws
121     global nl
122
123     global kk0
124     global kk1
125     global kk2
126     global kk3
127     global kk4
128     global kk5
129
130     gdb_test_multiple "$command" "$testname" {
131         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
132             # gcc 2.95.3, dwarf-2, no vbptr
133             # gcc 3.X, abi 1, dwarf-2
134             # gcc 3.X, abi 2, dwarf-2
135             pass "$testname$kk0"
136         }
137         -re "type = $re_class${wsopt}$re_vbptr${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
138             # gcc 2.95.3, dwarf-2, vbptr
139             # TODO: drow says the vbptr is a bug
140             pass "$testname$kk1"
141         }
142         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_2${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
143             # gcc 2.95.3, stabs+, no vbptr
144             pass "$testname$kk2"
145         }
146         -re "type = $re_class${wsopt}$re_vbptr${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_2${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
147             # gcc 2.95.3, stabs+, vbptr
148             # TODO: drow says the vbptr is a bug
149             pass "$testname$kk3"
150         }
151         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_synth_gcc_3${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
152             # gcc 3.X, abi 1, stabs+
153             pass "$testname$kk4"
154         }
155         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods${wsopt}$re_synth_gcc_3$nl\}$re_star$nl$gdb_prompt $" {
156             # gcc 3.X, abi 2, stabs+
157             pass "$testname$kk5"
158         }
159     }
160
161     set kk0 ""
162     set kk1 ""
163     set kk2 ""
164     set kk3 ""
165     set kk4 ""
166     set kk5 ""
167 }
168
169 proc test_ptype_of_classes {} {
170     global gdb_prompt
171     global ws
172     global nl
173
174     global kk0
175     global kk1
176     global kk2
177     global kk3
178     global kk4
179     global kk5
180
181     # class VA
182
183     set kk0 " (obsolescent gcc or gdb)"
184     test_one_ptype "ptype VA" "ptype VA" \
185         "((struct|class) VA \{${ws}public:|struct VA \{)" \
186         "" \
187         "" "int va;" \
188         "" "" \
189         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
190         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
191         ""
192
193     # class VB
194
195     set kk0 " (obsolescent gcc or gdb)"
196     test_one_ptype "ptype VB" "ptype VB" \
197         "((struct|class) VB \{${ws}public:|struct VB \{)" \
198         "" \
199         "" "int vb;" \
200         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
201         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
202         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
203         ""
204
205     # class V
206
207     set kk0 " (obsolescent gcc or gdb)"
208     test_one_ptype "ptype V" "ptype V" \
209         "class V : public VA, public VB \{${ws}public:" \
210         "" \
211         "" "int w;" \
212         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
213         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
214         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
215         ""
216
217     # class A
218
219     set kk0 " (aCC)"
220     set kk1 " (obsolescent gcc or gdb)"
221     test_one_ptype "ptype A" "ptype A" \
222         "class A : public virtual V \{(${ws}private:|)" \
223         "V \\*(_vb.1V|_vb.V);" \
224         "" "int a;" \
225         "public:" "virtual int f\\((void|)\\);" \
226         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
227         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
228         ""
229
230     # class B
231
232     set kk0 " (obsolescent gcc or gdb)"
233     test_one_ptype "ptype B" "ptype B" \
234         "class B : public A \{(${ws}private:|)" \
235         "V \\*(_vb.1V|_vb.V);" \
236         "" "int b;" \
237         "public:" "virtual int f\\((void|)\\);" \
238         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
239         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
240         ""
241
242     # class C
243
244     set kk0 " (aCC)"
245     set kk1 " (obsolescent gcc or gdb)"
246     test_one_ptype "ptype C" "ptype C" \
247         "class C : public virtual V \{(${ws}private:|)" \
248         "V \\*(_vb.1V|_vb.V);" \
249         "public:" "int c;" \
250         "" "" \
251         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
252         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\(\\);" \
253         ""
254
255     # class AD
256
257     set kk0 " (obsolescent gcc or gdb)"
258     test_one_ptype "ptype AD" "ptype AD" \
259         "((struct|class) AD \{${ws}public:|struct AD \{)" \
260         "" \
261         "" "" \
262         "" "virtual int vg\\((void|)\\);" \
263         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
264         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
265         ""
266
267     # class D
268
269     set kk0 " (aCC)"
270     set kk1 " (obsolescent gcc or gdb)"
271     test_one_ptype "ptype D" "ptype D" \
272         "class D : public AD, public virtual V \{(${ws}private:|)" \
273         "V \\*(_vb.1V|_vb.V);" \
274         "public:" "int d;" \
275         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
276         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
277         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
278         ""
279
280     # class E
281     # TODO: E does not show a vbptr for V.  That seems strange.
282
283     set kk0 " (obsolescent gcc or gdb)"
284     test_one_ptype "ptype E" "ptype E" \
285         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
286         "" \
287         "public:" "int e;" \
288         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
289         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
290         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
291         ""
292
293     # An instance of D
294
295     set kk0 " (aCC)"
296     set kk1 " (obsolescent gcc or gdb)"
297     test_one_ptype "ptype dd" "ptype dd" \
298         "class D : public AD, public virtual V \{(${ws}private:|)" \
299         "V \\*(_vb.1V|_vb.V);" \
300         "public:" "int d;" \
301         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
302         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
303         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
304         ""
305
306     # An instance of D *
307
308     set kk0 " (aCC)"
309     set kk1 " (obsolescent gcc or gdb)"
310     test_one_ptype "ptype ppd" "ptype ppd" \
311         "class D : public AD, public virtual V \{(${ws}private:|)" \
312         "V \\*(_vb.1V|_vb.V);" \
313         "public:" "int d;" \
314         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
315         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
316         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
317         " ?\\*"
318
319     # An instance of AD *
320     # TODO: this should be named pADd, not pAd.
321
322     set kk0 " (obsolescent gcc or gdb)"
323     test_one_ptype "ptype pAd" "ptype pAd" \
324         "((struct|class) AD \{${ws}public:|struct AD \{)" \
325         "" \
326         "" "" \
327         "" "virtual int vg\\((void|)\\);" \
328         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
329         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
330         " ?\\*"
331
332     # An instance of A
333
334     set kk0 " (aCC)"
335     set kk1 " (obsolescent gcc or gdb)"
336     test_one_ptype "ptype a" "ptype a" \
337         "class A : public virtual V \{(${ws}private:|)" \
338         "V \\*(_vb.1V|_vb.V);" \
339         "" "int a;" \
340         "public:" "virtual int f\\((void|)\\);" \
341         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
342         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
343         ""
344
345     # An instance of B
346
347     set kk0 " (obsolescent gcc or gdb)"
348     test_one_ptype "ptype b" "ptype b" \
349         "class B : public A \{(${ws}private:|)" \
350         "V \\*(_vb.1V|_vb.V);" \
351         "" "int b;" \
352         "public:" "virtual int f\\((void|)\\);" \
353         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
354         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
355         ""
356
357     # An instance of C
358
359     set kk0 " (aCC)"
360     set kk1 " (obsolescent gcc or gdb)"
361     test_one_ptype "ptype c" "ptype c" \
362         "class C : public virtual V \{(${ws}private:|)" \
363         "V \\*(_vb.1V|_vb.V);" \
364         "public:" "int c;" \
365         "" "" \
366         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
367         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\(\\);" \
368         ""
369
370     # An instance of D
371
372     set kk0 " (aCC)"
373     set kk1 " (obsolescent gcc or gdb)"
374     test_one_ptype "ptype d" "ptype d" \
375         "class D : public AD, public virtual V \{(${ws}private:|)" \
376         "V \\*(_vb.1V|_vb.V);" \
377         "public:" "int d;" \
378         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
379         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
380         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
381         ""
382
383     # An instance of E
384
385     set kk0 " (obsolescent gcc or gdb)"
386     test_one_ptype "ptype e" "ptype e" \
387         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
388         "" \
389         "public:" "int e;" \
390         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
391         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
392         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
393         ""
394
395     # An instance of V
396
397     set kk0 " (obsolescent gcc or gdb)"
398     test_one_ptype "ptype v" "ptype v" \
399         "class V : public VA, public VB \{${ws}public:" \
400         "" \
401         "" "int w;" \
402         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
403         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
404         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
405         ""
406
407     # An instance of VB
408
409     set kk0 " (obsolescent gcc or gdb)"
410     test_one_ptype "ptype vb" "ptype vb" \
411         "((struct|class) VB \{${ws}public:|struct VB \{)" \
412         "" \
413         "" "int vb;" \
414         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
415         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
416         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
417         ""
418
419     # An instance of A *
420
421     set kk0 " (aCC)"
422     set kk1 " (obsolescent gcc or gdb)"
423     test_one_ptype "ptype pAa" "ptype pAa" \
424         "class A : public virtual V \{(${ws}private:|)" \
425         "V \\*(_vb.1V|_vb.V);" \
426         "" "int a;" \
427         "public:" "virtual int f\\((void|)\\);" \
428         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
429         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
430         " ?\\*"
431
432     # An instance of A *
433
434     set kk0 " (aCC)"
435     set kk1 " (obsolescent gcc or gdb)"
436     test_one_ptype "ptype pAe" "ptype pAe" \
437         "class A : public virtual V \{(${ws}private:|)" \
438         "V \\*(_vb.1V|_vb.V);" \
439         "" "int a;" \
440         "public:" "virtual int f\\((void|)\\);" \
441         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
442         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
443         " ?\\*"
444
445     # An instance of B *
446
447     set kk0 " (obsolescent gcc or gdb)"
448     test_one_ptype "ptype pBe" "ptype pBe" \
449         "class B : public A \{(${ws}private:|)" \
450         "V \\*(_vb.1V|_vb.V);" \
451         "" "int b;" \
452         "public:" "virtual int f\\((void|)\\);" \
453         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
454         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
455         " ?\\*"
456
457     # An instance of D *
458
459     set kk0 " (aCC)"
460     set kk1 " (obsolescent gcc or gdb)"
461     test_one_ptype "ptype pDd" "ptype pDd" \
462         "class D : public AD, public virtual V \{(${ws}private:|)" \
463         "V \\*(_vb.1V|_vb.V);" \
464         "public:" "int d;" \
465         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
466         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
467         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
468         " ?\\*"
469
470     # An instance of D *
471
472     set kk0 " (aCC)"
473     set kk1 " (obsolescent gcc or gdb)"
474     test_one_ptype "ptype pDe" "ptype pDe" \
475         "class D : public AD, public virtual V \{(${ws}private:|)" \
476         "V \\*(_vb.1V|_vb.V);" \
477         "public:" "int d;" \
478         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
479         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
480         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
481         " ?\\*"
482
483     # An instance of V *
484
485     set kk0 " (obsolescent gcc or gdb)"
486     test_one_ptype "ptype pVa" "ptype pVa" \
487         "class V : public VA, public VB \{${ws}public:" \
488         "" \
489         "" "int w;" \
490         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
491         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
492         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
493         " ?\\*"
494
495     # An instance of V *
496
497     set kk0 " (obsolescent gcc or gdb)"
498     test_one_ptype "ptype pVv" "ptype pVv" \
499         "class V : public VA, public VB \{${ws}public:" \
500         "" \
501         "" "int w;" \
502         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
503         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
504         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
505         " ?\\*"
506
507     # An instance of V *
508
509     set kk0 " (obsolescent gcc or gdb)"
510     test_one_ptype "ptype pVe" "ptype pVe" \
511         "class V : public VA, public VB \{${ws}public:" \
512         "" \
513         "" "int w;" \
514         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
515         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
516         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
517         " ?\\*"
518
519     # An instance of V *
520
521     set kk0 " (obsolescent gcc or gdb)"
522     test_one_ptype "ptype pVd" "ptype pVd" \
523         "class V : public VA, public VB \{${ws}public:" \
524         "" \
525         "" "int w;" \
526         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
527         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
528         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
529         " ?\\*"
530
531     # An instance of AD *
532
533     set kk0 " (obsolescent gcc or gdb)"
534     test_one_ptype "ptype pADe" "ptype pADe" \
535         "((struct|class) AD \{${ws}public:|struct AD \{)" \
536         "" \
537         "" "" \
538         "" "virtual int vg\\((void|)\\);" \
539         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
540         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
541         " ?\\*"
542
543     # An instance of E *
544
545     set kk0 " (obsolescent gcc or gdb)"
546     test_one_ptype "ptype pEe" "ptype pEe" \
547         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
548         "" \
549         "public:" "int e;" \
550         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
551         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
552         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
553         " ?\\*"
554
555     # An instance of VB *
556
557     set kk0 " (obsolescent gcc or gdb)"
558     test_one_ptype "ptype pVB" "ptype pVB" \
559         "((struct|class) VB \{${ws}public:|struct VB \{)" \
560         "" \
561         "" "int vb;" \
562         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
563         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
564         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
565         " ?\\*"
566 }
567
568 # Call virtual functions.
569
570 proc test_virtual_calls {} {
571     global gdb_prompt
572     global nl
573
574     if [target_info exists gdb,cannot_call_functions] {
575         setup_xfail "*-*-*" 2416
576         fail "This target can not call functions"
577         return 0
578     }
579
580     gdb_test "print pAe->f()"   "\\$\[0-9\]+ = 20"
581     gdb_test "print pAa->f()"   "\\$\[0-9\]+ = 1"
582     gdb_test "print pDe->vg()"  "\\$\[0-9\]+ = 202"
583     gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
584     gdb_test "print pDd->vg()"  "\\$\[0-9\]+ = 101"
585     gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
586     gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
587     gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
588     gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
589     gdb_test "print pEe->vd()"  "\\$\[0-9\]+ = 282"
590     gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
591
592     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
593     # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gdwarf-2.
594     #
595     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
596     # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gstabs+.
597     #
598     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
599     # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gdwarf-2.
600     #
601     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
602     # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gstabs+.
603     #
604     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
605     # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gdwarf-2.
606     #
607     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
608     # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gstabs+.
609     #
610     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
611     # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gdwarf-2.
612     #
613     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
614     # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gstabs+.
615     #
616     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
617     # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gdwarf-2.
618     #
619     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
620     # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gstabs+.
621     #
622     # -- chastain 2002-02-20
623
624     # more recent results:
625     # wrong value "202"
626     #   gcc 2.95.3 -gdwarf-2
627     #   gcc 2.95.3 -gstabs+
628     # attempt to take addres of value not located in memory
629     #   gcc 3.3.2 -gdwarf-2
630     #   gcc 3.3.2 -gstabs+
631     #
632     # -- chastain 2003-12-31
633
634     gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
635         -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
636             pass "print pEe->D::vg()"
637         }
638         -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
639             kfail "gdb/1064" "print pEe->D::vg()"
640         }
641     }
642 }
643
644 proc do_tests {} {
645     global prms_id
646     global bug_id
647     global srcdir subdir binfile
648     global gdb_prompt
649
650     set prms_id 0
651     set bug_id 0
652
653     gdb_exit
654     gdb_start
655     gdb_reinitialize_dir $srcdir/$subdir
656     gdb_load $binfile
657
658     gdb_test "set language c++" "" ""
659     gdb_test "set width 0" "" ""
660
661     runto_main
662     test_ptype_of_classes
663
664     gdb_breakpoint test_calls
665     gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
666     test_virtual_calls
667 }
668
669 do_tests