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