* cp-valprint.c (cp_print_value_fields): Use
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.cp / inherit.exp
CommitLineData
0b302171
JB
1# Copyright 1992-1999, 2001-2004, 2006-2012 Free Software Foundation,
2# Inc.
c906108c
SS
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
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
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.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c 17# This file was written by Fred Fish. (fnf@cygnus.com)
ebac27b4 18# And rewritten by Michael Chastain. (mec.gnu@mindspring.com)
c906108c 19
ebac27b4
MC
20set ws "\[\r\n\t \]+"
21set nl "\[\r\n\]+"
22set vhn "\\$\[0-9\]+"
c2d11a7d 23
d4f3574e
SS
24if { [skip_cplus_tests] } { continue }
25
25808999
MC
26load_lib "cp-support.exp"
27
c906108c
SS
28set testfile "inherit"
29set srcfile misc.cc
30set binfile ${objdir}/${subdir}/${testfile}
31
c906108c 32if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
b60f0898
JB
33 untested inherit.exp
34 return -1
c906108c
SS
35}
36
c906108c 37# Single inheritance, print type definitions.
c906108c 38
ebac27b4 39proc test_ptype_si { } {
c906108c
SS
40 global gdb_prompt
41 global ws
42 global nl
43
25808999 44 # A simple class.
c906108c 45
25808999
MC
46 cp_test_ptype_class \
47 "ptype A" "ptype A (FIXME)" "class" "A" \
48 {
49 { field public "int a;" }
50 { field public "int x;" }
ebac27b4 51 }
25808999
MC
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
c906108c 54
25808999 55 # A derived class.
c906108c 56
25808999
MC
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;" }
ebac27b4 63 }
25808999
MC
64 cp_test_ptype_class "ptype class B" "" "class" "B" ibid
65 cp_test_ptype_class "ptype g_B" "" "class" "B" ibid
c906108c 66
25808999 67 # Another derived class.
c906108c 68
25808999
MC
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;" }
ebac27b4 75 }
25808999
MC
76 cp_test_ptype_class "ptype class C" "" "class" "C" ibid
77 cp_test_ptype_class "ptype g_C" "" "class" "C" ibid
c906108c 78
25808999
MC
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.
ebac27b4
MC
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
9366563b 95 pass "$name"
c906108c 96 }
ebac27b4
MC
97 -re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" {
98 # gcc 2.95.3 -gstabs+
9366563b 99 pass "$name"
c906108c 100 }
ebac27b4 101 -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
9366563b
MC
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"
c906108c 107 }
ebac27b4 108 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
9366563b
MC
109 # gcc 3.3.4 -gstabs+
110 # gcc 3.4.1 -gstabs+
ebac27b4 111 pass "$name"
c906108c 112 }
907af001
UW
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 }
c906108c
SS
118 }
119
ebac27b4
MC
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
9366563b 124 pass "$name"
3e36a0f4 125 }
ebac27b4
MC
126 -re "type = $re_class${ws}$re_fields${ws}$XX_synth_gcc_23$nl\}$nl$gdb_prompt $" {
127 # gcc 2.95.3 -gstabs+
9366563b 128 pass "$name"
c906108c 129 }
ebac27b4 130 -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
9366563b
MC
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"
c906108c 136 }
ebac27b4 137 -re "type = $re_class${ws}$re_fields${ws}$re_synth_gcc_23$nl\}$nl$gdb_prompt $" {
9366563b
MC
138 # gcc 3.3.4 -gstabs+
139 # gcc 3.4.1 -gstabs+
ebac27b4 140 pass "$name"
c906108c
SS
141 }
142 }
143}
144
ebac27b4 145# Multiple inheritance, print type definitions.
c906108c 146
ebac27b4 147proc test_ptype_mi { } {
ebac27b4 148
25808999 149 # A class with two bases.
ebac27b4 150
25808999
MC
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;" }
c906108c 158 }
25808999
MC
159 cp_test_ptype_class "ptype class D" "" "class" "D" ibid
160 cp_test_ptype_class "ptype g_D" "" "class" "D" ibid
ebac27b4 161
25808999 162 # A class derived from the previous class.
ebac27b4 163
25808999
MC
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;" }
3e36a0f4 170 }
25808999
MC
171 cp_test_ptype_class "ptype class E" "" "class" "E" ibid
172 cp_test_ptype_class "ptype g_E" "" "class" "E" ibid
c906108c
SS
173}
174
ebac27b4 175# Single virtual inheritance, print type definitions.
c906108c 176
ebac27b4 177proc test_ptype_vi { } {
c906108c 178
25808999 179 # class vA
c906108c 180
25808999
MC
181 cp_test_ptype_class \
182 "ptype vA" "" "class" "vA" \
183 {
184 { field public "int va;" }
185 { field public "int vx;" }
ebac27b4 186 }
25808999
MC
187 cp_test_ptype_class "ptype class vA" "" "class" "vA" ibid
188 cp_test_ptype_class "ptype g_vA" "" "class" "vA" ibid
c906108c 189
25808999 190 # class vB
c906108c 191
25808999
MC
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;" }
ebac27b4 199 }
25808999
MC
200 cp_test_ptype_class "ptype class vB" "" "class" "vB" ibid
201 cp_test_ptype_class "ptype g_vB" "" "class" "vB" ibid
c906108c 202
25808999 203 # class vC
c906108c 204
25808999
MC
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;" }
ebac27b4 212 }
25808999
MC
213 cp_test_ptype_class "ptype class vC" "" "class" "vC" ibid
214 cp_test_ptype_class "ptype g_vC" "" "class" "vC" ibid
c906108c 215
ebac27b4 216}
c906108c 217
ebac27b4 218# Multiple virtual inheritance, print type definitions.
c906108c 219
ebac27b4 220proc test_ptype_mvi { } {
c906108c 221
25808999 222 # class vD
c906108c 223
25808999
MC
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;" }
ebac27b4 233 }
25808999
MC
234 cp_test_ptype_class "ptype class vD" "" "class" "vD" ibid
235 cp_test_ptype_class "ptype g_vD" "" "class" "vD" ibid
c906108c 236
25808999 237 # class vE
c906108c 238
25808999
MC
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;" }
ebac27b4 246 }
25808999
MC
247 cp_test_ptype_class "ptype class vE" "" "class" "vE" ibid
248 cp_test_ptype_class "ptype g_vE" "" "class" "vE" ibid
c906108c 249
c906108c
SS
250}
251
ebac27b4 252# Single inheritance, print individual members.
c906108c 253
ebac27b4
MC
254proc test_print_si_members { } {
255 global vhn
c906108c 256
ebac27b4
MC
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"
c906108c 260
ebac27b4
MC
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"
c906108c 264
ebac27b4
MC
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"
c906108c 270
ebac27b4
MC
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"
c906108c 275
ebac27b4
MC
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"
c906108c 281
ebac27b4
MC
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"
c906108c
SS
286}
287
ebac27b4 288# Single inheritance, print complete classes.
c906108c 289
ebac27b4
MC
290proc test_print_si_classes { } {
291 global vhn
c906108c 292
ebac27b4
MC
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\}"
c906108c
SS
297}
298
ebac27b4 299# Multiple inheritance, print individual members.
c906108c 300
ebac27b4 301proc test_print_mi_members {} {
c906108c 302 global gdb_prompt
c906108c 303 global nl
ebac27b4 304 global vhn
c906108c 305
ebac27b4
MC
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"
c906108c 309
ebac27b4
MC
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"
c906108c 315
ebac27b4
MC
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"
c906108c 321
ebac27b4
MC
322 # Print all members of g_D.
323 #
324 # g_D.A::a and g_D.A::x are ambiguous member accesses, and gdb
325 # should detect these. There are no ways to PASS these tests
326 # because I don't know what the gdb message will be. -- chastain
327 # 2004-01-27.
328
329 set name "print g_D.A::a"
330 gdb_test_multiple "print g_D.A::a" $name {
331 -re "$vhn = (15|11)$nl$gdb_prompt $" {
332 kfail "gdb/68" "print g_D.A::a"
c906108c 333 }
c906108c
SS
334 }
335
ebac27b4
MC
336 set name "print g_D.A::x"
337 gdb_test_multiple "print g_D.A::x" $name {
338 -re "$vhn = (16|12)$nl$gdb_prompt $" {
339 kfail "gdb/68" "print g_D.A::x"
340 }
341 }
c906108c 342
ebac27b4
MC
343 gdb_test "print g_D.B::b" "$vhn = 13"
344 gdb_test "print g_D.B::x" "$vhn = 14"
345 gdb_test "print g_D.C::c" "$vhn = 17"
346 gdb_test "print g_D.C::x" "$vhn = 18"
347 gdb_test "print g_D.D::d" "$vhn = 19"
348 gdb_test "print g_D.D::x" "$vhn = 20"
c906108c 349
ebac27b4
MC
350 # Print all members of g_E.
351 # g_E.A::a and g_E.A::x are ambiguous.
c906108c 352
ebac27b4
MC
353 set name "print g_E.A::a"
354 gdb_test_multiple "print g_E.A::a" $name {
355 -re "$vhn = (21|25)$nl$gdb_prompt $" {
356 kfail "gdb/68" "print g_E.A::a"
357 }
358 }
c906108c 359
ebac27b4
MC
360 set name "print g_E.A::x"
361 gdb_test_multiple "print g_E.A::x" $name {
362 -re "$vhn = (26|22)$nl$gdb_prompt $" {
363 kfail "gdb/68" "print g_E.A::x"
364 }
365 }
c906108c 366
ebac27b4
MC
367 gdb_test "print g_E.B::b" "$vhn = 23"
368 gdb_test "print g_E.B::x" "$vhn = 24"
369 gdb_test "print g_E.C::c" "$vhn = 27"
370 gdb_test "print g_E.C::x" "$vhn = 28"
371 gdb_test "print g_E.D::d" "$vhn = 29"
372 gdb_test "print g_E.D::x" "$vhn = 30"
373 gdb_test "print g_E.E::e" "$vhn = 31"
374 gdb_test "print g_E.E::x" "$vhn = 32"
375}
c906108c 376
9733fc94
DJ
377# Multiple inheritance, print individual member types.
378
379proc test_print_mi_member_types {} {
380 global gdb_prompt
381 global nl
382 global vhn
383
384 # Print the types of some members of g_D without qualifying them.
385 gdb_test "ptype g_D.b" "type = int"
386 gdb_test "ptype g_D.c" "type = int"
387 gdb_test "ptype g_D.d" "type = int"
388
389 # Print the types of qualified members; none of these tests pass today.
390
391 # Print all members of g_A.
9733fc94 392 gdb_test "ptype g_A.A::a" "type = int"
9733fc94
DJ
393 gdb_test "ptype g_A.A::x" "type = int"
394
395 # Print all members of g_B.
9733fc94 396 gdb_test "ptype g_B.A::a" "type = int"
9733fc94 397 gdb_test "ptype g_B.A::x" "type = int"
9733fc94 398 gdb_test "ptype g_B.B::b" "type = int"
9733fc94
DJ
399 gdb_test "ptype g_B.B::x" "type = int"
400
401 # Print all members of g_C.
9733fc94 402 gdb_test "ptype g_C.A::a" "type = int"
9733fc94 403 gdb_test "ptype g_C.A::x" "type = int"
9733fc94 404 gdb_test "ptype g_C.C::c" "type = int"
9733fc94
DJ
405 gdb_test "ptype g_C.C::x" "type = int"
406
407 # Print all members of g_D.
408 #
409 # g_D.A::a and g_D.A::x are ambiguous member accesses, and gdb
410 # should detect these. There are no ways to PASS these tests
411 # because I don't know what the gdb message will be. -- chastain
412 # 2004-01-27.
413
414 set name "ptype g_D.A::a"
415 gdb_test_multiple "ptype g_D.A::a" $name {
9733fc94
DJ
416 -re "type = int$nl$gdb_prompt $" {
417 kfail "gdb/68" "ptype g_D.A::a"
418 }
419 }
420
421 set name "ptype g_D.A::x"
422 gdb_test_multiple "ptype g_D.A::x" $name {
9733fc94
DJ
423 -re "type = int$nl$gdb_prompt $" {
424 kfail "gdb/68" "ptype g_D.A::x"
425 }
426 }
427
9733fc94 428 gdb_test "ptype g_D.B::b" "type = int"
9733fc94 429 gdb_test "ptype g_D.B::x" "type = int"
9733fc94 430 gdb_test "ptype g_D.C::c" "type = int"
9733fc94 431 gdb_test "ptype g_D.C::x" "type = int"
9733fc94 432 gdb_test "ptype g_D.D::d" "type = int"
9733fc94
DJ
433 gdb_test "ptype g_D.D::x" "type = int"
434
435 # Print all members of g_E.
436 # g_E.A::a and g_E.A::x are ambiguous.
437
438 set name "ptype g_E.A::a"
439 gdb_test_multiple "ptype g_E.A::a" $name {
9733fc94
DJ
440 -re "type = int$nl$gdb_prompt $" {
441 kfail "gdb/68" "ptype g_E.A::a"
442 }
443 }
444
445 set name "ptype g_E.A::x"
446 gdb_test_multiple "ptype g_E.A::x" $name {
9733fc94
DJ
447 -re "type = int$nl$gdb_prompt $" {
448 kfail "gdb/68" "ptype g_E.A::x"
449 }
450 }
451
9733fc94 452 gdb_test "ptype g_E.B::b" "type = int"
9733fc94 453 gdb_test "ptype g_E.B::x" "type = int"
9733fc94 454 gdb_test "ptype g_E.C::c" "type = int"
9733fc94 455 gdb_test "ptype g_E.C::x" "type = int"
9733fc94 456 gdb_test "ptype g_E.D::d" "type = int"
9733fc94 457 gdb_test "ptype g_E.D::x" "type = int"
9733fc94 458 gdb_test "ptype g_E.E::e" "type = int"
9733fc94
DJ
459 gdb_test "ptype g_E.E::x" "type = int"
460}
461
ebac27b4 462# Multiple inheritance, print complete classes.
c906108c 463
ebac27b4
MC
464proc test_print_mi_classes { } {
465 global vhn
c906108c 466
ebac27b4
MC
467 # Print all members of g_D.
468 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\}"
c906108c 469
ebac27b4
MC
470 # Print all members of g_E.
471 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\}"
c906108c
SS
472}
473
ebac27b4
MC
474# Single inheritance, print anonymous unions.
475# GDB versions prior to 4.14 entered an infinite loop when printing
476# the type of a class containing an anonymous union, and they were also
477# incapable of printing the member of an anonymous union.
478# We test the printing of the member first, and perform the other tests
479# only if the test succeeds, to avoid the infinite loop.
c906108c 480#
ebac27b4
MC
481# GDB HEAD 2004-01-27 with hp aCC A.03.45 crashes on the first test.
482# -- chastain 2004-01-27
c906108c 483
ebac27b4 484proc test_print_anon_union {} {
c906108c 485 global gdb_prompt
a0b3c4fd 486 global ws
c906108c 487 global nl
ebac27b4 488 global vhn
c906108c 489
ebac27b4 490 gdb_test "print g_anon_union.a" "$vhn = 2" "print anonymous union member"
c906108c 491
ebac27b4
MC
492 set name "print variable of type anonymous union"
493 gdb_test_multiple "print g_anon_union" $name {
907af001 494 -re "$vhn = \{one = 1, \{a = 2, b = \[0-9\]+\}\}$nl$gdb_prompt $" {
ebac27b4 495 pass $name
c906108c 496 }
c906108c
SS
497 }
498
907af001
UW
499 set name "print type of anonymous union"
500 set re_tag "class_with_anon_union"
5984a431 501 set re_class "(class $re_tag \{${ws}public:|struct $re_tag \{)"
907af001
UW
502 set re_fields "int one;${ws}union \{${ws}int a;${ws}long( int)? b;${ws}\};"
503 gdb_test_multiple "ptype g_anon_union" $name {
504 -re "type = $re_class${ws}$re_fields$nl\}$nl$gdb_prompt $" {
505 pass $name
a0b3c4fd 506 }
907af001 507 }
ebac27b4 508}
c906108c 509
c906108c 510
ebac27b4 511# Single virtual inheritance, print individual members.
c906108c 512
ebac27b4
MC
513proc test_print_svi_members { } {
514 global vhn
c906108c 515
ebac27b4
MC
516 # Print all members of g_vA.
517 gdb_test "print g_vA.vA::va" "$vhn = 1"
518 gdb_test "print g_vA.vA::vx" "$vhn = 2"
c906108c 519
ebac27b4
MC
520 # Print members of g_vA using compact form.
521 gdb_test "print g_vA.va" "$vhn = 1"
522 gdb_test "print g_vA.vx" "$vhn = 2"
523
524 # Print all members of g_vB.
525 gdb_test "print g_vB.vA::va" "$vhn = 3"
526 gdb_test "print g_vB.vA::vx" "$vhn = 4"
527 gdb_test "print g_vB.vB::vb" "$vhn = 5"
528 gdb_test "print g_vB.vB::vx" "$vhn = 6"
529
530 # Print members of g_vB using compact form.
531 gdb_test "print g_vB.va" "$vhn = 3"
532 gdb_test "print g_vB.vb" "$vhn = 5"
533 gdb_test "print g_vB.vx" "$vhn = 6"
534
535 # Print all members of g_vC.
536 gdb_test "print g_vC.vA::va" "$vhn = 7"
537 gdb_test "print g_vC.vA::vx" "$vhn = 8"
538 gdb_test "print g_vC.vC::vc" "$vhn = 9"
539 gdb_test "print g_vC.vC::vx" "$vhn = 10"
540
541 # Print members of g_vC using compact form.
542 gdb_test "print g_vC.va" "$vhn = 7" "print g_vC.va"
543 gdb_test "print g_vC.vc" "$vhn = 9" "print g_vC.vc"
544 gdb_test "print g_vC.vx" "$vhn = 10" "print g_vC.vx"
c906108c
SS
545}
546
c906108c 547# Single virtual inheritance, print complete classes.
c906108c 548
ebac27b4 549proc test_print_svi_classes { } {
c906108c
SS
550 global gdb_prompt
551 global hex
c906108c 552 global nl
ebac27b4 553 global vhn
c906108c
SS
554
555 # Print all members of g_vA.
ebac27b4 556 gdb_test "print g_vA" "$vhn = \{va = 1, vx = 2\}"
c906108c
SS
557
558 # Print all members of g_vB.
ebac27b4
MC
559 set re_vbptr_2 "(_vb.2vA|_vb.vA)"
560 set re_vbptr_3 "_vptr.vB"
561
562 set name "print g_vB"
563 gdb_test_multiple "print g_vB" $name {
564 -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_2 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
565 # gcc 2.95.3 -gdwarf-2
566 # gcc 2.95.3 -gstabs+
567 pass $name
568 }
569 -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
9366563b
MC
570 # gcc 3.3.4 -gdwarf-2
571 # gcc 3.4.1 -gdwarf-2
572 # gcc 3.4.1 -gstabs+
573 # gcc HEAD 2004-07-31 -gdwarf-2
ebac27b4
MC
574 pass "$name (FIXME v3 vtbl ptr)"
575 }
576 -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <VTT for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" {
9366563b
MC
577 # gcc 3.3.4 -gstabs+
578 pass $name
579 }
580 -re "$vhn = \{<vA> = \{va = 3, vx = 4\}, $re_vbptr_3 = $hex <typeinfo for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" {
581 # gcc HEAD 2004-07-31 -gstabs+
ebac27b4 582 pass $name
5178b9d6 583 }
c906108c
SS
584 }
585
586 # Print all members of g_vC.
ebac27b4
MC
587 set re_vbptr_2 "(_vb.2vA|_vb.vA)"
588 set re_vbptr_3 "_vptr.vC"
589
590 set name "print g_vC"
591 gdb_test_multiple "print g_vC" $name {
592 -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_2 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
593 # gcc 2.95.3 -gdwarf-2
594 # gcc 2.95.3 -gstabs+
595 pass $name
596 }
597 -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
9366563b
MC
598 # gcc 3.3.4 -gdwarf-2
599 # gcc 3.4.1 -gdwarf-2
600 # gcc 3.4.1 -gstabs+
601 # gcc HEAD 2004-07-31 -gdwarf-2
ebac27b4
MC
602 pass "$name (FIXME v3 vtbl ptr)"
603 }
604 -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <VTT for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" {
9366563b
MC
605 # gcc 3.3.4 -gstabs+
606 pass $name
607 }
608 -re "$vhn = \{<vA> = \{va = 7, vx = 8\}, $re_vbptr_3 = $hex <typeinfo for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" {
609 # gcc HEAD 2004-07-31 -gstabs+
ebac27b4 610 pass $name
a0b3c4fd 611 }
a0b3c4fd 612 }
c906108c
SS
613}
614
c906108c 615# Multiple virtual inheritance, print individual members.
c906108c 616
ebac27b4
MC
617proc test_print_mvi_members { } {
618 global vhn
c906108c
SS
619
620 # Print all members of g_vD.
ebac27b4
MC
621 gdb_test "print g_vD.vA::va" "$vhn = 19"
622 gdb_test "print g_vD.vA::vx" "$vhn = 20"
623 gdb_test "print g_vD.vB::vb" "$vhn = 21"
624 gdb_test "print g_vD.vB::vx" "$vhn = 22"
625 gdb_test "print g_vD.vC::vc" "$vhn = 23"
626 gdb_test "print g_vD.vC::vx" "$vhn = 24"
627 gdb_test "print g_vD.vD::vd" "$vhn = 25"
628 gdb_test "print g_vD.vD::vx" "$vhn = 26"
c906108c
SS
629
630 # Print all members of g_vE.
ebac27b4
MC
631 gdb_test "print g_vE.vA::va" "$vhn = 0"
632 gdb_test "print g_vE.vA::vx" "$vhn = 0"
633 gdb_test "print g_vE.vB::vb" "$vhn = 0"
634 gdb_test "print g_vE.vB::vx" "$vhn = 0"
635 gdb_test "print g_vE.vC::vc" "$vhn = 0"
636 gdb_test "print g_vE.vC::vx" "$vhn = 0"
637 gdb_test "print g_vE.vD::vd" "$vhn = 0"
638 gdb_test "print g_vE.vD::vx" "$vhn = 0"
639 gdb_test "print g_vE.vE::ve" "$vhn = 27"
640 gdb_test "print g_vE.vE::vx" "$vhn = 28"
c906108c
SS
641}
642
ebac27b4 643# Multiple virtual inheritance, print complete classes.
c906108c 644
ebac27b4 645proc test_print_mvi_classes { } {
a0b3c4fd 646 global gdb_prompt
ebac27b4 647 global hex
a0b3c4fd 648 global ws
c906108c 649 global nl
ebac27b4 650 global vhn
c906108c 651
ebac27b4 652 # Virtual base pointers for everybody.
c906108c 653
ebac27b4
MC
654 set re_vbptr_2_vA "(_vb.2vA|_vb.vA)"
655 set re_vbptr_2_vB "(_vb.2vB|_vb.vB)"
656 set re_vbptr_2_vC "(_vb.2vC|_vb.vC)"
657 set re_vbptr_2_vD "(_vb.2vD|_vb.vD)"
658 set re_vbptr_3_vA "_vptr.vA"
659 set re_vbptr_3_vB "_vptr.vB"
660 set re_vbptr_3_vC "_vptr.vC"
661 set re_vbptr_3_vD "_vptr.vD"
662 set re_vbptr_3_vE "_vptr.vE"
c906108c
SS
663
664 # Print all members of g_vD.
665
ebac27b4
MC
666 set name "print g_vD"
667 gdb_test_multiple "print g_vD" $name {
668 -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 $" {
669 # gcc 2.95.3 -gdwarf-2
670 # gcc 2.95.3 -gstabs+
671 pass $name
c906108c 672 }
410528f0 673 -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 $" {
ebac27b4
MC
674 # gcc 3.3.2 -gdwarf-2
675 # gcc HEAD 2004-01-21 -gdwarf-2
676 # gcc HEAD 2004-01-21 -gstabs+
677 pass "$name (FIXME v3 vtbl ptr)"
5178b9d6 678 }
ebac27b4
MC
679 -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 $" {
680 # gcc 3.3.2 -gstabs+
681 pass "$name"
3c6cb4a1 682 }
c906108c
SS
683 }
684
685 # Print all members of g_vE.
686
ebac27b4
MC
687 set name "print g_vE"
688 gdb_test_multiple "print g_vE" $name {
689 -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 $" {
690 # gcc 2.95.3 -gdwarf-2
691 # gcc 2.95.3 -gstabs+
692 pass $name
a0b3c4fd 693 }
410528f0 694 -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 $" {
9366563b
MC
695 # gcc 3.3.4 -gdwarf-2
696 # gcc 3.3.4 -gstabs+
697 # gcc 3.4.1 -gdwarf-2
698 # gcc 3.4.1 -gstabs+
699 # gcc HEAD 2004-07-31 -gdwarf-2
ebac27b4 700 pass "$name (FIXME v3 vtbl ptr)"
5178b9d6 701 }
ec4646ef
MC
702 -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 $" {
703 # gcc 3.2.7-rh -gstabs+
9366563b
MC
704 pass $name
705 }
706 -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 $" {
707 # gcc HEAD 2004-07-31 -gstabs+
708 pass $name
ec4646ef 709 }
a0b3c4fd 710 }
c906108c
SS
711}
712
ebac27b4 713proc do_tests { } {
c906108c
SS
714 global subdir
715 global objdir
716 global srcdir
717 global binfile
718
c906108c
SS
719
720 # Start with a fresh gdb.
721
722 gdb_exit
723 gdb_start
724 gdb_reinitialize_dir $srcdir/$subdir
725 gdb_load $binfile
726
a8d52276 727 gdb_test_no_output "set width 0"
c906108c 728
ebac27b4
MC
729 if { ![runto_main] } then {
730 perror "couldn't run to main"
731 return
c906108c
SS
732 }
733
1cf0e11f 734 gdb_test_no_output "set language c++"
c906108c
SS
735 test_ptype_si
736 test_ptype_mi
737 test_ptype_vi
738 test_ptype_mvi
739
ebac27b4
MC
740 if { ![runto 'inheritance2'] } then {
741 perror "couldn't run to inheritance2"
742 return
c906108c
SS
743 }
744
745 test_print_si_members
746 test_print_si_classes
747 test_print_mi_members
9733fc94 748 test_print_mi_member_types
c906108c
SS
749 test_print_mi_classes
750 test_print_anon_union
751
ebac27b4
MC
752 if { ![runto 'inheritance4'] } {
753 perror "couldn't run to inheritance4"
754 return
c906108c
SS
755 }
756
757 test_print_svi_members
758 test_print_svi_classes
759 test_print_mvi_members
760 test_print_mvi_classes
761}
762
763do_tests
This page took 1.300527 seconds and 4 git commands to generate.