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