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