xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.cp/inherit.exp (revision c38e7cc395b1472a774ff828e46123de44c628e9)
1# Copyright 1992-2016 Free Software Foundation, Inc.
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# This file was written by Fred Fish. (fnf@cygnus.com)
17# And rewritten by Michael Chastain. (mec.gnu@mindspring.com)
18
19set ws  "\[\r\n\t \]+"
20set nl  "\[\r\n\]+"
21set vhn "\\$\[0-9\]+"
22
23if { [skip_cplus_tests] } { continue }
24
25load_lib "cp-support.exp"
26
27standard_testfile misc.cc
28
29if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
30    return -1
31}
32
33# Single inheritance, print type definitions.
34
35proc test_ptype_si { } {
36    global gdb_prompt
37    global ws
38    global nl
39
40    # A simple class.
41
42    cp_test_ptype_class \
43	"A" "ptype A (FIXME)" "class" "A" \
44	{
45	    { field public "int a;" }
46	    { field public "int x;" }
47	}
48    cp_test_ptype_class "class A" "ptype class A (FIXME)" "class" "A" ibid
49    cp_test_ptype_class "g_A" "ptype g_A (FIXME)" "class" "A" ibid
50
51    # A derived class.
52
53    cp_test_ptype_class \
54	"B" "" "class" "B" \
55	{
56	    { base         "public A" }
57	    { field public "int b;" }
58	    { field public "int x;" }
59	}
60    cp_test_ptype_class "class B" "" "class" "B" ibid
61    cp_test_ptype_class "g_B" "" "class" "B" ibid
62
63    # Another derived class.
64
65    cp_test_ptype_class \
66	"C" "" "class" "C" \
67	{
68	    { base         "public A" }
69	    { field public "int c;" }
70	    { field public "int x;" }
71	}
72    cp_test_ptype_class "class C" "" "class" "C" ibid
73    cp_test_ptype_class "g_C" "" "class" "C" ibid
74
75    # A structure with no tag.
76    # TODO: move this mess into a separate file, and re-specify
77    # which results are PASS, KFAIL, XFAIL, and FAIL.
78
79    set re_tag		"tagless_struct"
80    set XX_tag		"\\._1"
81    set re_class	"(class $re_tag \{${ws}public:|class \{${ws}public:|struct $re_tag \{|struct \{)"
82    set XX_class	"(class $XX_tag \{${ws}public:|struct $XX_tag \{)"
83    set re_fields	"int one;${ws}int two;"
84    set re_synth_gcc_23	"$re_tag & operator=\\($re_tag const ?&\\);${ws}$re_tag\\($re_tag const ?&\\);${ws}$re_tag\\((void|)\\);"
85    set XX_synth_gcc_23	"($re_tag|$XX_tag) & operator=\\($XX_tag const ?&\\);${ws}$XX_tag\\($XX_tag const ?&\\);${ws}$XX_tag\\((void|)\\);"
86
87    set name "ptype tagless struct"
88    gdb_test_multiple "ptype tagless_struct" $name {
89	-re "type = $XX_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
90	    # gcc 2.95.3 -gdwarf-2
91	    pass "$name"
92	}
93	-re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" {
94	    # gcc 2.95.3 -gstabs+
95	    pass "$name"
96	}
97	-re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
98	    # gcc 3.3.4 -gdwarf-2
99	    # gcc 3.4.1 -gdwarf-2
100	    # gcc HEAD 2004-07-31 -gdwarf-2
101	    # gcc HEAD 2004-07-31 -gstabs+
102	    pass "$name"
103	}
104	-re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
105	    # gcc 3.3.4 -gstabs+
106	    # gcc 3.4.1 -gstabs+
107	    pass "$name"
108	}
109	-re "No symbol \"tagless_struct\" in current context.$nl$gdb_prompt $" {
110	    # Several GCC 4.x versions provide neither a DW_TAG_typedef DIE
111	    # nor use the typedef name as struct tag name.
112	    xfail "$name"
113	}
114    }
115
116    set name "ptype variable of type tagless struct"
117    gdb_test_multiple "ptype v_tagless" $name {
118	-re "type = $XX_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
119	    # gcc 2.95.3 -gdwarf-2
120	    pass "$name"
121	}
122	-re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" {
123	    # gcc 2.95.3 -gstabs+
124	    pass "$name"
125	}
126	-re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
127	    # gcc 3.3.4 -gdwarf-2
128	    # gcc 3.4.1 -gdwarf-2
129	    # gcc HEAD 2004-07-31 -gdwarf-2
130	    # gcc HEAD 2004-07-31 -gstabs+
131	    pass "$name"
132	}
133	-re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
134	    # gcc 3.3.4 -gstabs+
135	    # gcc 3.4.1 -gstabs+
136	    pass "$name"
137	}
138    }
139}
140
141# Multiple inheritance, print type definitions.
142
143proc test_ptype_mi { } {
144
145    # A class with two bases.
146
147    cp_test_ptype_class \
148	"D" "" "class" "D" \
149	{
150	    { base         "public B" }
151	    { base         "public C" }
152	    { field public "int d;" }
153	    { field public "int x;" }
154	}
155    cp_test_ptype_class "class D" "" "class" "D" ibid
156    cp_test_ptype_class "g_D" "" "class" "D" ibid
157
158    # A class derived from the previous class.
159
160    cp_test_ptype_class \
161	"E" "" "class" "E" \
162	{
163	    { base         "public D" }
164	    { field public "int e;" }
165	    { field public "int x;" }
166	}
167    cp_test_ptype_class "class E" "" "class" "E" ibid
168    cp_test_ptype_class "g_E" "" "class" "E" ibid
169}
170
171# Single virtual inheritance, print type definitions.
172
173proc test_ptype_vi { } {
174
175    # class vA
176
177    cp_test_ptype_class \
178	"vA" "" "class" "vA" \
179	{
180	    { field public "int va;" }
181	    { field public "int vx;" }
182	}
183    cp_test_ptype_class "class vA" "" "class" "vA" ibid
184    cp_test_ptype_class "g_vA" "" "class" "vA" ibid
185
186    # class vB
187
188    cp_test_ptype_class \
189	"vB" "" "class" "vB" \
190	{
191	    { base         "public virtual vA" }
192	    { vbase        "vA" }
193	    { field public "int vb;" }
194	    { field public "int vx;" }
195	}
196    cp_test_ptype_class "class vB" "" "class" "vB" ibid
197    cp_test_ptype_class "g_vB" "" "class" "vB" ibid
198
199    # class vC
200
201    cp_test_ptype_class \
202	"vC" "" "class" "vC" \
203	{
204	    { base         "public virtual vA" }
205	    { vbase        "vA" }
206	    { field public "int vc;" }
207	    { field public "int vx;" }
208	}
209    cp_test_ptype_class "class vC" "" "class" "vC" ibid
210    cp_test_ptype_class "g_vC" "" "class" "vC" ibid
211
212}
213
214# Multiple virtual inheritance, print type definitions.
215
216proc test_ptype_mvi { } {
217
218    # class vD
219
220    cp_test_ptype_class \
221	"vD" "" "class" "vD" \
222	{
223	    { base         "public virtual vB" }
224	    { base         "public virtual vC" }
225	    { vbase        "vC" }
226	    { vbase        "vB" }
227	    { field public "int vd;" }
228	    { field public "int vx;" }
229	}
230    cp_test_ptype_class "class vD" "" "class" "vD" ibid
231    cp_test_ptype_class "g_vD" "" "class" "vD" ibid
232
233    # class vE
234
235    cp_test_ptype_class \
236	"vE" "" "class" "vE" \
237	{
238	    { base         "public virtual vD" }
239	    { vbase        "vD" }
240	    { field public "int ve;" }
241	    { field public "int vx;" }
242	}
243    cp_test_ptype_class "class vE" "" "class" "vE" ibid
244    cp_test_ptype_class "g_vE" "" "class" "vE" ibid
245
246}
247
248# Single inheritance, print individual members.
249
250proc test_print_si_members { } {
251    global vhn
252
253    # Print all members of g_A using fully qualified form.
254    gdb_test "print g_A.A::a" "$vhn = 1"
255    gdb_test "print g_A.A::x" "$vhn = 2"
256
257    # Print members of g_A using nonambiguous compact form.
258    gdb_test "print g_A.a" "$vhn = 1"
259    gdb_test "print g_A.x" "$vhn = 2"
260
261    # Print all members of g_B using fully qualified form.
262    gdb_test "print g_B.A::a" "$vhn = 3"
263    gdb_test "print g_B.A::x" "$vhn = 4"
264    gdb_test "print g_B.B::b" "$vhn = 5"
265    gdb_test "print g_B.B::x" "$vhn = 6"
266
267    # Print members of g_B using nonambiguous compact form.
268    gdb_test "print g_B.a" "$vhn = 3"
269    gdb_test "print g_B.b" "$vhn = 5"
270    gdb_test "print g_B.x" "$vhn = 6"
271
272    # Print all members of g_C using fully qualified form.
273    gdb_test "print g_C.A::a" "$vhn = 7"
274    gdb_test "print g_C.A::x" "$vhn = 8"
275    gdb_test "print g_C.C::c" "$vhn = 9"
276    gdb_test "print g_C.C::x" "$vhn = 10"
277
278    # Print members of g_C using nonambiguous compact form.
279    gdb_test "print g_C.a" "$vhn = 7"
280    gdb_test "print g_C.c" "$vhn = 9"
281    gdb_test "print g_C.x" "$vhn = 10"
282}
283
284# Single inheritance, print complete classes.
285
286proc test_print_si_classes { } {
287    global vhn
288
289    # Print all members of g_A, g_B, g_C.
290    gdb_test "print g_A" "$vhn = \{a = 1, x = 2\}"
291    gdb_test "print g_B" "$vhn = \{<(class A|A)> = \{a = 3, x = 4\}, b = 5, x = 6\}"
292    gdb_test "print g_C" "$vhn = \{<(class A|A)> = \{a = 7, x = 8\}, c = 9, x = 10\}"
293}
294
295# Multiple inheritance, print individual members.
296
297proc test_print_mi_members {} {
298    global gdb_prompt
299    global nl
300    global vhn
301
302    # Print all members of g_A.
303    gdb_test "print g_A.A::a" "$vhn = 1"
304    gdb_test "print g_A.A::x" "$vhn = 2"
305
306    # Print all members of g_B.
307    gdb_test "print g_B.A::a" "$vhn = 3"
308    gdb_test "print g_B.A::x" "$vhn = 4"
309    gdb_test "print g_B.B::b" "$vhn = 5"
310    gdb_test "print g_B.B::x" "$vhn = 6"
311
312    # Print all members of g_C.
313    gdb_test "print g_C.A::a" "$vhn = 7"
314    gdb_test "print g_C.A::x" "$vhn = 8"
315    gdb_test "print g_C.C::c" "$vhn = 9"
316    gdb_test "print g_C.C::x" "$vhn = 10"
317
318    # Print all members of g_D.
319    #
320    # g_D.A::a and g_D.A::x are ambiguous member accesses.
321    gdb_test "print g_D.A::a" "base class 'A' is ambiguous in type 'D'"
322    gdb_test "print g_D.C::a" "$vhn = 15"
323    gdb_test "print g_D.B::a" "$vhn = 11"
324    gdb_test "print g_D.A::x" "base class 'A' is ambiguous in type 'D'"
325    gdb_test "print g_D.B::b" "$vhn = 13"
326    gdb_test "print g_D.B::x" "$vhn = 14"
327    gdb_test "print g_D.C::c" "$vhn = 17"
328    gdb_test "print g_D.C::x" "$vhn = 18"
329    gdb_test "print g_D.D::d" "$vhn = 19"
330    gdb_test "print g_D.D::x" "$vhn = 20"
331
332    # Print all members of g_E.
333    # g_E.A::a and g_E.A::x are ambiguous.
334
335    gdb_test "print g_E.A::a" "base class 'A' is ambiguous in type 'E'"
336    gdb_test "print g_E.A::x" "base class 'A' is ambiguous in type 'E'"
337    gdb_test "print g_E.B::b" "$vhn = 23"
338    gdb_test "print g_E.B::x" "$vhn = 24"
339    gdb_test "print g_E.C::c" "$vhn = 27"
340    gdb_test "print g_E.C::x" "$vhn = 28"
341    gdb_test "print g_E.D::d" "$vhn = 29"
342    gdb_test "print g_E.D::x" "$vhn = 30"
343    gdb_test "print g_E.E::e" "$vhn = 31"
344    gdb_test "print g_E.E::x" "$vhn = 32"
345}
346
347# Multiple inheritance, print individual member types.
348
349proc test_print_mi_member_types {} {
350    global gdb_prompt
351    global nl
352    global vhn
353
354    # Print the types of some members of g_D without qualifying them.
355    gdb_test "ptype g_D.b" "type = int"
356    gdb_test "ptype g_D.c" "type = int"
357    gdb_test "ptype g_D.d" "type = int"
358
359    # Print the types of qualified members; none of these tests pass today.
360
361    # Print all members of g_A.
362    gdb_test "ptype g_A.A::a" "type = int"
363    gdb_test "ptype g_A.A::x" "type = int"
364
365    # Print all members of g_B.
366    gdb_test "ptype g_B.A::a" "type = int"
367    gdb_test "ptype g_B.A::x" "type = int"
368    gdb_test "ptype g_B.B::b" "type = int"
369    gdb_test "ptype g_B.B::x" "type = int"
370
371    # Print all members of g_C.
372    gdb_test "ptype g_C.A::a" "type = int"
373    gdb_test "ptype g_C.A::x" "type = int"
374    gdb_test "ptype g_C.C::c" "type = int"
375    gdb_test "ptype g_C.C::x" "type = int"
376
377    # Print all members of g_D.
378    #
379    # g_D.A::a and g_D.A::x are ambiguous member accesses.
380
381    gdb_test "ptype g_D.A::a" "base class 'A' is ambiguous in type 'D'"
382    gdb_test "ptype g_D.A::x" "base class 'A' is ambiguous in type 'D'"
383    gdb_test "ptype g_D.B::b" "type = int"
384    gdb_test "ptype g_D.B::x" "type = int"
385    gdb_test "ptype g_D.C::c" "type = int"
386    gdb_test "ptype g_D.C::x" "type = int"
387    gdb_test "ptype g_D.D::d" "type = int"
388    gdb_test "ptype g_D.D::x" "type = int"
389
390    # Print all members of g_E.
391    # g_E.A::a and g_E.A::x are ambiguous.
392
393    gdb_test "ptype g_E.A::a" "base class 'A' is ambiguous in type 'E'"
394    gdb_test "ptype g_E.A::x" "base class 'A' is ambiguous in type 'E'"
395    gdb_test "ptype g_E.B::b" "type = int"
396    gdb_test "ptype g_E.B::x" "type = int"
397    gdb_test "ptype g_E.C::c" "type = int"
398    gdb_test "ptype g_E.C::x" "type = int"
399    gdb_test "ptype g_E.D::d" "type = int"
400    gdb_test "ptype g_E.D::x" "type = int"
401    gdb_test "ptype g_E.E::e" "type = int"
402    gdb_test "ptype g_E.E::x" "type = int"
403}
404
405# Multiple inheritance, print complete classes.
406
407proc test_print_mi_classes { } {
408    global vhn
409
410    # Print all members of g_D.
411    gdb_test "print g_D" "$vhn = \{\<(class |)B\> = \{\<(class |)A\> = \{a = 11, x = 12\}, b = 13, x = 14\}, \<(class |)C\> = \{\<(class |)A\> = \{a = 15, x = 16\}, c = 17, x = 18\}, d = 19, x = 20\}"
412
413    # Print all members of g_E.
414    gdb_test "print g_E" "$vhn = \{\<(class |)D\> = \{\<(class |)B\> = \{\<(class |)A\> = \{a = 21, x = 22\}, b = 23, x = 24\}, \<(class |)C\> = \{\<(class |)A\> = \{a = 25, x = 26\}, c = 27, x = 28\}, d = 29, x = 30\}, e = 31, x = 32\}"
415}
416
417# Single inheritance, print anonymous unions.
418# GDB versions prior to 4.14 entered an infinite loop when printing
419# the type of a class containing an anonymous union, and they were also
420# incapable of printing the member of an anonymous union.
421# We test the printing of the member first, and perform the other tests
422# only if the test succeeds, to avoid the infinite loop.
423
424proc test_print_anon_union {} {
425    global gdb_prompt
426    global ws
427    global nl
428    global vhn
429
430    gdb_test "print g_anon_union.a" "$vhn = 2" "print anonymous union member"
431
432    set name "print variable of type anonymous union"
433    gdb_test_multiple "print g_anon_union" $name {
434	-re "$vhn = \{one = 1, \{a = 2, b = \[0-9\]+\}\}$nl$gdb_prompt $" {
435	    pass $name
436	}
437    }
438
439    set name "print type of anonymous union"
440    set re_tag "class_with_anon_union"
441    set re_class "(class $re_tag \{${ws}public:|struct $re_tag \{)"
442    set re_fields "int one;${ws}union \{${ws}int a;${ws}long( int)? b;${ws}\};"
443    gdb_test_multiple "ptype g_anon_union" $name {
444	-re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
445	    pass $name
446	}
447    }
448}
449
450
451# Single virtual inheritance, print individual members.
452
453proc test_print_svi_members { } {
454    global vhn
455
456    # Print all members of g_vA.
457    gdb_test "print g_vA.vA::va" "$vhn = 1"
458    gdb_test "print g_vA.vA::vx" "$vhn = 2"
459
460    # Print members of g_vA using compact form.
461    gdb_test "print g_vA.va" "$vhn = 1"
462    gdb_test "print g_vA.vx" "$vhn = 2"
463
464    # Print all members of g_vB.
465    gdb_test "print g_vB.vA::va" "$vhn = 3"
466    gdb_test "print g_vB.vA::vx" "$vhn = 4"
467    gdb_test "print g_vB.vB::vb" "$vhn = 5"
468    gdb_test "print g_vB.vB::vx" "$vhn = 6"
469
470    # Print members of g_vB using compact form.
471    gdb_test "print g_vB.va" "$vhn = 3"
472    gdb_test "print g_vB.vb" "$vhn = 5"
473    gdb_test "print g_vB.vx" "$vhn = 6"
474
475    # Print all members of g_vC.
476    gdb_test "print g_vC.vA::va" "$vhn = 7"
477    gdb_test "print g_vC.vA::vx" "$vhn = 8"
478    gdb_test "print g_vC.vC::vc" "$vhn = 9"
479    gdb_test "print g_vC.vC::vx" "$vhn = 10"
480
481    # Print members of g_vC using compact form.
482    gdb_test "print g_vC.va" "$vhn = 7" "print g_vC.va"
483    gdb_test "print g_vC.vc" "$vhn = 9" "print g_vC.vc"
484    gdb_test "print g_vC.vx" "$vhn = 10" "print g_vC.vx"
485}
486
487# Single virtual inheritance, print complete classes.
488
489proc test_print_svi_classes { } {
490    global gdb_prompt
491    global hex
492    global nl
493    global vhn
494
495    # Print all members of g_vA.
496    gdb_test "print g_vA" "$vhn = \{va = 1, vx = 2\}"
497
498    # Print all members of g_vB.
499    set re_vbptr_2	"(_vb.2vA|_vb.vA)"
500    set re_vbptr_3	"_vptr.vB"
501
502    set name "print g_vB"
503    gdb_test_multiple "print g_vB" $name {
504	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_2 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
505	    # gcc 2.95.3 -gdwarf-2
506	    # gcc 2.95.3 -gstabs+
507	    pass $name
508	}
509	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
510	    # gcc 3.3.4 -gdwarf-2
511	    # gcc 3.4.1 -gdwarf-2
512	    # gcc 3.4.1 -gstabs+
513	    # gcc HEAD 2004-07-31 -gdwarf-2
514	    pass "$name (FIXME v3 vtbl ptr)"
515	}
516	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <VTT for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" {
517	    # gcc 3.3.4 -gstabs+
518	    pass $name
519	}
520	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <typeinfo for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" {
521	    # gcc HEAD 2004-07-31 -gstabs+
522	    pass $name
523	}
524	-re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = ${hex}( <\[^>]*>)?, vb = 5, vx = 6\}$nl$gdb_prompt $" {
525	    # gcc HEAD 2015?+
526	    # the vptr is set to the address *after* the vtable,
527	    # so the # symbol shown is unpredictable.
528	    pass "$name (symbols ignored)"
529	}
530    }
531
532    # Print all members of g_vC.
533    set re_vbptr_2	"(_vb.2vA|_vb.vA)"
534    set re_vbptr_3	"_vptr.vC"
535
536    set name "print g_vC"
537    gdb_test_multiple "print g_vC" $name {
538	-re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_2 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
539	    # gcc 2.95.3 -gdwarf-2
540	    # gcc 2.95.3 -gstabs+
541	    pass $name
542	}
543	-re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
544	    # gcc 3.3.4 -gdwarf-2
545	    # gcc 3.4.1 -gdwarf-2
546	    # gcc 3.4.1 -gstabs+
547	    # gcc HEAD 2004-07-31 -gdwarf-2
548	    pass "$name (FIXME v3 vtbl ptr)"
549	}
550	-re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <VTT for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" {
551	    # gcc 3.3.4 -gstabs+
552	    pass $name
553	}
554	-re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <typeinfo for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" {
555	    # gcc HEAD 2004-07-31 -gstabs+
556	    pass $name
557	}
558	-re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = ${hex}( <\[^>]*>)?, vc = 9, vx = 10\}$nl$gdb_prompt $" {
559	    # gcc HEAD 2015?+
560	    # the vptr is set to the address *after* the vtable,
561	    # so the symbol shown is unpredictable.
562	    pass "$name (symbols ignored)"
563	}
564    }
565}
566
567# Multiple virtual inheritance, print individual members.
568
569proc test_print_mvi_members { } {
570    global vhn
571
572    # Print all members of g_vD.
573    gdb_test "print g_vD.vA::va" "$vhn = 19"
574    gdb_test "print g_vD.vA::vx" "$vhn = 20"
575    gdb_test "print g_vD.vB::vb" "$vhn = 21"
576    gdb_test "print g_vD.vB::vx" "$vhn = 22"
577    gdb_test "print g_vD.vC::vc" "$vhn = 23"
578    gdb_test "print g_vD.vC::vx" "$vhn = 24"
579    gdb_test "print g_vD.vD::vd" "$vhn = 25"
580    gdb_test "print g_vD.vD::vx" "$vhn = 26"
581
582    # Print all members of g_vE.
583    gdb_test "print g_vE.vA::va" "$vhn = 0"
584    gdb_test "print g_vE.vA::vx" "$vhn = 0"
585    gdb_test "print g_vE.vB::vb" "$vhn = 0"
586    gdb_test "print g_vE.vB::vx" "$vhn = 0"
587    gdb_test "print g_vE.vC::vc" "$vhn = 0"
588    gdb_test "print g_vE.vC::vx" "$vhn = 0"
589    gdb_test "print g_vE.vD::vd" "$vhn = 0"
590    gdb_test "print g_vE.vD::vx" "$vhn = 0"
591    gdb_test "print g_vE.vE::ve" "$vhn = 27"
592    gdb_test "print g_vE.vE::vx" "$vhn = 28"
593}
594
595# Multiple virtual inheritance, print complete classes.
596
597proc test_print_mvi_classes { } {
598    global gdb_prompt
599    global hex
600    global ws
601    global nl
602    global vhn
603
604    # Virtual base pointers for everybody.
605
606    set re_vbptr_2_vA	"(_vb.2vA|_vb.vA)"
607    set re_vbptr_2_vB	"(_vb.2vB|_vb.vB)"
608    set re_vbptr_2_vC	"(_vb.2vC|_vb.vC)"
609    set re_vbptr_2_vD	"(_vb.2vD|_vb.vD)"
610    set re_vbptr_3_vA	"_vptr.vA"
611    set re_vbptr_3_vB	"_vptr.vB"
612    set re_vbptr_3_vC	"_vptr.vC"
613    set re_vbptr_3_vD	"_vptr.vD"
614    set re_vbptr_3_vE	"_vptr.vE"
615
616    # Print all members of g_vD.
617
618    set name "print g_vD"
619    gdb_test_multiple "print g_vD" $name {
620	-re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_2_vA = $hex, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_2_vA = $hex, vc = 23, vx = 24\}, $re_vbptr_2_vC = $hex, $re_vbptr_2_vB = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" {
621	    # gcc 2.95.3 -gdwarf-2
622	    # gcc 2.95.3 -gstabs+
623	    pass $name
624	}
625	-re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = ${hex}( <vtable for vD.*>)?, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <vtable for vC.*>)?, vc = 23, vx = 24\}, $re_vbptr_3_vD = ${hex}( <vtable for vD.*>)?, vd = 25, vx = 26\}$nl$gdb_prompt $" {
626	    # gcc 3.3.2 -gdwarf-2
627	    # gcc HEAD 2004-01-21 -gdwarf-2
628	    # gcc HEAD 2004-01-21 -gstabs+
629	    pass "$name (FIXME v3 vtbl ptr)"
630	}
631	-re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = $hex, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = $hex <VTT for vD>, vc = 23, vx = 24\}, $re_vbptr_3_vD = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" {
632	    # gcc 3.3.2 -gstabs+
633	    pass "$name"
634	}
635	-re "$vhn = \{<vB> = \{<vA> = \{va = 19, vx = 20\}, $re_vbptr_3_vB = ${hex}( <\[^>]*>)?, vb = 21, vx = 22\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <\[^>]*>)?, vc = 23, vx = 24\}, $re_vbptr_3_vD = ${hex}( <\[^>]*>)?, vd = 25, vx = 26\}$nl$gdb_prompt $" {
636	    # gcc HEAD 2015?+
637	    # the vptr is set to the address *after* the vtable,
638	    # so the symbol shown is unpredictable.
639	    pass "$name (symbols ignored)"
640	}
641    }
642
643    # Print all members of g_vE.
644
645    set name "print g_vE"
646    gdb_test_multiple "print g_vE" $name {
647	-re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_2_vA = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_2_vA = $hex, vc = 0, vx = 0\}, $re_vbptr_2_vC = $hex, $re_vbptr_2_vB = $hex, vd = 0, vx = 0\}, $re_vbptr_2_vD = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" {
648	    # gcc 2.95.3 -gdwarf-2
649	    # gcc 2.95.3 -gstabs+
650	    pass $name
651	}
652	-re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = ${hex}( <vtable for vE.*>)?, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <vtable for vE.*>)?, vc = 0, vx = 0\}, $re_vbptr_3_vD = ${hex}( <vtable for vE.*>)?, vd = 0, vx = 0\}, $re_vbptr_3_vE = ${hex}( <vtable for vE.*>)?, ve = 27, vx = 28\}$nl$gdb_prompt $" {
653	    # gcc 3.3.4 -gdwarf-2
654	    # gcc 3.3.4 -gstabs+
655	    # gcc 3.4.1 -gdwarf-2
656	    # gcc 3.4.1 -gstabs+
657	    # gcc HEAD 2004-07-31 -gdwarf-2
658	    pass "$name (FIXME v3 vtbl ptr)"
659	}
660	-re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = $hex <VTT for vD>, vc = 0, vx = 0\}, $re_vbptr_3_vD = $hex, vd = 0, vx = 0\}, $re_vbptr_3_vE = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" {
661	    # gcc 3.2.7-rh -gstabs+
662	    pass $name
663	}
664	-re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = $hex, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = $hex <typeinfo for vE>, vc = 0, vx = 0\}, $re_vbptr_3_vD = $hex, vd = 0, vx = 0\}, $re_vbptr_3_vE = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" {
665	    # gcc HEAD 2004-07-31 -gstabs+
666	    pass $name
667	}
668	-re "$vhn = \{<vD> = \{<vB> = \{<vA> = \{va = 0, vx = 0\}, $re_vbptr_3_vB = ${hex}( <\[^>]*>)?, vb = 0, vx = 0\}, <vC> = \{$re_vbptr_3_vC = ${hex}( <\[^>]*>)?, vc = 0, vx = 0\}, $re_vbptr_3_vD = ${hex}( <\[^>]*>)?, vd = 0, vx = 0\}, $re_vbptr_3_vE = ${hex}( <\[^>]*>)?, ve = 27, vx = 28\}$nl$gdb_prompt $" {
669	    # gcc HEAD 2015?+
670	    # the vptr is set to the address *after* the vtable,
671	    # so the symbol shown is unpredictable.
672	    pass "$name (symbols ignored)"
673	}
674    }
675}
676
677proc do_tests { } {
678    gdb_test_no_output "set width 0"
679
680    if { ![runto_main] } then {
681	perror "couldn't run to main"
682	return
683    }
684
685    gdb_test_no_output "set language c++"
686    test_ptype_si
687    test_ptype_mi
688    test_ptype_vi
689    test_ptype_mvi
690
691    if { ![runto 'inheritance2'] } then {
692	perror "couldn't run to inheritance2"
693	return
694    }
695
696    test_print_si_members
697    test_print_si_classes
698    test_print_mi_members
699    test_print_mi_member_types
700    test_print_mi_classes
701    test_print_anon_union
702
703    if { ![runto 'inheritance4'] } {
704	perror "couldn't run to inheritance4"
705	return
706    }
707
708    test_print_svi_members
709    test_print_svi_classes
710    test_print_mvi_members
711    test_print_mvi_classes
712}
713
714do_tests
715