Remove superfluous semicolons from testsuite throughout.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields2.exp
1 # Copyright 1992-2013 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 adapted from bitfields.exp by Paul Hilfinger
17 # (Hilfinger@gnat.com)
18
19 #
20 # Tests for bit-fields that do not fit in type (unsigned) int, but do fit
21 # in type (unsigned) long long. We perform essentially the same tests as
22 # in bitfields.c, which considers only bit-fields that are <= 9 bits long.
23 #
24
25
26 set testfile "bitfields2"
27 set srcfile ${testfile}.c
28 set binfile ${objdir}/${subdir}/${testfile}
29 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
30 untested bitfields2.exp
31 return -1
32 }
33
34 set has_signed_bitfields 1
35
36 #
37 # Continue to expected breakpoint at FUNCTION. Append TAG to make pass/fail
38 # messages (to make them unique). Suppress tests on failure.
39 #
40 proc continue_test { function tag } {
41 global decimal
42 global srcfile
43
44 if [gdb_test "cont" "Break.*$function \\(\\) at .*$srcfile:$decimal.*" "continuing to $function $tag"] {
45 gdb_suppress_tests
46 }
47 }
48
49 #
50 # Start next test by running to tester and then to FUNCTION. Suppresses
51 # tests on failure.
52 #
53 proc start_test { function } {
54 delete_breakpoints
55 if [gdb_test "break tester" ".*" "break tester prior to $function"] {
56 gdb_suppress_tests
57 }
58 continue_test "tester" "prior to $function"
59 if ![gdb_breakpoint $function] {
60 gdb_suppress_tests
61 }
62 continue_test $function "#0"
63 }
64
65
66 #
67 # Test bitfield locating and uniqueness.
68 # For each member, set that member to 1 and verify that the member (and only
69 # that member) is 1, then reset it back to 0.
70 #
71
72 proc bitfield_uniqueness {} {
73 global decimal
74 global hex
75 global gdb_prompt
76 global srcfile
77
78 start_test break1
79
80 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 1, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.s1 = 1"] {
81 gdb_suppress_tests
82 }
83 continue_test break1 "#1"
84 if [gdb_test "print flags" ".*u1 = 1, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u1 = 1"] {
85 gdb_suppress_tests
86 }
87 continue_test break1 "#2"
88 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 1, s3 = 0.*" "bitfield uniqueness; flags.s2 = 1"] {
89 gdb_suppress_tests
90 }
91 continue_test break1 "#3"
92 if [gdb_test "print flags" ".*u1 = 0, u2 = 1, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u2 = 1"] {
93 gdb_suppress_tests
94 }
95 continue_test break1 "#4"
96 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 1.*" "bitfield uniqueness; flags.s3 = 1"] {
97 gdb_suppress_tests
98 }
99 continue_test break1 "#5"
100 if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 1, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u3 = 1"] {
101 gdb_suppress_tests
102 }
103 gdb_stop_suppressing_tests
104 }
105
106
107 #
108 # Test bitfield containment.
109 # Fill alternating fields with all 1's and verify that none of the bits
110 # "bleed over" to the other fields.
111 #
112
113 proc bitfield_containment {} {
114 global decimal
115 global hex
116 global gdb_prompt
117 global srcfile
118
119 start_test break2
120
121 # If program is compiled with Sun CC, signed fields print out as their
122 # actual sizes; if compiled with gcc, they print out as 0xffffffff.
123 if [gdb_test "print/x flags" "= {u1 = 0x7fff, u2 = 0x0, u3 = 0xffff, s1 = 0x0, s2 = 0x(1ffffffff|f*), s3 = 0x0}" "bitfield containment; flags.u1, flags.u3, and flags.s3 to all 1s"] {
124 gdb_suppress_tests
125 }
126
127 continue_test break2 "#1"
128
129 if [gdb_test "print/x flags" "= {u1 = 0x0, u2 = 0x1ffffffff, u3 = 0x0, s1 = 0x(7fff|f*), s2 = 0x0, s3 = 0xf*}" "bitfield containment; flags.u2, flags.s1, flags.s2 to all 1s"] {
130 gdb_suppress_tests
131 }
132 gdb_stop_suppressing_tests
133 }
134
135 # Test unsigned bitfields for unsignedness and range.
136 # Fill the unsigned fields with the maximum positive value and verify that
137 # the values are printed correctly.
138
139 proc bitfield_unsignedness {} {
140 global decimal
141 global hex
142 global gdb_prompt
143 global srcfile
144
145 start_test break3
146
147 if [gdb_test "print flags" ".*u1 = 32767, u2 = 8589934591, u3 = 65535, s1 = 0, s2 = 0, s3 = 0.*" "maximum unsigned bitfield values"] {
148 gdb_suppress_tests
149 }
150 gdb_stop_suppressing_tests
151 }
152
153 #
154 # Test signed bitfields for signedness and range.
155 # Fill the signed fields with the maximum positive value, then the maximally
156 # negative value, then -1, and verify in each case that the values are
157 # printed correctly.
158 #
159
160 proc bitfield_signedness {} {
161 global decimal
162 global hex
163 global gdb_prompt
164 global srcfile
165 global has_signed_bitfields
166
167 start_test break4
168
169 if [gdb_test "print flags" "= {.*u1 = 0, u2 = 0, u3 = 0, s1 = 16383, s2 = 4294967295, s3 = 32767.*}" "maximum signed bitfield values"] {
170 gdb_suppress_tests
171 }
172
173 continue_test break4 "#1"
174
175 # Determine if the target has signed bitfields so we can skip
176 # the signed bitfield tests if it doesn't.
177 set test "determining signed-ness of bitfields"
178 set has_signed_bitfields 0
179 gdb_test_multiple "print i" $test {
180 -re ".* = -32768.*$gdb_prompt $" {
181 set has_signed_bitfields 1
182 pass "determining signed-ness of bitfields"
183 }
184 -re ".* = 32768.*$gdb_prompt $" {
185 pass "determining signed-ness of bitfields"
186 }
187 -re ".*$gdb_prompt $" {
188 fail "determining signed-ness of bitfields"
189 gdb_suppress_tests
190 }
191 }
192
193 set test "most negative signed bitfield values"
194 if $has_signed_bitfields then {
195 if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -16384, s2 = -4294967296, s3 = -32768.*" $test ] {
196 gdb_suppress_tests
197 }
198 } else {
199 unsupported $test
200 }
201
202 continue_test break4 "#2"
203
204 set test "signed bitfields containing -1"
205 if $has_signed_bitfields then {
206 if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -1, s2 = -1, s3 = -1.*" $test ] {
207 gdb_suppress_tests
208 }
209 } else {
210 unsupported $test
211 }
212
213 gdb_stop_suppressing_tests
214 }
215
216
217 # Test setting of long long bit fields from within GDB.
218
219 proc bitfield_set {} {
220 global decimal
221 global hex
222 global gdb_prompt
223 global srcfile
224 global has_signed_bitfields
225
226 start_test break5
227
228 set big_set_failed 0
229 set test "set long long unsigned bitfield"
230 gdb_test_multiple "print flags.u2 = 0x100000000" $test {
231 -re "warning: Value does not fit.*$gdb_prompt $" {
232 fail "$test"
233 gdb_suppress_tests
234 }
235 -re "= 4294967296.*$gdb_prompt $" {
236 pass "$test"
237 }
238 }
239
240 set test "set long long signed bitfield positive"
241 gdb_test_multiple "print flags.s2 = 0x80000000" $test {
242 -re "warning: Value does not fit.*$gdb_prompt $" {
243 fail "$test"
244 gdb_suppress_tests
245 }
246 -re "= 2147483648.*$gdb_prompt $" {
247 pass "$test"
248 }
249 }
250
251 if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = 2147483648, s3 = 0.*" "long long bitfield values after set"] {
252 gdb_suppress_tests
253 }
254
255 set test "set long long signed bitfield negative"
256 if $has_signed_bitfields then {
257 gdb_test_multiple "print flags.s2 = -1" $test {
258 -re "warning: Value does not fit.*$gdb_prompt $" {
259 fail "$test"
260 gdb_suppress_tests
261 }
262 -re "= -1.*$gdb_prompt $" {
263 pass "$test"
264 }
265 }
266 } else {
267 unsupported $test
268 }
269
270 set test "long long bitfield values after set negative"
271 if $has_signed_bitfields then {
272 if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = -1, s3 = 0.*" $test] {
273 gdb_suppress_tests
274 }
275 } else {
276 unsupported $test
277 }
278
279 gdb_stop_suppressing_tests
280 }
281
282 gdb_start
283 gdb_reinitialize_dir $srcdir/$subdir
284 gdb_load ${binfile}
285
286 gdb_test_no_output "set print sevenbit-strings"
287 runto_main
288
289 bitfield_uniqueness
290 bitfield_containment
291 bitfield_unsignedness
292 bitfield_signedness
293 bitfield_set
294
This page took 0.041373 seconds and 4 git commands to generate.