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