]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/ptype.exp
* gdb.base/default.exp: Remove obsolete code.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ptype.exp
CommitLineData
b9c07f0f
AC
1# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1999,
2# 2000, 2002 Free Software Foundation, Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Please email any bugs, comments, and/or additions to this file to:
19# bug-gdb@prep.ai.mit.edu
20
21# This file was written by Rob Savoye. (rob@cygnus.com)
22
23if $tracelevel then {
24 strace $tracelevel
25 }
26
27#
28# test running programs
29#
30set prms_id 0
31set bug_id 0
32
33set testfile "ptype"
34set srcfile ${testfile}.c
35set binfile ${objdir}/${subdir}/${testfile}
36if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
37 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
38}
39
40# Create and source the file that provides information about the compiler
41# used to compile the test case.
42if [get_compiler_info ${binfile}] {
43 return -1;
44}
45
46gdb_exit
47gdb_start
48gdb_reinitialize_dir $srcdir/$subdir
49gdb_load ${binfile}
50
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).
55
56send_gdb "ptype red1\n"
57gdb_expect {
58 -re "type = enum primary1_tag \{red1, green1, blue1\}.*$gdb_prompt $"\
59 {
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)"
63 }
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" }
68}
69
70#
71# test ptype command with structures
72#
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).
76gdb_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"
77
78
79# Test the equivalence between '.' and '->' for struct member references.
80
81if [gdb_test "ptype v_struct1.v_float_member" "type = float"]<0 then {
82 return -1
83}
84if [gdb_test "ptype v_struct1->v_float_member" "type = float"]<0 then {
85 return -1
86}
87if [gdb_test "ptype v_t_struct_p.v_float_member" "type = float"]<0 then {
88 return -1
89}
90if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then {
91 return -1
92}
93
94
95# IBM's xlc puts out bogus stabs--the stuff field is type 42,
96# which isn't defined.
97
085dd6e6 98gdb_test "ptype struct link" "type = struct link \{\[\r\n\]+\[ \t\]+struct link \\*next;\[\r\n\]+\[ \t\]+struct link \\*\\(\\*linkfunc\\)\\((struct link \\*, int|void|)\\);\[\r\n\]+\[ \t\]+struct t_struct stuff.1..2..3.;\[\r\n\]+\}.*" "ptype linked list structure"
c906108c
SS
99
100#
101# test ptype command with unions
102#
103gdb_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"
104
105# IBM's xlc puts out bogus stabs--the stuff field is type 42,
106# which isn't defined.
085dd6e6 107gdb_test "ptype union tu_link" "type = union tu_link \{\[\r\n\]+\[ \t\]+struct link \\*next;\[\r\n\]+\[ \t\]+struct link \\*\\(\\*linkfunc\\)\\((struct link \\*, int|void|)\\);\[\r\n\]+\[ \t\]+struct t_struct stuff.1..2..3.;\[\r\n\]+\}.*" "ptype linked list union"
c906108c
SS
108
109#
110# test ptype command with enums
111#
112
113gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration"
114
115gdb_test "ptype enum colors" "type = enum colors \{yellow, purple, pink\}.*" "ptype named enumeration"
116
117
118#
119# test ptype command with enums as typedef
120#
085dd6e6 121gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
c906108c
SS
122
123# And check that whatis shows the name, not "enum {...}".
124# This probably fails for all DWARF 1 cases, so assume so for now. -fnf
125# The problem with xlc is that the stabs look like
126# :t51=eFALSE:0,TRUE:1,;
127# boolean:t55=51
128# v_boolean:G51
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.
131
085dd6e6 132if {!$gcc_compiled && !$hp_aCC_compiler} {
a0b3c4fd
JM
133 setup_xfail "rs6000-*-*" "i*86-*-sysv4*"
134 setup_xfail "hppa*-*-*" CLLbs14773
085dd6e6 135}
dfcd3bfb
JM
136
137# For get_debug_format to do its job, we need to have a current source file.
138gdb_test "list main" ""
9846de1b 139get_debug_format
c906108c 140setup_xfail_format "DWARF 1"
085dd6e6 141gdb_test "whatis v_boolean" "type = (enum |)boolean" \
c906108c
SS
142 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
143
144# Same thing with struct and union.
085dd6e6 145gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
c906108c
SS
146 *double v_double_member;.*
147 *int v_int_member;.*\}" "printing typedef'd struct"
148
085dd6e6 149gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
c906108c
SS
150 *double v_double_member;.*
151 *int v_int_member;.*\}" "printing typedef'd union"
152
085dd6e6 153gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"
c906108c
SS
154
155#
156# test ptype command with out-of-order enum values
157#
158gdb_test "ptype enum misordered" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype misordered enumeration"
159
160#
161# test ptype command with a named enum's value
162#
163gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member"
164
165gdb_test "ptype red" "type = enum \{red, green, blue\}.*" "ptype unnamed enumeration member #2"
166
167#
168# test ptype command with basic C types
169#
170# I've commented most of this out because it duplicates tests in whatis.exp.
171# I've just left in a token test or 2 which is designed to test that ptype
172# acts like whatis for basic types. If it is thought to be necessary to
173# test both whatis and ptype for all the types, the tests should be
174# merged into whatis.exp, or else maintenance will be a royal pain -kingdon
175#setup_xfail "i960-*-*" 1821
9fbfe2dc 176#setup_xfail "mips-idt-*" "mips-sgi-*"
c906108c
SS
177#send "ptype v_char\n"
178#gdb_expect {
179# -re "type = char.*$gdb_prompt $" { pass "ptype char" }
180# -re ".*$gdb_prompt $" { fail "ptype char" }
181# timeout { fail "(timeout) ptype char" }
182#}
183#
184#
9fbfe2dc 185#setup_xfail "mips-*-*"
c906108c
SS
186#send "ptype v_signed_char\n"
187#gdb_expect {
188# -re "type = signed char.*$gdb_prompt $" { pass "ptype signed char" }
189# -re ".*$gdb_prompt $" { fail "ptype signed char" }
190# timeout { fail "(timeout) ptype signed char" }
191#}
192#
193#
194#send "ptype v_unsigned_char\n"
195#gdb_expect {
196# -re "type = unsigned char.*$gdb_prompt $" { pass "ptype unsigned char" }
197# -re ".*$gdb_prompt $" { fail "ptype unsigned char" }
198# timeout { fail "(timeout) ptype unsigned char" }
199#}
200
201gdb_test "ptype v_short" "type = short(| int).*" "ptype short"
202
203#send "ptype v_signed_short\n"
204#gdb_expect {
205# -re "type = short.*$gdb_prompt $" { pass "ptype signed short" }
206# -re ".*$gdb_prompt $" { fail "ptype signed short" }
207# timeout { fail "(timeout) ptype signed short" }
208#}
209#
210#
211#send "ptype v_unsigned_short\n"
212#gdb_expect {
213# -re "type = unsigned short.*$gdb_prompt $" { pass "ptype unsigned short" }
214# -re ".*$gdb_prompt $" { fail "ptype unsigned short" }
215# timeout { fail "(timeout) ptype unsigned short" }
216#}
217
218
219gdb_test "ptype v_int" "type = int.*" "ptype int"
220
221#send "ptype v_signed_int\n"
222#gdb_expect {
223# -re "type = int.*$gdb_prompt $" { pass "ptype signed int" }
224# -re ".*$gdb_prompt $" { fail "ptype signed int" }
225# timeout { fail "(timeout) ptype signed int" }
226#}
227#
228#
229#send "ptype v_unsigned_int\n"
230#gdb_expect {
231# -re "type = unsigned int.*$gdb_prompt $" { pass "ptype unsigned int" }
232# -re ".*$gdb_prompt $" { fail "ptype unsigned int" }
233# timeout { fail "(timeout) ptype unsigned int" }
234#}
235#
236#
237#send "ptype v_long\n"
238#gdb_expect {
239# -re "type = long.*$gdb_prompt $" { pass "ptype long" }
240# -re ".*$gdb_prompt $" { fail "ptype long" }
241# timeout { fail "(timeout) ptype long" }
242#}
243#
244#
245#send "ptype v_signed_long\n"
246#gdb_expect {
247# -re "type = long.*$gdb_prompt $" { pass "ptype signed long" }
248# -re ".*$gdb_prompt $" { fail "ptype signed long" }
249# timeout { fail "(timeout) ptype signed long" }
250#}
251#
252#
253#send "ptype v_unsigned_long\n"
254#gdb_expect {
255# -re "type = unsigned long.*$gdb_prompt $" { pass "ptype unsigned long" }
256# -re ".*$gdb_prompt $" { fail "ptype unsigned long" }
257# timeout { fail "(timeout) ptype unsigned long" }
258#}
259#
260#
261#send "ptype v_float\n"
262#gdb_expect {
263# -re "type = float.*$gdb_prompt $" { pass "ptype float" }
264# -re ".*$gdb_prompt $" { fail "ptype float" }
265# timeout { fail "(timeout) ptype float" }
266#}
267#
268#
269#send "ptype v_double\n"
270#gdb_expect {
271# -re "type = double.*$gdb_prompt $" { pass "ptype double" }
272# -re ".*$gdb_prompt $" { fail "ptype double" }
273# timeout { fail "(timeout) ptype double" }
274#}
275
276
277#
278# test ptype command with arrays
279#
280#setup_xfail "i960-*-*" 1821
9fbfe2dc 281#setup_xfail "mips-idt-*" "mips-sgi-*"
c906108c
SS
282#send "ptype v_char_array\n"
283#gdb_expect {
284# -re "type = char .2..*$gdb_prompt $" { pass "ptype char array" }
285# -re ".*$gdb_prompt $" { fail "ptype char array" }
286# timeout { fail "(timeout) ptype char array" }
287#}
288#
289#
9fbfe2dc 290#setup_xfail "mips-*-*"
c906108c
SS
291#send "ptype v_signed_char_array\n"
292#gdb_expect {
293# -re "type = (|signed )char .2..*$gdb_prompt $" { pass "ptype signed char array" }
294# -re ".*$gdb_prompt $" { fail "ptype signed char array" }
295# timeout { fail "(timeout) ptype signed char array" }
296#}
297#
298#
299#send "ptype v_unsigned_char_array\n"
300#gdb_expect {
301# -re "type = unsigned char .2..*$gdb_prompt $" { pass "ptype unsigned char array" }
302# -re ".*$gdb_prompt $" { fail "ptype unsigned char array" }
303# timeout { fail "(timeout) ptype unsigned char array" }
304#}
305#
306#
307#
308#send "ptype v_int_array\n"
309#gdb_expect {
310# -re "type = int .2..*$gdb_prompt $" { pass "ptype int array" }
311# -re ".*$gdb_prompt $" { fail "ptype int array" }
312# timeout { fail "(timeout) ptype int array" }
313#}
314#
315#
316#send "ptype v_signed_int_array\n"
317#gdb_expect {
318# -re "type = int .2..*$gdb_prompt $" { pass "ptype signed int array" }
319# -re ".*$gdb_prompt $" { fail "ptype signed int array" }
320# timeout { fail "(timeout) ptype signed int array" }
321#}
322#
323#
324#send "ptype v_unsigned_int_array\n"
325#gdb_expect {
326# -re "type = unsigned int .2..*$gdb_prompt $" { pass "ptype unsigned int array" }
327# -re ".*$gdb_prompt $" { fail "ptype unsigned int array" }
328# timeout { fail "(timeout) ptype unsigned int array" }
329#}
330#
331#
332#send "ptype v_long_array\n"
333#gdb_expect {
334# -re "type = (long|int|long int) .2..*$gdb_prompt $" {
335# pass "ptype long array" }
336# -re ".*$gdb_prompt $" { fail "ptype long array" }
337# timeout { fail "(timeout) ptype long array" }
338#}
339#
340#
341#send "ptype v_signed_long_array\n"
342#gdb_expect {
343# -re "type = (long|int|long int) .2..*$gdb_prompt $" {
344# pass "ptype signed long array" }
345# -re ".*$gdb_prompt $" { fail "ptype signed long array" }
346# timeout { fail "(timeout) ptype signed long array" }
347#}
348#
349#
350#send "ptype v_unsigned_long_array\n"
351#gdb_expect {
352# -re "type = unsigned long .2..*$gdb_prompt $" { pass "ptype unsigned long array" }
353# -re ".*$gdb_prompt $" { fail "ptype unsigned long array" }
354# timeout { fail "(timeout) ptype unsigned long array" }
355#}
356#
357#
358#send "ptype v_float_array\n"
359#gdb_expect {
360# -re "type = float .2..*$gdb_prompt $" { pass "ptype float array" }
361# -re ".*$gdb_prompt $" { fail "ptype float array" }
362# timeout { fail "(timeout) ptype float array" }
363#}
364#
365#
366#send "ptype v_double_array\n"
367#gdb_expect {
368# -re "type = double .2..*$gdb_prompt $" { pass "ptype double array" }
369# -re ".*$gdb_prompt $" { fail "ptype double array" }
370# timeout { fail "(timeout) ptype double array" }
371#}
372#
373
374if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
375setup_xfail_format "DWARF 1"
085dd6e6 376if {$hp_aCC_compiler} {setup_xfail "hppa*-*-*"}
c906108c
SS
377gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
378
379#
380##
381## test ptype command with pointers
382##
383#setup_xfail "i960-*-*" 1821
9fbfe2dc 384#setup_xfail "mips-idt-*" "mips-sgi-*"
c906108c
SS
385#send "ptype v_char_pointer\n"
386#gdb_expect {
387# -re "type = char \*.*$gdb_prompt $" { pass "ptype char pointer" }
388# -re ".*$gdb_prompt $" { fail "ptype char pointer" }
389# timeout { fail "(timeout) ptype char pointer" }
390#}
391#
392#
9fbfe2dc 393#setup_xfail "mips-*-*"
c906108c
SS
394#send "ptype v_signed_char_pointer\n"
395#gdb_expect {
396# -re "type = (|signed )char \*.*$gdb_prompt $"
397# { pass "ptype signed char pointer" }
398# -re ".*$gdb_prompt $" { fail "ptype signed char pointer" }
399# timeout { fail "(timeout) ptype signed char pointer" }
400#}
401#
402#
403#send "ptype v_unsigned_char_pointer\n"
404#gdb_expect {
405# -re "type = unsigned char \*.*$gdb_prompt $" { pass "ptype unsigned char pointer" }
406# -re ".*$gdb_prompt $" { fail "ptype unsigned char pointer" }
407# timeout { fail "(timeout) ptype unsigned char pointer" }
408#}
409#
410#
411#send "ptype v_short_pointer\n"
412#gdb_expect {
413# -re "type = (short|short int) \*.*$gdb_prompt $" { pass "ptype short pointer" }
414# -re ".*$gdb_prompt $" { fail "ptype short pointer" }
415# timeout { fail "(timeout) ptype short pointer" }
416#}
417#
418#
419#send "ptype v_signed_short_pointer\n"
420#gdb_expect {
421# -re "type = short \*.*$gdb_prompt $" { pass "ptype signed short pointer" }
422# -re ".*$gdb_prompt $" { fail "ptype signed short pointer" }
423# timeout { fail "(timeout) ptype signed short pointer" }
424#}
425#
426#
427#send "ptype v_unsigned_short_pointer\n"
428#gdb_expect {
429# -re "type = unsigned short \*.*$gdb_prompt $" { pass "ptype unsigned short pointer" }
430# -re ".*$gdb_prompt $" { fail "ptype unsigned short pointer" }
431# timeout { fail "(timeout) ptype unsigned short pointer" }
432#}
433#
434#
435#send "ptype v_int_pointer\n"
436#gdb_expect {
437# -re "type = int \*.*$gdb_prompt $" { pass "ptype int pointer" }
438# -re ".*$gdb_prompt $" { fail "ptype int pointer" }
439# timeout { fail "(timeout) ptype int pointer" }
440#}
441#
442#
443#send "ptype v_signed_int_pointer\n"
444#gdb_expect {
445# -re "type = int \*.*$gdb_prompt $" { pass "ptype signed int pointer" }
446# -re ".*$gdb_prompt $" { fail "ptype signed int pointer" }
447# timeout { fail "(timeout) ptype signed int pointer" }
448#}
449#
450#
451#send "ptype v_unsigned_int_pointer\n"
452#gdb_expect {
453# -re "type = unsigned int \*.*$gdb_prompt $" { pass "ptype unsigned int pointer" }
454# -re ".*$gdb_prompt $" { fail "ptype unsigned int pointer" }
455# timeout { fail "(timeout) ptype unsigned int pointer" }
456#}
457#
458#
459#send "ptype v_long_pointer\n"
460#gdb_expect {
461# -re "type = long \*.*$gdb_prompt $" { pass "ptype long pointer" }
462# -re ".*$gdb_prompt $" { fail "ptype long pointer" }
463# timeout { fail "(timeout) ptype long pointer" }
464#}
465#
466#
467#send "ptype v_signed_long_pointer\n"
468#gdb_expect {
469# -re "type = long \*.*$gdb_prompt $" { pass "ptype signed long pointer" }
470# -re ".*$gdb_prompt $" { fail "ptype signed long pointer" }
471# timeout { fail "(timeout) ptype signed long pointer" }
472#}
473#
474#
475#send "ptype v_unsigned_long_pointer\n"
476#gdb_expect {
477# -re "type = unsigned long \*.*$gdb_prompt $" { pass "ptype unsigned long pointer" }
478# -re ".*$gdb_prompt $" { fail "ptype unsigned long pointer" }
479# timeout { fail "(timeout) ptype unsigned long pointer" }
480#}
481#
482#
483#send "ptype v_float_pointer\n"
484#gdb_expect {
485# -re "type = float \*.*$gdb_prompt $" { pass "ptype float pointer" }
486# -re ".*$gdb_prompt $" { fail "ptype float pointer" }
487# timeout { fail "(timeout) ptype float pointer" }
488#}
489#
490#
491#send "ptype v_double_pointer\n"
492#gdb_expect {
493# -re "type = double \*.*$gdb_prompt $" { pass "ptype double pointer" }
494# -re ".*$gdb_prompt $" { fail "ptype double pointer" }
495# timeout { fail "(timeout) ptype double pointer" }
496#}
497
498#
499# test ptype command with nested structure and union
500#
085dd6e6
JM
501if {$hp_aCC_compiler} {
502 set outer "outer_struct::"
503 set struct ""
504 set union ""
505} else {
506 set outer ""
507 set struct "struct"
508 set union "union"
509}
510gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\]+\
511.*int outer_int;.*\[\r\n\]+\
512.*(struct|) ${outer}inner_struct inner_struct_instance;.*\[\r\n\]+\
513.*(union|) ${outer}inner_union inner_union_instance;.*\[\r\n\]+\
514.*(long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype outer structure"
c906108c 515
085dd6e6 516gdb_test "ptype ${struct} ${outer}inner_struct" "type = struct ${outer}inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype inner structure"
c906108c 517
085dd6e6 518gdb_test "ptype ${union} ${outer}inner_union" "type = union ${outer}inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype inner union"
c906108c 519
085dd6e6 520gdb_test "ptype nested_su" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] (struct |)${outer}inner_struct inner_struct_instance;.*\[\r\n\] (union |)${outer}inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype nested structure"
c906108c
SS
521
522gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
523
085dd6e6 524gdb_test "ptype nested_su.inner_struct_instance" "type = struct ${outer}inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype nested structure #2"
c906108c
SS
525
526gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
527
085dd6e6 528gdb_test "ptype nested_su.inner_union_instance" "type = union ${outer}inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype nested union"
c906108c 529
a640f7fc
JB
530
531get_debug_format
532
533# Print the type of the identifier ID, and check the response:
534# - Expect to see PROTOTYPED as the type. PROTOTYPED is not a regular
535# expression; it's a literal string.
536# - If we instead see the unprototyped type PLAIN, and we're using STABS
537# generated by GCC, that's an xfail; as of 9 Feb 2002, GCC never emits
538# prototyped function types in STABS. Like PROTOTYPED, PLAIN is a
539# literal string, not a regular expression.
540# - Otherwise, it's a failure.
541proc ptype_maybe_prototyped { id prototyped plain } {
542 global gdb_prompt
543 global gcc_compiled
544
545 # Turn `prototyped' and `plain', which are literal strings, into
546 # regular expressions by quoting any special characters they contain.
547 regsub -all "\[\]\[*()\]" $prototyped "\\\\&" prototyped
548 regsub -all "\[\]\[*()\]" $plain "\\\\&" plain
549
550 send_gdb "ptype $id\n"
551 gdb_expect {
552 -re "type = $prototyped\[\r\n\]+$gdb_prompt $" {
553 pass "ptype $id"
554 }
555 -re "type = $plain\[\r\n\]+$gdb_prompt $" {
556 if {$gcc_compiled} { setup_xfail_format "stabs" }
557 fail "ptype $id (compiler doesn't emit prototyped types)"
558 }
559 -re "$gdb_prompt $" {
560 fail "ptype $id"
561 }
562 timeout {
563 fail "ptype $id (timeout)"
564 }
565 }
566}
567
568ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
569 "int (*)()"
570ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()"
571ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
572ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
573ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
574 "int *(*)()"
575ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
576 "int (*)()"
577ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
578 "int (*(*)())()"
579ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
580 "int (*(*(*)())())()"
581
c906108c
SS
582# Test printing type of string constants and array constants, but
583# requires a running process. These call malloc, and can take a long
584# time to execute over a slow serial link, so increase the timeout.
585
586# UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
587# the operation causes a slow painful death rather than a nice simple failure.
588
589if [runto_main] then {
590
c906108c
SS
591 if [target_info exists gdb,cannot_call_functions] {
592 setup_xfail "*-*-*" 2416
593 fail "This target can not call functions"
594 continue
595 }
596
9846de1b
JM
597 # We need to up this because this can be really slow on some boards.
598 # (malloc() is called as part of the test).
599 set timeout 60;
600
c906108c
SS
601 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
602 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
603 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
604 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
605 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
606 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
607 gdb_test "ptype {4,5,6}\[2\]" "type = int"
608 gdb_test "ptype *&{4,5,6}\[1\]" "type = int"
609}