]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.cp/inherit.exp
2003-08-22 Michael Chastain <mec@shout.net>
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.cp / inherit.exp
1 # Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003
2 # Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 # Please email any bugs, comments, and/or additions to this file to:
19 # bug-gdb@prep.ai.mit.edu
20
21 # This file was written by Fred Fish. (fnf@cygnus.com)
22
23 set ws "\[\r\n\t \]+"
24 set nl "\[\r\n\]+"
25
26 # The format of a g++ virtual base pointer.
27 set vbptr "(_vb\[$.\]|__vb_)\[0-9\]?"
28
29 if $tracelevel then {
30 strace $tracelevel
31 }
32
33 if { [skip_cplus_tests] } { continue }
34
35 # Note - create separate "inherit" executable from misc.cc
36
37 set testfile "inherit"
38 set srcfile misc.cc
39 set binfile ${objdir}/${subdir}/${testfile}
40
41
42 # Create and source the file that provides information about the compiler
43 # used to compile the test case.
44
45 if [get_compiler_info ${binfile} "c++"] {
46 return -1
47 }
48
49 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
50 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
51 }
52
53 #
54 # Single inheritance, print individual members.
55 #
56
57 proc test_print_si_members {} {
58 # Print all members of g_A using fully qualified form.
59
60 gdb_test "print g_A.A::a" ".* = 1" "print g_A.A::a"
61
62 gdb_test "print g_A.A::x" ".* = 2" "print g_A.A::x"
63
64 # Print members of g_A using nonambiguous compact form.
65
66 gdb_test "print g_A.a" ".* = 1" "print g_A.a"
67
68 gdb_test "print g_A.x" ".* = 2" "print g_A.x"
69
70 # Print all members of g_B using fully qualified form.
71
72 gdb_test "print g_B.A::a" ".* = 3" "print g_B.A::a"
73
74 gdb_test "print g_B.A::x" ".* = 4" "print g_B.A::x"
75
76 gdb_test "print g_B.B::b" ".* = 5" "print g_B.B::b"
77
78 gdb_test "print g_B.B::x" ".* = 6" "print g_B.B::x"
79
80 # Print members of g_B using nonambiguous compact form.
81
82 gdb_test "print g_B.a" ".* = 3" "print g_B.a"
83
84 gdb_test "print g_B.b" ".* = 5" "print g_B.b"
85
86 gdb_test "print g_B.x" ".* = 6" "print g_B.x"
87
88 # Print all members of g_C using fully qualified form.
89
90 gdb_test "print g_C.A::a" ".* = 7" "print g_C.A::a"
91
92 gdb_test "print g_C.A::x" ".* = 8" "print g_C.A::x"
93
94 gdb_test "print g_C.C::c" ".* = 9" "print g_C.C::c"
95
96 gdb_test "print g_C.C::x" ".* = 10" "print g_C.C::x"
97
98 # Print members of g_C using nonambiguous compact form.
99
100 gdb_test "print g_C.a" ".* = 7" "print g_C.a"
101
102 gdb_test "print g_C.c" ".* = 9" "print g_C.c"
103
104 gdb_test "print g_C.x" ".* = 10" "print g_C.x"
105 }
106
107 #
108 # Single inheritance, print type definitions.
109 #
110
111 proc test_ptype_si {} {
112 global gdb_prompt
113 global ws
114 global nl
115 global hp_aCC_compiler
116
117 # Print class A as a type.
118
119 send_gdb "ptype A\n"
120 gdb_expect {
121 -re "type = class A \{$nl.*\[ \]*int a;$nl\[ \]*int x;$nl.*\[ \]*\}$nl$gdb_prompt $" {
122 pass "ptype A (FIXME)"
123 }
124 -re "type = struct A \{$nl\[ \]*int a;$nl\[ \]*int x;$nl\[ \]*\}$nl$gdb_prompt $" {
125 setup_xfail "*-*-*"
126 fail "ptype A (FIXME)"
127 }
128 -re ".*$gdb_prompt $" { fail "ptype A" }
129 timeout { fail "ptype A (timeout)" ; return }
130 }
131
132 # Print class A as an explicit class.
133
134 send_gdb "ptype class A\n"
135 gdb_expect {
136 -re "type = class A \{$nl.*\[ \]*int a;$nl\[ \]*int x;$nl.*\[ \]*\}$nl$gdb_prompt $" {
137 pass "ptype class A (FIXME)"
138 }
139 -re "type = struct A \{$nl\[ \]*int a;$nl\[ \]*int x;$nl\[ \]*\}$nl$gdb_prompt $" {
140 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
141 fail "ptype class A (FIXME)"
142 }
143 -re ".*$gdb_prompt $" { fail "ptype class A" }
144 timeout { fail "ptype class A (timeout)" ; return }
145 }
146
147 # Print type of an object of type A.
148
149 send_gdb "ptype g_A\n"
150 gdb_expect {
151 -re "type = class A \{$nl.*\[ \]*int a;$nl\[ \]*int x;$nl.*\[ \]*\}$nl$gdb_prompt $" {
152 pass "ptype g_A (FIXME)"
153 }
154 -re "type = struct A \{$nl\[ \]*int a;$nl\[ \]*int x;$nl\[ \]*\}$nl$gdb_prompt $" {
155 if {!$hp_aCC_compiler} {setup_xfail "*-*-*"}
156 fail "ptype g_A (FIXME)"
157 }
158 -re ".*$gdb_prompt $" { fail "ptype g_A" }
159 timeout { fail "ptype g_A (timeout)" ; return }
160 }
161
162 # Print class B as a type.
163
164 gdb_test "ptype B" "type = class B : public A \{$nl\[ \]*public:$nl\[ \]*int b;$nl\[ \]*int x;$nl.*\}" "ptype B"
165
166 # Print class B as an explicit class.
167
168 gdb_test "ptype class B" "type = class B : public A \{$nl\[ \]*public:$nl\[ \]*int b;$nl\[ \]*int x;$nl.*\}" "ptype class B"
169
170 # Print type of an object of type B.
171
172 gdb_test "ptype g_B" "type = class B : public A \{$nl\[ \]*public:$nl\[ \]*int b;$nl\[ \]*int x;$nl.*\}" "ptype g_B"
173
174 # Print class C as a type.
175
176 gdb_test "ptype C" "type = class C : public A \{$nl\[ \]*public:$nl\[ \]*int c;$nl\[ \]*int x;$nl.*\}" "ptype C"
177
178 # Print class C as an explicit class.
179
180 gdb_test "ptype class C" "type = class C : public A \{$nl\[ \]*public:$nl\[ \]*int c;$nl\[ \]*int x;$nl.*\}" "ptype class C"
181
182 # Print type of an object of type g_C.
183
184 gdb_test "ptype g_C" "type = class C : public A \{$nl\[ \]*public:$nl\[ \]*int c;$nl\[ \]*int x;$nl.*\}" "ptype g_C"
185
186 # gcc cygnus-2.3.3 (Q1) has this bug, but it was fixed as of
187 # cygnus-2.3.3-930417. PR 2819.
188 send_gdb "ptype tagless_struct\n"
189 gdb_expect {
190 -re "type = class \{${ws}public:${ws}int one;${ws}int two;${ws}tagless_struct & operator=\\(tagless_struct (const ?)?&\\);${ws}tagless_struct\\(tagless_struct (const ?)?&\\);${ws}tagless_struct\\(\\);${ws}\}$nl$gdb_prompt $" {
191 pass "ptype tagless struct"
192 }
193 -re "type = class \{${ws}public:${ws}int one;${ws}int two;;${ws}\}$nl$gdb_prompt $" {
194 pass "ptype tagless struct"
195 }
196 -re "type = (struct|class).*\{.*int one;.*int two;.*\}$nl$gdb_prompt $" {
197 pass "ptype tagless struct (obsolete gcc or gdb)"
198 }
199 -re ".*$gdb_prompt $" {
200 fail "ptype tagless struct"
201 }
202 timeout {
203 fail "ptype tagless struct (timeout)"
204 }
205 }
206
207 send_gdb "ptype v_tagless\n"
208 gdb_expect {
209 -re "type = class \{${ws}public:${ws}int one;${ws}int two;${ws}tagless_struct & operator=\\(tagless_struct (const ?)?&\\);${ws}tagless_struct\\(tagless_struct (const ?)?&\\);${ws}tagless_struct\\(\\);${ws}\}$nl$gdb_prompt $" {
210 pass "ptype variable of type tagless struct"
211 }
212 -re "type = class \{${ws}public:${ws}int one;${ws}int two;;${ws}\}$nl$gdb_prompt $" {
213 pass "ptype tagless struct"
214 }
215 -re "type = (struct|class).*\{.*int one;.*int two;.*\}$nl$gdb_prompt $" {
216 pass "ptype variable of type tagless struct (obsolete gcc or gdb)"
217 }
218 -re ".*$gdb_prompt $" {
219 fail "ptype variable of type tagless struct"
220 }
221 timeout {
222 fail "ptype variable of type tagless struct (timeout)"
223 }
224 }
225 }
226
227 #
228 # Single inheritance, print complete classes.
229 #
230
231 proc test_print_si_classes {} {
232 # Print all members of g_A.
233
234 gdb_test "print g_A" ".* = \{a = 1, x = 2\}" "print g_A"
235
236 # Print all members of g_B.
237
238 gdb_test "print g_B" ".* = \{\<(class |)A\> = \{a = 3, x = 4\}, b = 5, x = 6\}" "print g_B"
239
240 # Print all members of g_C.
241
242 gdb_test "print g_C" ".* = \{\<(class |)A\> = \{a = 7, x = 8\}, c = 9, x = 10\}" "print g_C"
243 }
244
245 #
246 # Single inheritance, print anonymous unions.
247 # GDB versions prior to 4.14 entered an infinite loop when printing
248 # the type of a class containing an anonymous union, and they were also
249 # incapable of printing the member of an anonymous union.
250 # We test the printing of the member first, and perform the other tests
251 # only if the test succeeds, to avoid the infinite loop.
252 #
253
254 proc test_print_anon_union {} {
255 global gdb_prompt
256 global ws
257 global nl
258
259 gdb_test "print g_anon_union.a" ".* = 2" "print anonymous union member"
260 send_gdb "print g_anon_union\n"
261 gdb_expect {
262 -re ".* = \{one = 1, ( = |)\{a = 2, b = 2\}\}$nl$gdb_prompt $" {
263 pass "print variable of type anonymous union"
264 }
265 -re ".* = .*\{one = 1, ( = |)\{a = 2, b = .*\}\}$nl$gdb_prompt $" {
266 pass "print variable of type anonymous union (obsolete gcc or gdb)"
267 }
268 -re ".*$nl$gdb_prompt $" {
269 fail "print variable of type anonymous union"
270 }
271 timeout {
272 fail "print variableof type anonymous union (timeout)"
273 }
274 }
275 send_gdb "ptype g_anon_union\n"
276 gdb_expect {
277 -re "type = class class_with_anon_union \{${ws}public:${ws}int one;${ws}union \{${ws}public:${ws}int a;${ws}long int b;${ws}union \{\.\.\.\} & operator=\\(union \{\.\.\.\} &\\);${ws}\\\$_0 \\(union \{\.\.\.\} &\\);${ws}\\\$_0 \\(\\);${ws}\};${ws}class_with_anon_union & operator=\\(class_with_anon_union const &\\);${ws}class_with_anon_union\\(class_with_anon_union const &\\);${ws}class_with_anon_union\\(void\\);${ws}\}$nl$gdb_prompt $" {
278 pass "print type of anonymous union"
279 }
280 -re "type = class class_with_anon_union \{${ws}public:${ws}int one;${ws}union \{${ws}int a;${ws}long int b;${ws}\};${ws}class_with_anon_union & operator=\\(class_with_anon_union const ?&\\);${ws}class_with_anon_union\\(class_with_anon_union const ?&\\);${ws}class_with_anon_union\\((void|)\\);${ws}\}$nl$gdb_prompt $" {
281 pass "print type of anonymous union"
282 }
283 -re "type = class class_with_anon_union \{${ws}public:${ws}int one;${ws}union \{${ws}int a;${ws}long int b;${ws}\};${ws}\}$nl$gdb_prompt $" {
284 pass "print type of anonymous union"
285 }
286 -re "type = (struct|class).*\{.*int one;.*union \{.*int a;.*(long|long int|int) b;.*\};.*\}$nl$gdb_prompt $" {
287 pass "print type of anonymous union (obsolete gcc or gdb)"
288 }
289 -re ".*$nl$gdb_prompt $" {
290 fail "print type of anonymous union"
291 }
292 timeout {
293 fail "print type of anonymous union (timeout)"
294 }
295 }
296 }
297
298 #
299 # Multiple inheritance, print individual members.
300 #
301
302 proc test_print_mi_members {} {
303 global gdb_prompt
304 global nl
305 global hp_aCC_compiler
306
307 # Print all members of g_A.
308
309 gdb_test "print g_A.A::a" ".* = 1" "print g_A.A::a"
310
311 gdb_test "print g_A.A::x" ".* = 2" "print g_A.A::x"
312
313 # Print all members of g_B.
314
315 gdb_test "print g_B.A::a" ".* = 3" "print g_B.A::a"
316
317 gdb_test "print g_B.A::x" ".* = 4" "print g_B.A::x"
318
319 gdb_test "print g_B.B::b" ".* = 5" "print g_B.B::b"
320
321 gdb_test "print g_B.B::x" ".* = 6" "print g_B.B::x"
322
323 # Print all members of g_C.
324
325 gdb_test "print g_C.A::a" ".* = 7" "print g_C.A::a"
326
327 gdb_test "print g_C.A::x" ".* = 8" "print g_C.A::x"
328
329 gdb_test "print g_C.C::c" ".* = 9" "print g_C.C::c"
330
331 gdb_test "print g_C.C::x" ".* = 10" "print g_C.C::x"
332
333 # Print all members of g_D.
334
335 # The following is ambiguous, and gdb should detect this.
336 # For now, accept gdb's behavior as an expected failure if it
337 # simply prints either member correctly.
338
339 send_gdb "print g_D.A::a\n"
340 gdb_expect {
341 -re "warning: A ambiguous; using D::C::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 15$nl$gdb_prompt $" {
342 pass "print g_D.A::a"
343 }
344 -re "warning: A ambiguous; using D::B::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 11$nl$gdb_prompt $" {
345 pass "print g_D.A::a (using B)"
346 }
347 -re ".* = 15$nl$gdb_prompt $" {
348 kfail "gdb/68" "print g_D.A::a"
349 }
350 -re ".* = 11$nl$gdb_prompt $" {
351 kfail "gdb/68" "print g_D.A::a"
352 }
353 -re ".*$gdb_prompt $" { fail "print g_D.A::a" }
354 timeout { fail "print g_D.A::a (timeout)" ; return }
355 }
356
357 # The following is ambiguous, and gdb should detect this.
358 # For now, accept gdb's behavior as an expected failure if it
359 # simply prints either member correctly.
360
361 send_gdb "print g_D.A::x\n"
362 gdb_expect {
363 -re "warning: A ambiguous; using D::C::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 16$nl$gdb_prompt $" {
364 pass "print g_D.A::x"
365 }
366 -re "warning: A ambiguous; using D::B::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 12$nl$gdb_prompt $" {
367 pass "print g_D.A::x (using B)"
368 }
369 -re ".* = 16$nl$gdb_prompt $" {
370 kfail "gdb/68" "print g_D.A::x"
371 }
372 -re ".* = 12$nl$gdb_prompt $" {
373 kfail "gdb/68" "print g_D.A::x"
374 }
375 -re ".*$gdb_prompt $" { fail "print g_D.A::x" }
376 timeout { fail "print g_D.A::x (timeout)" ; return }
377 }
378
379 gdb_test "print g_D.B::b" ".* = 13" "print g_D.B::b"
380
381 gdb_test "print g_D.B::x" ".* = 14" "print g_D.B::x"
382
383 gdb_test "print g_D.C::c" ".* = 17" "print g_D.C::c"
384
385 gdb_test "print g_D.C::x" ".* = 18" "print g_D.C::x"
386
387 gdb_test "print g_D.D::d" ".* = 19" "print g_D.D::d"
388
389 gdb_test "print g_D.D::x" ".* = 20" "print g_D.D::x"
390
391 # Print all members of g_E.
392
393 # The following is ambiguous, and gdb should detect this.
394 # For now, accept gdb's behavior as an expected failure if it
395 # simply prints either member correctly.
396
397 send_gdb "print g_E.A::a\n"
398 gdb_expect {
399 -re ".* = 21$nl$gdb_prompt $" {
400 kfail "gdb/68" "print g_E.A::a"
401 }
402 -re ".* = 25$nl$gdb_prompt $" {
403 kfail "gdb/68" "print g_E.A::a"
404 }
405 -re ".*$gdb_prompt $" { fail "print g_E.A::a" }
406 timeout { fail "print g_E.A::a (timeout)" ; return }
407 }
408
409 # The following is ambiguous, and gdb should detect this.
410 # For now, accept gdb's behavior as an expected failure if it
411 # simply prints either member correctly.
412
413 send_gdb "print g_E.A::x\n"
414 gdb_expect {
415 -re "warning: A ambiguous; using E::D::C::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 26$nl$gdb_prompt $" {
416 pass "print g_E.A::x"
417 }
418 -re "warning: A ambiguous; using E::D::B::A. Use a cast to disambiguate.$nl\\$\[0-9\]* = 22$nl$gdb_prompt $" {
419 pass "print g_E.A::x (using B)"
420 }
421 -re ".* = 26$nl$gdb_prompt $" {
422 kfail "gdb/68" "print g_E.A::x"
423 }
424 -re ".* = 22$nl$gdb_prompt $" {
425 kfail "gdb/68" "print g_E.A::x"
426 }
427 -re ".*$gdb_prompt $" { fail "print g_E.A::x" }
428 timeout { fail "print g_E.A::x (timeout)" ; return }
429 }
430
431 gdb_test "print g_E.B::b" ".* = 23" "print g_E.B::b"
432
433 gdb_test "print g_E.B::x" ".* = 24" "print g_E.B::x"
434
435 gdb_test "print g_E.C::c" ".* = 27" "print g_E.C::c"
436
437 gdb_test "print g_E.C::x" ".* = 28" "print g_E.C::x"
438
439 gdb_test "print g_E.D::d" ".* = 29" "print g_E.D::d"
440
441 gdb_test "print g_E.D::x" ".* = 30" "print g_E.D::x"
442
443 gdb_test "print g_E.E::e" ".* = 31" "print g_E.E::e"
444
445 gdb_test "print g_E.E::x" ".* = 32" "print g_E.E::x"
446 }
447
448 #
449 # Multiple inheritance, print type definitions.
450 #
451
452 proc test_ptype_mi {} {
453 global nl
454
455 gdb_test "ptype D" "type = class D : public B, public C \{$nl\[ \]*public:$nl\[ \]*int d;$nl\[ \]*int x;$nl.*\}" "ptype D"
456
457 gdb_test "ptype class D" "type = class D : public B, public C \{$nl\[ \]*public:$nl\[ \]*int d;$nl\[ \]*int x;$nl.*\}" "ptype class D"
458
459 gdb_test "ptype g_D" "type = class D : public B, public C \{$nl\[ \]*public:$nl\[ \]*int d;$nl\[ \]*int x;$nl.*\}" "ptype g_D"
460
461 gdb_test "ptype E" "type = class E : public D \{$nl\[ \]*public:$nl\[ \]*int e;$nl\[ \]*int x;$nl.*\}" "ptype E"
462
463 gdb_test "ptype class E" "type = class E : public D \{$nl\[ \]*public:$nl\[ \]*int e;$nl\[ \]*int x;$nl.*\}" "ptype class E"
464
465 gdb_test "ptype g_E" "type = class E : public D \{$nl\[ \]*public:$nl\[ \]*int e;$nl\[ \]*int x;$nl.*\}" "ptype g_E"
466 }
467
468 #
469 # Multiple inheritance, print complete classes.
470 #
471
472 proc test_print_mi_classes {} {
473 # Print all members of g_D.
474
475 gdb_test "print g_D" ".* = \{\<(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\}" "print g_D"
476
477 # Print all members of g_E.
478
479 gdb_test "print g_E" ".* = \{\<(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\}" "print g_E"
480 }
481
482 #
483 # Single virtual inheritance, print individual members.
484 #
485
486 proc test_print_svi_members {} {
487 global gdb_prompt
488 global decimal
489 global nl
490
491 # Print all members of g_vA.
492
493 gdb_test "print g_vA.vA::va" ".* = 1" "print g_vA.vA::va"
494
495 gdb_test "print g_vA.vA::vx" ".* = 2" "print g_vA.vA::vx"
496
497 # Print members of g_vA using compact form.
498
499 gdb_test "print g_vA.va" ".* = 1" "print g_vA.va"
500
501 gdb_test "print g_vA.vx" ".* = 2" "print g_vA.vx"
502
503 # Print all members of g_vB.
504
505 send_gdb "print g_vB.vA::va\n"
506 gdb_expect {
507 -re ".* = 3$nl$gdb_prompt $" { pass "print g_vB.vA::va" }
508 -re ".*virtual baseclass botch.*$gdb_prompt $" {
509 # Does not happen with gcc cygnus-2.4.5-930828
510 fail "print g_vB.vA::va (known bug with gcc cygnus-2.4.5-930417)"
511 # Many of the rest of these tests have the same problem.
512 return 0
513 }
514 -re ".*$gdb_prompt $" { fail "print g_vB.vA::va" }
515 timeout { fail "print g_vB.vA::va (timeout)" ; return }
516 }
517
518 gdb_test "print g_vB.vA::vx" ".* = 4" "print g_vB.vA::vx"
519
520 gdb_test "print g_vB.vB::vb" ".* = 5" "print g_vB.vB::vb"
521
522 gdb_test "print g_vB.vB::vx" ".* = 6" "print g_vB.vB::vx"
523
524 # Print members of g_vB using compact form.
525
526 gdb_test "print g_vB.va" ".* = 3" "print g_vB.va"
527
528 gdb_test "print g_vB.vb" ".* = 5" "print g_vB.vb"
529
530 gdb_test "print g_vB.vx" ".* = 6" "print g_vB.vx"
531
532 # Print all members of g_vC.
533
534 gdb_test "print g_vC.vA::va" ".* = 7" "print g_vC.vA::va"
535
536 gdb_test "print g_vC.vA::vx" ".* = 8" "print g_vC.vA::vx"
537
538 gdb_test "print g_vC.vC::vc" ".* = 9" "print g_vC.vC::vc"
539
540 gdb_test "print g_vC.vC::vx" ".* = 10" "print g_vC.vC::vx"
541
542 # Print members of g_vC using compact form.
543
544 gdb_test "print g_vC.va" ".* = 7" "print g_vC.va"
545
546 gdb_test "print g_vC.vc" ".* = 9" "print g_vC.vc"
547
548 gdb_test "print g_vC.vx" ".* = 10" "print g_vC.vx"
549 }
550
551 #
552 # Single virtual inheritance, print type definitions.
553 #
554
555 proc test_ptype_vi {} {
556 global gdb_prompt
557 global ws
558 global nl
559 global vbptr
560
561 # This class does not use any C++-specific features, so it's fine for
562 # it to print as "struct".
563 send_gdb "ptype vA\n"
564 gdb_expect {
565 -re "type = class vA \{$nl\[ \]*public:$nl\[ \]*int va;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
566 pass "ptype vA"
567 }
568 -re "type = struct vA \{$nl\[ \]*int va;$nl\[ \]*int vx;$nl\}$nl$gdb_prompt $" {
569 pass "ptype vA"
570 }
571 -re ".*$gdb_prompt $" { fail "ptype vA" }
572 timeout { fail "ptype vA (timeout)" ; return }
573 }
574
575 # This class does not use any C++-specific features, so it's fine for
576 # it to print as "struct".
577 send_gdb "ptype class vA\n"
578 gdb_expect {
579 -re "type = class vA \{$nl\[ \]*public:$nl\[ \]*int va;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
580 pass "ptype class vA"
581 }
582 -re "type = struct vA \{$nl\[ \]*int va;$nl\[ \]*int vx;$nl\}$nl$gdb_prompt $" {
583 pass "ptype class vA"
584 }
585 -re ".*$gdb_prompt $" { fail "ptype class vA" }
586 timeout { fail "ptype class vA (timeout)" ; return }
587 }
588
589 # This class does not use any C++-specific features, so it's fine for
590 # it to print as "struct".
591 send_gdb "ptype g_vA\n"
592 gdb_expect {
593 -re "type = class vA \{$nl\[ \]*public:$nl\[ \]*int va;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
594 pass "ptype g_vA"
595 }
596 -re "type = struct vA \{$nl\[ \]*int va;$nl\[ \]*int vx;$nl\}$nl$gdb_prompt $" {
597 pass "ptype g_vA"
598 }
599 -re ".*$gdb_prompt $" { fail "ptype g_vA" }
600 timeout { fail "ptype g_vA (timeout)" ; return }
601 }
602
603 send_gdb "ptype vB\n"
604 gdb_expect {
605 -re "ptype vB${nl}type = class vB : public virtual vA \{$nl private:${ws}vA \\*${vbptr}vA;$nl public:${ws}int vb;${ws}int vx;$nl.*\}$nl$gdb_prompt $" {
606 pass "ptype vB"
607 }
608 -re "ptype vB${nl}type = class vB : public virtual vA \{$nl public:${ws}int vb;${ws}int vx;$nl.*\}$nl$gdb_prompt $" {
609 pass "ptype vB (aCC)"
610 }
611 -re ".*$gdb_prompt $" { fail "ptype vB" }
612 timeout { fail "ptype vB (timeout)" }
613 }
614
615 send_gdb "ptype class vB\n"
616 gdb_expect {
617 -re "type = class vB : public virtual vA \{$nl\[ \]*private:$nl\[ \]*vA \\*${vbptr}vA;$nl\[ \]*public:$nl\[ \]*int vb;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
618 pass "ptype class vB"
619 }
620 -re "type = class vB : public virtual vA \{$nl\[ \]*public:$nl\[ \]*int vb;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
621 pass "ptype class vB (aCC)"
622 }
623 -re ".*$gdb_prompt $" { fail "ptype class vB" }
624 timeout { fail "ptype class vB (timeout)" }
625 }
626
627 send_gdb "ptype g_vB\n"
628 gdb_expect {
629 -re "type = class vB : public virtual vA \{$nl\[ \]*private:$nl\[ \]*vA \\*${vbptr}vA;$nl\[ \]*public:$nl\[ \]*int vb;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
630 pass "ptype g_vB"
631 }
632 -re "type = class vB : public virtual vA \{$nl\[ \]*public:$nl\[ \]*int vb;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
633 pass "ptype g_vB (aCC)"
634 }
635 -re ".*$gdb_prompt $" { fail "ptype g_vB" }
636 timeout { fail "ptype g_vB (timeout)" }
637 }
638
639 send_gdb "ptype vC\n"
640 gdb_expect {
641 -re "type = class vC : public virtual vA \{$nl\[ \]*private:$nl\[ \]*vA \\*${vbptr}vA;$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
642 pass "ptype vC"
643 }
644 -re "type = class vC : public virtual vA \{$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
645 pass "ptype vC (aCC)"
646 }
647 -re ".*$gdb_prompt $" { fail "ptype vC" }
648 timeout { fail "ptype vC (timeout)" }
649 }
650
651 send_gdb "ptype class vC\n"
652 gdb_expect {
653 -re "type = class vC : public virtual vA \{$nl\[ \]*private:$nl\[ \]*vA \\*${vbptr}vA;$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
654 pass "ptype class vC"
655 }
656 -re "type = class vC : public virtual vA \{$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
657 pass "ptype class vC (aCC)"
658 }
659 -re ".*$gdb_prompt $" { fail "ptype class vC" }
660 timeout { fail "ptype class vC (timeout)" }
661 }
662
663 send_gdb "ptype g_vC\n"
664 gdb_expect {
665 -re "type = class vC : public virtual vA \{$nl\[ \]*private:$nl\[ \]*vA \\*${vbptr}vA;$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
666 pass "ptype g_vC"
667 }
668 -re "type = class vC : public virtual vA \{$nl\[ \]*public:$nl\[ \]*int vc;$nl\[ \]*int vx;$nl.*\}$nl$gdb_prompt $" {
669 pass "ptype g_vC (aCC)"
670 }
671 -re ".*$gdb_prompt $" { fail "ptype g_vC" }
672 timeout { fail "ptype g_vC (timeout)" }
673 }
674 }
675
676 #
677 # Single virtual inheritance, print complete classes.
678 #
679
680 proc test_print_svi_classes {} {
681 global gdb_prompt
682 global hex
683 global decimal
684 global nl
685 global vbptr
686
687 # Print all members of g_vA.
688
689 gdb_test "print g_vA" ".* = \{va = 1, vx = 2\}" "print g_vA"
690
691 # Print all members of g_vB.
692
693 send_gdb "print g_vB\n"
694 gdb_expect {
695 -re ".* = \{\<class vA\> = \{va = 3, vx = 4\}, vb = 5, vx = 6, Virtual table at $hex\}$nl$gdb_prompt $" {
696 pass "print g_vB (aCC)"
697 }
698 -re ".* = \{\<class vA\> = \{va = 3, vx = 4\}, vb = 5, vx = 6, __vfp = $hex\}$nl$gdb_prompt $" {
699 pass "print g_vB (aCC)"
700 }
701 -re ".* = \{\<vA\> = \{va = 3, vx = 4\}, ${vbptr}vA = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
702 pass "print g_vB"
703 }
704 -re ".* = \{\<vA\> = \{va = 3, vx = 4\}, _vptr.vB = $hex, vb = 5, vx = 6\}$nl$gdb_prompt $" {
705 pass "print g_vB (FIXME v3 vtbl ptr)"
706 }
707 -re ".* = \{\<vA\> = \{va = 3, vx = 4\}, _vptr.vB = $hex <VTT for vB>, vb = 5, vx = 6\}$nl$gdb_prompt $" {
708 # Happens with gcc 3.3 -gstabs+
709 # Does not happen with gcc 3.2.3 -gstabs+.
710 # Does not happen gcc HEAD%20030624 (pre-3.4) -gstabs+.
711 # -- chastain 2003-06-29
712 pass "print g_vB"
713 }
714
715 -re ".*invalid address 0x0.*$gdb_prompt $" {
716 # Does not happen with gcc cygnus-2.4.5-930828
717 fail "print g_vB (known bug with gcc cygnus-2.4.5-930417)"
718 # Many of the rest of these tests have the same problem.
719 return 0
720 }
721 -re ".*$gdb_prompt $" { fail "print g_vB" }
722 timeout { fail "print g_vB (timeout)" ; return }
723 }
724
725 # Print all members of g_vC.
726
727 send_gdb "print g_vC\n"
728 gdb_expect {
729 -re ".* = \{\<class vA\> = \{va = 7, vx = 8\}, vc = 9, vx = 10, Virtual table at $hex\}$nl$gdb_prompt $" {
730 pass "print g_vC (aCC)"
731 }
732 -re ".* = \{\<class vA\> = \{va = 7, vx = 8\}, vc = 9, vx = 10, __vfp = $hex\}$nl$gdb_prompt $" {
733 pass "print g_vC (aCC)"
734 }
735 -re ".* = \{\<vA\> = \{va = 7, vx = 8\}, ${vbptr}vA = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
736 pass "print g_vC"
737 }
738 -re ".* = \{\<vA\> = \{va = 7, vx = 8\}, _vptr.vC = $hex, vc = 9, vx = 10\}$nl$gdb_prompt $" {
739 pass "print g_vC (FIXME v3 vtbl ptr)"
740 }
741 -re ".* = \{\<vA\> = \{va = 7, vx = 8\}, _vptr.vC = $hex <VTT for vC>, vc = 9, vx = 10\}$nl$gdb_prompt $" {
742 # Happens with gcc 3.3 -gstabs+
743 # Does not happen with gcc 3.2.3 -gstabs+.
744 # Does not happen gcc HEAD%20030624 (pre-3.4) -gstabs+.
745 # -- chastain 2003-06-29
746 pass "print g_vC"
747 }
748 -re ".*$gdb_prompt $" { fail "print g_vC" }
749 timeout { fail "print g_vC (timeout)" }
750 }
751 }
752
753 #
754 # Multiple virtual inheritance, print individual members.
755 #
756
757 proc test_print_mvi_members {} {
758 global gdb_prompt
759 global decimal
760 global nl
761
762 # Print all members of g_vD.
763
764 send_gdb "print g_vD.vA::va\n"
765 gdb_expect {
766 -re ".* = 19$nl$gdb_prompt $" { pass "print g_vD.vA::va" }
767 -re ".*virtual baseclass botch.*$gdb_prompt $" {
768 # Does not happen with gcc cygnus-2.4.5-930828
769 fail "print g_vD.vA::va (known bug with gcc cygnus-2.4.5-930417)"
770 # Many of the rest of these tests have the same problem.
771 return 0
772 }
773 -re ".*$gdb_prompt $" { fail "print g_vD.vA::va" }
774 timeout { fail "print g_vD.vA::va (timeout)" ; return }
775 }
776
777 gdb_test "print g_vD.vA::vx" ".* = 20" "print g_vD.vA::vx"
778
779 gdb_test "print g_vD.vB::vb" ".* = 21" "print g_vD.vB::vb"
780
781 gdb_test "print g_vD.vB::vx" ".* = 22" "print g_vD.vB::vx"
782
783 gdb_test "print g_vD.vC::vc" ".* = 23" "print g_vD.vC::vc"
784
785 gdb_test "print g_vD.vC::vx" ".* = 24" "print g_vD.vC::vx"
786
787 gdb_test "print g_vD.vD::vd" ".* = 25" "print g_vD.vD::vd"
788
789 gdb_test "print g_vD.vD::vx" ".* = 26" "print g_vD.vD::vx"
790
791 # Print all members of g_vE.
792
793 gdb_test "print g_vE.vA::va" ".* = 0" "print g_vE.vA::va"
794
795 gdb_test "print g_vE.vA::vx" ".* = 0" "print g_vE.vA::vx"
796
797 gdb_test "print g_vE.vB::vb" ".* = 0" "print g_vE.vB::vb"
798
799 gdb_test "print g_vE.vB::vx" ".* = 0" "print g_vE.vB::vx"
800
801 gdb_test "print g_vE.vC::vc" ".* = 0" "print g_vE.vC::vc"
802
803 gdb_test "print g_vE.vC::vx" ".* = 0" "print g_vE.vC::vx"
804
805 gdb_test "print g_vE.vD::vd" ".* = 0" "print g_vE.vD::vd"
806
807 gdb_test "print g_vE.vD::vx" ".* = 0" "print g_vE.vD::vx"
808
809 gdb_test "print g_vE.vE::ve" ".* = 27" "print g_vE.vE::ve"
810
811 gdb_test "print g_vE.vE::vx" ".* = 28" "print g_vE.vE::vx"
812 }
813
814 #
815 # Multiple virtual inheritance, print type definitions.
816 #
817
818 proc test_ptype_mvi {} {
819 global gdb_prompt
820 global ws
821 global nl
822 global vbptr
823
824 send_gdb "ptype vD\n"
825 gdb_expect {
826 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*${vbptr}vC;${ws}vB \\*${vbptr}vB;${ws}public:${ws}int vd;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
827 pass "ptype vD"
828 }
829 -re ".*class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;.*\}.*$gdb_prompt $" {
830 pass "ptype vD"
831 }
832 -re ".*$gdb_prompt $" { fail "ptype vD" }
833 timeout { fail "(timeout) ptype vD" }
834 }
835
836 send_gdb "ptype class vD\n"
837 gdb_expect {
838 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*${vbptr}vC;${ws}vB \\*${vbptr}vB;${ws}public:${ws}int vd;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
839 pass "ptype class vD"
840 }
841 -re ".*class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;.*\}.*$gdb_prompt $" {
842 pass "ptype class vD"
843 }
844 -re ".*$gdb_prompt $" { fail "ptype class vD" }
845 timeout { fail "(timeout) ptype class vD" }
846 }
847
848 send_gdb "ptype g_vD\n"
849 gdb_expect {
850 -re "type = class vD : public virtual vB, public virtual vC \{${ws}private:${ws}vC \\*${vbptr}vC;${ws}vB \\*${vbptr}vB;${ws}public:${ws}int vd;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
851 pass "ptype g_vD"
852 }
853 -re ".*class vD : public virtual vB, public virtual vC \{${ws}public:${ws}int vd;${ws}int vx;\r\n.*\}.*$gdb_prompt $" {
854 pass "ptype g_vD"
855 }
856 -re ".*$gdb_prompt $" { fail "ptype g_vD" }
857 timeout { fail "(timeout) ptype g_vD" }
858 }
859
860 send_gdb "ptype vE\n"
861 gdb_expect {
862 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*${vbptr}vD;${ws}public:${ws}int ve;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
863 pass "ptype vE"
864 }
865 -re ".*class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;\r\n.*\}.*$gdb_prompt $" {
866 pass "ptype vE"
867 }
868 -re ".*$gdb_prompt $" { fail "ptype vE" }
869 timeout { fail "(timeout) ptype vE" }
870 }
871
872 send_gdb "ptype class vE\n"
873 gdb_expect {
874 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*${vbptr}vD;${ws}public:${ws}int ve;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
875 pass "ptype class vE"
876 }
877 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;\r\n.*\}.*$gdb_prompt $" {
878 pass "ptype class vE"
879 }
880 -re ".*$gdb_prompt $" { fail "ptype class vE" }
881 timeout { fail "(timeout) ptype class vE" }
882 }
883
884 send_gdb "ptype g_vE\n"
885 gdb_expect {
886 -re "type = class vE : public virtual vD \{${ws}private:${ws}vD \\*${vbptr}vD;${ws}public:${ws}int ve;${ws}int vx;$nl.*\}.*$gdb_prompt $" {
887 pass "ptype g_vE"
888 }
889 -re "type = class vE : public virtual vD \{${ws}public:${ws}int ve;${ws}int vx;\r\n.*\}.*$gdb_prompt $" {
890 pass "ptype g_vE"
891 }
892 -re ".*$gdb_prompt $" { fail "ptype g_vE" }
893 timeout { fail "(timeout) ptype g_vE" }
894 }
895 }
896
897 #
898 # Multiple virtual inheritance, print complete classes.
899 #
900
901 proc test_print_mvi_classes {} {
902 global gdb_prompt
903 global hex
904 global decimal
905 global nl
906 global vbptr
907
908 # Print all members of g_vD.
909
910 send_gdb "print g_vD\n"
911 gdb_expect {
912 -re ".* = \{\<class vB\> = \{\<class vA\> = \{va = 19, vx = 20\}, vb = 21, vx = 22, Virtual table at $hex\}, \<class vC\> = \{vc = 23, vx = 24, Virtual table at $hex\}, vd = 25, vx = 26, Virtual table at $hex\}$nl$gdb_prompt $" {
913 pass "print g_vD (aCC)"
914 }
915 -re ".* = \{\<class vB\> = \{\<class vA\> = \{va = 19, vx = 20\}, vb = 21, vx = 22, __vfp = $hex\}, \<class vC\> = \{vc = 23, vx = 24, __vfp = $hex\}, vd = 25, vx = 26, __vfp = $hex\}$nl$gdb_prompt $" {
916 pass "print g_vD (aCC)"
917 }
918 -re ".* = \{\<vB\> = \{\<vA\> = \{va = 19, vx = 20\}, ${vbptr}vA = $hex, vb = 21, vx = 22\}, \<vC\> = \{${vbptr}vA = $hex, vc = 23, vx = 24\}, ${vbptr}vC = $hex, ${vbptr}vB = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" {
919 pass "print g_vD"
920 }
921 -re ".* = \{\<vB\> = \{\<vA\> = \{va = 19, vx = 20\}, _vptr.vB = $hex, vb = 21, vx = 22\}, \<vC\> = \{_vptr.vC = $hex, vc = 23, vx = 24\}, _vptr.vD = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" {
922 pass "print g_vD (FIXME v3 vtbl ptr)"
923 }
924 -re ".* = \{\<vB\> = \{\<vA\> = \{va = 19, vx = 20\}, _vptr.vB = $hex, vb = 21, vx = 22\}, \<vC\> = \{_vptr.vC = $hex <VTT for vD>, vc = 23, vx = 24\}, _vptr.vD = $hex, vd = 25, vx = 26\}$nl$gdb_prompt $" {
925 # Happens with gcc 3.3 -gstabs+
926 # Does not happen with gcc 3.2.3 -gstabs+.
927 # Does not happen gcc HEAD%20030624 (pre-3.4) -gstabs+.
928 # -- chastain 2003-06-29
929 pass "print g_vD"
930 }
931 -re ".*invalid address 0x0.*$gdb_prompt $" {
932 # Does not happen with gcc cygnus-2.4.5-930828
933 fail "print g_vD (known bug with gcc cygnus-2.4.5-930417)"
934 # Many of the rest of these tests have the same problem.
935 return 0
936 }
937 -re ".*$gdb_prompt $" { fail "print g_vD" }
938 timeout { fail "print g_vD (timeout)" ; return }
939 }
940
941 # Print all members of g_vE.
942
943 send_gdb "print g_vE\n"
944 gdb_expect {
945 -re ".* = \{\<class vD\> = \{\<class vB\> = \{\<class vA\> = \{va = 0, vx = 0\}, vb = 0, vx = 0, Virtual table at $hex\}, \<class vC\> = \{vc = 0, vx = 0, Virtual table at $hex\}, vd = 0, vx = 0, Virtual table at $hex\}, ve = 27, vx = 28, Virtual table at $hex\}$nl$gdb_prompt $" {
946 pass "print g_vE (aCC)"
947 }
948 -re ".* = \{\<class vD\> = \{\<class vB\> = \{\<class vA\> = \{va = 0, vx = 0\}, vb = 0, vx = 0, __vfp = $hex\}, \<class vC\> = \{vc = 0, vx = 0, __vfp = $hex\}, vd = 0, vx = 0, __vfp = $hex\}, ve = 27, vx = 28, __vfp = $hex\}$nl$gdb_prompt $" {
949 pass "print g_vE (aCC)"
950 }
951 -re ".* = \{\<vD\> = \{\<vB\> = \{\<vA\> = \{va = 0, vx = 0\}, ${vbptr}vA = $hex, vb = 0, vx = 0\}, \<vC\> = \{${vbptr}vA = $hex, vc = 0, vx = 0\}, ${vbptr}vC = $hex, ${vbptr}vB = $hex, vd = 0, vx = 0\}, ${vbptr}vD = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" {
952 pass "print g_vE"
953 }
954 -re ".* = \{\<vD\> = \{\<vB\> = \{\<vA\> = \{va = 0, vx = 0\}, _vptr.vB = $hex *(\<VTT for vD\>)?, vb = 0, vx = 0\}, \<vC\> = \{_vptr.vC = $hex *(\<VTT for vD\>)?, vc = 0, vx = 0\}, _vptr.vD = $hex, vd = 0, vx = 0\}, _vptr.vE = $hex, ve = 27, vx = 28\}$nl$gdb_prompt $" {
955 pass "print g_vE (FIXME v3 vtbl ptr)"
956 }
957 -re ".*$gdb_prompt $" { fail "print g_vE" }
958 timeout { fail "print g_vE (timeout)" }
959 }
960 }
961
962 proc do_tests {} {
963 global prms_id
964 global bug_id
965 global subdir
966 global objdir
967 global srcdir
968 global binfile
969
970 set prms_id 0
971 set bug_id 0
972
973 # Start with a fresh gdb.
974
975 gdb_exit
976 gdb_start
977 gdb_reinitialize_dir $srcdir/$subdir
978 gdb_load $binfile
979
980 gdb_test "set language c++" ""
981 gdb_test "set width 0" ""
982
983 # Get the debug format for the compiled test case.
984
985 if { ![ runto_main] } {
986 gdb_suppress_tests;
987 }
988
989 test_ptype_si
990 test_ptype_mi
991 test_ptype_vi
992 test_ptype_mvi
993
994 gdb_stop_suppressing_tests;
995
996 if { ![ runto 'inheritance2' ] } {
997 gdb_suppress_tests;
998 }
999
1000 test_print_si_members
1001 test_print_si_classes
1002 test_print_mi_members
1003 test_print_mi_classes
1004 test_print_anon_union
1005
1006 gdb_stop_suppressing_tests;
1007
1008 if { ![ runto 'inheritance4' ] } {
1009 gdb_suppress_tests;
1010 }
1011
1012 test_print_svi_members
1013 test_print_svi_classes
1014 test_print_mvi_members
1015 test_print_mvi_classes
1016 }
1017
1018 do_tests