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