1 # Copyright (C) 1988, 1990, 1991, 1992 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., 675 Mass Ave, Cambridge, MA 02139, 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 gdb_test "whatis v_boolean" "type = boolean" \
202 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
204 # Same thing with struct and union.
205 gdb_test "ptype t_struct3" "type = struct \{.*
206 *double v_double_member;.*
207 *int v_int_member;.*\}" "printing typedef'd struct"
209 gdb_test "ptype t_union3" "type = union \{.*
210 *double v_double_member;.*
211 *int v_int_member;.*\}" "printing typedef'd union"
213 send "ptype enum bvals\n"
215 -re "type = enum bvals \{false, true\}.*$prompt $" { pass "ptype named typedef'd enumf'd enum" }
216 -re ".*$prompt $" { fail "ptype named typedef'd enumeration" }
217 timeout { fail "(timeout) ptype named typedef'd enumeration" }
222 # test ptype command with out-of-order enum values
224 send "ptype enum misordered\n"
226 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
227 { pass "ptype misordered enumeration" }
228 -re ".*$prompt $" { fail "ptype misordered enumeration" }
229 timeout { fail "(timeout) ptype misordered enumeration" }
234 # test ptype command with a named enum's value
238 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
239 { pass "ptype named enumeration member" }
240 -re ".*$prompt $" { fail "ptype named enumeration member" }
241 timeout { fail "(timeout) ptype named enumeration member" }
247 -re "type = enum \{red, green, blue\}.*$prompt $"\
248 { pass "ptype unnamed enumeration member" }
249 -re ".*$prompt $" { fail "ptype unnamed enumeration member" }
250 timeout { fail "(timeout) ptype unnamed enumeration member" }
255 # test ptype command with basic C types
257 # I've commented most of this out because it duplicates tests in whatis.exp.
258 # I've just left in a token test or 2 which is designed to test that ptype
259 # acts like whatis for basic types. If it is thought to be necessary to
260 # test both whatis and ptype for all the types, the tests should be
261 # merged into whatis.exp, or else maintenance will be a royal pain -kingdon
262 #setup_xfail "i960-*-*" 1821
263 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
264 #send "ptype v_char\n"
266 # -re "type = char.*$prompt $" { pass "ptype char" }
267 # -re ".*$prompt $" { fail "ptype char" }
268 # timeout { fail "(timeout) ptype char" }
272 #setup_xfail "mips-*-*" "a29k-*-*"
273 #send "ptype v_signed_char\n"
275 # -re "type = signed char.*$prompt $" { pass "ptype signed char" }
276 # -re ".*$prompt $" { fail "ptype signed char" }
277 # timeout { fail "(timeout) ptype signed char" }
281 #send "ptype v_unsigned_char\n"
283 # -re "type = unsigned char.*$prompt $" { pass "ptype unsigned char" }
284 # -re ".*$prompt $" { fail "ptype unsigned char" }
285 # timeout { fail "(timeout) ptype unsigned char" }
289 send "ptype v_short\n"
291 -re "type = short(| int).*$prompt $" { pass "ptype short" }
292 -re ".*$prompt $" { fail "ptype short" }
293 timeout { fail "(timeout) ptype short" }
297 #send "ptype v_signed_short\n"
299 # -re "type = short.*$prompt $" { pass "ptype signed short" }
300 # -re ".*$prompt $" { fail "ptype signed short" }
301 # timeout { fail "(timeout) ptype signed short" }
305 #send "ptype v_unsigned_short\n"
307 # -re "type = unsigned short.*$prompt $" { pass "ptype unsigned short" }
308 # -re ".*$prompt $" { fail "ptype unsigned short" }
309 # timeout { fail "(timeout) ptype unsigned short" }
315 -re "type = int.*$prompt $" { pass "ptype int" }
316 -re ".*$prompt $" { fail "ptype int" }
317 timeout { fail "(timeout) ptype int" }
321 #send "ptype v_signed_int\n"
323 # -re "type = int.*$prompt $" { pass "ptype signed int" }
324 # -re ".*$prompt $" { fail "ptype signed int" }
325 # timeout { fail "(timeout) ptype signed int" }
329 #send "ptype v_unsigned_int\n"
331 # -re "type = unsigned int.*$prompt $" { pass "ptype unsigned int" }
332 # -re ".*$prompt $" { fail "ptype unsigned int" }
333 # timeout { fail "(timeout) ptype unsigned int" }
337 #send "ptype v_long\n"
339 # -re "type = long.*$prompt $" { pass "ptype long" }
340 # -re ".*$prompt $" { fail "ptype long" }
341 # timeout { fail "(timeout) ptype long" }
345 #send "ptype v_signed_long\n"
347 # -re "type = long.*$prompt $" { pass "ptype signed long" }
348 # -re ".*$prompt $" { fail "ptype signed long" }
349 # timeout { fail "(timeout) ptype signed long" }
353 #send "ptype v_unsigned_long\n"
355 # -re "type = unsigned long.*$prompt $" { pass "ptype unsigned long" }
356 # -re ".*$prompt $" { fail "ptype unsigned long" }
357 # timeout { fail "(timeout) ptype unsigned long" }
361 #send "ptype v_float\n"
363 # -re "type = float.*$prompt $" { pass "ptype float" }
364 # -re ".*$prompt $" { fail "ptype float" }
365 # timeout { fail "(timeout) ptype float" }
369 #send "ptype v_double\n"
371 # -re "type = double.*$prompt $" { pass "ptype double" }
372 # -re ".*$prompt $" { fail "ptype double" }
373 # timeout { fail "(timeout) ptype double" }
378 # test ptype command with arrays
380 #setup_xfail "i960-*-*" 1821
381 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
382 #send "ptype v_char_array\n"
384 # -re "type = char .2..*$prompt $" { pass "ptype char array" }
385 # -re ".*$prompt $" { fail "ptype char array" }
386 # timeout { fail "(timeout) ptype char array" }
390 #setup_xfail "mips-*-*" "a29k-*-*"
391 #send "ptype v_signed_char_array\n"
393 # -re "type = (|signed )char .2..*$prompt $" { pass "ptype signed char array" }
394 # -re ".*$prompt $" { fail "ptype signed char array" }
395 # timeout { fail "(timeout) ptype signed char array" }
399 #send "ptype v_unsigned_char_array\n"
401 # -re "type = unsigned char .2..*$prompt $" { pass "ptype unsigned char array" }
402 # -re ".*$prompt $" { fail "ptype unsigned char array" }
403 # timeout { fail "(timeout) ptype unsigned char array" }
408 #send "ptype v_int_array\n"
410 # -re "type = int .2..*$prompt $" { pass "ptype int array" }
411 # -re ".*$prompt $" { fail "ptype int array" }
412 # timeout { fail "(timeout) ptype int array" }
416 #send "ptype v_signed_int_array\n"
418 # -re "type = int .2..*$prompt $" { pass "ptype signed int array" }
419 # -re ".*$prompt $" { fail "ptype signed int array" }
420 # timeout { fail "(timeout) ptype signed int array" }
424 #send "ptype v_unsigned_int_array\n"
426 # -re "type = unsigned int .2..*$prompt $" { pass "ptype unsigned int array" }
427 # -re ".*$prompt $" { fail "ptype unsigned int array" }
428 # timeout { fail "(timeout) ptype unsigned int array" }
432 #send "ptype v_long_array\n"
434 # -re "type = (long|int|long int) .2..*$prompt $" {
435 # pass "ptype long array" }
436 # -re ".*$prompt $" { fail "ptype long array" }
437 # timeout { fail "(timeout) ptype long array" }
441 #send "ptype v_signed_long_array\n"
443 # -re "type = (long|int|long int) .2..*$prompt $" {
444 # pass "ptype signed long array" }
445 # -re ".*$prompt $" { fail "ptype signed long array" }
446 # timeout { fail "(timeout) ptype signed long array" }
450 #send "ptype v_unsigned_long_array\n"
452 # -re "type = unsigned long .2..*$prompt $" { pass "ptype unsigned long array" }
453 # -re ".*$prompt $" { fail "ptype unsigned long array" }
454 # timeout { fail "(timeout) ptype unsigned long array" }
458 #send "ptype v_float_array\n"
460 # -re "type = float .2..*$prompt $" { pass "ptype float array" }
461 # -re ".*$prompt $" { fail "ptype float array" }
462 # timeout { fail "(timeout) ptype float array" }
466 #send "ptype v_double_array\n"
468 # -re "type = double .2..*$prompt $" { pass "ptype double array" }
469 # -re ".*$prompt $" { fail "ptype double array" }
470 # timeout { fail "(timeout) ptype double array" }
475 ## test ptype command with pointers
477 #setup_xfail "i960-*-*" 1821
478 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
479 #send "ptype v_char_pointer\n"
481 # -re "type = char \*.*$prompt $" { pass "ptype char pointer" }
482 # -re ".*$prompt $" { fail "ptype char pointer" }
483 # timeout { fail "(timeout) ptype char pointer" }
487 #setup_xfail "mips-*-*" "a29k-*-*"
488 #send "ptype v_signed_char_pointer\n"
490 # -re "type = (|signed )char \*.*$prompt $"
491 # { pass "ptype signed char pointer" }
492 # -re ".*$prompt $" { fail "ptype signed char pointer" }
493 # timeout { fail "(timeout) ptype signed char pointer" }
497 #send "ptype v_unsigned_char_pointer\n"
499 # -re "type = unsigned char \*.*$prompt $" { pass "ptype unsigned char pointer" }
500 # -re ".*$prompt $" { fail "ptype unsigned char pointer" }
501 # timeout { fail "(timeout) ptype unsigned char pointer" }
505 #send "ptype v_short_pointer\n"
507 # -re "type = (short|short int) \*.*$prompt $" { pass "ptype short pointer" }
508 # -re ".*$prompt $" { fail "ptype short pointer" }
509 # timeout { fail "(timeout) ptype short pointer" }
513 #send "ptype v_signed_short_pointer\n"
515 # -re "type = short \*.*$prompt $" { pass "ptype signed short pointer" }
516 # -re ".*$prompt $" { fail "ptype signed short pointer" }
517 # timeout { fail "(timeout) ptype signed short pointer" }
521 #send "ptype v_unsigned_short_pointer\n"
523 # -re "type = unsigned short \*.*$prompt $" { pass "ptype unsigned short pointer" }
524 # -re ".*$prompt $" { fail "ptype unsigned short pointer" }
525 # timeout { fail "(timeout) ptype unsigned short pointer" }
529 #send "ptype v_int_pointer\n"
531 # -re "type = int \*.*$prompt $" { pass "ptype int pointer" }
532 # -re ".*$prompt $" { fail "ptype int pointer" }
533 # timeout { fail "(timeout) ptype int pointer" }
537 #send "ptype v_signed_int_pointer\n"
539 # -re "type = int \*.*$prompt $" { pass "ptype signed int pointer" }
540 # -re ".*$prompt $" { fail "ptype signed int pointer" }
541 # timeout { fail "(timeout) ptype signed int pointer" }
545 #send "ptype v_unsigned_int_pointer\n"
547 # -re "type = unsigned int \*.*$prompt $" { pass "ptype unsigned int pointer" }
548 # -re ".*$prompt $" { fail "ptype unsigned int pointer" }
549 # timeout { fail "(timeout) ptype unsigned int pointer" }
553 #send "ptype v_long_pointer\n"
555 # -re "type = long \*.*$prompt $" { pass "ptype long pointer" }
556 # -re ".*$prompt $" { fail "ptype long pointer" }
557 # timeout { fail "(timeout) ptype long pointer" }
561 #send "ptype v_signed_long_pointer\n"
563 # -re "type = long \*.*$prompt $" { pass "ptype signed long pointer" }
564 # -re ".*$prompt $" { fail "ptype signed long pointer" }
565 # timeout { fail "(timeout) ptype signed long pointer" }
569 #send "ptype v_unsigned_long_pointer\n"
571 # -re "type = unsigned long \*.*$prompt $" { pass "ptype unsigned long pointer" }
572 # -re ".*$prompt $" { fail "ptype unsigned long pointer" }
573 # timeout { fail "(timeout) ptype unsigned long pointer" }
577 #send "ptype v_float_pointer\n"
579 # -re "type = float \*.*$prompt $" { pass "ptype float pointer" }
580 # -re ".*$prompt $" { fail "ptype float pointer" }
581 # timeout { fail "(timeout) ptype float pointer" }
585 #send "ptype v_double_pointer\n"
587 # -re "type = double \*.*$prompt $" { pass "ptype double pointer" }
588 # -re ".*$prompt $" { fail "ptype double pointer" }
589 # timeout { fail "(timeout) ptype double pointer" }
594 # test ptype command with nested structure and union
596 send "ptype struct outer_struct\n"
598 -re "type = struct outer_struct \{.*
600 struct inner_struct inner_struct_instance;.*
601 union inner_union inner_union_instance;.*
602 (long|long int|int) outer_long;.*
603 \}.*$prompt $" { pass "ptype outer structure" }
604 -re ".*$prompt $" { fail "ptype outer structure" }
605 timeout { fail "(timeout) ptype outer structure" }
609 send "ptype struct inner_struct\n"
611 -re "type = struct inner_struct \{.*
613 (long|long int|int) inner_long;.*
614 \}.*$prompt $" { pass "ptype inner structure" }
615 -re ".*$prompt $" { fail "ptype inner structure" }
616 timeout { fail "(timeout) ptype inner structure" }
620 send "ptype union inner_union\n"
622 -re "type = union inner_union \{.*
623 int inner_union_int;.*
624 (long|long int|int) inner_union_long;.*
625 \}.*$prompt $" { pass "ptype inner union" }
626 -re ".*$prompt $" { fail "ptype inner union" }
627 timeout { fail "(timeout) ptype inner union" }
631 send "ptype nested_su\n"
633 -re "type = struct outer_struct \{.*
635 struct inner_struct inner_struct_instance;.*
636 union inner_union inner_union_instance;.*
637 (long|long int|int) outer_long;.*
638 \}.*$prompt $" { pass "ptype nested structure" }
639 -re ".*$prompt $" { fail "ptype nested structure" }
640 timeout { fail "(timeout) ptype nested structure" }
644 send "ptype nested_su.outer_int\n"
646 -re "type = int.*$prompt $" { pass "ptype outer int" }
647 -re ".*$prompt $" { fail "ptype outer int" }
648 timeout { fail "(timeout) ptype outer int" }
652 send "ptype nested_su.inner_struct_instance\n"
654 -re "type = struct inner_struct \{.*
656 (long|long int|int) inner_long;.*
657 \}.*$prompt $" { pass "ptype nested structure" }
658 -re ".*$prompt $" { fail "ptype nested structure" }
659 timeout { fail "(timeout) ptype nested structure" }
663 send "ptype nested_su.inner_struct_instance.inner_int\n"
665 -re "type = int.*$prompt $" { pass "ptype inner int" }
666 -re ".*$prompt $" { fail "ptype inner int" }
667 timeout { fail "(timeout) ptype inner int" }
671 send "ptype nested_su.inner_union_instance\n"
673 -re "type = union inner_union \{.*
674 int inner_union_int;.*
675 (long|long int|int) inner_union_long;.*
676 \}.*$prompt $" { pass "ptype nested union" }
677 -re ".*$prompt $" { fail "ptype nested union" }
678 timeout { fail "(timeout) ptype nested union" }
681 # Test printing type of string constants and array constants, but
682 # requires a running process. These call malloc, and can take a long
683 # time to execute over a slow serial link, so increase the timeout.
685 # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
686 # the operation causes a slow painful death rather than a nice simple failure.
688 if ![istarget "*-*-udi*"] then {
689 if [runto main] then {
691 setup_xfail "a29k-*-udi" 2416
692 gdb_test "ptype \\\"abc\\\"" "type = char \\\[4\\\]"
693 setup_xfail "a29k-*-udi" 2416
694 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
695 setup_xfail "a29k-*-udi" 2416
696 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
697 setup_xfail "a29k-*-udi" 2416
698 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
699 setup_xfail "a29k-*-udi" 2416
700 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
701 setup_xfail "a29k-*-udi" 2416
702 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
703 setup_xfail "a29k-*-udi" 2416
704 gdb_test "ptype {4,5,6}\\\[2\\\]" "type = int"
705 setup_xfail "a29k-*-udi" 2416
706 gdb_test "ptype *&{4,5,6}\\\[1\\\]" "type = int"
708 if [istarget "a29k-*-udi"] then {
709 # FIXME: If PR 2415 is fixed, this is not needed.