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