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