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