1 # Copyright (C) 1988, 1990, 1991, 1992, 1994 Free Software Foundation, Inc.
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.
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.
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. */
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
20 # This file was written by Rob Savoye. (rob@cygnus.com)
27 # test running programs
34 if ![file exists $objdir/$subdir/$binfile] then {
35 perror "$objdir/$subdir/$binfile does not exist."
41 gdb_reinitialize_dir $srcdir/$subdir
42 gdb_load $objdir/$subdir/$binfile
44 # Test ptype of unnamed enumeration members before any action causes
45 # the partial symbol table to be expanded to full symbols. This fails
46 # with stabs compilers which fail to use a nameless stab (such as
47 # pre-2.4.5 versions of gcc and most non-gcc compilers).
51 -re "type = enum primary1_tag \{red1, green1, blue1\}.*$prompt $"\
53 # The workaround is in effect. As this is a compiler, not GDB,
54 # bug, we'll make it a PASS but perhaps it should be an XFAIL.
55 pass "ptype unnamed enumeration member (worked around)"
57 -re "type = enum \{red1, green1, blue1\}.*$prompt $"\
58 { pass "ptype unnamed enumeration member" }
59 -re ".*$prompt $" { fail "ptype unnamed enumeration member" }
60 timeout { fail "(timeout) ptype unnamed enumeration member" }
64 # test ptype command with structures
66 # Here and elsewhere, we accept
67 # "long", "long int", or "int" for long variables (whatis.exp already
68 # has an XFAIL for "int" (Sun cc bug), so no need to fail it here).
69 send "ptype struct t_struct\n"
71 -re "type = struct t_struct \{.*
72 (unsigned |)char v_char_member;.*
73 (short|short int) v_short_member;.*
75 (long|long int|int) v_long_member;.*
76 float v_float_member;.*
77 double v_double_member;.*
78 \}.*$prompt $" { pass "ptype structure" }
79 -re ".*$prompt $" { fail "ptype structure" }
80 timeout { fail "(timeout) ptype structure" }
83 # Test the equivalence between '.' and '->' for struct member references.
85 if [gdb_test "ptype v_struct1.v_float_member" "type = float"]<0 then {
90 if [gdb_test "ptype v_struct1->v_float_member" "type = float"]<0 then {
95 if [gdb_test "ptype v_t_struct_p.v_float_member" "type = float"]<0 then {
100 if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then {
107 send "ptype struct link\n"
109 -re "type = struct link \{.*
110 struct link \[*\]next;.*
111 struct link \[*(\]+linkfunc\[)(\]+;.*
112 struct t_struct stuff.1..2..3.;.*
113 \}.*$prompt $" { pass "ptype linked list structure" }
116 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
117 # which isn't defined.
119 fail "ptype linked list structure (compiler bug in IBM's xlc)"
121 timeout { fail "(timeout) ptype linked list structure" }
126 # test ptype command with unions
128 send "ptype union t_union\n"
130 -re "type = union t_union \{.*
131 (unsigned |)char v_char_member;.*
132 (short|short int) v_short_member;.*
134 (long|long int|int) v_long_member;.*
135 float v_float_member;.*
136 double v_double_member;.*
137 \}.*$prompt $" { pass "ptype union" }
138 -re ".*$prompt $" { fail "ptype union" }
139 timeout { fail "(timeout) ptype union" }
143 send "ptype union tu_link\n"
145 -re "type = union tu_link .*
146 struct link \[*\]next;.*
147 struct link \[(\*\]+linkfunc\[)(\]+;.*
148 struct t_struct stuff.1..2..3.;.*
149 \}.*$prompt $" { pass "ptype linked list union" }
152 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
153 # which isn't defined.
155 fail "ptype linked list union (compiler bug in IBM's xlc)"
157 timeout { fail "(timeout) ptype linked list union" }
162 # test ptype command with enums
165 send "ptype primary\n"
167 -re "type = enum .red, green, blue.*$prompt $" { pass "ptype unnamed enumeration" }
168 -re ".*$prompt $" { fail "ptype unnamed enumeration" }
169 timeout { fail "(timeout) ptype unnamed enumeration" }
173 send "ptype enum colors\n"
175 -re "type = enum colors \{yellow, purple, pink\}.*$prompt $"\
176 { pass "ptype named enumeration" }
177 -re ".*$prompt $" { fail "ptype named enumeration" }
178 timeout { fail "(timeout) ptype named enumeration" }
183 # test ptype command with enums as typedef
185 send "ptype boolean\n"
187 -re "type = enum \{FALSE, TRUE\}.*$prompt $" { pass "ptype unnamed typedef'd enumeration" }
188 -re ".*$prompt $" { fail "ptype unnamed typedef'd enumeration" }
189 timeout { fail "(timeout) ptype unnamed typedef'd enumeration" }
192 # And check that whatis shows the name, not "enum {...}".
194 # The problem with xlc is that the stabs look like
195 # :t51=eFALSE:0,TRUE:1,;
198 # GDB's behavior is correct; the type which the variable is defined
199 # as (51) doesn't have a name. Only 55 has a name.
201 setup_xfail "i*86-*-sysv4*"
202 gdb_test "whatis v_boolean" "type = boolean" \
203 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
205 # Same thing with struct and union.
206 gdb_test "ptype t_struct3" "type = struct \{.*
207 *double v_double_member;.*
208 *int v_int_member;.*\}" "printing typedef'd struct"
210 gdb_test "ptype t_union3" "type = union \{.*
211 *double v_double_member;.*
212 *int v_int_member;.*\}" "printing typedef'd union"
214 send "ptype enum bvals\n"
216 -re "type = enum bvals \{false, true\}.*$prompt $" { pass "ptype named typedef'd enumf'd enum" }
217 -re ".*$prompt $" { fail "ptype named typedef'd enumeration" }
218 timeout { fail "(timeout) ptype named typedef'd enumeration" }
223 # test ptype command with out-of-order enum values
225 send "ptype enum misordered\n"
227 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
228 { pass "ptype misordered enumeration" }
229 -re ".*$prompt $" { fail "ptype misordered enumeration" }
230 timeout { fail "(timeout) ptype misordered enumeration" }
235 # test ptype command with a named enum's value
239 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
240 { pass "ptype named enumeration member" }
241 -re ".*$prompt $" { fail "ptype named enumeration member" }
242 timeout { fail "(timeout) ptype named enumeration member" }
248 -re "type = enum \{red, green, blue\}.*$prompt $"\
249 { pass "ptype unnamed enumeration member" }
250 -re ".*$prompt $" { fail "ptype unnamed enumeration member" }
251 timeout { fail "(timeout) ptype unnamed enumeration member" }
256 # test ptype command with basic C types
258 # I've commented most of this out because it duplicates tests in whatis.exp.
259 # I've just left in a token test or 2 which is designed to test that ptype
260 # acts like whatis for basic types. If it is thought to be necessary to
261 # test both whatis and ptype for all the types, the tests should be
262 # merged into whatis.exp, or else maintenance will be a royal pain -kingdon
263 #setup_xfail "i960-*-*" 1821
264 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
265 #send "ptype v_char\n"
267 # -re "type = char.*$prompt $" { pass "ptype char" }
268 # -re ".*$prompt $" { fail "ptype char" }
269 # timeout { fail "(timeout) ptype char" }
273 #setup_xfail "mips-*-*" "a29k-*-*"
274 #send "ptype v_signed_char\n"
276 # -re "type = signed char.*$prompt $" { pass "ptype signed char" }
277 # -re ".*$prompt $" { fail "ptype signed char" }
278 # timeout { fail "(timeout) ptype signed char" }
282 #send "ptype v_unsigned_char\n"
284 # -re "type = unsigned char.*$prompt $" { pass "ptype unsigned char" }
285 # -re ".*$prompt $" { fail "ptype unsigned char" }
286 # timeout { fail "(timeout) ptype unsigned char" }
290 send "ptype v_short\n"
292 -re "type = short(| int).*$prompt $" { pass "ptype short" }
293 -re ".*$prompt $" { fail "ptype short" }
294 timeout { fail "(timeout) ptype short" }
298 #send "ptype v_signed_short\n"
300 # -re "type = short.*$prompt $" { pass "ptype signed short" }
301 # -re ".*$prompt $" { fail "ptype signed short" }
302 # timeout { fail "(timeout) ptype signed short" }
306 #send "ptype v_unsigned_short\n"
308 # -re "type = unsigned short.*$prompt $" { pass "ptype unsigned short" }
309 # -re ".*$prompt $" { fail "ptype unsigned short" }
310 # timeout { fail "(timeout) ptype unsigned short" }
316 -re "type = int.*$prompt $" { pass "ptype int" }
317 -re ".*$prompt $" { fail "ptype int" }
318 timeout { fail "(timeout) ptype int" }
322 #send "ptype v_signed_int\n"
324 # -re "type = int.*$prompt $" { pass "ptype signed int" }
325 # -re ".*$prompt $" { fail "ptype signed int" }
326 # timeout { fail "(timeout) ptype signed int" }
330 #send "ptype v_unsigned_int\n"
332 # -re "type = unsigned int.*$prompt $" { pass "ptype unsigned int" }
333 # -re ".*$prompt $" { fail "ptype unsigned int" }
334 # timeout { fail "(timeout) ptype unsigned int" }
338 #send "ptype v_long\n"
340 # -re "type = long.*$prompt $" { pass "ptype long" }
341 # -re ".*$prompt $" { fail "ptype long" }
342 # timeout { fail "(timeout) ptype long" }
346 #send "ptype v_signed_long\n"
348 # -re "type = long.*$prompt $" { pass "ptype signed long" }
349 # -re ".*$prompt $" { fail "ptype signed long" }
350 # timeout { fail "(timeout) ptype signed long" }
354 #send "ptype v_unsigned_long\n"
356 # -re "type = unsigned long.*$prompt $" { pass "ptype unsigned long" }
357 # -re ".*$prompt $" { fail "ptype unsigned long" }
358 # timeout { fail "(timeout) ptype unsigned long" }
362 #send "ptype v_float\n"
364 # -re "type = float.*$prompt $" { pass "ptype float" }
365 # -re ".*$prompt $" { fail "ptype float" }
366 # timeout { fail "(timeout) ptype float" }
370 #send "ptype v_double\n"
372 # -re "type = double.*$prompt $" { pass "ptype double" }
373 # -re ".*$prompt $" { fail "ptype double" }
374 # timeout { fail "(timeout) ptype double" }
379 # test ptype command with arrays
381 #setup_xfail "i960-*-*" 1821
382 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
383 #send "ptype v_char_array\n"
385 # -re "type = char .2..*$prompt $" { pass "ptype char array" }
386 # -re ".*$prompt $" { fail "ptype char array" }
387 # timeout { fail "(timeout) ptype char array" }
391 #setup_xfail "mips-*-*" "a29k-*-*"
392 #send "ptype v_signed_char_array\n"
394 # -re "type = (|signed )char .2..*$prompt $" { pass "ptype signed char array" }
395 # -re ".*$prompt $" { fail "ptype signed char array" }
396 # timeout { fail "(timeout) ptype signed char array" }
400 #send "ptype v_unsigned_char_array\n"
402 # -re "type = unsigned char .2..*$prompt $" { pass "ptype unsigned char array" }
403 # -re ".*$prompt $" { fail "ptype unsigned char array" }
404 # timeout { fail "(timeout) ptype unsigned char array" }
409 #send "ptype v_int_array\n"
411 # -re "type = int .2..*$prompt $" { pass "ptype int array" }
412 # -re ".*$prompt $" { fail "ptype int array" }
413 # timeout { fail "(timeout) ptype int array" }
417 #send "ptype v_signed_int_array\n"
419 # -re "type = int .2..*$prompt $" { pass "ptype signed int array" }
420 # -re ".*$prompt $" { fail "ptype signed int array" }
421 # timeout { fail "(timeout) ptype signed int array" }
425 #send "ptype v_unsigned_int_array\n"
427 # -re "type = unsigned int .2..*$prompt $" { pass "ptype unsigned int array" }
428 # -re ".*$prompt $" { fail "ptype unsigned int array" }
429 # timeout { fail "(timeout) ptype unsigned int array" }
433 #send "ptype v_long_array\n"
435 # -re "type = (long|int|long int) .2..*$prompt $" {
436 # pass "ptype long array" }
437 # -re ".*$prompt $" { fail "ptype long array" }
438 # timeout { fail "(timeout) ptype long array" }
442 #send "ptype v_signed_long_array\n"
444 # -re "type = (long|int|long int) .2..*$prompt $" {
445 # pass "ptype signed long array" }
446 # -re ".*$prompt $" { fail "ptype signed long array" }
447 # timeout { fail "(timeout) ptype signed long array" }
451 #send "ptype v_unsigned_long_array\n"
453 # -re "type = unsigned long .2..*$prompt $" { pass "ptype unsigned long array" }
454 # -re ".*$prompt $" { fail "ptype unsigned long array" }
455 # timeout { fail "(timeout) ptype unsigned long array" }
459 #send "ptype v_float_array\n"
461 # -re "type = float .2..*$prompt $" { pass "ptype float array" }
462 # -re ".*$prompt $" { fail "ptype float array" }
463 # timeout { fail "(timeout) ptype float array" }
467 #send "ptype v_double_array\n"
469 # -re "type = double .2..*$prompt $" { pass "ptype double array" }
470 # -re ".*$prompt $" { fail "ptype double array" }
471 # timeout { fail "(timeout) ptype double array" }
475 setup_xfail "i*86-*-sysv4*"
476 gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
480 ## test ptype command with pointers
482 #setup_xfail "i960-*-*" 1821
483 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
484 #send "ptype v_char_pointer\n"
486 # -re "type = char \*.*$prompt $" { pass "ptype char pointer" }
487 # -re ".*$prompt $" { fail "ptype char pointer" }
488 # timeout { fail "(timeout) ptype char pointer" }
492 #setup_xfail "mips-*-*" "a29k-*-*"
493 #send "ptype v_signed_char_pointer\n"
495 # -re "type = (|signed )char \*.*$prompt $"
496 # { pass "ptype signed char pointer" }
497 # -re ".*$prompt $" { fail "ptype signed char pointer" }
498 # timeout { fail "(timeout) ptype signed char pointer" }
502 #send "ptype v_unsigned_char_pointer\n"
504 # -re "type = unsigned char \*.*$prompt $" { pass "ptype unsigned char pointer" }
505 # -re ".*$prompt $" { fail "ptype unsigned char pointer" }
506 # timeout { fail "(timeout) ptype unsigned char pointer" }
510 #send "ptype v_short_pointer\n"
512 # -re "type = (short|short int) \*.*$prompt $" { pass "ptype short pointer" }
513 # -re ".*$prompt $" { fail "ptype short pointer" }
514 # timeout { fail "(timeout) ptype short pointer" }
518 #send "ptype v_signed_short_pointer\n"
520 # -re "type = short \*.*$prompt $" { pass "ptype signed short pointer" }
521 # -re ".*$prompt $" { fail "ptype signed short pointer" }
522 # timeout { fail "(timeout) ptype signed short pointer" }
526 #send "ptype v_unsigned_short_pointer\n"
528 # -re "type = unsigned short \*.*$prompt $" { pass "ptype unsigned short pointer" }
529 # -re ".*$prompt $" { fail "ptype unsigned short pointer" }
530 # timeout { fail "(timeout) ptype unsigned short pointer" }
534 #send "ptype v_int_pointer\n"
536 # -re "type = int \*.*$prompt $" { pass "ptype int pointer" }
537 # -re ".*$prompt $" { fail "ptype int pointer" }
538 # timeout { fail "(timeout) ptype int pointer" }
542 #send "ptype v_signed_int_pointer\n"
544 # -re "type = int \*.*$prompt $" { pass "ptype signed int pointer" }
545 # -re ".*$prompt $" { fail "ptype signed int pointer" }
546 # timeout { fail "(timeout) ptype signed int pointer" }
550 #send "ptype v_unsigned_int_pointer\n"
552 # -re "type = unsigned int \*.*$prompt $" { pass "ptype unsigned int pointer" }
553 # -re ".*$prompt $" { fail "ptype unsigned int pointer" }
554 # timeout { fail "(timeout) ptype unsigned int pointer" }
558 #send "ptype v_long_pointer\n"
560 # -re "type = long \*.*$prompt $" { pass "ptype long pointer" }
561 # -re ".*$prompt $" { fail "ptype long pointer" }
562 # timeout { fail "(timeout) ptype long pointer" }
566 #send "ptype v_signed_long_pointer\n"
568 # -re "type = long \*.*$prompt $" { pass "ptype signed long pointer" }
569 # -re ".*$prompt $" { fail "ptype signed long pointer" }
570 # timeout { fail "(timeout) ptype signed long pointer" }
574 #send "ptype v_unsigned_long_pointer\n"
576 # -re "type = unsigned long \*.*$prompt $" { pass "ptype unsigned long pointer" }
577 # -re ".*$prompt $" { fail "ptype unsigned long pointer" }
578 # timeout { fail "(timeout) ptype unsigned long pointer" }
582 #send "ptype v_float_pointer\n"
584 # -re "type = float \*.*$prompt $" { pass "ptype float pointer" }
585 # -re ".*$prompt $" { fail "ptype float pointer" }
586 # timeout { fail "(timeout) ptype float pointer" }
590 #send "ptype v_double_pointer\n"
592 # -re "type = double \*.*$prompt $" { pass "ptype double pointer" }
593 # -re ".*$prompt $" { fail "ptype double pointer" }
594 # timeout { fail "(timeout) ptype double pointer" }
598 # test ptype command with nested structure and union
600 send "ptype struct outer_struct\n"
602 -re "type = struct outer_struct \{.*
604 struct inner_struct inner_struct_instance;.*
605 union inner_union inner_union_instance;.*
606 (long|long int|int) outer_long;.*
607 \}.*$prompt $" { pass "ptype outer structure" }
608 -re ".*$prompt $" { fail "ptype outer structure" }
609 timeout { fail "(timeout) ptype outer structure" }
613 send "ptype struct inner_struct\n"
615 -re "type = struct inner_struct \{.*
617 (long|long int|int) inner_long;.*
618 \}.*$prompt $" { pass "ptype inner structure" }
619 -re ".*$prompt $" { fail "ptype inner structure" }
620 timeout { fail "(timeout) ptype inner structure" }
624 send "ptype union inner_union\n"
626 -re "type = union inner_union \{.*
627 int inner_union_int;.*
628 (long|long int|int) inner_union_long;.*
629 \}.*$prompt $" { pass "ptype inner union" }
630 -re ".*$prompt $" { fail "ptype inner union" }
631 timeout { fail "(timeout) ptype inner union" }
635 send "ptype nested_su\n"
637 -re "type = struct outer_struct \{.*
639 struct inner_struct inner_struct_instance;.*
640 union inner_union inner_union_instance;.*
641 (long|long int|int) outer_long;.*
642 \}.*$prompt $" { pass "ptype nested structure" }
643 -re ".*$prompt $" { fail "ptype nested structure" }
644 timeout { fail "(timeout) ptype nested structure" }
648 send "ptype nested_su.outer_int\n"
650 -re "type = int.*$prompt $" { pass "ptype outer int" }
651 -re ".*$prompt $" { fail "ptype outer int" }
652 timeout { fail "(timeout) ptype outer int" }
656 send "ptype nested_su.inner_struct_instance\n"
658 -re "type = struct inner_struct \{.*
660 (long|long int|int) inner_long;.*
661 \}.*$prompt $" { pass "ptype nested structure" }
662 -re ".*$prompt $" { fail "ptype nested structure" }
663 timeout { fail "(timeout) ptype nested structure" }
667 send "ptype nested_su.inner_struct_instance.inner_int\n"
669 -re "type = int.*$prompt $" { pass "ptype inner int" }
670 -re ".*$prompt $" { fail "ptype inner int" }
671 timeout { fail "(timeout) ptype inner int" }
675 send "ptype nested_su.inner_union_instance\n"
677 -re "type = union inner_union \{.*
678 int inner_union_int;.*
679 (long|long int|int) inner_union_long;.*
680 \}.*$prompt $" { pass "ptype nested union" }
681 -re ".*$prompt $" { fail "ptype nested union" }
682 timeout { fail "(timeout) ptype nested union" }
685 # Test printing type of string constants and array constants, but
686 # requires a running process. These call malloc, and can take a long
687 # time to execute over a slow serial link, so increase the timeout.
689 # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
690 # the operation causes a slow painful death rather than a nice simple failure.
692 if ![istarget "*-*-udi*"] then {
693 if [runto_main] then {
694 setup_xfail "a29k-*-udi" 2416
695 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
696 setup_xfail "a29k-*-udi" 2416
697 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
698 setup_xfail "a29k-*-udi" 2416
699 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
700 setup_xfail "a29k-*-udi" 2416
701 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
702 setup_xfail "a29k-*-udi" 2416
703 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
704 setup_xfail "a29k-*-udi" 2416
705 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
706 setup_xfail "a29k-*-udi" 2416
707 gdb_test "ptype {4,5,6}\[2\]" "type = int"
708 setup_xfail "a29k-*-udi" 2416
709 gdb_test "ptype *&{4,5,6}\[1\]" "type = int"