Major revision to testsuites for cross-testing and DOS testing support.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields.exp
1 # Copyright (C) 1992, 1994 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 perror "Couldn't compile ${srcfile}"
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 prompt
47 global srcfile
48
49 if [gdb_test "break break1" "Break.* at $hex: file .*$srcfile, line $decimal\\."] {
50 return
51 }
52
53 gdb_run_cmd
54 expect {
55 -re "Break.*break1 \\(\\) at .*$srcfile:$decimal.*$prompt $" {
56 pass "running to break1"
57 }
58 timeout { fail "(timeout) running to break1"; return }
59 }
60
61 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.*"] {
62 return
63 }
64 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] {
65 return
66 }
67 # Note that we check for s1 as either 1 or -1, so that failure to
68 # treat it correctly as a signed 1bit field (values 0 or -1) while
69 # printing its value does not cause a spurious failure. We do the
70 # signedness preservation test later.
71 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)"] {
72 return
73 }
74 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] {
75 return
76 }
77 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)"] {
78 return
79 }
80 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] {
81 return
82 }
83 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)"] {
84 return
85 }
86 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] {
87 return
88 }
89 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)"] {
90 return
91 }
92 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] {
93 return
94 }
95 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)"] {
96 return
97 }
98 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] {
99 return
100 }
101 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)"] {
102 return
103 }
104 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] {
105 return
106 }
107 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)"] {
108 return
109 }
110 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] {
111 return
112 }
113 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)"] {
114 return
115 }
116 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] {
117 return
118 }
119 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)"] {
120 return
121 }
122 }
123
124
125 #
126 # Test bitfield containment.
127 # Fill alternating fields with all 1's and verify that none of the bits
128 # "bleed over" to the other fields.
129 #
130
131 proc bitfield_containment {} {
132 global decimal
133 global hex
134 global prompt
135 global srcfile
136
137 delete_breakpoints
138
139 if [gdb_test "break break2" "Break.* at $hex: file .*$srcfile, line $decimal\\." "setting breakpoint at break2"] {
140 return
141 }
142
143 gdb_run_cmd
144 expect {
145 -re "Break.*break2 \\(\\) at .*$srcfile:$decimal.*$prompt $" {
146 pass "running to break2"
147 }
148 timeout { fail "(timeout) running to break2"; return }
149 }
150
151 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"] {
152 return
153 }
154
155 if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] {
156 return
157 }
158
159 # If program is compiled with Sun CC, then these print out as their
160 # actual sizes; if compiled with gcc, they print out as 0xffffffff
161 # (which strikes me as bogus, but accept it at least for now).
162 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"] {
163 return
164 }
165 }
166
167 # Test unsigned bitfields for unsignedness and range.
168 # Fill the unsigned fields with the maximum positive value and verify that
169 # the values are printed correctly.
170
171 proc bitfield_unsignedness {} {
172 global decimal
173 global hex
174 global prompt
175 global srcfile
176
177 delete_breakpoints
178
179 if [gdb_test "break break3" "Break.* at $hex: file .*$srcfile, line $decimal\\." "setting breakpoint at break3"] {
180 return
181 }
182
183 gdb_run_cmd
184 expect {
185 -re "Break.*break3 \\(\\) at .*$srcfile:$decimal.*$prompt $" {
186 pass "running to break3"
187 }
188 timeout { fail "(timeout) running to break3"; return }
189 }
190
191 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"] {
192 return
193 }
194 }
195
196 #
197 # Test signed bitfields for signedness and range.
198 # Fill the signed fields with the maximum positive value, then the maximally
199 # negative value, then -1, and verify in each case that the values are
200 # printed correctly.
201 #
202
203 proc bitfield_signedness {} {
204 global decimal
205 global hex
206 global prompt
207 global srcfile
208
209 delete_breakpoints
210
211 if [gdb_test "break break4" "Break.* at $hex: file .*$srcfile, line $decimal\\." "setting breakpoint at break4"] {
212 return
213 }
214
215 gdb_run_cmd
216 expect {
217 -re "Break.*break4 \\(\\) at .*$srcfile:$decimal.*$prompt $" {
218 pass "running to break4"
219 }
220 timeout { fail "(timeout) running to break4"; return }
221 }
222
223 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"] {
224 return
225 }
226
227 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] {
228 return
229 }
230
231 # Determine if the target has signed bitfields so we can xfail the
232 # the signed bitfield tests if it doesn't.
233 send_gdb "print i\n"
234 expect {
235 -re ".* = -256.*$prompt $" {
236 pass "determining signed-ness of bitfields"
237 }
238 -re ".* = 256.*$prompt $" {
239 pass "determining signed-ness of bitfields"
240 setup_xfail "*-*-*"
241 }
242 -re ".*$prompt $" {
243 fail "determining signed-ness of bitfields"
244 return
245 }
246 default { fail "determining signed-ness of bitfields" ; return }
247 }
248
249 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"] {
250 return
251 }
252
253 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] {
254 return
255 }
256
257 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"] {
258 return
259 }
260 }
261
262 gdb_start
263 gdb_reinitialize_dir $srcdir/$subdir
264 gdb_load ${binfile}
265
266 send_gdb "set print sevenbit-strings\n" ; expect -re "$prompt $"
267 bitfield_uniqueness
268 if [istarget "mips-idt-*"] then {
269 # Restart because IDT/SIM runs out of file descriptors.
270 gdb_exit
271 gdb_start
272 gdb_reinitialize_dir $srcdir/$subdir
273 gdb_load ${binfile}
274 }
275 bitfield_containment
276 if [istarget "mips-idt-*"] then {
277 # Restart because IDT/SIM runs out of file descriptors.
278 gdb_exit
279 gdb_start
280 gdb_reinitialize_dir $srcdir/$subdir
281 gdb_load ${binfile}
282 }
283 bitfield_unsignedness
284 if [istarget "mips-idt-*"] then {
285 # Restart because IDT/SIM runs out of file descriptors.
286 gdb_exit
287 gdb_start
288 gdb_reinitialize_dir $srcdir/$subdir
289 gdb_load ${binfile}
290 }
291 bitfield_signedness
This page took 0.045744 seconds and 4 git commands to generate.