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\}.*$gdb_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\}.*$gdb_prompt $"\
65 { pass "ptype unnamed enumeration member" }
66 -re ".*$gdb_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 gdb_test "ptype struct t_struct" "type = struct t_struct \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype structure"
79 # Test the equivalence between '.' and '->' for struct member references.
81 if [gdb_test "ptype v_struct1.v_float_member" "type = float"]<0 then {
84 if [gdb_test "ptype v_struct1->v_float_member" "type = float"]<0 then {
87 if [gdb_test "ptype v_t_struct_p.v_float_member" "type = float"]<0 then {
90 if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then {
95 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
96 # which isn't defined.
98 gdb_test "ptype struct link" "type = struct link \{.*\[\r\n\] struct link \[*\]next;.*\[\r\n\] struct link \[*(\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*\[\r\n\] struct t_struct stuff.1..2..3.;.*\[\r\n\]\}.*" "ptype linked list structure"
101 # test ptype command with unions
103 gdb_test "ptype union t_union" "type = union t_union \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype union"
105 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
106 # which isn't defined.
107 gdb_test "ptype union tu_link" "type = union tu_link .*\[\r\n\] struct link \[*\]next;.*\[\r\n\] struct link \[(\*\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*\[\r\n\] struct t_struct stuff.1..2..3.;.*\[\r\n\]\}.*" "ptype linked list union"
110 # test ptype command with enums
113 gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration"
115 gdb_test "ptype enum colors" "type = enum colors \{yellow, purple, pink\}.*" "ptype named enumeration"
119 # test ptype command with enums as typedef
121 gdb_test "ptype boolean" "type = enum \{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
123 # And check that whatis shows the name, not "enum {...}".
125 # The problem with xlc is that the stabs look like
126 # :t51=eFALSE:0,TRUE:1,;
129 # GDB's behavior is correct; the type which the variable is defined
130 # as (51) doesn't have a name. Only 55 has a name.
132 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
133 gdb_test "whatis v_boolean" "type = boolean" \
134 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
136 # Same thing with struct and union.
137 gdb_test "ptype t_struct3" "type = struct \{.*
138 *double v_double_member;.*
139 *int v_int_member;.*\}" "printing typedef'd struct"
141 gdb_test "ptype t_union3" "type = union \{.*
142 *double v_double_member;.*
143 *int v_int_member;.*\}" "printing typedef'd union"
145 gdb_test "ptype enum bvals" "type = enum bvals \{false, true\}.*" "ptype named typedef'd enumf'd enum"
148 # test ptype command with out-of-order enum values
150 gdb_test "ptype enum misordered" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype misordered enumeration"
153 # test ptype command with a named enum's value
155 gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member"
157 gdb_test "ptype red" "type = enum \{red, green, blue\}.*" "ptype unnamed enumeration member"
160 # test ptype command with basic C types
162 # I've commented most of this out because it duplicates tests in whatis.exp.
163 # I've just left in a token test or 2 which is designed to test that ptype
164 # acts like whatis for basic types. If it is thought to be necessary to
165 # test both whatis and ptype for all the types, the tests should be
166 # merged into whatis.exp, or else maintenance will be a royal pain -kingdon
167 #setup_xfail "i960-*-*" 1821
168 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
169 #send "ptype v_char\n"
171 # -re "type = char.*$gdb_prompt $" { pass "ptype char" }
172 # -re ".*$gdb_prompt $" { fail "ptype char" }
173 # timeout { fail "(timeout) ptype char" }
177 #setup_xfail "mips-*-*" "a29k-*-*"
178 #send "ptype v_signed_char\n"
180 # -re "type = signed char.*$gdb_prompt $" { pass "ptype signed char" }
181 # -re ".*$gdb_prompt $" { fail "ptype signed char" }
182 # timeout { fail "(timeout) ptype signed char" }
186 #send "ptype v_unsigned_char\n"
188 # -re "type = unsigned char.*$gdb_prompt $" { pass "ptype unsigned char" }
189 # -re ".*$gdb_prompt $" { fail "ptype unsigned char" }
190 # timeout { fail "(timeout) ptype unsigned char" }
193 gdb_test "ptype v_short" "type = short(| int).*" "ptype short"
195 #send "ptype v_signed_short\n"
197 # -re "type = short.*$gdb_prompt $" { pass "ptype signed short" }
198 # -re ".*$gdb_prompt $" { fail "ptype signed short" }
199 # timeout { fail "(timeout) ptype signed short" }
203 #send "ptype v_unsigned_short\n"
205 # -re "type = unsigned short.*$gdb_prompt $" { pass "ptype unsigned short" }
206 # -re ".*$gdb_prompt $" { fail "ptype unsigned short" }
207 # timeout { fail "(timeout) ptype unsigned short" }
211 gdb_test "ptype v_int" "type = int.*" "ptype int"
213 #send "ptype v_signed_int\n"
215 # -re "type = int.*$gdb_prompt $" { pass "ptype signed int" }
216 # -re ".*$gdb_prompt $" { fail "ptype signed int" }
217 # timeout { fail "(timeout) ptype signed int" }
221 #send "ptype v_unsigned_int\n"
223 # -re "type = unsigned int.*$gdb_prompt $" { pass "ptype unsigned int" }
224 # -re ".*$gdb_prompt $" { fail "ptype unsigned int" }
225 # timeout { fail "(timeout) ptype unsigned int" }
229 #send "ptype v_long\n"
231 # -re "type = long.*$gdb_prompt $" { pass "ptype long" }
232 # -re ".*$gdb_prompt $" { fail "ptype long" }
233 # timeout { fail "(timeout) ptype long" }
237 #send "ptype v_signed_long\n"
239 # -re "type = long.*$gdb_prompt $" { pass "ptype signed long" }
240 # -re ".*$gdb_prompt $" { fail "ptype signed long" }
241 # timeout { fail "(timeout) ptype signed long" }
245 #send "ptype v_unsigned_long\n"
247 # -re "type = unsigned long.*$gdb_prompt $" { pass "ptype unsigned long" }
248 # -re ".*$gdb_prompt $" { fail "ptype unsigned long" }
249 # timeout { fail "(timeout) ptype unsigned long" }
253 #send "ptype v_float\n"
255 # -re "type = float.*$gdb_prompt $" { pass "ptype float" }
256 # -re ".*$gdb_prompt $" { fail "ptype float" }
257 # timeout { fail "(timeout) ptype float" }
261 #send "ptype v_double\n"
263 # -re "type = double.*$gdb_prompt $" { pass "ptype double" }
264 # -re ".*$gdb_prompt $" { fail "ptype double" }
265 # timeout { fail "(timeout) ptype double" }
270 # test ptype command with arrays
272 #setup_xfail "i960-*-*" 1821
273 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
274 #send "ptype v_char_array\n"
276 # -re "type = char .2..*$gdb_prompt $" { pass "ptype char array" }
277 # -re ".*$gdb_prompt $" { fail "ptype char array" }
278 # timeout { fail "(timeout) ptype char array" }
282 #setup_xfail "mips-*-*" "a29k-*-*"
283 #send "ptype v_signed_char_array\n"
285 # -re "type = (|signed )char .2..*$gdb_prompt $" { pass "ptype signed char array" }
286 # -re ".*$gdb_prompt $" { fail "ptype signed char array" }
287 # timeout { fail "(timeout) ptype signed char array" }
291 #send "ptype v_unsigned_char_array\n"
293 # -re "type = unsigned char .2..*$gdb_prompt $" { pass "ptype unsigned char array" }
294 # -re ".*$gdb_prompt $" { fail "ptype unsigned char array" }
295 # timeout { fail "(timeout) ptype unsigned char array" }
300 #send "ptype v_int_array\n"
302 # -re "type = int .2..*$gdb_prompt $" { pass "ptype int array" }
303 # -re ".*$gdb_prompt $" { fail "ptype int array" }
304 # timeout { fail "(timeout) ptype int array" }
308 #send "ptype v_signed_int_array\n"
310 # -re "type = int .2..*$gdb_prompt $" { pass "ptype signed int array" }
311 # -re ".*$gdb_prompt $" { fail "ptype signed int array" }
312 # timeout { fail "(timeout) ptype signed int array" }
316 #send "ptype v_unsigned_int_array\n"
318 # -re "type = unsigned int .2..*$gdb_prompt $" { pass "ptype unsigned int array" }
319 # -re ".*$gdb_prompt $" { fail "ptype unsigned int array" }
320 # timeout { fail "(timeout) ptype unsigned int array" }
324 #send "ptype v_long_array\n"
326 # -re "type = (long|int|long int) .2..*$gdb_prompt $" {
327 # pass "ptype long array" }
328 # -re ".*$gdb_prompt $" { fail "ptype long array" }
329 # timeout { fail "(timeout) ptype long array" }
333 #send "ptype v_signed_long_array\n"
335 # -re "type = (long|int|long int) .2..*$gdb_prompt $" {
336 # pass "ptype signed long array" }
337 # -re ".*$gdb_prompt $" { fail "ptype signed long array" }
338 # timeout { fail "(timeout) ptype signed long array" }
342 #send "ptype v_unsigned_long_array\n"
344 # -re "type = unsigned long .2..*$gdb_prompt $" { pass "ptype unsigned long array" }
345 # -re ".*$gdb_prompt $" { fail "ptype unsigned long array" }
346 # timeout { fail "(timeout) ptype unsigned long array" }
350 #send "ptype v_float_array\n"
352 # -re "type = float .2..*$gdb_prompt $" { pass "ptype float array" }
353 # -re ".*$gdb_prompt $" { fail "ptype float array" }
354 # timeout { fail "(timeout) ptype float array" }
358 #send "ptype v_double_array\n"
360 # -re "type = double .2..*$gdb_prompt $" { pass "ptype double array" }
361 # -re ".*$gdb_prompt $" { fail "ptype double array" }
362 # timeout { fail "(timeout) ptype double array" }
366 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
367 gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
371 ## test ptype command with pointers
373 #setup_xfail "i960-*-*" 1821
374 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
375 #send "ptype v_char_pointer\n"
377 # -re "type = char \*.*$gdb_prompt $" { pass "ptype char pointer" }
378 # -re ".*$gdb_prompt $" { fail "ptype char pointer" }
379 # timeout { fail "(timeout) ptype char pointer" }
383 #setup_xfail "mips-*-*" "a29k-*-*"
384 #send "ptype v_signed_char_pointer\n"
386 # -re "type = (|signed )char \*.*$gdb_prompt $"
387 # { pass "ptype signed char pointer" }
388 # -re ".*$gdb_prompt $" { fail "ptype signed char pointer" }
389 # timeout { fail "(timeout) ptype signed char pointer" }
393 #send "ptype v_unsigned_char_pointer\n"
395 # -re "type = unsigned char \*.*$gdb_prompt $" { pass "ptype unsigned char pointer" }
396 # -re ".*$gdb_prompt $" { fail "ptype unsigned char pointer" }
397 # timeout { fail "(timeout) ptype unsigned char pointer" }
401 #send "ptype v_short_pointer\n"
403 # -re "type = (short|short int) \*.*$gdb_prompt $" { pass "ptype short pointer" }
404 # -re ".*$gdb_prompt $" { fail "ptype short pointer" }
405 # timeout { fail "(timeout) ptype short pointer" }
409 #send "ptype v_signed_short_pointer\n"
411 # -re "type = short \*.*$gdb_prompt $" { pass "ptype signed short pointer" }
412 # -re ".*$gdb_prompt $" { fail "ptype signed short pointer" }
413 # timeout { fail "(timeout) ptype signed short pointer" }
417 #send "ptype v_unsigned_short_pointer\n"
419 # -re "type = unsigned short \*.*$gdb_prompt $" { pass "ptype unsigned short pointer" }
420 # -re ".*$gdb_prompt $" { fail "ptype unsigned short pointer" }
421 # timeout { fail "(timeout) ptype unsigned short pointer" }
425 #send "ptype v_int_pointer\n"
427 # -re "type = int \*.*$gdb_prompt $" { pass "ptype int pointer" }
428 # -re ".*$gdb_prompt $" { fail "ptype int pointer" }
429 # timeout { fail "(timeout) ptype int pointer" }
433 #send "ptype v_signed_int_pointer\n"
435 # -re "type = int \*.*$gdb_prompt $" { pass "ptype signed int pointer" }
436 # -re ".*$gdb_prompt $" { fail "ptype signed int pointer" }
437 # timeout { fail "(timeout) ptype signed int pointer" }
441 #send "ptype v_unsigned_int_pointer\n"
443 # -re "type = unsigned int \*.*$gdb_prompt $" { pass "ptype unsigned int pointer" }
444 # -re ".*$gdb_prompt $" { fail "ptype unsigned int pointer" }
445 # timeout { fail "(timeout) ptype unsigned int pointer" }
449 #send "ptype v_long_pointer\n"
451 # -re "type = long \*.*$gdb_prompt $" { pass "ptype long pointer" }
452 # -re ".*$gdb_prompt $" { fail "ptype long pointer" }
453 # timeout { fail "(timeout) ptype long pointer" }
457 #send "ptype v_signed_long_pointer\n"
459 # -re "type = long \*.*$gdb_prompt $" { pass "ptype signed long pointer" }
460 # -re ".*$gdb_prompt $" { fail "ptype signed long pointer" }
461 # timeout { fail "(timeout) ptype signed long pointer" }
465 #send "ptype v_unsigned_long_pointer\n"
467 # -re "type = unsigned long \*.*$gdb_prompt $" { pass "ptype unsigned long pointer" }
468 # -re ".*$gdb_prompt $" { fail "ptype unsigned long pointer" }
469 # timeout { fail "(timeout) ptype unsigned long pointer" }
473 #send "ptype v_float_pointer\n"
475 # -re "type = float \*.*$gdb_prompt $" { pass "ptype float pointer" }
476 # -re ".*$gdb_prompt $" { fail "ptype float pointer" }
477 # timeout { fail "(timeout) ptype float pointer" }
481 #send "ptype v_double_pointer\n"
483 # -re "type = double \*.*$gdb_prompt $" { pass "ptype double pointer" }
484 # -re ".*$gdb_prompt $" { fail "ptype double pointer" }
485 # timeout { fail "(timeout) ptype double pointer" }
489 # test ptype command with nested structure and union
491 gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] struct inner_struct inner_struct_instance;.*\[\r\n\] union inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype outer structure"
493 gdb_test "ptype struct inner_struct" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype inner structure"
495 gdb_test "ptype union inner_union" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype inner union"
497 gdb_test "ptype nested_su" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] struct inner_struct inner_struct_instance;.*\[\r\n\] union inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype nested structure"
499 gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
501 gdb_test "ptype nested_su.inner_struct_instance" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype nested structure"
503 gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
505 gdb_test "ptype nested_su.inner_union_instance" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype nested union"
507 # Test printing type of string constants and array constants, but
508 # requires a running process. These call malloc, and can take a long
509 # time to execute over a slow serial link, so increase the timeout.
511 # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
512 # the operation causes a slow painful death rather than a nice simple failure.
514 if [runto_main] then {
516 if [target_info exists gdb,cannot_call_functions] {
517 setup_xfail "*-*-*" 2416
518 fail "This target can not call functions"
522 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
523 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
524 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
525 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
526 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
527 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
528 gdb_test "ptype {4,5,6}\[2\]" "type = int"
529 gdb_test "ptype *&{4,5,6}\[1\]" "type = int"