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