]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/ptype.exp
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / ptype.exp
1 # Copyright 1988-2024 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
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.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file was written by Rob Savoye. (rob@cygnus.com)
17
18 #
19 # test running programs
20 #
21
22 standard_testfile .c ptype1.c
23
24 if {[prepare_for_testing "failed to prepare" ${testfile} \
25 [list $srcfile $srcfile2] {debug nowarnings}]} {
26 return -1
27 }
28
29 # Some tests require GCC.
30 set gcc_compiled [is_c_compiler_gcc]
31
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
37 gdb_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 }
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).
54 gdb_test "ptype struct t_struct" "type = struct t_struct \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype structure"
55
56
57 # Test the equivalence between '.' and '->' for struct member references.
58
59 if {[gdb_test "ptype v_struct1.v_float_member" "type = float"] < 0} {
60 return -1
61 }
62 if {[gdb_test "ptype v_struct1->v_float_member" "type = float"] < 0} {
63 return -1
64 }
65 if {[gdb_test "ptype v_t_struct_p.v_float_member" "type = float"] < 0} {
66 return -1
67 }
68 if {[gdb_test "ptype v_t_struct_p->v_float_member" "type = float"] < 0} {
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
76 gdb_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"
77
78 #
79 # test ptype command with unions
80 #
81 gdb_test "ptype union t_union" "type = union t_union \{.*\[\r\n\] (unsigned |)char v_char_member;.*\[\r\n\] (short|short int) v_short_member;.*\[\r\n\] int v_int_member;.*\[\r\n\] (long|long int|int) v_long_member;.*\[\r\n\] float v_float_member;.*\[\r\n\] double v_double_member;.*\[\r\n\]\}.*" "ptype union"
82
83 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
84 # which isn't defined.
85 gdb_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"
86
87 #
88 # test ptype command with enums
89 #
90
91 gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration"
92
93 gdb_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 #
99 gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
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
110 if {!$gcc_compiled} {
111 setup_xfail "rs6000-*-*" "i*86-*-sysv4*"
112 setup_xfail "hppa*-*-*" CLLbs14773
113 }
114
115 # For get_debug_format to do its job, we need to have a current source file.
116 gdb_test "list -q main" ".*"
117 get_debug_format
118 gdb_test "whatis v_boolean" "type = (enum |)boolean" \
119 "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
120
121 # Same thing with struct and union.
122 gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
123 *double v_double_member;.*
124 *int v_int_member;.*\}" "printing typedef'd struct"
125
126 gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
127 *double v_double_member;.*
128 *int v_int_member;.*\}" "printing typedef'd union"
129
130 gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"
131
132 #
133 # test ptype command with out-of-order enum values
134 #
135 gdb_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 #
140 gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member"
141
142 gdb_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
152 #setup_xfail "mips-sgi-*"
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 #
161 #setup_xfail "mips-*-*"
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
177 gdb_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
195 gdb_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 #
256 #setup_xfail "mips-sgi-*"
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 #
265 #setup_xfail "mips-*-*"
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
349 if {!$gcc_compiled} { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
350 gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
351
352 gdb_test "ptype pv_char_array" "type = (|unsigned )char \\(\\*\\)\\\[0?\\\]"
353
354 #
355 ##
356 ## test ptype command with pointers
357 ##
358 #setup_xfail "mips-sgi-*"
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 #
367 #setup_xfail "mips-*-*"
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 #
475 gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\]+\
476 .*int outer_int;.*\[\r\n\]+\
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"
480
481 gdb_test "ptype struct inner_struct" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype inner structure"
482
483 gdb_test "ptype union inner_union" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype inner union"
484
485 gdb_test "ptype nested_su" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] (struct |)inner_struct inner_struct_instance;.*\[\r\n\] (union |)inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype nested structure"
486
487 gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
488
489 gdb_test "ptype nested_su.inner_struct_instance" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype nested structure #2"
490
491 gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
492
493 gdb_test "ptype nested_su.inner_union_instance" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype nested union"
494
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
499 gdb_test "ptype the_highest" \
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\]}.*"
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
507 gdb_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\]}.*" \
509 "ptype the_highest.anonymous_level_1"
510
511 get_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.
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.
523 # - Otherwise, it's a failure.
524 proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" } } {
525 global gdb_prompt
526 global gcc_compiled
527
528 # Turn the arguments, which are literal strings, into
529 # regular expressions by quoting any special characters they contain.
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 }
537
538 gdb_test_multiple "ptype $id" "ptype $id" {
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 }
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 }
552 }
553 }
554
555 ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
556 "int (*)()"
557 ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()" \
558 "double (*)(void)"
559 ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
560 ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
561 ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
562 "int *(*)()"
563 ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
564 "int (*)()" \
565 "int (*)(int (*)(void), int (*)(void), int)"
566 ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
567 "int (*(*)())()"
568 ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
569 "int (*(*(*)())())()"
570
571 # Test printing type of typedefs in different scopes, with same name
572 # but different type.
573
574 gdb_test "list intfoo" ".*"
575 gdb_test "ptype foo" "type = int" "ptype foo typedef after first list of intfoo"
576 gdb_test "list charfoo" ".*"
577 gdb_test "ptype foo" "type = char" "ptype foo typedef after first list of charfoo"
578 gdb_test "list intfoo" ".*" "second list intfoo"
579 gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
580 gdb_test "list charfoo" ".*" "second list charfoo"
581 gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
582
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
587 if {[runto_main]} {
588
589 if [target_info exists gdb,cannot_call_functions] {
590 unsupported "this target can not call functions"
591 return
592 }
593
594 # We need to up this because this can be really slow on some boards.
595 # (malloc() is called as part of the test).
596 set prev_timeout $timeout
597 set timeout 60
598
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"
606 gdb_test "ptype *&{4,5,6}\[1\]" "Attempt to take address of value not located in memory."
607
608 set timeout $prev_timeout
609
610 # Test ptype of user register
611 gdb_test "ptype \$pc" "void \\(\\*\\)\\(\\)"
612 }