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