2004-01-01 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 set fk5 ""
102
103 proc kk_debug { } {
104     global kk0
105     global kk1
106     global kk2
107     global kk3
108     global kk4
109     global kk5
110     global fk5
111     set kk0 " (0)"
112     set kk1 " (1)"
113     set kk2 " (2)"
114     set kk3 " (3)"
115     set kk4 " (4)"
116     set kk5 " (5)"
117     set fk5 ""
118 }
119
120 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 } {
121     global gdb_prompt
122     global wsopt
123     global ws
124     global nl
125
126     global kk0
127     global kk1
128     global kk2
129     global kk3
130     global kk4
131     global kk5
132     global fk5
133
134     gdb_test_multiple "$command" "$testname" {
135         -re "type = $re_class${wsopt}$re_access_fields${wsopt}$re_fields${wsopt}$re_access_methods${wsopt}$re_methods$nl\}$re_star$nl$gdb_prompt $" {
136             # gcc 2.95.3, dwarf-2, no vbptr
137             # gcc 3.X, abi 1, dwarf-2
138             # gcc 3.X, abi 2, dwarf-2
139             pass "$testname$kk0"
140         }
141         -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 $" {
142             # gcc 2.95.3, dwarf-2, vbptr
143             # TODO: drow says the vbptr is a bug
144             pass "$testname$kk1"
145         }
146         -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 $" {
147             # gcc 2.95.3, stabs+, no vbptr
148             pass "$testname$kk2"
149         }
150         -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 $" {
151             # gcc 2.95.3, stabs+, vbptr
152             # TODO: drow says the vbptr is a bug
153             pass "$testname$kk3"
154         }
155         -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 $" {
156             # gcc 3.X, abi 1, stabs+
157             pass "$testname$kk4"
158         }
159         -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 $" {
160             # gcc 3.X, abi 2, stabs+
161             if { "$fk5" == "fail" } {
162                 fail "$testname$kk5"
163             } else {
164                 pass "$testname$kk5"
165             }
166         }
167     }
168
169     set kk0 ""
170     set kk1 ""
171     set kk2 ""
172     set kk3 ""
173     set kk4 ""
174     set kk5 ""
175     set fk5 ""
176 }
177
178 proc test_ptype_of_classes {} {
179     global gdb_prompt
180     global ws
181     global nl
182
183     global kk0
184     global kk1
185     global kk2
186     global kk3
187     global kk4
188     global kk5
189     global fk5
190
191     # class VA
192
193     set kk0 " (obsolescent gcc or gdb)"
194     test_one_ptype "ptype VA" "ptype VA" \
195         "((struct|class) VA \{${ws}public:|struct VA \{)" \
196         "" \
197         "" "int va;" \
198         "" "" \
199         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
200         "VA & operator=\\(VA const ?&\\);${ws}VA\\(VA const ?&\\);${ws}VA\\((void|)\\);" \
201         ""
202
203     # class VB
204
205     set kk0 " (obsolescent gcc or gdb)"
206     set kk5 " (obsolescent gcc or gdb)"
207     test_one_ptype "ptype VB" "ptype VB" \
208         "((struct|class) VB \{${ws}public:|struct VB \{)" \
209         "" \
210         "" "int vb;" \
211         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
212         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
213         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
214         ""
215
216     # class V
217
218     set kk0 " (obsolescent gcc or gdb)"
219     set kk5 " (obsolescent gcc or gdb)"
220     test_one_ptype "ptype V" "ptype V" \
221         "class V : public VA, public VB \{${ws}public:" \
222         "" \
223         "" "int w;" \
224         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
225         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
226         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
227         ""
228
229     # class A
230
231     set kk0 " (aCC)"
232     set kk1 " (obsolescent gcc or gdb)"
233     set fk5 "fail"
234     test_one_ptype "ptype A" "ptype A" \
235         "class A : public virtual V \{(${ws}private:|)" \
236         "V \\*(_vb.1V|_vb.V);" \
237         "" "int a;" \
238         "public:" "virtual int f\\((void|)\\);" \
239         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
240         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
241         ""
242
243     # class B
244
245     set kk0 " (obsolescent gcc or gdb)"
246     set fk5 "fail"
247     test_one_ptype "ptype B" "ptype B" \
248         "class B : public A \{(${ws}private:|)" \
249         "V \\*(_vb.1V|_vb.V);" \
250         "" "int b;" \
251         "public:" "virtual int f\\((void|)\\);" \
252         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
253         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
254         ""
255
256     # class C
257
258     set kk0 " (aCC)"
259     set kk1 " (obsolescent gcc or gdb)"
260     test_one_ptype "ptype C" "ptype C" \
261         "class C : public virtual V \{(${ws}private:|)" \
262         "V \\*(_vb.1V|_vb.V);" \
263         "public:" "int c;" \
264         "" "" \
265         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
266         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\(\\);" \
267         ""
268
269     # class AD
270
271     set kk0 " (obsolescent gcc or gdb)"
272     set kk5 " (obsolescent gcc or gdb)"
273     test_one_ptype "ptype AD" "ptype AD" \
274         "((struct|class) AD \{${ws}public:|struct AD \{)" \
275         "" \
276         "" "" \
277         "" "virtual int vg\\((void|)\\);" \
278         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
279         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
280         ""
281
282     # class D
283
284     set kk0 " (aCC)"
285     set kk1 " (obsolescent gcc or gdb)"
286     set fk5 "fail"
287     test_one_ptype "ptype D" "ptype D" \
288         "class D : public AD, public virtual V \{(${ws}private:|)" \
289         "V \\*(_vb.1V|_vb.V);" \
290         "public:" "int d;" \
291         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
292         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
293         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
294         ""
295
296     # class E
297     # TODO: E does not show a vbptr for V.  That seems strange.
298
299     set kk0 " (obsolescent gcc or gdb)"
300     set fk5 "fail"
301     test_one_ptype "ptype E" "ptype E" \
302         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
303         "" \
304         "public:" "int e;" \
305         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
306         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
307         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
308         ""
309
310     # An instance of D
311
312     set kk0 " (aCC)"
313     set kk1 " (obsolescent gcc or gdb)"
314     set fk5 "fail"
315     test_one_ptype "ptype dd" "ptype dd" \
316         "class D : public AD, public virtual V \{(${ws}private:|)" \
317         "V \\*(_vb.1V|_vb.V);" \
318         "public:" "int d;" \
319         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
320         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
321         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
322         ""
323
324     # An instance of D *
325
326     set kk0 " (aCC)"
327     set kk1 " (obsolescent gcc or gdb)"
328     set fk5 "fail"
329     test_one_ptype "ptype ppd" "ptype ppd" \
330         "class D : public AD, public virtual V \{(${ws}private:|)" \
331         "V \\*(_vb.1V|_vb.V);" \
332         "public:" "int d;" \
333         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
334         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
335         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
336         " ?\\*"
337
338     # An instance of AD *
339     # TODO: this should be named pADd, not pAd.
340
341     set kk0 " (obsolescent gcc or gdb)"
342     set kk5 " (obsolescent gcc or gdb)"
343     test_one_ptype "ptype pAd" "ptype pAd" \
344         "((struct|class) AD \{${ws}public:|struct AD \{)" \
345         "" \
346         "" "" \
347         "" "virtual int vg\\((void|)\\);" \
348         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
349         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
350         " ?\\*"
351
352     # An instance of A
353
354     set kk0 " (aCC)"
355     set kk1 " (obsolescent gcc or gdb)"
356     set fk5 "fail"
357     test_one_ptype "ptype a" "ptype a" \
358         "class A : public virtual V \{(${ws}private:|)" \
359         "V \\*(_vb.1V|_vb.V);" \
360         "" "int a;" \
361         "public:" "virtual int f\\((void|)\\);" \
362         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
363         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
364         ""
365
366     # An instance of B
367
368     set kk0 " (obsolescent gcc or gdb)"
369     set fk5 "fail"
370     test_one_ptype "ptype b" "ptype b" \
371         "class B : public A \{(${ws}private:|)" \
372         "V \\*(_vb.1V|_vb.V);" \
373         "" "int b;" \
374         "public:" "virtual int f\\((void|)\\);" \
375         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
376         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
377         ""
378
379     # An instance of C
380
381     set kk0 " (aCC)"
382     set kk1 " (obsolescent gcc or gdb)"
383     test_one_ptype "ptype c" "ptype c" \
384         "class C : public virtual V \{(${ws}private:|)" \
385         "V \\*(_vb.1V|_vb.V);" \
386         "public:" "int c;" \
387         "" "" \
388         "C & operator=\\(C const ?&\\);${ws}C\\(int, C const ?&\\);${ws}C\\(int\\);" \
389         "C & operator=\\(C const ?&\\);${ws}C\\(C const ?&\\);${ws}C\\(\\);" \
390         ""
391
392     # An instance of D
393
394     set kk0 " (aCC)"
395     set kk1 " (obsolescent gcc or gdb)"
396     set fk5 "fail"
397     test_one_ptype "ptype d" "ptype d" \
398         "class D : public AD, public virtual V \{(${ws}private:|)" \
399         "V \\*(_vb.1V|_vb.V);" \
400         "public:" "int d;" \
401         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
402         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
403         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
404         ""
405
406     # An instance of E
407
408     set kk0 " (obsolescent gcc or gdb)"
409     set fk5 "fail"
410     test_one_ptype "ptype e" "ptype e" \
411         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
412         "" \
413         "public:" "int e;" \
414         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
415         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
416         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
417         ""
418
419     # An instance of V
420
421     set kk0 " (obsolescent gcc or gdb)"
422     set kk5 " (obsolescent gcc or gdb)"
423     test_one_ptype "ptype v" "ptype v" \
424         "class V : public VA, public VB \{${ws}public:" \
425         "" \
426         "" "int w;" \
427         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
428         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
429         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
430         ""
431
432     # An instance of VB
433
434     set kk0 " (obsolescent gcc or gdb)"
435     set kk5 " (obsolescent gcc or gdb)"
436     test_one_ptype "ptype vb" "ptype vb" \
437         "((struct|class) VB \{${ws}public:|struct VB \{)" \
438         "" \
439         "" "int vb;" \
440         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
441         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
442         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
443         ""
444
445     # An instance of A *
446
447     set kk0 " (aCC)"
448     set kk1 " (obsolescent gcc or gdb)"
449     set fk5 "fail"
450     test_one_ptype "ptype pAa" "ptype pAa" \
451         "class A : public virtual V \{(${ws}private:|)" \
452         "V \\*(_vb.1V|_vb.V);" \
453         "" "int a;" \
454         "public:" "virtual int f\\((void|)\\);" \
455         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
456         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
457         " ?\\*"
458
459     # An instance of A *
460
461     set kk0 " (aCC)"
462     set kk1 " (obsolescent gcc or gdb)"
463     set fk5 "fail"
464     test_one_ptype "ptype pAe" "ptype pAe" \
465         "class A : public virtual V \{(${ws}private:|)" \
466         "V \\*(_vb.1V|_vb.V);" \
467         "" "int a;" \
468         "public:" "virtual int f\\((void|)\\);" \
469         "A & operator=\\(A const ?&\\);${ws}A\\(int, A const ?&\\);${ws}A\\(int\\);" \
470         "A & operator=\\(A const ?&\\);${ws}A\\(A const ?&\\);${ws}A\\(\\);" \
471         " ?\\*"
472
473     # An instance of B *
474
475     set kk0 " (obsolescent gcc or gdb)"
476     set fk5 "fail"
477     test_one_ptype "ptype pBe" "ptype pBe" \
478         "class B : public A \{(${ws}private:|)" \
479         "V \\*(_vb.1V|_vb.V);" \
480         "" "int b;" \
481         "public:" "virtual int f\\((void|)\\);" \
482         "B & operator=\\(B const ?&\\);${ws}B\\(int, B const ?&\\);${ws}B\\(int\\);" \
483         "B & operator=\\(B const ?&\\);${ws}B\\(B const ?&\\);${ws}B\\(\\);" \
484         " ?\\*"
485
486     # An instance of D *
487
488     set kk0 " (aCC)"
489     set kk1 " (obsolescent gcc or gdb)"
490     set fk5 "fail"
491     test_one_ptype "ptype pDd" "ptype pDd" \
492         "class D : public AD, public virtual V \{(${ws}private:|)" \
493         "V \\*(_vb.1V|_vb.V);" \
494         "public:" "int d;" \
495         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
496         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
497         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
498         " ?\\*"
499
500     # An instance of D *
501
502     set kk0 " (aCC)"
503     set kk1 " (obsolescent gcc or gdb)"
504     set fk5 "fail"
505     test_one_ptype "ptype pDe" "ptype pDe" \
506         "class D : public AD, public virtual V \{(${ws}private:|)" \
507         "V \\*(_vb.1V|_vb.V);" \
508         "public:" "int d;" \
509         "" "static void s\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vd\\((void|)\\);${ws}int fd\\((void|)\\);" \
510         "D & operator=\\(D const ?&\\);${ws}D\\(int, D const ?&\\);${ws}D\\(int\\);" \
511         "D & operator=\\(D const ?&\\);${ws}D\\(D const ?&\\);${ws}D\\(\\);" \
512         " ?\\*"
513
514     # An instance of V *
515
516     set kk0 " (obsolescent gcc or gdb)"
517     set kk5 " (obsolescent gcc or gdb)"
518     test_one_ptype "ptype pVa" "ptype pVa" \
519         "class V : public VA, public VB \{${ws}public:" \
520         "" \
521         "" "int w;" \
522         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
523         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
524         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
525         " ?\\*"
526
527     # An instance of V *
528
529     set kk0 " (obsolescent gcc or gdb)"
530     set kk5 " (obsolescent gcc or gdb)"
531     test_one_ptype "ptype pVv" "ptype pVv" \
532         "class V : public VA, public VB \{${ws}public:" \
533         "" \
534         "" "int w;" \
535         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
536         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
537         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
538         " ?\\*"
539
540     # An instance of V *
541
542     set kk0 " (obsolescent gcc or gdb)"
543     set kk5 " (obsolescent gcc or gdb)"
544     test_one_ptype "ptype pVe" "ptype pVe" \
545         "class V : public VA, public VB \{${ws}public:" \
546         "" \
547         "" "int w;" \
548         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
549         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
550         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
551         " ?\\*"
552
553     # An instance of V *
554
555     set kk0 " (obsolescent gcc or gdb)"
556     set kk5 " (obsolescent gcc or gdb)"
557     test_one_ptype "ptype pVd" "ptype pVd" \
558         "class V : public VA, public VB \{${ws}public:" \
559         "" \
560         "" "int w;" \
561         "" "int f\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
562         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
563         "V & operator=\\(V const ?&\\);${ws}V\\(V const ?&\\);${ws}V\\((void|)\\);" \
564         " ?\\*"
565
566     # An instance of AD *
567
568     set kk0 " (obsolescent gcc or gdb)"
569     set kk5 " (obsolescent gcc or gdb)"
570     test_one_ptype "ptype pADe" "ptype pADe" \
571         "((struct|class) AD \{${ws}public:|struct AD \{)" \
572         "" \
573         "" "" \
574         "" "virtual int vg\\((void|)\\);" \
575         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
576         "AD & operator=\\(AD const ?&\\);${ws}AD\\(AD const ?&\\);${ws}AD\\((void|)\\);" \
577         " ?\\*"
578
579     # An instance of E *
580
581     set kk0 " (obsolescent gcc or gdb)"
582     set fk5 "fail"
583     test_one_ptype "ptype pEe" "ptype pEe" \
584         "class E : public B, public virtual V, public D, public C \{(${ws}private:|)" \
585         "" \
586         "public:" "int e;" \
587         "" "virtual int f\\((void|)\\);${ws}virtual int vg\\((void|)\\);${ws}virtual int vv\\((void|)\\);" \
588         "E & operator=\\(E const ?&\\);${ws}E\\(int, E const ?&\\);${ws}E\\(int\\);" \
589         "E & operator=\\(E const ?&\\);${ws}E\\(E const ?&\\);${ws}E\\(\\);" \
590         " ?\\*"
591
592     # An instance of VB *
593
594     set kk0 " (obsolescent gcc or gdb)"
595     set kk5 " (obsolescent gcc or gdb)"
596     test_one_ptype "ptype pVB" "ptype pVB" \
597         "((struct|class) VB \{${ws}public:|struct VB \{)" \
598         "" \
599         "" "int vb;" \
600         "" "int fvb\\((void|)\\);${ws}virtual int vvb\\((void|)\\);" \
601         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
602         "VB & operator=\\(VB const ?&\\);${ws}VB\\(VB const ?&\\);${ws}VB\\((void|)\\);" \
603         " ?\\*"
604 }
605
606 # Call virtual functions.
607
608 proc test_virtual_calls {} {
609     global gdb_prompt
610     global nl
611
612     if [target_info exists gdb,cannot_call_functions] {
613         setup_xfail "*-*-*" 2416
614         fail "This target can not call functions"
615         return 0
616     }
617
618     gdb_test "print pAe->f()"   "\\$\[0-9\]+ = 20"
619     gdb_test "print pAa->f()"   "\\$\[0-9\]+ = 1"
620     gdb_test "print pDe->vg()"  "\\$\[0-9\]+ = 202"
621     gdb_test "print pADe->vg()" "\\$\[0-9\]+ = 202"
622     gdb_test "print pDd->vg()"  "\\$\[0-9\]+ = 101"
623     gdb_test "print pEe->vvb()" "\\$\[0-9\]+ = 411"
624     gdb_test "print pVB->vvb()" "\\$\[0-9\]+ = 407"
625     gdb_test "print pBe->vvb()" "\\$\[0-9\]+ = 411"
626     gdb_test "print pDe->vvb()" "\\$\[0-9\]+ = 411"
627     gdb_test "print pEe->vd()"  "\\$\[0-9\]+ = 282"
628     gdb_test "print pEe->fvb()" "\\$\[0-9\]+ = 311"
629
630     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
631     # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gdwarf-2.
632     #
633     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
634     # gdb=HEAD%2002-02-16, gcc=2.95.3, goption=-gstabs+.
635     #
636     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
637     # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gdwarf-2.
638     #
639     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
640     # gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gstabs+.
641     #
642     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
643     # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gdwarf-2.
644     #
645     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
646     # gdb=HEAD%2002-02-16, gcc=3.0.4-20020215, goption=-gstabs+.
647     #
648     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
649     # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gdwarf-2.
650     #
651     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
652     # gdb=HEAD%2002-02-16, gcc=gcc-3_0-branch%2002-02-16, goption=-gstabs+.
653     #
654     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
655     # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gdwarf-2.
656     #
657     # fails on target=native, host=i686-pc-linux-gnu%rh-7.2,
658     # gdb=HEAD%2002-02-16, gcc=HEAD%2002-02-16, goption=-gstabs+.
659     #
660     # -- chastain 2002-02-20
661
662     # more recent results:
663     # wrong value "202"
664     #   gcc 2.95.3 -gdwarf-2
665     #   gcc 2.95.3 -gstabs+
666     # attempt to take addres of value not located in memory
667     #   gcc 3.3.2 -gdwarf-2
668     #   gcc 3.3.2 -gstabs+
669     #
670     # -- chastain 2003-12-31
671
672     gdb_test_multiple "print pEe->D::vg()" "print pEe->D::vg()" {
673         -re "\\$\[0-9]+ = 102$nl$gdb_prompt $" {
674             pass "print pEe->D::vg()"
675         }
676         -re "Attempt to take address of value not located in memory.$nl$gdb_prompt $" {
677             kfail "gdb/1064" "print pEe->D::vg()"
678         }
679     }
680 }
681
682 proc do_tests {} {
683     global prms_id
684     global bug_id
685     global srcdir subdir binfile
686     global gdb_prompt
687
688     set prms_id 0
689     set bug_id 0
690
691     gdb_exit
692     gdb_start
693     gdb_reinitialize_dir $srcdir/$subdir
694     gdb_load $binfile
695
696     gdb_test "set language c++" "" ""
697     gdb_test "set width 0" "" ""
698
699     runto_main
700     test_ptype_of_classes
701
702     gdb_breakpoint test_calls
703     gdb_test "continue" ".*Breakpoint .* test_calls.*" ""
704     test_virtual_calls
705 }
706
707 do_tests