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