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