1 # Copyright 2000, 2002 Free Software Foundation, Inc.
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 2 of the License, or
6 # (at your option) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
25 # test running programs
31 set srcfile ${testfile}.c
32 set binfile ${objdir}/${subdir}/${testfile}
33 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
34 gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail."
37 if [get_compiler_info ${binfile}] {
43 gdb_reinitialize_dir $srcdir/$subdir
47 # set it up at a breakpoint so we can play with the variable values
50 if ![runto_main] then {
51 perror "couldn't run to breakpoint"
56 # Query GDB for the size of various types
59 proc get_valueof { fmt exp default } {
61 send_gdb "print${fmt} ${exp}\n"
63 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
64 set val $expect_out(1,string)
65 pass "get value of ${exp} ($val)"
69 fail "get value of ${exp} (timeout)"
75 proc get_sizeof { type default } {
76 return [get_valueof "/d" "sizeof (${type})" $default]
81 set sizeof_char [get_sizeof "char" 1]
82 set sizeof_short [get_sizeof "short" 2]
83 set sizeof_int [get_sizeof "int" 4]
84 set sizeof_long [get_sizeof "long" 4]
85 set sizeof_long_long [get_sizeof "long long" 8]
87 set sizeof_data_ptr [get_sizeof "void *" 4]
88 set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
90 set sizeof_float [get_sizeof "float" 4]
91 set sizeof_double [get_sizeof "double" 8]
92 set sizeof_long_double [get_sizeof "long double" 8]
95 # Compare GDB's idea of types with the running program
98 proc check_sizeof { type size } {
101 if [gdb_skip_stdio_test "check sizeof $type == $size"] {
105 set pat [string_to_regexp "sizeof (${type}) == ${size}"]
108 -re "${pat}\[\r\n\].*$gdb_prompt $" {
109 pass "check sizeof ${type} == ${size}"
111 -re ".*$gdb_prompt $" {
112 fail "check sizeof ${type} == ${size}"
115 fail "check sizeof ${type} == ${size} (timeout)"
120 check_sizeof "char" ${sizeof_char}
121 check_sizeof "short" ${sizeof_short}
122 check_sizeof "int" ${sizeof_int}
123 check_sizeof "long" ${sizeof_long}
124 check_sizeof "long long" ${sizeof_long_long}
126 check_sizeof "void *" ${sizeof_data_ptr}
127 check_sizeof "void (*)(void)" ${sizeof_func_ptr}
129 check_sizeof "float" ${sizeof_float}
130 check_sizeof "double" ${sizeof_double}
131 check_sizeof "long double" ${sizeof_long_double}
133 proc check_valueof { exp val } {
136 if [gdb_skip_stdio_test "check valueof $exp == $val"] {
140 set pat [string_to_regexp "valueof (${exp}) == ${val}"]
143 -re "${pat}\[\r\n\].*$gdb_prompt $" {
144 pass "check valueof ${exp} == ${val}"
146 -re ".*$gdb_prompt $" {
147 fail "check valueof ${exp} == ${val}"
150 fail "check valueof ${exp} == ${val} (timeout)"
155 # Check that GDB and the target agree over the sign of a character.
157 set signof_byte [get_valueof "/d" "'\\377'" -1]
158 set signof_char [get_valueof "/d" "(int) (char) -1" -1]
159 set signof_signed_char [get_valueof "/d" "(int) (signed char) -1" -1]
160 set signof_unsigned_char [get_valueof "/d" "(int) (unsigned char) -1" -1]
162 check_valueof "'\\\\377'" ${signof_byte}
163 check_valueof "(int) (char) -1" ${signof_char}
164 check_valueof "(int) (signed char) -1" ${signof_signed_char}
165 check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
167 proc check_padding { fmt type val } {
169 gdb_test "set padding_${type}.v = ${val}"
170 gdb_test "print padding_${type}.p1" "= \"The quick brown \""
171 gdb_test "print${fmt} padding_${type}.v" "= ${val}"
172 gdb_test "print padding_${type}.p2" "\"The quick brown \".*"
175 # Check that GDB is managing to store a value in a struct field
176 # without corrupting the fields immediately adjacent to it.
178 check_padding "/d" "char" 1
179 check_padding "/d" "short" 2
180 check_padding "/d" "int" 4
181 check_padding "/d" "long" 4
182 check_padding "/d" "long_long" 8
184 # use multiples of two which can be represented exactly
185 check_padding "/f" "float" 1
186 check_padding "/f" "double" 2
187 check_padding "/f" "long_double" 4
190 # For reference, dump out the entire architecture
192 # The output is very long so use a while loop to consume it
193 send_gdb "maint print arch\n"
198 #pass "maint print arch $ok"
199 #set ok [expr $ok + 1]
201 -re "$gdb_prompt $" {
202 pass "maint print arch"
206 fail "maint print arch (timeout)"