Commit | Line | Data |
---|---|---|
ecd75fc8 | 1 | # Copyright 1992-2014 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 | 18 | |
a64d2530 TT |
19 | standard_testfile |
20 | ||
21 | if {[prepare_for_testing $testfile.exp $testfile $srcfile debug]} { | |
22 | untested $testfile.exp | |
b60f0898 | 23 | return -1 |
c906108c SS |
24 | } |
25 | ||
26 | # | |
27 | # Test bitfield locating and uniqueness. | |
28 | # For each member, set that member to 1 and verify that the member (and only | |
29 | # that member) is 1, then reset it back to 0. | |
30 | # | |
31 | ||
32 | proc bitfield_uniqueness {} { | |
33 | global decimal | |
34 | global hex | |
35 | global gdb_prompt | |
36 | global srcfile | |
37 | ||
38 | if { ! [runto break1] } { | |
4ec70201 | 39 | gdb_suppress_tests |
c906108c SS |
40 | } |
41 | ||
42 | 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.*"] { | |
4ec70201 | 43 | gdb_suppress_tests |
c906108c SS |
44 | } |
45 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] { | |
4ec70201 | 46 | gdb_suppress_tests |
c906108c SS |
47 | } |
48 | # Note that we check for s1 as either 1 or -1, so that failure to | |
49 | # treat it correctly as a signed 1bit field (values 0 or -1) while | |
50 | # printing its value does not cause a spurious failure. We do the | |
51 | # signedness preservation test later. | |
52 | 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)"] { | |
4ec70201 | 53 | gdb_suppress_tests |
c906108c SS |
54 | } |
55 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] { | |
4ec70201 | 56 | gdb_suppress_tests |
c906108c SS |
57 | } |
58 | 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)"] { | |
4ec70201 | 59 | gdb_suppress_tests |
c906108c SS |
60 | } |
61 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] { | |
4ec70201 | 62 | gdb_suppress_tests |
c906108c SS |
63 | } |
64 | 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)"] { | |
4ec70201 | 65 | gdb_suppress_tests |
c906108c SS |
66 | } |
67 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] { | |
4ec70201 | 68 | gdb_suppress_tests |
c906108c SS |
69 | } |
70 | 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)"] { | |
4ec70201 | 71 | gdb_suppress_tests |
c906108c SS |
72 | } |
73 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] { | |
4ec70201 | 74 | gdb_suppress_tests |
c906108c SS |
75 | } |
76 | 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)"] { | |
4ec70201 | 77 | gdb_suppress_tests |
c906108c SS |
78 | } |
79 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] { | |
4ec70201 | 80 | gdb_suppress_tests |
c906108c SS |
81 | } |
82 | 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)"] { | |
83 | gdb_suppress_tests | |
84 | } | |
85 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] { | |
86 | gdb_suppress_tests | |
87 | } | |
88 | 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)"] { | |
89 | gdb_suppress_tests | |
90 | } | |
91 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] { | |
92 | gdb_suppress_tests | |
93 | } | |
94 | 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)"] { | |
95 | gdb_suppress_tests | |
96 | } | |
97 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] { | |
98 | gdb_suppress_tests | |
99 | } | |
100 | 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)"] { | |
101 | gdb_suppress_tests | |
102 | } | |
103 | # Hmmmm? | |
4ec70201 | 104 | gdb_stop_suppressing_tests |
c906108c SS |
105 | } |
106 | ||
107 | ||
108 | # | |
109 | # Test bitfield containment. | |
110 | # Fill alternating fields with all 1's and verify that none of the bits | |
111 | # "bleed over" to the other fields. | |
112 | # | |
113 | ||
114 | proc bitfield_containment {} { | |
115 | global decimal | |
116 | global hex | |
117 | global gdb_prompt | |
118 | global srcfile | |
119 | ||
120 | delete_breakpoints | |
121 | ||
122 | if { ![runto break2] } { | |
123 | gdb_suppress_tests | |
124 | } | |
125 | ||
126 | 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"] { | |
127 | gdb_suppress_tests | |
128 | } | |
129 | ||
130 | if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] { | |
131 | gdb_suppress_tests | |
132 | } | |
133 | ||
134 | # If program is compiled with Sun CC, then these print out as their | |
135 | # actual sizes; if compiled with gcc, they print out as 0xffffffff | |
136 | # (which strikes me as bogus, but accept it at least for now). | |
137 | 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"] { | |
138 | gdb_suppress_tests | |
139 | } | |
4ec70201 | 140 | gdb_stop_suppressing_tests |
c906108c SS |
141 | } |
142 | ||
143 | # Test unsigned bitfields for unsignedness and range. | |
144 | # Fill the unsigned fields with the maximum positive value and verify that | |
145 | # the values are printed correctly. | |
146 | ||
147 | proc bitfield_unsignedness {} { | |
148 | global decimal | |
149 | global hex | |
150 | global gdb_prompt | |
151 | global srcfile | |
152 | ||
153 | delete_breakpoints | |
154 | ||
155 | if { ![runto break3] } { | |
156 | gdb_suppress_tests | |
157 | } | |
158 | ||
159 | 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"] { | |
160 | gdb_suppress_tests | |
161 | } | |
4ec70201 | 162 | gdb_stop_suppressing_tests |
c906108c SS |
163 | } |
164 | ||
165 | # | |
166 | # Test signed bitfields for signedness and range. | |
167 | # Fill the signed fields with the maximum positive value, then the maximally | |
168 | # negative value, then -1, and verify in each case that the values are | |
169 | # printed correctly. | |
170 | # | |
171 | ||
172 | proc bitfield_signedness {} { | |
173 | global decimal | |
174 | global hex | |
175 | global gdb_prompt | |
176 | global srcfile | |
177 | ||
178 | delete_breakpoints | |
179 | ||
180 | if { ! [runto break4] } { | |
181 | gdb_suppress_tests | |
182 | } | |
183 | ||
184 | 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"] { | |
185 | gdb_suppress_tests | |
186 | } | |
187 | ||
188 | if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] { | |
189 | gdb_suppress_tests | |
190 | } | |
191 | ||
192 | # Determine if the target has signed bitfields so we can xfail the | |
193 | # the signed bitfield tests if it doesn't. | |
6acb16a2 | 194 | gdb_test_multiple "print i" "determining signed-ness of bitfields" { |
c906108c SS |
195 | -re ".* = -256.*$gdb_prompt $" { |
196 | pass "determining signed-ness of bitfields" | |
197 | } | |
198 | -re ".* = 256.*$gdb_prompt $" { | |
199 | pass "determining signed-ness of bitfields" | |
200 | setup_xfail "*-*-*" | |
201 | } | |
202 | -re ".*$gdb_prompt $" { | |
203 | fail "determining signed-ness of bitfields" | |
204 | gdb_suppress_tests | |
205 | } | |
206 | default { | |
4ec70201 PA |
207 | fail "determining signed-ness of bitfields" |
208 | gdb_suppress_tests | |
c906108c SS |
209 | } |
210 | } | |
211 | ||
212 | 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"] { | |
213 | gdb_suppress_tests | |
214 | } | |
215 | ||
216 | if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] { | |
217 | gdb_suppress_tests | |
218 | } | |
219 | ||
220 | 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"] { | |
221 | gdb_suppress_tests | |
222 | } | |
223 | # Hmmmm??? | |
4ec70201 | 224 | gdb_stop_suppressing_tests |
c906108c SS |
225 | } |
226 | ||
4a76eae5 DJ |
227 | # Test bitfields at non-zero offsets in a struct. |
228 | ||
229 | proc bitfield_at_offset {} { | |
230 | global decimal | |
231 | global hex | |
232 | global gdb_prompt | |
233 | global srcfile | |
234 | ||
235 | gdb_breakpoint break5 | |
236 | if [gdb_test "cont" "Break.*break5 \\(\\) at .*$srcfile:$decimal.*" "continuing to break5"] { | |
237 | return | |
238 | } | |
239 | ||
240 | set one ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 5, s9 = 0, u9 = 0, sc = 0.*" | |
241 | set two ".*uc = 0 .*, s1 = 0, u1 = 0, s2 = 0, u2 = 0, s3 = 0, u3 = 3, s9 = 0, u9 = 0, sc = 0.*" | |
242 | gdb_test "print container" "$one$two" "distinct bitfields in container" | |
243 | gdb_test "print container.one.u3" ".* = 5" | |
244 | gdb_test "print container.two.u3" ".* = 3" | |
245 | } | |
246 | ||
d9e98382 SDJ |
247 | proc bitfield_internalvar {} { |
248 | global gdb_prompt | |
249 | ||
250 | # First, we create an internal var holding an instance of | |
251 | # the struct (zeroed out). | |
252 | gdb_test "set \$myvar = (struct internalvartest) \{0\}" "" \ | |
253 | "set internal var" | |
254 | ||
255 | # Now, we set the proper bits. | |
256 | gdb_test_no_output "set \$myvar.a = 0" | |
257 | gdb_test_no_output "set \$myvar.inner.b = 1" | |
258 | gdb_test_no_output "set \$myvar.inner.deep.c = 0" | |
259 | gdb_test_no_output "set \$myvar.inner.deep.d = -1" | |
260 | gdb_test_no_output "set \$myvar.inner.e = 1" | |
261 | gdb_test_no_output "set \$myvar.f = 1" | |
262 | ||
263 | # Here comes the true testing. | |
264 | gdb_test "print \$myvar.a" "\\$\[0-9\]\+ = 0" | |
265 | gdb_test "print \$myvar.inner.b" "\\$\[0-9\]\+ = 1" | |
266 | gdb_test "print \$myvar.inner.deep.c" "\\$\[0-9\]\+ = 0" | |
267 | gdb_test "print \$myvar.inner.deep.d" "\\$\[0-9\]\+ = -1" | |
268 | gdb_test "print \$myvar.inner.e" "\\$\[0-9\]\+ = -1" | |
269 | gdb_test "print \$myvar.f" "\\$\[0-9\]\+ = -1" | |
270 | } | |
271 | ||
6acb16a2 | 272 | gdb_test_no_output "set print sevenbit-strings" |
c906108c SS |
273 | |
274 | bitfield_uniqueness | |
c906108c | 275 | bitfield_containment |
c906108c | 276 | bitfield_unsignedness |
c906108c | 277 | bitfield_signedness |
4a76eae5 | 278 | bitfield_at_offset |
d9e98382 | 279 | bitfield_internalvar |