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