OSDN Git Service

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