-# Copyright (C) 1988, 1990, 1991, 1992, 1994, 1997 Free Software Foundation, Inc.
+# Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2002,
+# 2003, 2007 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
set bug_id 0
set testfile "ptype"
-set srcfile ${testfile}.c
+set srcfile0 ${testfile}.c
+set srcfile1 ${testfile}1.c
set binfile ${objdir}/${subdir}/${testfile}
-if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
- gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile0}" "${binfile}0.o" object {debug}] != "" } {
+ untested ptype.exp
+ return -1
+}
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile1}" "${binfile}1.o" object {debug}] != "" } {
+ untested ptype.exp
+ return -1
+}
+if { [gdb_compile "${binfile}0.o ${binfile}1.o" "${binfile}" executable {debug}] != "" } {
+ untested ptype.exp
+ return -1
}
# Create and source the file that provides information about the compiler
# IBM's xlc puts out bogus stabs--the stuff field is type 42,
# which isn't defined.
-gdb_test "ptype struct link" "type = struct link \{.*\[\r\n\] struct link \[*\]next;.*\[\r\n\] struct link \[*(\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*\[\r\n\] struct t_struct stuff.1..2..3.;.*\[\r\n\]\}.*" "ptype linked list structure"
+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"
#
# test ptype command with unions
# IBM's xlc puts out bogus stabs--the stuff field is type 42,
# which isn't defined.
-gdb_test "ptype union tu_link" "type = union tu_link .*\[\r\n\] struct link \[*\]next;.*\[\r\n\] struct link \[(\*\]+linkfunc\[)(\]+(struct link \[*\], int\[)\]|);.*\[\r\n\] struct t_struct stuff.1..2..3.;.*\[\r\n\]\}.*" "ptype linked list union"
+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"
#
# test ptype command with enums
#
# test ptype command with enums as typedef
#
-gdb_test "ptype boolean" "type = enum \{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
+gdb_test "ptype boolean" "type = enum (boolean |)\{FALSE, TRUE\}.*" "ptype unnamed typedef'd enumeration"
# And check that whatis shows the name, not "enum {...}".
# This probably fails for all DWARF 1 cases, so assume so for now. -fnf
# GDB's behavior is correct; the type which the variable is defined
# as (51) doesn't have a name. Only 55 has a name.
-if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
-setup_xfail_format "DWARF 1"
-gdb_test "whatis v_boolean" "type = boolean" \
+if {!$gcc_compiled && !$hp_aCC_compiler} {
+ setup_xfail "rs6000-*-*" "i*86-*-sysv4*"
+ setup_xfail "hppa*-*-*" CLLbs14773
+}
+
+# For get_debug_format to do its job, we need to have a current source file.
+gdb_test "list main" ""
+get_debug_format
+gdb_test "whatis v_boolean" "type = (enum |)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 \{.*
+gdb_test "ptype t_struct3" "type = struct (t_struct3 |)\{.*
*double v_double_member;.*
*int v_int_member;.*\}" "printing typedef'd struct"
-gdb_test "ptype t_union3" "type = union \{.*
+gdb_test "ptype t_union3" "type = union (t_union3 |)\{.*
*double v_double_member;.*
*int v_int_member;.*\}" "printing typedef'd union"
-gdb_test "ptype enum bvals" "type = enum bvals \{false, true\}.*" "ptype named typedef'd enumf'd enum"
+gdb_test "ptype enum bvals" "type = enum bvals \{my_false, my_true\}.*" "ptype named typedef'd enumf'd enum"
#
# test ptype command with out-of-order enum values
# 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-*-*"
+#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char\n"
#gdb_expect {
# -re "type = char.*$gdb_prompt $" { pass "ptype char" }
#}
#
#
-#setup_xfail "mips-*-*" "a29k-*-*"
+#setup_xfail "mips-*-*"
#send "ptype v_signed_char\n"
#gdb_expect {
# -re "type = signed char.*$gdb_prompt $" { pass "ptype signed char" }
#
# test ptype command with arrays
#
-#setup_xfail "i960-*-*" 1821
-#setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
+#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char_array\n"
#gdb_expect {
# -re "type = char .2..*$gdb_prompt $" { pass "ptype char array" }
#}
#
#
-#setup_xfail "mips-*-*" "a29k-*-*"
+#setup_xfail "mips-*-*"
#send "ptype v_signed_char_array\n"
#gdb_expect {
# -re "type = (|signed )char .2..*$gdb_prompt $" { pass "ptype signed char array" }
#
if {!$gcc_compiled} then { setup_xfail "rs6000-*-*" "i*86-*-sysv4*" }
-setup_xfail_format "DWARF 1"
+if {$hp_aCC_compiler} {setup_xfail "hppa*-*-*"}
gdb_test "ptype t_char_array" "type = (|unsigned )char \\\[0?\\\]"
#
##
## test ptype command with pointers
##
-#setup_xfail "i960-*-*" 1821
-#setup_xfail "mips-idt-*" "mips-sgi-*" "a29k-*-*"
+#setup_xfail "mips-idt-*" "mips-sgi-*"
#send "ptype v_char_pointer\n"
#gdb_expect {
# -re "type = char \*.*$gdb_prompt $" { pass "ptype char pointer" }
#}
#
#
-#setup_xfail "mips-*-*" "a29k-*-*"
+#setup_xfail "mips-*-*"
#send "ptype v_signed_char_pointer\n"
#gdb_expect {
# -re "type = (|signed )char \*.*$gdb_prompt $"
#
# test ptype command with nested structure and union
#
-gdb_test "ptype struct outer_struct" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] struct inner_struct inner_struct_instance;.*\[\r\n\] union inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype outer structure"
+if {$hp_aCC_compiler} {
+ set outer "outer_struct::"
+ set struct ""
+ set union ""
+} else {
+ set outer ""
+ set struct "struct"
+ set union "union"
+}
+gdb_test "ptype struct outer_struct" "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 outer structure"
-gdb_test "ptype struct inner_struct" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype inner structure"
+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"
-gdb_test "ptype union inner_union" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype inner union"
+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"
-gdb_test "ptype nested_su" "type = struct outer_struct \{.*\[\r\n\] int outer_int;.*\[\r\n\] struct inner_struct inner_struct_instance;.*\[\r\n\] union inner_union inner_union_instance;.*\[\r\n\] (long|long int|int) outer_long;.*\[\r\n\]\}.*" "ptype nested structure"
+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"
gdb_test "ptype nested_su.outer_int" "type = int.*" "ptype outer int"
-gdb_test "ptype nested_su.inner_struct_instance" "type = struct inner_struct \{.*\[\r\n\] int inner_int;.*\[\r\n\] (long|long int|int) inner_long;.*\[\r\n\]\}.*" "ptype nested structure #2"
+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"
gdb_test "ptype nested_su.inner_struct_instance.inner_int" "type = int.*" "ptype inner int"
-gdb_test "ptype nested_su.inner_union_instance" "type = union inner_union \{.*\[\r\n\] int inner_union_int;.*\[\r\n\] (long|long int|int) inner_union_long;.*\[\r\n\]\}.*" "ptype nested union"
+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"
+
+
+get_debug_format
+
+# Print the type of the identifier ID, and check the response:
+# - Expect to see PROTOTYPED as the type. PROTOTYPED is not a regular
+# expression; it's a literal string.
+# - If we instead see the unprototyped type PLAIN, and we're using STABS
+# generated by GCC, that's an xfail; as of 9 Feb 2002, GCC never emits
+# prototyped function types in STABS. Like PROTOTYPED, PLAIN is a
+# literal string, not a regular expression.
+# - Otherwise, it's a failure.
+proc ptype_maybe_prototyped { id prototyped plain } {
+ global gdb_prompt
+ global gcc_compiled
+
+ # Turn `prototyped' and `plain', which are literal strings, into
+ # regular expressions by quoting any special characters they contain.
+ regsub -all "\[\]\[*()\]" $prototyped "\\\\&" prototyped
+ regsub -all "\[\]\[*()\]" $plain "\\\\&" plain
+
+ send_gdb "ptype $id\n"
+ gdb_expect {
+ -re "type = $prototyped\[\r\n\]+$gdb_prompt $" {
+ pass "ptype $id"
+ }
+ -re "type = $plain\[\r\n\]+$gdb_prompt $" {
+ if {$gcc_compiled} { setup_xfail_format "stabs" }
+ fail "ptype $id (compiler doesn't emit prototyped types)"
+ }
+ -re "$gdb_prompt $" {
+ fail "ptype $id"
+ }
+ timeout {
+ fail "ptype $id (timeout)"
+ }
+ }
+}
+
+ptype_maybe_prototyped "func_type" "int (*)(int (*)(int, float), float)" \
+ "int (*)()"
+ptype_maybe_prototyped "old_fptr" "double (*)()" "double (*)()"
+ptype_maybe_prototyped "new_fptr" "double (*)(void)" "double (*)()"
+ptype_maybe_prototyped "fptr" "int (*)(int, float)" "int (*)()"
+ptype_maybe_prototyped "fptr2" "int *(*)(int (*)(int, float), float)" \
+ "int *(*)()"
+ptype_maybe_prototyped "xptr" "int (*)(int (*)(), int (*)(void), int)" \
+ "int (*)()"
+ptype_maybe_prototyped "ffptr" "int (*(*)(char))(short int)" \
+ "int (*(*)())()"
+ptype_maybe_prototyped "fffptr" "int (*(*(*)(char))(short int))(long int)" \
+ "int (*(*(*)())())()"
+
+# Test printing type of typedefs in different scopes, with same name
+# but different type.
+
+gdb_test "list intfoo" ""
+gdb_test "ptype foo" "type = int" "ptype foo typedef after first list of intfoo"
+gdb_test "list charfoo" ""
+gdb_test "ptype foo" "type = char" "ptype foo typedef after first list of charfoo"
+gdb_test "list intfoo" ""
+gdb_test "ptype foo" "type = int" "ptype foo typedef after second list of intfoo"
+gdb_test "list charfoo" ""
+gdb_test "ptype foo" "type = char" "ptype foo typedef after second list of charfoo"
# Test printing type of string constants and array constants, but
# requires a running process. These call malloc, and can take a long
if [runto_main] then {
- get_debug_format
if [target_info exists gdb,cannot_call_functions] {
setup_xfail "*-*-*" 2416
fail "This target can not call functions"
continue
}
+ # We need to up this because this can be really slow on some boards.
+ # (malloc() is called as part of the test).
+ set timeout 60;
+
gdb_test "ptype \"abc\"" "type = char \\\[4\\\]"
gdb_test "ptype {'a','b','c'}" "type = char \\\[3\\\]"
gdb_test "ptype {0,1,2}" "type = int \\\[3\\\]"