* gdb.base/exe-lock.exp (binfile): Add $EXEEXT suffix to fix
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / sizeof.exp
CommitLineData
1bf404ef
AC
1# This testcase is part of GDB, the GNU debugger.
2
0fb0cc75 3# Copyright 2000, 2002, 2003, 2004, 2005, 2007, 2008, 2009
9b254dd1 4# Free Software Foundation, Inc.
2391e11d
AC
5
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
e22f8b7c 8# the Free Software Foundation; either version 3 of the License, or
2391e11d
AC
9# (at your option) any later version.
10#
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.
15#
16# You should have received a copy of the GNU General Public License
e22f8b7c 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
2391e11d 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
AC
64gdb_test "next"
65
2391e11d
AC
66set sizeof_char [get_sizeof "char" 1]
67set sizeof_short [get_sizeof "short" 2]
68set sizeof_int [get_sizeof "int" 4]
69set sizeof_long [get_sizeof "long" 4]
70set sizeof_long_long [get_sizeof "long long" 8]
71
72set sizeof_data_ptr [get_sizeof "void *" 4]
73set sizeof_func_ptr [get_sizeof "void (*)(void)" 4]
74
75set sizeof_float [get_sizeof "float" 4]
76set sizeof_double [get_sizeof "double" 8]
77set sizeof_long_double [get_sizeof "long double" 8]
78
2391e11d
AC
79#
80# Compare GDB's idea of types with the running program
81#
82
83proc check_sizeof { type size } {
84 global gdb_prompt
13a5e3b8 85
edcc8c75 86 set pat [string_to_regexp "sizeof (${type}) == ${size}"]
6bf46641 87 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check sizeof \"$type\""
2391e11d
AC
88}
89
90check_sizeof "char" ${sizeof_char}
91check_sizeof "short" ${sizeof_short}
92check_sizeof "int" ${sizeof_int}
93check_sizeof "long" ${sizeof_long}
94check_sizeof "long long" ${sizeof_long_long}
95
96check_sizeof "void *" ${sizeof_data_ptr}
97check_sizeof "void (*)(void)" ${sizeof_func_ptr}
98
99check_sizeof "float" ${sizeof_float}
100check_sizeof "double" ${sizeof_double}
101check_sizeof "long double" ${sizeof_long_double}
102
edcc8c75
AC
103proc check_valueof { exp val } {
104 global gdb_prompt
105
edcc8c75 106 set pat [string_to_regexp "valueof (${exp}) == ${val}"]
6bf46641 107 gdb_test "next" "${pat}\[\r\n\]+\[0-9\].*" "check valueof \"$exp\""
edcc8c75
AC
108}
109
110# Check that GDB and the target agree over the sign of a character.
111
417e16e2
PM
112set signof_byte [get_integer_valueof "'\\377'" -1]
113set signof_char [get_integer_valueof "(int) (char) -1" -1]
114set signof_signed_char [get_integer_valueof "(int) (signed char) -1" -1]
115set signof_unsigned_char [get_integer_valueof "(int) (unsigned char) -1" -1]
edcc8c75 116
39fb8e9e 117check_valueof "'\\377'" ${signof_byte}
edcc8c75
AC
118check_valueof "(int) (char) -1" ${signof_char}
119check_valueof "(int) (signed char) -1" ${signof_signed_char}
120check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
121
122proc check_padding { fmt type val } {
123 global gdb_prompt
124 gdb_test "set padding_${type}.v = ${val}"
125 gdb_test "print padding_${type}.p1" "= \"The quick brown \""
126 gdb_test "print${fmt} padding_${type}.v" "= ${val}"
127 gdb_test "print padding_${type}.p2" "\"The quick brown \".*"
128}
129
130# Check that GDB is managing to store a value in a struct field
131# without corrupting the fields immediately adjacent to it.
132
133check_padding "/d" "char" 1
134check_padding "/d" "short" 2
135check_padding "/d" "int" 4
136check_padding "/d" "long" 4
137check_padding "/d" "long_long" 8
138
139# use multiples of two which can be represented exactly
140check_padding "/f" "float" 1
141check_padding "/f" "double" 2
142check_padding "/f" "long_double" 4
2391e11d
AC
143
144#
145# For reference, dump out the entire architecture
146#
147# The output is very long so use a while loop to consume it
148send_gdb "maint print arch\n"
149set ok 1
150while { $ok } {
151 gdb_expect {
152 -re ".*dump" {
153 #pass "maint print arch $ok"
154 #set ok [expr $ok + 1]
155 }
156 -re "$gdb_prompt $" {
157 pass "maint print arch"
158 set ok 0
159 }
160 timeout {
161 fail "maint print arch (timeout)"
162 set ok 0
163 }
164 }
165}
This page took 0.813037 seconds and 4 git commands to generate.