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