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