gdb/testsuite/
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / bitfields.exp
CommitLineData
0b302171
JB
1# Copyright 1992, 1994-1995, 1997, 2007-2012 Free Software Foundation,
2# Inc.
c906108c
SS
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
e22f8b7c 6# the Free Software Foundation; either version 3 of the License, or
c906108c 7# (at your option) any later version.
e22f8b7c 8#
c906108c
SS
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
e22f8b7c 13#
c906108c 14# You should have received a copy of the GNU General Public License
e22f8b7c 15# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 16
c906108c
SS
17# This file was written by Fred Fish. (fnf@cygnus.com)
18
c906108c
SS
19
20set testfile "bitfields"
21set srcfile ${testfile}.c
22set binfile ${objdir}/${subdir}/${testfile}
23if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
b60f0898
JB
24 untested bitfields.exp
25 return -1
c906108c
SS
26}
27
28#
29# Test bitfield locating and uniqueness.
30# For each member, set that member to 1 and verify that the member (and only
31# that member) is 1, then reset it back to 0.
32#
33
34proc bitfield_uniqueness {} {
35 global decimal
36 global hex
37 global gdb_prompt
38 global srcfile
39
40 if { ! [runto break1] } {
41 gdb_suppress_tests;
42 }
43
44 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.*"] {
45 gdb_suppress_tests;
46 }
47 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] {
48 gdb_suppress_tests;
49 }
50 # Note that we check for s1 as either 1 or -1, so that failure to
51 # treat it correctly as a signed 1bit field (values 0 or -1) while
52 # printing its value does not cause a spurious failure. We do the
53 # signedness preservation test later.
54 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)"] {
55 gdb_suppress_tests;
56 }
57 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] {
58 gdb_suppress_tests;
59 }
60 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)"] {
61 gdb_suppress_tests;
62 }
63 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] {
64 gdb_suppress_tests;
65 }
66 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)"] {
67 gdb_suppress_tests;
68 }
69 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] {
70 gdb_suppress_tests;
71 }
72 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)"] {
73 gdb_suppress_tests;
74 }
75 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] {
76 gdb_suppress_tests;
77 }
78 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)"] {
79 gdb_suppress_tests;
80 }
81 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] {
82 gdb_suppress_tests;
83 }
84 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)"] {
85 gdb_suppress_tests
86 }
87 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] {
88 gdb_suppress_tests
89 }
90 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)"] {
91 gdb_suppress_tests
92 }
93 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] {
94 gdb_suppress_tests
95 }
96 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)"] {
97 gdb_suppress_tests
98 }
99 if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] {
100 gdb_suppress_tests
101 }
102 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)"] {
103 gdb_suppress_tests
104 }
105 # Hmmmm?
106 gdb_stop_suppressing_tests;
107}
108
109
110#
111# Test bitfield containment.
112# Fill alternating fields with all 1's and verify that none of the bits
113# "bleed over" to the other fields.
114#
115
116proc bitfield_containment {} {
117 global decimal
118 global hex
119 global gdb_prompt
120 global srcfile
121
122 delete_breakpoints
123
124 if { ![runto break2] } {
125 gdb_suppress_tests
126 }
127
128 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"] {
129 gdb_suppress_tests
130 }
131
132 if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] {
133 gdb_suppress_tests
134 }
135
136 # If program is compiled with Sun CC, then these print out as their
137 # actual sizes; if compiled with gcc, they print out as 0xffffffff
138 # (which strikes me as bogus, but accept it at least for now).
139 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"] {
140 gdb_suppress_tests
141 }
142 gdb_stop_suppressing_tests;
143}
144
145# Test unsigned bitfields for unsignedness and range.
146# Fill the unsigned fields with the maximum positive value and verify that
147# the values are printed correctly.
148
149proc bitfield_unsignedness {} {
150 global decimal
151 global hex
152 global gdb_prompt
153 global srcfile
154
155 delete_breakpoints
156
157 if { ![runto break3] } {
158 gdb_suppress_tests
159 }
160
161 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"] {
162 gdb_suppress_tests
163 }
164 gdb_stop_suppressing_tests;
165}
166
167#
168# Test signed bitfields for signedness and range.
169# Fill the signed fields with the maximum positive value, then the maximally
170# negative value, then -1, and verify in each case that the values are
171# printed correctly.
172#
173
174proc bitfield_signedness {} {
175 global decimal
176 global hex
177 global gdb_prompt
178 global srcfile
179
180 delete_breakpoints
181
182 if { ! [runto break4] } {
183 gdb_suppress_tests
184 }
185
186 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"] {
187 gdb_suppress_tests
188 }
189
190 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] {
191 gdb_suppress_tests
192 }
193
194 # Determine if the target has signed bitfields so we can xfail the
195 # the signed bitfield tests if it doesn't.
6acb16a2 196 gdb_test_multiple "print i" "determining signed-ness of bitfields" {
c906108c
SS
197 -re ".* = -256.*$gdb_prompt $" {
198 pass "determining signed-ness of bitfields"
199 }
200 -re ".* = 256.*$gdb_prompt $" {
201 pass "determining signed-ness of bitfields"
202 setup_xfail "*-*-*"
203 }
204 -re ".*$gdb_prompt $" {
205 fail "determining signed-ness of bitfields"
206 gdb_suppress_tests
207 }
208 default {
209 fail "determining signed-ness of bitfields" ;
210 gdb_suppress_tests;
211 }
212 }
213
214 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"] {
215 gdb_suppress_tests
216 }
217
218 if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] {
219 gdb_suppress_tests
220 }
221
222 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"] {
223 gdb_suppress_tests
224 }
225 # Hmmmm???
226 gdb_stop_suppressing_tests;
227}
228
4a76eae5
DJ
229# Test bitfields at non-zero offsets in a struct.
230
231proc bitfield_at_offset {} {
232 global decimal
233 global hex
234 global gdb_prompt
235 global srcfile
236
237 gdb_breakpoint break5
238 if [gdb_test "cont" "Break.*break5 \\(\\) at .*$srcfile:$decimal.*" "continuing to break5"] {
239 return
240 }
241
242 set one ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 5, s9 = 0, u9 = 0, sc = 0.*"
243 set two ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 3, s9 = 0, u9 = 0, sc = 0.*"
244 gdb_test "print container" "$one$two" "distinct bitfields in container"
245 gdb_test "print container.one.u3" ".* = 5"
246 gdb_test "print container.two.u3" ".* = 3"
247}
248
c906108c
SS
249gdb_start
250gdb_reinitialize_dir $srcdir/$subdir
251gdb_load ${binfile}
252
6acb16a2 253gdb_test_no_output "set print sevenbit-strings"
c906108c
SS
254
255bitfield_uniqueness
c906108c 256bitfield_containment
c906108c 257bitfield_unsignedness
c906108c 258bitfield_signedness
4a76eae5 259bitfield_at_offset
This page took 1.196365 seconds and 4 git commands to generate.