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
33 set srcfile ${testfile}.c
34 set binfile ${objdir}/${subdir}/${testfile}
35 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
36 perror "Couldn't compile ${srcfile}"
40 # Create and source the file that provides information about the compiler
41 # used to compile the test case.
42 if [get_compiler_info ${binfile}] {
48 gdb_reinitialize_dir $srcdir/$subdir
51 # Test ptype of unnamed enumeration members before any action causes
52 # the partial symbol table to be expanded to full symbols. This fails
53 # with stabs compilers which fail to use a nameless stab (such as
54 # pre-2.4.5 versions of gcc and most non-gcc compilers).
56 send_gdb "ptype red1\n"
58 -re "type = enum primary1_tag \{red1, green1, blue1\}.*$prompt $"\
60 # The workaround is in effect. As this is a compiler, not GDB,
61 # bug, we'll make it a PASS but perhaps it should be an XFAIL.
62 pass "ptype unnamed enumeration member (worked around)"
64 -re "type = enum \{red1, green1, blue1\}.*$prompt $"\
65 { pass "ptype unnamed enumeration member" }
66 -re ".*$prompt $" { fail "ptype unnamed enumeration member" }
67 timeout { fail "(timeout) ptype unnamed enumeration member" }
71 # test ptype command with structures
73 # Here and elsewhere, we accept
74 # "long", "long int", or "int" for long variables (whatis.exp already
75 # has an XFAIL for "int" (Sun cc bug), so no need to fail it here).
76 send_gdb "ptype struct t_struct\n"
78 -re "type = struct t_struct \{.*
79 (unsigned |)char v_char_member;.*
80 (short|short int) v_short_member;.*
82 (long|long int|int) v_long_member;.*
83 float v_float_member;.*
84 double v_double_member;.*
85 \}.*$prompt $" { pass "ptype structure" }
86 -re ".*$prompt $" { fail "ptype structure" }
87 timeout { fail "(timeout) ptype structure" }
90 # Test the equivalence between '.' and '->' for struct member references.
92 if [gdb_test "ptype v_struct1.v_float_member" "type = float"]<0 then {
97 if [gdb_test "ptype v_struct1->v_float_member" "type = float"]<0 then {
102 if [gdb_test "ptype v_t_struct_p.v_float_member" "type = float"]<0 then {
107 if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then {
114 send_gdb "ptype struct link\n"
116 -re "type = struct link \{.*
117 struct link \[*\]next;.*
118 struct link \[*(\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*
119 struct t_struct stuff.1..2..3.;.*
120 \}.*$prompt $" { pass "ptype linked list structure" }
123 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
124 # which isn't defined.
126 fail "ptype linked list structure (compiler bug in IBM's xlc)"
128 timeout { fail "(timeout) ptype linked list structure" }
133 # test ptype command with unions
135 send_gdb "ptype union t_union\n"
137 -re "type = union t_union \{.*
138 (unsigned |)char v_char_member;.*
139 (short|short int) v_short_member;.*
141 (long|long int|int) v_long_member;.*
142 float v_float_member;.*
143 double v_double_member;.*
144 \}.*$prompt $" { pass "ptype union" }
145 -re ".*$prompt $" { fail "ptype union" }
146 timeout { fail "(timeout) ptype union" }
150 send_gdb "ptype union tu_link\n"
152 -re "type = union tu_link .*
153 struct link \[*\]next;.*
154 struct link \[(\*\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*
155 struct t_struct stuff.1..2..3.;.*
156 \}.*$prompt $" { pass "ptype linked list union" }
159 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
160 # which isn't defined.
162 fail "ptype linked list union (compiler bug in IBM's xlc)"
164 timeout { fail "(timeout) ptype linked list union" }
169 # test ptype command with enums
172 send_gdb "ptype primary\n"
174 -re "type = enum .red, green, blue.*$prompt $" { pass "ptype unnamed enumeration" }
175 -re ".*$prompt $" { fail "ptype unnamed enumeration" }
176 timeout { fail "(timeout) ptype unnamed enumeration" }
180 send_gdb "ptype enum colors\n"
182 -re "type = enum colors \{yellow, purple, pink\}.*$prompt $"\
183 { pass "ptype named enumeration" }
184 -re ".*$prompt $" { fail "ptype named enumeration" }
185 timeout { fail "(timeout) ptype named enumeration" }
190 # test ptype command with enums as typedef
192 send_gdb "ptype boolean\n"
194 -re "type = enum \{FALSE, TRUE\}.*$prompt $" { pass "ptype unnamed typedef'd enumeration" }
195 -re ".*$prompt $" { fail "ptype unnamed typedef'd enumeration" }
196 timeout { fail "(timeout) ptype unnamed typedef'd enumeration" }
199 # And check that whatis shows the name, not "enum {...}".
201 # The problem with xlc is that the stabs look like
202 # :t51=eFALSE:0,TRUE:1,;
205 # GDB's behavior is correct; the type which the variable is defined
206 # as (51) doesn't have a name. Only 55 has a name.
208 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
209 gdb_test "whatis v_boolean" "type = boolean" \
210 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
212 # Same thing with struct and union.
213 gdb_test "ptype t_struct3" "type = struct \{.*
214 *double v_double_member;.*
215 *int v_int_member;.*\}" "printing typedef'd struct"
217 gdb_test "ptype t_union3" "type = union \{.*
218 *double v_double_member;.*
219 *int v_int_member;.*\}" "printing typedef'd union"
221 send_gdb "ptype enum bvals\n"
223 -re "type = enum bvals \{false, true\}.*$prompt $" { pass "ptype named typedef'd enumf'd enum" }
224 -re ".*$prompt $" { fail "ptype named typedef'd enumeration" }
225 timeout { fail "(timeout) ptype named typedef'd enumeration" }
230 # test ptype command with out-of-order enum values
232 send_gdb "ptype enum misordered\n"
234 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
235 { pass "ptype misordered enumeration" }
236 -re ".*$prompt $" { fail "ptype misordered enumeration" }
237 timeout { fail "(timeout) ptype misordered enumeration" }
242 # test ptype command with a named enum's value
244 send_gdb "ptype three\n"
246 -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\
247 { pass "ptype named enumeration member" }
248 -re ".*$prompt $" { fail "ptype named enumeration member" }
249 timeout { fail "(timeout) ptype named enumeration member" }
253 send_gdb "ptype red\n"
255 -re "type = enum \{red, green, blue\}.*$prompt $"\
256 { pass "ptype unnamed enumeration member" }
257 -re ".*$prompt $" { fail "ptype unnamed enumeration member" }
258 timeout { fail "(timeout) ptype unnamed enumeration member" }
263 # test ptype command with basic C types
265 # I've commented most of this out because it duplicates tests in whatis.exp.
266 # I've just left in a token test or 2 which is designed to test that ptype
267 # acts like whatis for basic types. If it is thought to be necessary to
268 # test both whatis and ptype for all the types, the tests should be
269 # merged into whatis.exp, or else maintenance will be a royal pain -kingdon
270 #setup_xfail "i960-*-*" 1821
271 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
272 #send "ptype v_char\n"
274 # -re "type = char.*$prompt $" { pass "ptype char" }
275 # -re ".*$prompt $" { fail "ptype char" }
276 # timeout { fail "(timeout) ptype char" }
280 #setup_xfail "mips-*-*" "a29k-*-*"
281 #send "ptype v_signed_char\n"
283 # -re "type = signed char.*$prompt $" { pass "ptype signed char" }
284 # -re ".*$prompt $" { fail "ptype signed char" }
285 # timeout { fail "(timeout) ptype signed char" }
289 #send "ptype v_unsigned_char\n"
291 # -re "type = unsigned char.*$prompt $" { pass "ptype unsigned char" }
292 # -re ".*$prompt $" { fail "ptype unsigned char" }
293 # timeout { fail "(timeout) ptype unsigned char" }
297 send_gdb "ptype v_short\n"
299 -re "type = short(| int).*$prompt $" { pass "ptype short" }
300 -re ".*$prompt $" { fail "ptype short" }
301 timeout { fail "(timeout) ptype short" }
305 #send "ptype v_signed_short\n"
307 # -re "type = short.*$prompt $" { pass "ptype signed short" }
308 # -re ".*$prompt $" { fail "ptype signed short" }
309 # timeout { fail "(timeout) ptype signed short" }
313 #send "ptype v_unsigned_short\n"
315 # -re "type = unsigned short.*$prompt $" { pass "ptype unsigned short" }
316 # -re ".*$prompt $" { fail "ptype unsigned short" }
317 # timeout { fail "(timeout) ptype unsigned short" }
321 send_gdb "ptype v_int\n"
323 -re "type = int.*$prompt $" { pass "ptype int" }
324 -re ".*$prompt $" { fail "ptype int" }
325 timeout { fail "(timeout) ptype int" }
329 #send "ptype v_signed_int\n"
331 # -re "type = int.*$prompt $" { pass "ptype signed int" }
332 # -re ".*$prompt $" { fail "ptype signed int" }
333 # timeout { fail "(timeout) ptype signed int" }
337 #send "ptype v_unsigned_int\n"
339 # -re "type = unsigned int.*$prompt $" { pass "ptype unsigned int" }
340 # -re ".*$prompt $" { fail "ptype unsigned int" }
341 # timeout { fail "(timeout) ptype unsigned int" }
345 #send "ptype v_long\n"
347 # -re "type = long.*$prompt $" { pass "ptype long" }
348 # -re ".*$prompt $" { fail "ptype long" }
349 # timeout { fail "(timeout) ptype long" }
353 #send "ptype v_signed_long\n"
355 # -re "type = long.*$prompt $" { pass "ptype signed long" }
356 # -re ".*$prompt $" { fail "ptype signed long" }
357 # timeout { fail "(timeout) ptype signed long" }
361 #send "ptype v_unsigned_long\n"
363 # -re "type = unsigned long.*$prompt $" { pass "ptype unsigned long" }
364 # -re ".*$prompt $" { fail "ptype unsigned long" }
365 # timeout { fail "(timeout) ptype unsigned long" }
369 #send "ptype v_float\n"
371 # -re "type = float.*$prompt $" { pass "ptype float" }
372 # -re ".*$prompt $" { fail "ptype float" }
373 # timeout { fail "(timeout) ptype float" }
377 #send "ptype v_double\n"
379 # -re "type = double.*$prompt $" { pass "ptype double" }
380 # -re ".*$prompt $" { fail "ptype double" }
381 # timeout { fail "(timeout) ptype double" }
386 # test ptype command with arrays
388 #setup_xfail "i960-*-*" 1821
389 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
390 #send "ptype v_char_array\n"
392 # -re "type = char .2..*$prompt $" { pass "ptype char array" }
393 # -re ".*$prompt $" { fail "ptype char array" }
394 # timeout { fail "(timeout) ptype char array" }
398 #setup_xfail "mips-*-*" "a29k-*-*"
399 #send "ptype v_signed_char_array\n"
401 # -re "type = (|signed )char .2..*$prompt $" { pass "ptype signed char array" }
402 # -re ".*$prompt $" { fail "ptype signed char array" }
403 # timeout { fail "(timeout) ptype signed char array" }
407 #send "ptype v_unsigned_char_array\n"
409 # -re "type = unsigned char .2..*$prompt $" { pass "ptype unsigned char array" }
410 # -re ".*$prompt $" { fail "ptype unsigned char array" }
411 # timeout { fail "(timeout) ptype unsigned char array" }
416 #send "ptype v_int_array\n"
418 # -re "type = int .2..*$prompt $" { pass "ptype int array" }
419 # -re ".*$prompt $" { fail "ptype int array" }
420 # timeout { fail "(timeout) ptype int array" }
424 #send "ptype v_signed_int_array\n"
426 # -re "type = int .2..*$prompt $" { pass "ptype signed int array" }
427 # -re ".*$prompt $" { fail "ptype signed int array" }
428 # timeout { fail "(timeout) ptype signed int array" }
432 #send "ptype v_unsigned_int_array\n"
434 # -re "type = unsigned int .2..*$prompt $" { pass "ptype unsigned int array" }
435 # -re ".*$prompt $" { fail "ptype unsigned int array" }
436 # timeout { fail "(timeout) ptype unsigned int array" }
440 #send "ptype v_long_array\n"
442 # -re "type = (long|int|long int) .2..*$prompt $" {
443 # pass "ptype long array" }
444 # -re ".*$prompt $" { fail "ptype long array" }
445 # timeout { fail "(timeout) ptype long array" }
449 #send "ptype v_signed_long_array\n"
451 # -re "type = (long|int|long int) .2..*$prompt $" {
452 # pass "ptype signed long array" }
453 # -re ".*$prompt $" { fail "ptype signed long array" }
454 # timeout { fail "(timeout) ptype signed long array" }
458 #send "ptype v_unsigned_long_array\n"
460 # -re "type = unsigned long .2..*$prompt $" { pass "ptype unsigned long array" }
461 # -re ".*$prompt $" { fail "ptype unsigned long array" }
462 # timeout { fail "(timeout) ptype unsigned long array" }
466 #send "ptype v_float_array\n"
468 # -re "type = float .2..*$prompt $" { pass "ptype float array" }
469 # -re ".*$prompt $" { fail "ptype float array" }
470 # timeout { fail "(timeout) ptype float array" }
474 #send "ptype v_double_array\n"
476 # -re "type = double .2..*$prompt $" { pass "ptype double array" }
477 # -re ".*$prompt $" { fail "ptype double array" }
478 # timeout { fail "(timeout) ptype double array" }
482 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
483 gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
487 ## test ptype command with pointers
489 #setup_xfail "i960-*-*" 1821
490 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
491 #send "ptype v_char_pointer\n"
493 # -re "type = char \*.*$prompt $" { pass "ptype char pointer" }
494 # -re ".*$prompt $" { fail "ptype char pointer" }
495 # timeout { fail "(timeout) ptype char pointer" }
499 #setup_xfail "mips-*-*" "a29k-*-*"
500 #send "ptype v_signed_char_pointer\n"
502 # -re "type = (|signed )char \*.*$prompt $"
503 # { pass "ptype signed char pointer" }
504 # -re ".*$prompt $" { fail "ptype signed char pointer" }
505 # timeout { fail "(timeout) ptype signed char pointer" }
509 #send "ptype v_unsigned_char_pointer\n"
511 # -re "type = unsigned char \*.*$prompt $" { pass "ptype unsigned char pointer" }
512 # -re ".*$prompt $" { fail "ptype unsigned char pointer" }
513 # timeout { fail "(timeout) ptype unsigned char pointer" }
517 #send "ptype v_short_pointer\n"
519 # -re "type = (short|short int) \*.*$prompt $" { pass "ptype short pointer" }
520 # -re ".*$prompt $" { fail "ptype short pointer" }
521 # timeout { fail "(timeout) ptype short pointer" }
525 #send "ptype v_signed_short_pointer\n"
527 # -re "type = short \*.*$prompt $" { pass "ptype signed short pointer" }
528 # -re ".*$prompt $" { fail "ptype signed short pointer" }
529 # timeout { fail "(timeout) ptype signed short pointer" }
533 #send "ptype v_unsigned_short_pointer\n"
535 # -re "type = unsigned short \*.*$prompt $" { pass "ptype unsigned short pointer" }
536 # -re ".*$prompt $" { fail "ptype unsigned short pointer" }
537 # timeout { fail "(timeout) ptype unsigned short pointer" }
541 #send "ptype v_int_pointer\n"
543 # -re "type = int \*.*$prompt $" { pass "ptype int pointer" }
544 # -re ".*$prompt $" { fail "ptype int pointer" }
545 # timeout { fail "(timeout) ptype int pointer" }
549 #send "ptype v_signed_int_pointer\n"
551 # -re "type = int \*.*$prompt $" { pass "ptype signed int pointer" }
552 # -re ".*$prompt $" { fail "ptype signed int pointer" }
553 # timeout { fail "(timeout) ptype signed int pointer" }
557 #send "ptype v_unsigned_int_pointer\n"
559 # -re "type = unsigned int \*.*$prompt $" { pass "ptype unsigned int pointer" }
560 # -re ".*$prompt $" { fail "ptype unsigned int pointer" }
561 # timeout { fail "(timeout) ptype unsigned int pointer" }
565 #send "ptype v_long_pointer\n"
567 # -re "type = long \*.*$prompt $" { pass "ptype long pointer" }
568 # -re ".*$prompt $" { fail "ptype long pointer" }
569 # timeout { fail "(timeout) ptype long pointer" }
573 #send "ptype v_signed_long_pointer\n"
575 # -re "type = long \*.*$prompt $" { pass "ptype signed long pointer" }
576 # -re ".*$prompt $" { fail "ptype signed long pointer" }
577 # timeout { fail "(timeout) ptype signed long pointer" }
581 #send "ptype v_unsigned_long_pointer\n"
583 # -re "type = unsigned long \*.*$prompt $" { pass "ptype unsigned long pointer" }
584 # -re ".*$prompt $" { fail "ptype unsigned long pointer" }
585 # timeout { fail "(timeout) ptype unsigned long pointer" }
589 #send "ptype v_float_pointer\n"
591 # -re "type = float \*.*$prompt $" { pass "ptype float pointer" }
592 # -re ".*$prompt $" { fail "ptype float pointer" }
593 # timeout { fail "(timeout) ptype float pointer" }
597 #send "ptype v_double_pointer\n"
599 # -re "type = double \*.*$prompt $" { pass "ptype double pointer" }
600 # -re ".*$prompt $" { fail "ptype double pointer" }
601 # timeout { fail "(timeout) ptype double pointer" }
605 # test ptype command with nested structure and union
607 send_gdb "ptype struct outer_struct\n"
609 -re "type = struct outer_struct \{.*
611 struct inner_struct inner_struct_instance;.*
612 union inner_union inner_union_instance;.*
613 (long|long int|int) outer_long;.*
614 \}.*$prompt $" { pass "ptype outer structure" }
615 -re ".*$prompt $" { fail "ptype outer structure" }
616 timeout { fail "(timeout) ptype outer structure" }
620 send_gdb "ptype struct inner_struct\n"
622 -re "type = struct inner_struct \{.*
624 (long|long int|int) inner_long;.*
625 \}.*$prompt $" { pass "ptype inner structure" }
626 -re ".*$prompt $" { fail "ptype inner structure" }
627 timeout { fail "(timeout) ptype inner structure" }
631 send_gdb "ptype union inner_union\n"
633 -re "type = union inner_union \{.*
634 int inner_union_int;.*
635 (long|long int|int) inner_union_long;.*
636 \}.*$prompt $" { pass "ptype inner union" }
637 -re ".*$prompt $" { fail "ptype inner union" }
638 timeout { fail "(timeout) ptype inner union" }
642 send_gdb "ptype nested_su\n"
644 -re "type = struct outer_struct \{.*
646 struct inner_struct inner_struct_instance;.*
647 union inner_union inner_union_instance;.*
648 (long|long int|int) outer_long;.*
649 \}.*$prompt $" { pass "ptype nested structure" }
650 -re ".*$prompt $" { fail "ptype nested structure" }
651 timeout { fail "(timeout) ptype nested structure" }
655 send_gdb "ptype nested_su.outer_int\n"
657 -re "type = int.*$prompt $" { pass "ptype outer int" }
658 -re ".*$prompt $" { fail "ptype outer int" }
659 timeout { fail "(timeout) ptype outer int" }
663 send_gdb "ptype nested_su.inner_struct_instance\n"
665 -re "type = struct inner_struct \{.*
667 (long|long int|int) inner_long;.*
668 \}.*$prompt $" { pass "ptype nested structure" }
669 -re ".*$prompt $" { fail "ptype nested structure" }
670 timeout { fail "(timeout) ptype nested structure" }
674 send_gdb "ptype nested_su.inner_struct_instance.inner_int\n"
676 -re "type = int.*$prompt $" { pass "ptype inner int" }
677 -re ".*$prompt $" { fail "ptype inner int" }
678 timeout { fail "(timeout) ptype inner int" }
682 send_gdb "ptype nested_su.inner_union_instance\n"
684 -re "type = union inner_union \{.*
685 int inner_union_int;.*
686 (long|long int|int) inner_union_long;.*
687 \}.*$prompt $" { pass "ptype nested union" }
688 -re ".*$prompt $" { fail "ptype nested union" }
689 timeout { fail "(timeout) ptype nested union" }
692 # Test printing type of string constants and array constants, but
693 # requires a running process. These call malloc, and can take a long
694 # time to execute over a slow serial link, so increase the timeout.
696 # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
697 # the operation causes a slow painful death rather than a nice simple failure.
699 if ![istarget "*-*-udi*"] then {
700 if [runto_main] then {
701 setup_xfail "a29k-*-udi" 2416
702 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
703 setup_xfail "a29k-*-udi" 2416
704 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
705 setup_xfail "a29k-*-udi" 2416
706 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
707 setup_xfail "a29k-*-udi" 2416
708 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
709 setup_xfail "a29k-*-udi" 2416
710 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
711 setup_xfail "a29k-*-udi" 2416
712 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
713 setup_xfail "a29k-*-udi" 2416
714 gdb_test "ptype {4,5,6}\[2\]" "type = int"
715 setup_xfail "a29k-*-udi" 2416
716 gdb_test "ptype *&{4,5,6}\[1\]" "type = int"