summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.base/ptype.exp
blob: 6e33d8548051cd1f0e83d129160b23dada517cbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1999,
# 2000, 2002 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  

# Please email any bugs, comments, and/or additions to this file to:
# bug-gdb@prep.ai.mit.edu

# This file was written by Rob Savoye. (rob@cygnus.com)

if $tracelevel then {
	strace $tracelevel
	}

#
# test running programs
#
set prms_id 0
set bug_id 0

set testfile "ptype"
set srcfile ${testfile}.c
set binfile ${objdir}/${subdir}/${testfile}
if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
     gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
}

# Create and source the file that provides information about the compiler
# used to compile the test case.
if [get_compiler_info ${binfile}] {
    return -1;
}

gdb_exit
gdb_start
gdb_reinitialize_dir $srcdir/$subdir
gdb_load ${binfile}

# Test ptype of unnamed enumeration members before any action causes
# the partial symbol table to be expanded to full symbols.  This fails
# with stabs compilers which fail to use a nameless stab (such as
# pre-2.4.5 versions of gcc and most non-gcc compilers).

send_gdb "ptype red1\n"
gdb_expect {
    -re "type = enum primary1_tag \{red1, green1, blue1\}.*$gdb_prompt $"\
	{
	    # The workaround is in effect.  As this is a compiler, not GDB,
	    # bug, we'll make it a PASS but perhaps it should be an XFAIL.
	    pass "ptype unnamed enumeration member (worked around)"
	}
    -re "type = enum \{red1, green1, blue1\}.*$gdb_prompt $"\
			{ pass "ptype unnamed enumeration member" }
    -re ".*$gdb_prompt $"	{ fail "ptype unnamed enumeration member" }
    timeout		{ fail "(timeout) ptype unnamed enumeration member" }
}

#
# test ptype command with structures
#
# Here and elsewhere, we accept
# "long", "long int", or "int" for long variables (whatis.exp already
# has an XFAIL for "int" (Sun cc bug), so no need to fail it here).
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" 


# Test the equivalence between '.' and '->' for struct member references.

if [gdb_test "ptype v_struct1.v_float_member"	"type = float"]<0 then {
    return -1
}
if [gdb_test "ptype v_struct1->v_float_member"	"type = float"]<0 then {
    return -1
}
if [gdb_test "ptype v_t_struct_p.v_float_member"	"type = float"]<0 then {
    return -1
}
if [gdb_test "ptype v_t_struct_p->v_float_member"	"type = float"]<0 then {
    return -1
}


# IBM's xlc puts out bogus stabs--the stuff field is type 42,
# which isn't defined.

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" 

#
# test ptype command with unions
#
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" 

# IBM's xlc puts out bogus stabs--the stuff field is type 42,
# which isn't defined.
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" 

#
# test ptype command with enums
#

gdb_test "ptype primary" "type = enum .red, green, blue.*" "ptype unnamed enumeration" 

gdb_test "ptype enum colors" "type = enum colors \{yellow, purple, pink\}.*" "ptype named enumeration" 


#
# test ptype command with enums as typedef
#
gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration" 

# And check that whatis shows the name, not "enum {...}".
# This probably fails for all DWARF 1 cases, so assume so for now. -fnf
# The problem with xlc is that the stabs look like
#   :t51=eFALSE:0,TRUE:1,;
#   boolean:t55=51
#   v_boolean:G51
# GDB's behavior is correct; the type which the variable is defined
# as (51) doesn't have a name.  Only 55 has a name.

if {!$gcc_compiled && !$hp_aCC_compiler} {
    setup_xfail "rs6000-*-*" "i*86-*-sysv4*"
    setup_xfail "hppa*-*-*" CLLbs14773
}

# For get_debug_format to do its job, we need to have a current source file.
gdb_test "list main" ""
get_debug_format
setup_xfail_format "DWARF 1"
gdb_test "whatis v_boolean" "type = (enum |)boolean" \
  "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)"

# Same thing with struct and union.
gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
 *double v_double_member;.*
 *int v_int_member;.*\}" "printing typedef'd struct"

gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
 *double v_double_member;.*
 *int v_int_member;.*\}" "printing typedef'd union"

gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"

#
# test ptype command with out-of-order enum values
#
gdb_test "ptype enum misordered" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype misordered enumeration" 

#
# test ptype command with a named enum's value
#
gdb_test "ptype three" "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*" "ptype named enumeration member" 

gdb_test "ptype red" "type = enum \{red, green, blue\}.*" "ptype unnamed enumeration member #2" 

#
# test ptype command with basic C types
#
# I've commented most of this out because it duplicates tests in whatis.exp.
# I've just left in a token test or 2 which is designed to test that ptype 
# acts like whatis for basic types.  If it is thought to be necessary to
# test both whatis and ptype for all the types, the tests should be
# merged into whatis.exp, or else maintenance will be a royal pain -kingdon
#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char\n"
#gdb_expect {
#    -re "type = char.*$gdb_prompt $"	{ pass "ptype char" }
#    -re ".*$gdb_prompt $"	{ fail "ptype char" }
#    timeout		{ fail "(timeout) ptype char" }
#}
#
#
#setup_xfail "mips-*-*"
#send "ptype v_signed_char\n"
#gdb_expect {
#    -re "type = signed char.*$gdb_prompt $"	{ pass "ptype signed char" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed char" }
#    timeout		{ fail "(timeout) ptype signed char" }
#}
#
#
#send "ptype v_unsigned_char\n"
#gdb_expect {
#    -re "type = unsigned char.*$gdb_prompt $"	{ pass "ptype unsigned char" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned char" }
#    timeout		{ fail "(timeout) ptype unsigned char" }
#}

gdb_test "ptype v_short" "type = short(| int).*" "ptype short" 

#send "ptype v_signed_short\n"
#gdb_expect {
#    -re "type = short.*$gdb_prompt $"	{ pass "ptype signed short" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed short" }
#    timeout		{ fail "(timeout) ptype signed short" }
#}
#
#
#send "ptype v_unsigned_short\n"
#gdb_expect {
#    -re "type = unsigned short.*$gdb_prompt $"	{ pass "ptype unsigned short" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned short" }
#    timeout		{ fail "(timeout) ptype unsigned short" }
#}


gdb_test "ptype v_int" "type = int.*" "ptype int" 

#send "ptype v_signed_int\n"
#gdb_expect {
#    -re "type = int.*$gdb_prompt $"	{ pass "ptype signed int" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed int" }
#    timeout		{ fail "(timeout) ptype signed int" }
#}
#
#
#send "ptype v_unsigned_int\n"
#gdb_expect {
#    -re "type = unsigned int.*$gdb_prompt $"	{ pass "ptype unsigned int" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned int" }
#    timeout		{ fail "(timeout) ptype unsigned int" }
#}
#
#
#send "ptype v_long\n"
#gdb_expect {
#    -re "type = long.*$gdb_prompt $"	{ pass "ptype long" }
#    -re ".*$gdb_prompt $"	{ fail "ptype long" }
#    timeout		{ fail "(timeout) ptype long" }
#}
#
#
#send "ptype v_signed_long\n"
#gdb_expect {
#    -re "type = long.*$gdb_prompt $"	{ pass "ptype signed long" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed long" }
#    timeout		{ fail "(timeout) ptype signed long" }
#}
#
#
#send "ptype v_unsigned_long\n"
#gdb_expect {
#    -re "type = unsigned long.*$gdb_prompt $"	{ pass "ptype unsigned long" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned long" }
#    timeout		{ fail "(timeout) ptype unsigned long" }
#}
#
#
#send "ptype v_float\n"
#gdb_expect {
#    -re "type = float.*$gdb_prompt $"	{ pass "ptype float" }
#    -re ".*$gdb_prompt $"	{ fail "ptype float" }
#    timeout		{ fail "(timeout) ptype float" }
#}
#
#
#send "ptype v_double\n"
#gdb_expect {
#    -re "type = double.*$gdb_prompt $"	{ pass "ptype double" }
#    -re ".*$gdb_prompt $"	{ fail "ptype double" }
#    timeout		{ fail "(timeout) ptype double" }
#}


#
# test ptype command with arrays
#
#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char_array\n"
#gdb_expect {
#    -re "type = char .2..*$gdb_prompt $"	{ pass "ptype char array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype char array" }
#    timeout		{ fail "(timeout) ptype char array" }
#}
#
#
#setup_xfail "mips-*-*"
#send "ptype v_signed_char_array\n"
#gdb_expect {
#    -re "type = (|signed )char .2..*$gdb_prompt $"	{ pass "ptype signed char array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed char array" }
#    timeout		{ fail "(timeout) ptype signed char array" }
#}
#
#
#send "ptype v_unsigned_char_array\n"
#gdb_expect {
#    -re "type = unsigned char .2..*$gdb_prompt $"	{ pass "ptype unsigned char array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned char array" }
#    timeout		{ fail "(timeout) ptype unsigned char array" }
#}
#
#
#
#send "ptype v_int_array\n"
#gdb_expect {
#    -re "type = int .2..*$gdb_prompt $"	{ pass "ptype int array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype int array" }
#    timeout		{ fail "(timeout) ptype int array" }
#}
#
#
#send "ptype v_signed_int_array\n"
#gdb_expect {
#    -re "type = int .2..*$gdb_prompt $"	{ pass "ptype signed int array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed int array" }
#    timeout		{ fail "(timeout) ptype signed int array" }
#}
#
#
#send "ptype v_unsigned_int_array\n"
#gdb_expect {
#    -re "type = unsigned int .2..*$gdb_prompt $"	{ pass "ptype unsigned int array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned int array" }
#    timeout		{ fail "(timeout) ptype unsigned int array" }
#}
#
#
#send "ptype v_long_array\n"
#gdb_expect {
#    -re "type = (long|int|long int) .2..*$gdb_prompt $"	{ 
#	pass "ptype long array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype long array" }
#    timeout		{ fail "(timeout) ptype long array" }
#}
#
#
#send "ptype v_signed_long_array\n"
#gdb_expect {
#    -re "type = (long|int|long int) .2..*$gdb_prompt $"	{ 
#	pass "ptype signed long array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed long array" }
#    timeout		{ fail "(timeout) ptype signed long array" }
#}
#
#
#send "ptype v_unsigned_long_array\n"
#gdb_expect {
#    -re "type = unsigned long .2..*$gdb_prompt $"	{ pass "ptype unsigned long array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned long array" }
#    timeout		{ fail "(timeout) ptype unsigned long array" }
#}
#
#
#send "ptype v_float_array\n"
#gdb_expect {
#    -re "type = float .2..*$gdb_prompt $"	{ pass "ptype float array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype float array" }
#    timeout		{ fail "(timeout) ptype float array" }
#}
#
#
#send "ptype v_double_array\n"
#gdb_expect {
#    -re "type = double .2..*$gdb_prompt $"	{ pass "ptype double array" }
#    -re ".*$gdb_prompt $"	{ fail "ptype double array" }
#    timeout		{ fail "(timeout) ptype double array" }
#}
#

if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
setup_xfail_format "DWARF 1"
if {$hp_aCC_compiler} {setup_xfail "hppa*-*-*"}
gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"

#
##
## test ptype command with pointers
##
#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char_pointer\n"
#gdb_expect {
#    -re "type = char \*.*$gdb_prompt $"	{ pass "ptype char pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype char pointer" }
#    timeout		{ fail "(timeout) ptype char pointer" }
#}
#
#
#setup_xfail "mips-*-*"
#send "ptype v_signed_char_pointer\n"
#gdb_expect {
#    -re "type = (|signed )char \*.*$gdb_prompt $"
#	{ pass "ptype signed char pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed char pointer" }
#    timeout		{ fail "(timeout) ptype signed char pointer" }
#}
#
#
#send "ptype v_unsigned_char_pointer\n"
#gdb_expect {
#    -re "type = unsigned char \*.*$gdb_prompt $"	{ pass "ptype unsigned char pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned char pointer" }
#    timeout		{ fail "(timeout) ptype unsigned char pointer" }
#}
#
#
#send "ptype v_short_pointer\n"
#gdb_expect {
#    -re "type = (short|short int) \*.*$gdb_prompt $"	{ pass "ptype short pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype short pointer" }
#    timeout		{ fail "(timeout) ptype short pointer" }
#}
#
#
#send "ptype v_signed_short_pointer\n"
#gdb_expect {
#    -re "type = short \*.*$gdb_prompt $"	{ pass "ptype signed short pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed short pointer" }
#    timeout		{ fail "(timeout) ptype signed short pointer" }
#}
#
#
#send "ptype v_unsigned_short_pointer\n"
#gdb_expect {
#    -re "type = unsigned short \*.*$gdb_prompt $"	{ pass "ptype unsigned short pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned short pointer" }
#    timeout		{ fail "(timeout) ptype unsigned short pointer" }
#}
#
#
#send "ptype v_int_pointer\n"
#gdb_expect {
#    -re "type = int \*.*$gdb_prompt $"	{ pass "ptype int pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype int pointer" }
#    timeout		{ fail "(timeout) ptype int pointer" }
#}
#
#
#send "ptype v_signed_int_pointer\n"
#gdb_expect {
#    -re "type = int \*.*$gdb_prompt $"	{ pass "ptype signed int pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed int pointer" }
#    timeout		{ fail "(timeout) ptype signed int pointer" }
#}
#
#
#send "ptype v_unsigned_int_pointer\n"
#gdb_expect {
#    -re "type = unsigned int \*.*$gdb_prompt $"	{ pass "ptype unsigned int pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned int pointer" }
#    timeout		{ fail "(timeout) ptype unsigned int pointer" }
#}
#
#
#send "ptype v_long_pointer\n"
#gdb_expect {
#    -re "type = long \*.*$gdb_prompt $"	{ pass "ptype long pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype long pointer" }
#    timeout		{ fail "(timeout) ptype long pointer" }
#}
#
#
#send "ptype v_signed_long_pointer\n"
#gdb_expect {
#    -re "type = long \*.*$gdb_prompt $"	{ pass "ptype signed long pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype signed long pointer" }
#    timeout		{ fail "(timeout) ptype signed long pointer" }
#}
#
#
#send "ptype v_unsigned_long_pointer\n"
#gdb_expect {
#    -re "type = unsigned long \*.*$gdb_prompt $"	{ pass "ptype unsigned long pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype unsigned long pointer" }
#    timeout		{ fail "(timeout) ptype unsigned long pointer" }
#}
#
#
#send "ptype v_float_pointer\n"
#gdb_expect {
#    -re "type = float \*.*$gdb_prompt $"	{ pass "ptype float pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype float pointer" }
#    timeout		{ fail "(timeout) ptype float pointer" }
#}
#
#
#send "ptype v_double_pointer\n"
#gdb_expect {
#    -re "type = double \*.*$gdb_prompt $"	{ pass "ptype double pointer" }
#    -re ".*$gdb_prompt $"	{ fail "ptype double pointer" }
#    timeout		{ fail "(timeout) ptype double pointer" }
#}

#
# test ptype command with nested structure and union
#
if {$hp_aCC_compiler} {
    set outer "outer_struct::"
    set struct ""
    set union ""
} else {
    set outer ""
    set struct "struct"
    set union "union"
}
gdb_test "ptype struct outer_struct" "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 outer structure" 

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" 

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" 

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" 

gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int" 

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" 

gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int" 

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" 


get_debug_format

# Print the type of the identifier ID, and check the response:
# - Expect to see PROTOTYPED as the type.  PROTOTYPED is not a regular
#   expression; it's a literal string.
# - If we instead see the unprototyped type PLAIN, and we're using STABS
#   generated by GCC, that's an xfail; as of 9 Feb 2002, GCC never emits
#   prototyped function types in STABS.  Like PROTOTYPED, PLAIN is a
#   literal string, not a regular expression.
# - Otherwise, it's a failure.
proc ptype_maybe_prototyped { id prototyped plain } {
    global gdb_prompt
    global gcc_compiled

    # Turn `prototyped' and `plain', which are literal strings, into
    # regular expressions by quoting any special characters they contain.
    regsub -all "\[\]\[*()\]" $prototyped "\\\\&" prototyped
    regsub -all "\[\]\[*()\]" $plain "\\\\&" plain

    send_gdb "ptype $id\n"
    gdb_expect {
        -re "type = $prototyped\[\r\n\]+$gdb_prompt $" {
            pass "ptype $id"
        }
        -re "type = $plain\[\r\n\]+$gdb_prompt $" {
            if {$gcc_compiled} { setup_xfail_format "stabs" }
            fail "ptype $id (compiler doesn't emit prototyped types)"
        }
        -re "$gdb_prompt $" {
            fail "ptype $id"
        }
        timeout {
            fail "ptype $id (timeout)"
        }
    }
}

ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
                                   "int (*)()"
ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()"
ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
                               "int *(*)()"
ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
                              "int (*)()"
ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
                               "int (*(*)())()"
ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
                                "int (*(*(*)())())()"

# Test printing type of string constants and array constants, but
# requires a running process.  These call malloc, and can take a long
# time to execute over a slow serial link, so increase the timeout.

# UDI can't do this (PR 2416).  XFAIL is not suitable, because attempting
# the operation causes a slow painful death rather than a nice simple failure.

if [runto_main] then {

  if [target_info exists gdb,cannot_call_functions] {
    setup_xfail "*-*-*" 2416
    fail "This target can not call functions"
    continue
  }

  # We need to up this because this can be really slow on some boards.
  # (malloc() is called as part of the test).
  set timeout 60;

  gdb_test "ptype \"abc\""	"type = char \\\[4\\\]"
  gdb_test "ptype {'a','b','c'}"	"type = char \\\[3\\\]"
  gdb_test "ptype {0,1,2}"		"type = int \\\[3\\\]"
  gdb_test "ptype {(long)0,(long)1,(long)2}"	  "type = long \\\[3\\\]"
  gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
  gdb_test "ptype {{0,1,2},{3,4,5}}"	"type = int \\\[2\\\]\\\[3\\\]"
  gdb_test "ptype {4,5,6}\[2\]"	"type = int"
  gdb_test "ptype *&{4,5,6}\[1\]"	"type = int"
}