1 # This testcase is part of GDB, the GNU debugger.
3 # Copyright 2000, 2002, 2003, 2004, 2005, 2007, 2008
4 # Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 if [target_info exists gdb,noinferiorio] {
20 verbose "Skipping fileio.exp because of no fileio capabilities."
29 # test running programs
35 set srcfile ${testfile}.c
36 set binfile ${objdir}/${subdir}/${testfile}
37 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
42 if [get_compiler_info ${binfile}] {
48 gdb_reinitialize_dir $srcdir/$subdir
52 # set it up at a breakpoint so we can play with the variable values
55 if ![runto_main] then {
56 perror "couldn't run to breakpoint"
61 # Query GDB for the size of various types
64 proc get_valueof { fmt exp default } {
67 set test "get valueof \"${exp}\""
69 gdb_test_multiple "print${fmt} ${exp}" "$test" {
70 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
71 set val $expect_out(1,string)
78 proc get_sizeof { type default } {
79 return [get_valueof "/d" "sizeof (${type})" $default]
84 set sizeof_char [get_sizeof "char" 1]
85 set sizeof_short [get_sizeof "short" 2]
86 set sizeof_int [get_sizeof "int" 4]
87 set sizeof_long [get_sizeof "long" 4]
88 set sizeof_long_long [get_sizeof "long long" 8]
90 set sizeof_data_ptr [get_sizeof "void *" 4]
91 set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
93 set sizeof_float [get_sizeof "float" 4]
94 set sizeof_double [get_sizeof "double" 8]
95 set sizeof_long_double [get_sizeof "long double" 8]
98 # Compare GDB's idea of types with the running program
101 proc check_sizeof { type size } {
104 set pat [string_to_regexp "sizeof (${type}) == ${size}"]
105 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check sizeof \"$type\""
108 check_sizeof "char" ${sizeof_char}
109 check_sizeof "short" ${sizeof_short}
110 check_sizeof "int" ${sizeof_int}
111 check_sizeof "long" ${sizeof_long}
112 check_sizeof "long long" ${sizeof_long_long}
114 check_sizeof "void *" ${sizeof_data_ptr}
115 check_sizeof "void (*)(void)" ${sizeof_func_ptr}
117 check_sizeof "float" ${sizeof_float}
118 check_sizeof "double" ${sizeof_double}
119 check_sizeof "long double" ${sizeof_long_double}
121 proc check_valueof { exp val } {
124 set pat [string_to_regexp "valueof (${exp}) == ${val}"]
125 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check valueof \"$exp\""
128 # Check that GDB and the target agree over the sign of a character.
130 set signof_byte [get_valueof "/d" "'\\377'" -1]
131 set signof_char [get_valueof "/d" "(int) (char) -1" -1]
132 set signof_signed_char [get_valueof "/d" "(int) (signed char) -1" -1]
133 set signof_unsigned_char [get_valueof "/d" "(int) (unsigned char) -1" -1]
135 check_valueof "'\\377'" ${signof_byte}
136 check_valueof "(int) (char) -1" ${signof_char}
137 check_valueof "(int) (signed char) -1" ${signof_signed_char}
138 check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
140 proc check_padding { fmt type val } {
142 gdb_test "set padding_${type}.v = ${val}"
143 gdb_test "print padding_${type}.p1" "= \"The quick brown \""
144 gdb_test "print${fmt} padding_${type}.v" "= ${val}"
145 gdb_test "print padding_${type}.p2" "\"The quick brown \".*"
148 # Check that GDB is managing to store a value in a struct field
149 # without corrupting the fields immediately adjacent to it.
151 check_padding "/d" "char" 1
152 check_padding "/d" "short" 2
153 check_padding "/d" "int" 4
154 check_padding "/d" "long" 4
155 check_padding "/d" "long_long" 8
157 # use multiples of two which can be represented exactly
158 check_padding "/f" "float" 1
159 check_padding "/f" "double" 2
160 check_padding "/f" "long_double" 4
163 # For reference, dump out the entire architecture
165 # The output is very long so use a while loop to consume it
166 send_gdb "maint print arch\n"
171 #pass "maint print arch $ok"
172 #set ok [expr $ok + 1]
174 -re "$gdb_prompt $" {
175 pass "maint print arch"
179 fail "maint print arch (timeout)"