# Copyright (C) 1988, 1990, 1991, 1992 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ # Please email any bugs, comments, and/or additions to this file to: # bug-gdb@prep.ai.mit.edu # This file was written by Rob Savoye. (rob@cygnus.com) if $tracelevel then { strace $tracelevel } # # test running programs # set prms_id 0 set bug_id 0 set binfile "ptype" if ![file exists $objdir/$subdir/$binfile] then { perror "$objdir/$subdir/$binfile does not exist." return 0 } gdb_exit gdb_start gdb_reinitialize_dir $srcdir/$subdir gdb_load $objdir/$subdir/$binfile # Test ptype of unnamed enumeration members before any action causes # the partial symbol table to be expanded to full symbols. This fails # with stabs compilers which fail to use a nameless stab (such as # pre-2.4.5 versions of gcc and most non-gcc compilers). send "ptype red1\n" expect { -re "type = enum primary1_tag \{red1, green1, blue1\}.*$prompt $"\ { # The workaround is in effect. As this is a compiler, not GDB, # bug, we'll make it a PASS but perhaps it should be an XFAIL. pass "ptype unnamed enumeration member (worked around)" } -re "type = enum \{red1, green1, blue1\}.*$prompt $"\ { pass "ptype unnamed enumeration member" } -re ".*$prompt $" { fail "ptype unnamed enumeration member" } timeout { fail "(timeout) ptype unnamed enumeration member" } } # # test ptype command with structures # # Here and elsewhere, we accept # "long", "long int", or "int" for long variables (whatis.exp already # has an XFAIL for "int" (Sun cc bug), so no need to fail it here). send "ptype struct t_struct\n" expect { -re "type = struct t_struct \{.* (unsigned |)char v_char_member;.* (short|short int) v_short_member;.* int v_int_member;.* (long|long int|int) v_long_member;.* float v_float_member;.* double v_double_member;.* \}.*$prompt $" { pass "ptype structure" } -re ".*$prompt $" { fail "ptype structure" } timeout { fail "(timeout) ptype structure" } } # Test the equivalence between '.' and '->' for struct member references. if [gdb_test "ptype v_struct1.v_float_member" "type = float"]<0 then { gdb_exit gdb_start return -1 } if [gdb_test "ptype v_struct1->v_float_member" "type = float"]<0 then { gdb_exit gdb_start return -1 } if [gdb_test "ptype v_t_struct_p.v_float_member" "type = float"]<0 then { gdb_exit gdb_start return -1 } if [gdb_test "ptype v_t_struct_p->v_float_member" "type = float"]<0 then { gdb_exit gdb_start return -1 } send "ptype struct link\n" expect { -re "type = struct link \{.* struct link \[*\]next;.* struct link \[*(\]+linkfunc\[)(\]+;.* struct t_struct stuff.1..2..3.;.* \}.*$prompt $" { pass "ptype linked list structure" } -re ".*$prompt $" { # IBM's xlc puts out bogus stabs--the stuff field is type 42, # which isn't defined. fail "ptype linked list structure (compiler bug in IBM's xlc)" } timeout { fail "(timeout) ptype linked list structure" } } # # test ptype command with unions # send "ptype union t_union\n" expect { -re "type = union t_union \{.* (unsigned |)char v_char_member;.* (short|short int) v_short_member;.* int v_int_member;.* (long|long int|int) v_long_member;.* float v_float_member;.* double v_double_member;.* \}.*$prompt $" { pass "ptype union" } -re ".*$prompt $" { fail "ptype union" } timeout { fail "(timeout) ptype union" } } send "ptype union tu_link\n" expect { -re "type = union tu_link .* struct link \[*\]next;.* struct link \[(\*\]+linkfunc\[)(\]+;.* struct t_struct stuff.1..2..3.;.* \}.*$prompt $" { pass "ptype linked list union" } -re ".*$prompt $" { # IBM's xlc puts out bogus stabs--the stuff field is type 42, # which isn't defined. fail "ptype linked list union (compiler bug in IBM's xlc)" } timeout { fail "(timeout) ptype linked list union" } } # # test ptype command with enums # send "ptype primary\n" expect { -re "type = enum .red, green, blue.*$prompt $" { pass "ptype unnamed enumeration" } -re ".*$prompt $" { fail "ptype unnamed enumeration" } timeout { fail "(timeout) ptype unnamed enumeration" } } send "ptype enum colors\n" expect { -re "type = enum colors \{yellow, purple, pink\}.*$prompt $"\ { pass "ptype named enumeration" } -re ".*$prompt $" { fail "ptype named enumeration" } timeout { fail "(timeout) ptype named enumeration" } } # # test ptype command with enums as typedef # send "ptype boolean\n" expect { -re "type = enum \{FALSE, TRUE\}.*$prompt $" { pass "ptype unnamed typedef'd enumeration" } -re ".*$prompt $" { fail "ptype unnamed typedef'd enumeration" } timeout { fail "(timeout) ptype unnamed typedef'd enumeration" } } # And check that whatis shows the name, not "enum {...}". # The problem with xlc is that the stabs look like # :t51=eFALSE:0,TRUE:1,; # boolean:t55=51 # v_boolean:G51 # GDB's behavior is correct; the type which the variable is defined # as (51) doesn't have a name. Only 55 has a name. gdb_test "whatis v_boolean" "type = boolean" \ "whatis unnamed typedef'd enum (compiler bug in IBM's xlc)" # Same thing with struct and union. gdb_test "ptype t_struct3" "type = struct \{.* *double v_double_member;.* *int v_int_member;.*\}" "printing typedef'd struct" gdb_test "ptype t_union3" "type = union \{.* *double v_double_member;.* *int v_int_member;.*\}" "printing typedef'd union" send "ptype enum bvals\n" expect { -re "type = enum bvals \{false, true\}.*$prompt $" { pass "ptype named typedef'd enumf'd enum" } -re ".*$prompt $" { fail "ptype named typedef'd enumeration" } timeout { fail "(timeout) ptype named typedef'd enumeration" } } # # test ptype command with out-of-order enum values # send "ptype enum misordered\n" expect { -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\ { pass "ptype misordered enumeration" } -re ".*$prompt $" { fail "ptype misordered enumeration" } timeout { fail "(timeout) ptype misordered enumeration" } } # # test ptype command with a named enum's value # send "ptype three\n" expect { -re "type = enum misordered \{two = 2, one = 1, zero = 0, three = 3\}.*$prompt $"\ { pass "ptype named enumeration member" } -re ".*$prompt $" { fail "ptype named enumeration member" } timeout { fail "(timeout) ptype named enumeration member" } } send "ptype red\n" expect { -re "type = enum \{red, green, blue\}.*$prompt $"\ { pass "ptype unnamed enumeration member" } -re ".*$prompt $" { fail "ptype unnamed enumeration member" } timeout { fail "(timeout) ptype unnamed enumeration member" } } # # test ptype command with basic C types # # I've commented most of this out because it duplicates tests in whatis.exp. # I've just left in a token test or 2 which is designed to test that ptype # acts like whatis for basic types. If it is thought to be necessary to # test both whatis and ptype for all the types, the tests should be # merged into whatis.exp, or else maintenance will be a royal pain -kingdon #setup_xfail "i960-*-*" 1821 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*" #send "ptype v_char\n" #expect { # -re "type = char.*$prompt $" { pass "ptype char" } # -re ".*$prompt $" { fail "ptype char" } # timeout { fail "(timeout) ptype char" } #} # # #setup_xfail "mips-*-*" "a29k-*-*" #send "ptype v_signed_char\n" #expect { # -re "type = signed char.*$prompt $" { pass "ptype signed char" } # -re ".*$prompt $" { fail "ptype signed char" } # timeout { fail "(timeout) ptype signed char" } #} # # #send "ptype v_unsigned_char\n" #expect { # -re "type = unsigned char.*$prompt $" { pass "ptype unsigned char" } # -re ".*$prompt $" { fail "ptype unsigned char" } # timeout { fail "(timeout) ptype unsigned char" } #} send "ptype v_short\n" expect { -re "type = short(| int).*$prompt $" { pass "ptype short" } -re ".*$prompt $" { fail "ptype short" } timeout { fail "(timeout) ptype short" } } #send "ptype v_signed_short\n" #expect { # -re "type = short.*$prompt $" { pass "ptype signed short" } # -re ".*$prompt $" { fail "ptype signed short" } # timeout { fail "(timeout) ptype signed short" } #} # # #send "ptype v_unsigned_short\n" #expect { # -re "type = unsigned short.*$prompt $" { pass "ptype unsigned short" } # -re ".*$prompt $" { fail "ptype unsigned short" } # timeout { fail "(timeout) ptype unsigned short" } #} send "ptype v_int\n" expect { -re "type = int.*$prompt $" { pass "ptype int" } -re ".*$prompt $" { fail "ptype int" } timeout { fail "(timeout) ptype int" } } #send "ptype v_signed_int\n" #expect { # -re "type = int.*$prompt $" { pass "ptype signed int" } # -re ".*$prompt $" { fail "ptype signed int" } # timeout { fail "(timeout) ptype signed int" } #} # # #send "ptype v_unsigned_int\n" #expect { # -re "type = unsigned int.*$prompt $" { pass "ptype unsigned int" } # -re ".*$prompt $" { fail "ptype unsigned int" } # timeout { fail "(timeout) ptype unsigned int" } #} # # #send "ptype v_long\n" #expect { # -re "type = long.*$prompt $" { pass "ptype long" } # -re ".*$prompt $" { fail "ptype long" } # timeout { fail "(timeout) ptype long" } #} # # #send "ptype v_signed_long\n" #expect { # -re "type = long.*$prompt $" { pass "ptype signed long" } # -re ".*$prompt $" { fail "ptype signed long" } # timeout { fail "(timeout) ptype signed long" } #} # # #send "ptype v_unsigned_long\n" #expect { # -re "type = unsigned long.*$prompt $" { pass "ptype unsigned long" } # -re ".*$prompt $" { fail "ptype unsigned long" } # timeout { fail "(timeout) ptype unsigned long" } #} # # #send "ptype v_float\n" #expect { # -re "type = float.*$prompt $" { pass "ptype float" } # -re ".*$prompt $" { fail "ptype float" } # timeout { fail "(timeout) ptype float" } #} # # #send "ptype v_double\n" #expect { # -re "type = double.*$prompt $" { pass "ptype double" } # -re ".*$prompt $" { fail "ptype double" } # timeout { fail "(timeout) ptype double" } #} # # test ptype command with arrays # #setup_xfail "i960-*-*" 1821 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*" #send "ptype v_char_array\n" #expect { # -re "type = char .2..*$prompt $" { pass "ptype char array" } # -re ".*$prompt $" { fail "ptype char array" } # timeout { fail "(timeout) ptype char array" } #} # # #setup_xfail "mips-*-*" "a29k-*-*" #send "ptype v_signed_char_array\n" #expect { # -re "type = (|signed )char .2..*$prompt $" { pass "ptype signed char array" } # -re ".*$prompt $" { fail "ptype signed char array" } # timeout { fail "(timeout) ptype signed char array" } #} # # #send "ptype v_unsigned_char_array\n" #expect { # -re "type = unsigned char .2..*$prompt $" { pass "ptype unsigned char array" } # -re ".*$prompt $" { fail "ptype unsigned char array" } # timeout { fail "(timeout) ptype unsigned char array" } #} # # # #send "ptype v_int_array\n" #expect { # -re "type = int .2..*$prompt $" { pass "ptype int array" } # -re ".*$prompt $" { fail "ptype int array" } # timeout { fail "(timeout) ptype int array" } #} # # #send "ptype v_signed_int_array\n" #expect { # -re "type = int .2..*$prompt $" { pass "ptype signed int array" } # -re ".*$prompt $" { fail "ptype signed int array" } # timeout { fail "(timeout) ptype signed int array" } #} # # #send "ptype v_unsigned_int_array\n" #expect { # -re "type = unsigned int .2..*$prompt $" { pass "ptype unsigned int array" } # -re ".*$prompt $" { fail "ptype unsigned int array" } # timeout { fail "(timeout) ptype unsigned int array" } #} # # #send "ptype v_long_array\n" #expect { # -re "type = (long|int|long int) .2..*$prompt $" { # pass "ptype long array" } # -re ".*$prompt $" { fail "ptype long array" } # timeout { fail "(timeout) ptype long array" } #} # # #send "ptype v_signed_long_array\n" #expect { # -re "type = (long|int|long int) .2..*$prompt $" { # pass "ptype signed long array" } # -re ".*$prompt $" { fail "ptype signed long array" } # timeout { fail "(timeout) ptype signed long array" } #} # # #send "ptype v_unsigned_long_array\n" #expect { # -re "type = unsigned long .2..*$prompt $" { pass "ptype unsigned long array" } # -re ".*$prompt $" { fail "ptype unsigned long array" } # timeout { fail "(timeout) ptype unsigned long array" } #} # # #send "ptype v_float_array\n" #expect { # -re "type = float .2..*$prompt $" { pass "ptype float array" } # -re ".*$prompt $" { fail "ptype float array" } # timeout { fail "(timeout) ptype float array" } #} # # #send "ptype v_double_array\n" #expect { # -re "type = double .2..*$prompt $" { pass "ptype double array" } # -re ".*$prompt $" { fail "ptype double array" } # timeout { fail "(timeout) ptype double array" } #} # # ## ## test ptype command with pointers ## #setup_xfail "i960-*-*" 1821 #setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*" #send "ptype v_char_pointer\n" #expect { # -re "type = char \*.*$prompt $" { pass "ptype char pointer" } # -re ".*$prompt $" { fail "ptype char pointer" } # timeout { fail "(timeout) ptype char pointer" } #} # # #setup_xfail "mips-*-*" "a29k-*-*" #send "ptype v_signed_char_pointer\n" #expect { # -re "type = (|signed )char \*.*$prompt $" # { pass "ptype signed char pointer" } # -re ".*$prompt $" { fail "ptype signed char pointer" } # timeout { fail "(timeout) ptype signed char pointer" } #} # # #send "ptype v_unsigned_char_pointer\n" #expect { # -re "type = unsigned char \*.*$prompt $" { pass "ptype unsigned char pointer" } # -re ".*$prompt $" { fail "ptype unsigned char pointer" } # timeout { fail "(timeout) ptype unsigned char pointer" } #} # # #send "ptype v_short_pointer\n" #expect { # -re "type = (short|short int) \*.*$prompt $" { pass "ptype short pointer" } # -re ".*$prompt $" { fail "ptype short pointer" } # timeout { fail "(timeout) ptype short pointer" } #} # # #send "ptype v_signed_short_pointer\n" #expect { # -re "type = short \*.*$prompt $" { pass "ptype signed short pointer" } # -re ".*$prompt $" { fail "ptype signed short pointer" } # timeout { fail "(timeout) ptype signed short pointer" } #} # # #send "ptype v_unsigned_short_pointer\n" #expect { # -re "type = unsigned short \*.*$prompt $" { pass "ptype unsigned short pointer" } # -re ".*$prompt $" { fail "ptype unsigned short pointer" } # timeout { fail "(timeout) ptype unsigned short pointer" } #} # # #send "ptype v_int_pointer\n" #expect { # -re "type = int \*.*$prompt $" { pass "ptype int pointer" } # -re ".*$prompt $" { fail "ptype int pointer" } # timeout { fail "(timeout) ptype int pointer" } #} # # #send "ptype v_signed_int_pointer\n" #expect { # -re "type = int \*.*$prompt $" { pass "ptype signed int pointer" } # -re ".*$prompt $" { fail "ptype signed int pointer" } # timeout { fail "(timeout) ptype signed int pointer" } #} # # #send "ptype v_unsigned_int_pointer\n" #expect { # -re "type = unsigned int \*.*$prompt $" { pass "ptype unsigned int pointer" } # -re ".*$prompt $" { fail "ptype unsigned int pointer" } # timeout { fail "(timeout) ptype unsigned int pointer" } #} # # #send "ptype v_long_pointer\n" #expect { # -re "type = long \*.*$prompt $" { pass "ptype long pointer" } # -re ".*$prompt $" { fail "ptype long pointer" } # timeout { fail "(timeout) ptype long pointer" } #} # # #send "ptype v_signed_long_pointer\n" #expect { # -re "type = long \*.*$prompt $" { pass "ptype signed long pointer" } # -re ".*$prompt $" { fail "ptype signed long pointer" } # timeout { fail "(timeout) ptype signed long pointer" } #} # # #send "ptype v_unsigned_long_pointer\n" #expect { # -re "type = unsigned long \*.*$prompt $" { pass "ptype unsigned long pointer" } # -re ".*$prompt $" { fail "ptype unsigned long pointer" } # timeout { fail "(timeout) ptype unsigned long pointer" } #} # # #send "ptype v_float_pointer\n" #expect { # -re "type = float \*.*$prompt $" { pass "ptype float pointer" } # -re ".*$prompt $" { fail "ptype float pointer" } # timeout { fail "(timeout) ptype float pointer" } #} # # #send "ptype v_double_pointer\n" #expect { # -re "type = double \*.*$prompt $" { pass "ptype double pointer" } # -re ".*$prompt $" { fail "ptype double pointer" } # timeout { fail "(timeout) ptype double pointer" } #} # # test ptype command with nested structure and union # send "ptype struct outer_struct\n" expect { -re "type = struct outer_struct \{.* int outer_int;.* struct inner_struct inner_struct_instance;.* union inner_union inner_union_instance;.* (long|long int|int) outer_long;.* \}.*$prompt $" { pass "ptype outer structure" } -re ".*$prompt $" { fail "ptype outer structure" } timeout { fail "(timeout) ptype outer structure" } } send "ptype struct inner_struct\n" expect { -re "type = struct inner_struct \{.* int inner_int;.* (long|long int|int) inner_long;.* \}.*$prompt $" { pass "ptype inner structure" } -re ".*$prompt $" { fail "ptype inner structure" } timeout { fail "(timeout) ptype inner structure" } } send "ptype union inner_union\n" expect { -re "type = union inner_union \{.* int inner_union_int;.* (long|long int|int) inner_union_long;.* \}.*$prompt $" { pass "ptype inner union" } -re ".*$prompt $" { fail "ptype inner union" } timeout { fail "(timeout) ptype inner union" } } send "ptype nested_su\n" expect { -re "type = struct outer_struct \{.* int outer_int;.* struct inner_struct inner_struct_instance;.* union inner_union inner_union_instance;.* (long|long int|int) outer_long;.* \}.*$prompt $" { pass "ptype nested structure" } -re ".*$prompt $" { fail "ptype nested structure" } timeout { fail "(timeout) ptype nested structure" } } send "ptype nested_su.outer_int\n" expect { -re "type = int.*$prompt $" { pass "ptype outer int" } -re ".*$prompt $" { fail "ptype outer int" } timeout { fail "(timeout) ptype outer int" } } send "ptype nested_su.inner_struct_instance\n" expect { -re "type = struct inner_struct \{.* int inner_int;.* (long|long int|int) inner_long;.* \}.*$prompt $" { pass "ptype nested structure" } -re ".*$prompt $" { fail "ptype nested structure" } timeout { fail "(timeout) ptype nested structure" } } send "ptype nested_su.inner_struct_instance.inner_int\n" expect { -re "type = int.*$prompt $" { pass "ptype inner int" } -re ".*$prompt $" { fail "ptype inner int" } timeout { fail "(timeout) ptype inner int" } } send "ptype nested_su.inner_union_instance\n" expect { -re "type = union inner_union \{.* int inner_union_int;.* (long|long int|int) inner_union_long;.* \}.*$prompt $" { pass "ptype nested union" } -re ".*$prompt $" { fail "ptype nested union" } timeout { fail "(timeout) ptype nested union" } } # Test printing type of string constants and array constants, but # requires a running process. These call malloc, and can take a long # time to execute over a slow serial link, so increase the timeout. # UDI can't do this (PR 2416). XFAIL is not suitable, because attempting # the operation causes a slow painful death rather than a nice simple failure. if ![istarget "*-*-udi*"] then { if [runto main] then { set timeout 120 setup_xfail "a29k-*-udi" 2416 gdb_test "ptype \\\"abc\\\"" "type = char \\\[4\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {(long)0,(long)1,(long)2}" "type = long \\\[3\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {(float)0,(float)1,(float)2}" "type = float \\\[3\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {{0,1,2},{3,4,5}}" "type = int \\\[2\\\]\\\[3\\\]" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype {4,5,6}\\\[2\\\]" "type = int" setup_xfail "a29k-*-udi" 2416 gdb_test "ptype *&{4,5,6}\\\[1\\\]" "type = int" set timeout 10 if [istarget "a29k-*-udi"] then { # FIXME: If PR 2415 is fixed, this is not needed. gdb_target_udi } } }