]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.base/sizeof.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / sizeof.exp
CommitLineData
1bf404ef
AC
1# This testcase is part of GDB, the GNU debugger.
2
6aba47ca 3# Copyright 2000, 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
2391e11d
AC
4
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
6bf46641
AC
19if [target_info exists gdb,noinferiorio] {
20 verbose "Skipping fileio.exp because of no fileio capabilities."
21 continue
22}
23
2391e11d
AC
24if $tracelevel {
25 strace $tracelevel
26}
27
28#
29# test running programs
30#
31set prms_id 0
32set bug_id 0
33
34set testfile "sizeof"
35set srcfile ${testfile}.c
36set binfile ${objdir}/${subdir}/${testfile}
37if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
38 untested sizeof.exp
39 return -1
2391e11d
AC
40}
41
42if [get_compiler_info ${binfile}] {
43 return -1;
44}
45
46gdb_exit
47gdb_start
48gdb_reinitialize_dir $srcdir/$subdir
49gdb_load ${binfile}
50
51#
52# set it up at a breakpoint so we can play with the variable values
53#
54
55if ![runto_main] then {
56 perror "couldn't run to breakpoint"
57 continue
58}
59
60#
61# Query GDB for the size of various types
62#
63
edcc8c75 64proc get_valueof { fmt exp default } {
2391e11d 65 global gdb_prompt
6bf46641
AC
66
67 set test "get valueof \"${exp}\""
68 set val ${default}
69 gdb_test_multiple "print${fmt} ${exp}" "$test" {
edcc8c75
AC
70 -re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
71 set val $expect_out(1,string)
6bf46641 72 pass "$test ($val)"
2391e11d
AC
73 }
74 }
edcc8c75
AC
75 return ${val}
76}
77
78proc get_sizeof { type default } {
79 return [get_valueof "/d" "sizeof (${type})" $default]
2391e11d
AC
80}
81
edcc8c75
AC
82gdb_test "next"
83
2391e11d
AC
84set sizeof_char [get_sizeof "char" 1]
85set sizeof_short [get_sizeof "short" 2]
86set sizeof_int [get_sizeof "int" 4]
87set sizeof_long [get_sizeof "long" 4]
88set sizeof_long_long [get_sizeof "long long" 8]
89
90set sizeof_data_ptr [get_sizeof "void *" 4]
91set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
92
93set sizeof_float [get_sizeof "float" 4]
94set sizeof_double [get_sizeof "double" 8]
95set sizeof_long_double [get_sizeof "long double" 8]
96
2391e11d
AC
97#
98# Compare GDB's idea of types with the running program
99#
100
101proc check_sizeof { type size } {
102 global gdb_prompt
13a5e3b8 103
edcc8c75 104 set pat [string_to_regexp "sizeof (${type}) == ${size}"]
6bf46641 105 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check sizeof \"$type\""
2391e11d
AC
106}
107
108check_sizeof "char" ${sizeof_char}
109check_sizeof "short" ${sizeof_short}
110check_sizeof "int" ${sizeof_int}
111check_sizeof "long" ${sizeof_long}
112check_sizeof "long long" ${sizeof_long_long}
113
114check_sizeof "void *" ${sizeof_data_ptr}
115check_sizeof "void (*)(void)" ${sizeof_func_ptr}
116
117check_sizeof "float" ${sizeof_float}
118check_sizeof "double" ${sizeof_double}
119check_sizeof "long double" ${sizeof_long_double}
120
edcc8c75
AC
121proc check_valueof { exp val } {
122 global gdb_prompt
123
edcc8c75 124 set pat [string_to_regexp "valueof (${exp}) == ${val}"]
6bf46641 125 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check valueof \"$exp\""
edcc8c75
AC
126}
127
128# Check that GDB and the target agree over the sign of a character.
129
71900fe8 130set signof_byte [get_valueof "/d" "'\\377'" -1]
edcc8c75
AC
131set signof_char [get_valueof "/d" "(int) (char) -1" -1]
132set signof_signed_char [get_valueof "/d" "(int) (signed char) -1" -1]
133set signof_unsigned_char [get_valueof "/d" "(int) (unsigned char) -1" -1]
134
39fb8e9e 135check_valueof "'\\377'" ${signof_byte}
edcc8c75
AC
136check_valueof "(int) (char) -1" ${signof_char}
137check_valueof "(int) (signed char) -1" ${signof_signed_char}
138check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
139
140proc check_padding { fmt type val } {
141 global gdb_prompt
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 \".*"
146}
147
148# Check that GDB is managing to store a value in a struct field
149# without corrupting the fields immediately adjacent to it.
150
151check_padding "/d" "char" 1
152check_padding "/d" "short" 2
153check_padding "/d" "int" 4
154check_padding "/d" "long" 4
155check_padding "/d" "long_long" 8
156
157# use multiples of two which can be represented exactly
158check_padding "/f" "float" 1
159check_padding "/f" "double" 2
160check_padding "/f" "long_double" 4
2391e11d
AC
161
162#
163# For reference, dump out the entire architecture
164#
165# The output is very long so use a while loop to consume it
166send_gdb "maint print arch\n"
167set ok 1
168while { $ok } {
169 gdb_expect {
170 -re ".*dump" {
171 #pass "maint print arch $ok"
172 #set ok [expr $ok + 1]
173 }
174 -re "$gdb_prompt $" {
175 pass "maint print arch"
176 set ok 0
177 }
178 timeout {
179 fail "maint print arch (timeout)"
180 set ok 0
181 }
182 }
183}