Support R_SPARC_WDISP10 and R_SPARC_H34.
[external/binutils.git] / gdb / testsuite / gdb.base / ptype.exp
1 # Copyright 1988, 1990-1992, 1994-1997, 1999-2000, 2002-2003, 2007-2012
2 # 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 3 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, see <http://www.gnu.org/licenses/>.
16
17 # This file was written by Rob Savoye. (rob@cygnus.com)
18
19 #
20 # test running programs
21 #
22
23 set testfile "ptype"
24 set srcfile0 ${testfile}.c
25 set srcfile1 ${testfile}1.c
26 set binfile ${objdir}/${subdir}/${testfile}
27
28 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile0}" "${binfile}0.o" object {debug}] != "" } {
29      untested ptype.exp
30      return -1
31 }
32 if  { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug}] != "" } {
33      untested ptype.exp
34      return -1
35 }
36 if  { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug}] != "" } {
37      untested ptype.exp
38      return -1
39 }
40
41 # Create and source the file that provides information about the compiler
42 # used to compile the test case.
43 if [get_compiler_info ${binfile}] {
44     return -1;
45 }
46
47 gdb_exit
48 gdb_start
49 gdb_reinitialize_dir $srcdir/$subdir
50 gdb_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
57 gdb_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     }
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).
74 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" 
75
76
77 # Test the equivalence between '.' and '->' for struct member references.
78
79 if [gdb_test "ptype v_struct1.v_float_member"   "type = float"]<0 then {
80     return -1
81 }
82 if [gdb_test "ptype v_struct1->v_float_member"  "type = float"]<0 then {
83     return -1
84 }
85 if [gdb_test "ptype v_t_struct_p.v_float_member"        "type = float"]<0 then {
86     return -1
87 }
88 if [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
96 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" 
97
98 #
99 # test ptype command with unions
100 #
101 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" 
102
103 # IBM's xlc puts out bogus stabs--the stuff field is type 42,
104 # which isn't defined.
105 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" 
106
107 #
108 # test ptype command with enums
109 #
110
111 gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration" 
112
113 gdb_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 #
119 gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration" 
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
130 if {!$gcc_compiled && !$hp_aCC_compiler} {
131     setup_xfail "rs6000-*-*" "i*86-*-sysv4*"
132     setup_xfail "hppa*-*-*" CLLbs14773
133 }
134
135 # For get_debug_format to do its job, we need to have a current source file.
136 gdb_test "list main" ".*"
137 get_debug_format
138 gdb_test "whatis v_boolean" "type = (enum |)boolean" \
139   "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"
140
141 # Same thing with struct and union.
142 gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
143  *double v_double_member;.*
144  *int v_int_member;.*\}" "printing typedef'd struct"
145
146 gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
147  *double v_double_member;.*
148  *int v_int_member;.*\}" "printing typedef'd union"
149
150 gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"
151
152 #
153 # test ptype command with out-of-order enum values
154 #
155 gdb_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 #
160 gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member" 
161
162 gdb_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
172 #setup_xfail "mips-sgi-*"
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 #
181 #setup_xfail "mips-*-*"
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
197 gdb_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
215 gdb_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 #
276 #setup_xfail "mips-sgi-*"
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 #
285 #setup_xfail "mips-*-*"
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
369 if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
370 if {$hp_aCC_compiler} {setup_xfail "hppa*-*-*"}
371 gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
372
373 #
374 ##
375 ## test ptype command with pointers
376 ##
377 #setup_xfail "mips-sgi-*"
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 #
386 #setup_xfail "mips-*-*"
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 #
494 if {$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 }
503 gdb_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" 
508
509 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" 
510
511 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" 
512
513 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" 
514
515 gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int" 
516
517 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" 
518
519 gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int" 
520
521 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" 
522
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
527 gdb_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
536 gdb_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" 
539
540 get_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.
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.
552 # - Otherwise, it's a failure.
553 proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" } } {
554     global gdb_prompt
555     global gcc_compiled
556
557     # Turn the arguments, which are literal strings, into
558     # regular expressions by quoting any special characters they contain.
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     }
566
567     gdb_test_multiple "ptype $id" "ptype $id" {
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         }
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         }
581     }
582 }
583
584 ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
585                                    "int (*)()"
586 ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()" \
587                                   "double (*)(void)"
588 ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
589 ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
590 ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
591                                "int *(*)()"
592 ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
593                               "int (*)()" \
594                               "int (*)(int (*)(void), int (*)(void), int)"
595 ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
596                                "int (*(*)())()"
597 ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
598                                 "int (*(*(*)())())()"
599
600 # Test printing type of typedefs in different scopes, with same name
601 # but different type.
602
603 gdb_test "list intfoo" ".*"
604 gdb_test "ptype foo" "type = int" "ptype foo typedef after first list of intfoo"
605 gdb_test "list charfoo" ".*"
606 gdb_test "ptype foo" "type = char" "ptype foo typedef after first list of charfoo"
607 gdb_test "list intfoo" ".*"
608 gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
609 gdb_test "list charfoo" ".*"
610 gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
611
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
619 if [runto_main] then {
620
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
627   # We need to up this because this can be really slow on some boards.
628   # (malloc() is called as part of the test).
629   set prev_timeout $timeout
630   set timeout 60
631
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"
639   gdb_test "ptype *&{4,5,6}\[1\]"       "Attempt to take address of value not located in memory."
640
641   set timeout $prev_timeout
642
643   # Test ptype of user register
644   gdb_test "ptype \$pc" "void \\(\\*\\)\\(\\)" "ptype \$pc"
645 }