http://sourceware.org/ml/gdb-patches/2012-09/msg00013.html
[deliverable/binutils-gdb.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] {
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 gdb_test "ptype pv_char_array" "type = (|unsigned )char \\(\\*\\)\\\[0?\\\]"
374
375 #
376 ##
377 ## test ptype command with pointers
378 ##
379 #setup_xfail "mips-sgi-*"
380 #send "ptype v_char_pointer\n"
381 #gdb_expect {
382 # -re "type = char \*.*$gdb_prompt $" { pass "ptype char pointer" }
383 # -re ".*$gdb_prompt $" { fail "ptype char pointer" }
384 # timeout { fail "(timeout) ptype char pointer" }
385 #}
386 #
387 #
388 #setup_xfail "mips-*-*"
389 #send "ptype v_signed_char_pointer\n"
390 #gdb_expect {
391 # -re "type = (|signed )char \*.*$gdb_prompt $"
392 # { pass "ptype signed char pointer" }
393 # -re ".*$gdb_prompt $" { fail "ptype signed char pointer" }
394 # timeout { fail "(timeout) ptype signed char pointer" }
395 #}
396 #
397 #
398 #send "ptype v_unsigned_char_pointer\n"
399 #gdb_expect {
400 # -re "type = unsigned char \*.*$gdb_prompt $" { pass "ptype unsigned char pointer" }
401 # -re ".*$gdb_prompt $" { fail "ptype unsigned char pointer" }
402 # timeout { fail "(timeout) ptype unsigned char pointer" }
403 #}
404 #
405 #
406 #send "ptype v_short_pointer\n"
407 #gdb_expect {
408 # -re "type = (short|short int) \*.*$gdb_prompt $" { pass "ptype short pointer" }
409 # -re ".*$gdb_prompt $" { fail "ptype short pointer" }
410 # timeout { fail "(timeout) ptype short pointer" }
411 #}
412 #
413 #
414 #send "ptype v_signed_short_pointer\n"
415 #gdb_expect {
416 # -re "type = short \*.*$gdb_prompt $" { pass "ptype signed short pointer" }
417 # -re ".*$gdb_prompt $" { fail "ptype signed short pointer" }
418 # timeout { fail "(timeout) ptype signed short pointer" }
419 #}
420 #
421 #
422 #send "ptype v_unsigned_short_pointer\n"
423 #gdb_expect {
424 # -re "type = unsigned short \*.*$gdb_prompt $" { pass "ptype unsigned short pointer" }
425 # -re ".*$gdb_prompt $" { fail "ptype unsigned short pointer" }
426 # timeout { fail "(timeout) ptype unsigned short pointer" }
427 #}
428 #
429 #
430 #send "ptype v_int_pointer\n"
431 #gdb_expect {
432 # -re "type = int \*.*$gdb_prompt $" { pass "ptype int pointer" }
433 # -re ".*$gdb_prompt $" { fail "ptype int pointer" }
434 # timeout { fail "(timeout) ptype int pointer" }
435 #}
436 #
437 #
438 #send "ptype v_signed_int_pointer\n"
439 #gdb_expect {
440 # -re "type = int \*.*$gdb_prompt $" { pass "ptype signed int pointer" }
441 # -re ".*$gdb_prompt $" { fail "ptype signed int pointer" }
442 # timeout { fail "(timeout) ptype signed int pointer" }
443 #}
444 #
445 #
446 #send "ptype v_unsigned_int_pointer\n"
447 #gdb_expect {
448 # -re "type = unsigned int \*.*$gdb_prompt $" { pass "ptype unsigned int pointer" }
449 # -re ".*$gdb_prompt $" { fail "ptype unsigned int pointer" }
450 # timeout { fail "(timeout) ptype unsigned int pointer" }
451 #}
452 #
453 #
454 #send "ptype v_long_pointer\n"
455 #gdb_expect {
456 # -re "type = long \*.*$gdb_prompt $" { pass "ptype long pointer" }
457 # -re ".*$gdb_prompt $" { fail "ptype long pointer" }
458 # timeout { fail "(timeout) ptype long pointer" }
459 #}
460 #
461 #
462 #send "ptype v_signed_long_pointer\n"
463 #gdb_expect {
464 # -re "type = long \*.*$gdb_prompt $" { pass "ptype signed long pointer" }
465 # -re ".*$gdb_prompt $" { fail "ptype signed long pointer" }
466 # timeout { fail "(timeout) ptype signed long pointer" }
467 #}
468 #
469 #
470 #send "ptype v_unsigned_long_pointer\n"
471 #gdb_expect {
472 # -re "type = unsigned long \*.*$gdb_prompt $" { pass "ptype unsigned long pointer" }
473 # -re ".*$gdb_prompt $" { fail "ptype unsigned long pointer" }
474 # timeout { fail "(timeout) ptype unsigned long pointer" }
475 #}
476 #
477 #
478 #send "ptype v_float_pointer\n"
479 #gdb_expect {
480 # -re "type = float \*.*$gdb_prompt $" { pass "ptype float pointer" }
481 # -re ".*$gdb_prompt $" { fail "ptype float pointer" }
482 # timeout { fail "(timeout) ptype float pointer" }
483 #}
484 #
485 #
486 #send "ptype v_double_pointer\n"
487 #gdb_expect {
488 # -re "type = double \*.*$gdb_prompt $" { pass "ptype double pointer" }
489 # -re ".*$gdb_prompt $" { fail "ptype double pointer" }
490 # timeout { fail "(timeout) ptype double pointer" }
491 #}
492
493 #
494 # test ptype command with nested structure and union
495 #
496 if {$hp_aCC_compiler} {
497 set outer "outer_struct::"
498 set struct ""
499 set union ""
500 } else {
501 set outer ""
502 set struct "struct"
503 set union "union"
504 }
505 gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\]+\
506 .*int outer_int;.*\[\r\n\]+\
507 .*(struct|) ${outer}inner_struct inner_struct_instance;.*\[\r\n\]+\
508 .*(union|) ${outer}inner_union inner_union_instance;.*\[\r\n\]+\
509 .*(long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype outer structure"
510
511 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"
512
513 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"
514
515 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"
516
517 gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
518
519 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"
520
521 gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
522
523 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"
524
525 # Print the type description of variable the_highest, and verify that
526 # the type description for the fields whose type is anonymous are
527 # correctly printed (at nesting level 1 and 2).
528
529 gdb_test "ptype the_highest" \
530 "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\]}.*" \
531 "ptype the_highest"
532
533 # Print the type descrption for one of the fields of variable the_highest.
534 # The purpose is to verify that the type of a field that was printed above
535 # as "struct {...}" is now printed in a more descriptive way (because the
536 # nesting level is now one level less).
537
538 gdb_test "ptype the_highest.anonymous_level_1" \
539 "type = struct \{.*\[\r\n\] *int b;.*\[\r\n\] *struct \{.*\[\r\n\] *int c;.*\[\r\n\] *\} anonymous_level_2;.*\[\r\n\]}.*" \
540 "ptype the_highest"
541
542 get_debug_format
543
544 # Print the type of the identifier ID, and check the response:
545 # - Expect to see PROTOTYPED as the type. PROTOTYPED is not a regular
546 # expression; it's a literal string.
547 # - If we instead see the unprototyped type PLAIN, and we're using STABS
548 # generated by GCC, that's an xfail; as of 9 Feb 2002, GCC never emits
549 # prototyped function types in STABS. Like PROTOTYPED, PLAIN is a
550 # literal string, not a regular expression.
551 # - If we see OVERPROTOTYPED, it's an xfail for RealView; RealView
552 # does not distinguish prototyped and unprototyped functions, and
553 # GDB defaults to prototyped.
554 # - Otherwise, it's a failure.
555 proc ptype_maybe_prototyped { id prototyped plain { overprototyped "NO-MATCH" } } {
556 global gdb_prompt
557 global gcc_compiled
558
559 # Turn the arguments, which are literal strings, into
560 # regular expressions by quoting any special characters they contain.
561 foreach var { prototyped plain overprototyped } {
562 eval "set val \$$var"
563 regsub -all "\[\]\[*()\]" $val "\\\\&" val
564 regsub -all "short int" $val "short( int)?" val
565 regsub -all "long int" $val "long( int)?" val
566 eval "set $var \$val"
567 }
568
569 gdb_test_multiple "ptype $id" "ptype $id" {
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 "type = $overprototyped\[\r\n\]+$gdb_prompt $" {
578 if { [test_compiler_info "armcc-*"] } {
579 setup_xfail "*-*-*"
580 }
581 fail "ptype $id (compiler doesn't emit unprototyped types)"
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 "double (*)(void)"
590 ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
591 ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
592 ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
593 "int *(*)()"
594 ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
595 "int (*)()" \
596 "int (*)(int (*)(void), int (*)(void), int)"
597 ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
598 "int (*(*)())()"
599 ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
600 "int (*(*(*)())())()"
601
602 # Test printing type of typedefs in different scopes, with same name
603 # but different type.
604
605 gdb_test "list intfoo" ".*"
606 gdb_test "ptype foo" "type = int" "ptype foo typedef after first list of intfoo"
607 gdb_test "list charfoo" ".*"
608 gdb_test "ptype foo" "type = char" "ptype foo typedef after first list of charfoo"
609 gdb_test "list intfoo" ".*"
610 gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
611 gdb_test "list charfoo" ".*"
612 gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
613
614 # Test printing type of string constants and array constants, but
615 # requires a running process. These call malloc, and can take a long
616 # time to execute over a slow serial link, so increase the timeout.
617
618 # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting
619 # the operation causes a slow painful death rather than a nice simple failure.
620
621 if [runto_main] then {
622
623 if [target_info exists gdb,cannot_call_functions] {
624 setup_xfail "*-*-*" 2416
625 fail "This target can not call functions"
626 continue
627 }
628
629 # We need to up this because this can be really slow on some boards.
630 # (malloc() is called as part of the test).
631 set prev_timeout $timeout
632 set timeout 60
633
634 gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
635 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
636 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"
637 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]"
638 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]"
639 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]"
640 gdb_test "ptype {4,5,6}\[2\]" "type = int"
641 gdb_test "ptype *&{4,5,6}\[1\]" "Attempt to take address of value not located in memory."
642
643 set timeout $prev_timeout
644
645 # Test ptype of user register
646 gdb_test "ptype \$pc" "void \\(\\*\\)\\(\\)" "ptype \$pc"
647 }
This page took 0.044543 seconds and 5 git commands to generate.