]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.base/bitfields.exp
Copyright updates for 2007.
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields.exp
1 # Copyright 1992, 1994, 1995, 1997, 2007 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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.
16
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-gdb@prep.ai.mit.edu
19
20 # This file was written by Fred Fish. (fnf@cygnus.com)
21
22 if $tracelevel then {
23 strace $tracelevel
24 }
25
26 set prms_id 0
27 set bug_id 0
28
29 set testfile "bitfields"
30 set srcfile ${testfile}.c
31 set binfile ${objdir}/${subdir}/${testfile}
32 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
33 untested bitfields.exp
34 return -1
35 }
36
37 #
38 # Test bitfield locating and uniqueness.
39 # For each member, set that member to 1 and verify that the member (and only
40 # that member) is 1, then reset it back to 0.
41 #
42
43 proc bitfield_uniqueness {} {
44 global decimal
45 global hex
46 global gdb_prompt
47 global srcfile
48
49 if { ! [runto break1] } {
50 gdb_suppress_tests;
51 }
52
53 if [gdb_test "print flags" ".*uc = 1 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*"] {
54 gdb_suppress_tests;
55 }
56 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] {
57 gdb_suppress_tests;
58 }
59 # Note that we check for s1 as either 1 or -1, so that failure to
60 # treat it correctly as a signed 1bit field (values 0 or -1) while
61 # printing its value does not cause a spurious failure. We do the
62 # signedness preservation test later.
63 if [gdb_test "print flags" ".*uc = 0 .*, s1 = (1|-1), u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s1)"] {
64 gdb_suppress_tests;
65 }
66 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] {
67 gdb_suppress_tests;
68 }
69 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 1, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u1)"] {
70 gdb_suppress_tests;
71 }
72 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] {
73 gdb_suppress_tests;
74 }
75 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 1, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s2)"] {
76 gdb_suppress_tests;
77 }
78 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] {
79 gdb_suppress_tests;
80 }
81 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 1, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u2)"] {
82 gdb_suppress_tests;
83 }
84 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] {
85 gdb_suppress_tests;
86 }
87 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 1, u3 = 0, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (s3)"] {
88 gdb_suppress_tests;
89 }
90 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] {
91 gdb_suppress_tests;
92 }
93 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 1, s9 = 0, u9 = 0, sc = 0.*" "bitfield uniqueness (u3)"] {
94 gdb_suppress_tests
95 }
96 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] {
97 gdb_suppress_tests
98 }
99 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 1, u9 = 0, sc = 0.*" "bitfield uniqueness (s9)"] {
100 gdb_suppress_tests
101 }
102 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] {
103 gdb_suppress_tests
104 }
105 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 1, sc = 0.*" "bitfield uniqueness (u9)"] {
106 gdb_suppress_tests
107 }
108 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] {
109 gdb_suppress_tests
110 }
111 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 0, s9 = 0, u9 = 0, sc = 1.*" "bitfield uniqueness (sc)"] {
112 gdb_suppress_tests
113 }
114 # Hmmmm?
115 gdb_stop_suppressing_tests;
116 }
117
118
119 #
120 # Test bitfield containment.
121 # Fill alternating fields with all 1's and verify that none of the bits
122 # "bleed over" to the other fields.
123 #
124
125 proc bitfield_containment {} {
126 global decimal
127 global hex
128 global gdb_prompt
129 global srcfile
130
131 delete_breakpoints
132
133 if { ![runto break2] } {
134 gdb_suppress_tests
135 }
136
137 if [gdb_test "print/x flags" "= {uc = 0xff, s1 = 0x0, u1 = 0x1, s2 = 0x0, u2 = 0x3, s3 = 0x0, u3 = 0x7, s9 = 0x0, u9 = 0x1ff, sc = 0x0}" "bitfield containment #1"] {
138 gdb_suppress_tests
139 }
140
141 if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] {
142 gdb_suppress_tests
143 }
144
145 # If program is compiled with Sun CC, then these print out as their
146 # actual sizes; if compiled with gcc, they print out as 0xffffffff
147 # (which strikes me as bogus, but accept it at least for now).
148 if [gdb_test "print/x flags" "= {uc = 0x0, s1 = 0x(1|f*), u1 = 0x0, s2 = 0x(3|f*), u2 = 0x0, s3 = 0x(7|f*), u3 = 0x0, s9 = 0x(1ff|f*), u9 = 0x0, sc = 0xff}" "bitfield containment #2"] {
149 gdb_suppress_tests
150 }
151 gdb_stop_suppressing_tests;
152 }
153
154 # Test unsigned bitfields for unsignedness and range.
155 # Fill the unsigned fields with the maximum positive value and verify that
156 # the values are printed correctly.
157
158 proc bitfield_unsignedness {} {
159 global decimal
160 global hex
161 global gdb_prompt
162 global srcfile
163
164 delete_breakpoints
165
166 if { ![runto break3] } {
167 gdb_suppress_tests
168 }
169
170 if [gdb_test "print flags" ".*uc = 0 .*, s1 = 0, u1 = 1, s2 = 0, u2 = 3, s3 = 0, u3 = 7, s9 = 0, u9 = 511, sc = 0.*" "unsigned bitfield ranges"] {
171 gdb_suppress_tests
172 }
173 gdb_stop_suppressing_tests;
174 }
175
176 #
177 # Test signed bitfields for signedness and range.
178 # Fill the signed fields with the maximum positive value, then the maximally
179 # negative value, then -1, and verify in each case that the values are
180 # printed correctly.
181 #
182
183 proc bitfield_signedness {} {
184 global decimal
185 global hex
186 global gdb_prompt
187 global srcfile
188
189 delete_breakpoints
190
191 if { ! [runto break4] } {
192 gdb_suppress_tests
193 }
194
195 if [gdb_test "print flags" "= {uc = 0 .*, s1 = 0, u1 = 0, s2 = 1, u2 = 0, s3 = 3, u3 = 0, s9 = 255, u9 = 0, sc = 0 .*}" "signed bitfields, max positive values"] {
196 gdb_suppress_tests
197 }
198
199 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] {
200 gdb_suppress_tests
201 }
202
203 # Determine if the target has signed bitfields so we can xfail the
204 # the signed bitfield tests if it doesn't.
205 send_gdb "print i\n"
206 gdb_expect {
207 -re ".* = -256.*$gdb_prompt $" {
208 pass "determining signed-ness of bitfields"
209 }
210 -re ".* = 256.*$gdb_prompt $" {
211 pass "determining signed-ness of bitfields"
212 setup_xfail "*-*-*"
213 }
214 -re ".*$gdb_prompt $" {
215 fail "determining signed-ness of bitfields"
216 gdb_suppress_tests
217 }
218 default {
219 fail "determining signed-ness of bitfields" ;
220 gdb_suppress_tests;
221 }
222 }
223
224 if [gdb_test "print flags" ".*uc = 0 .*, s1 = -1, u1 = 0, s2 = -2, u2 = 0, s3 = -4, u3 = 0, s9 = -256, u9 = 0, sc = 0.*" "signed bitfields, max negative values"] {
225 gdb_suppress_tests
226 }
227
228 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] {
229 gdb_suppress_tests
230 }
231
232 if [gdb_test "print flags" ".*uc = 0 .*, s1 = -1, u1 = 0, s2 = -1, u2 = 0, s3 = -1, u3 = 0, s9 = -1, u9 = 0, sc = 0.*" "signed bitfields with -1"] {
233 gdb_suppress_tests
234 }
235 # Hmmmm???
236 gdb_stop_suppressing_tests;
237 }
238
239 gdb_start
240 gdb_reinitialize_dir $srcdir/$subdir
241 gdb_load ${binfile}
242
243 send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $"
244
245 bitfield_uniqueness
246 if [istarget "mips-idt-*"] then {
247 # Restart because IDT/SIM runs out of file descriptors.
248 gdb_exit
249 gdb_start
250 gdb_reinitialize_dir $srcdir/$subdir
251 gdb_load ${binfile}
252 }
253 bitfield_containment
254 if [istarget "mips-idt-*"] then {
255 # Restart because IDT/SIM runs out of file descriptors.
256 gdb_exit
257 gdb_start
258 gdb_reinitialize_dir $srcdir/$subdir
259 gdb_load ${binfile}
260 }
261 bitfield_unsignedness
262 if [istarget "mips-idt-*"] then {
263 # Restart because IDT/SIM runs out of file descriptors.
264 gdb_exit
265 gdb_start
266 gdb_reinitialize_dir $srcdir/$subdir
267 gdb_load ${binfile}
268 }
269 bitfield_signedness