Commit | Line | Data |
---|---|---|
b6ba6518 | 1 | # Copyright 1992, 1994, 1995, 1997 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 | |
5 | # the Free Software Foundation; either version 2 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, write to the Free Software | |
15 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
16 | ||
17 | # Please email any bugs, comments, and/or additions to this file to: | |
18 | # bug-gdb@prep.ai.mit.edu | |
19 | ||
20 | # This file was written by Fred Fish. (fnf@cygnus.com) | |
21 | ||
22 | if $tracelevel then { | |
23 | strace $tracelevel | |
24 | } | |
25 | ||
26 | set prms_id 0 | |
27 | set bug_id 0 | |
28 | ||
29 | set testfile "bitfields" | |
30 | set srcfile ${testfile}.c | |
31 | set binfile ${objdir}/${subdir}/${testfile} | |
32 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { | |
33 | gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will automatically fail." | |
34 | } | |
35 | ||
36 | # | |
37 | # Test bitfield locating and uniqueness. | |
38 | # For each member, set that member to 1 and verify that the member (and only | |
39 | # that member) is 1, then reset it back to 0. | |
40 | # | |
41 | ||
42 | proc bitfield_uniqueness {} { | |
43 | global decimal | |
44 | global hex | |
45 | global gdb_prompt | |
46 | global srcfile | |
47 | ||
48 | if { ! [runto break1] } { | |
49 | gdb_suppress_tests; | |
50 | } | |
51 | ||
52 | 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.*"] { | |
53 | gdb_suppress_tests; | |
54 | } | |
55 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #1"] { | |
56 | gdb_suppress_tests; | |
57 | } | |
58 | # Note that we check for s1 as either 1 or -1, so that failure to | |
59 | # treat it correctly as a signed 1bit field (values 0 or -1) while | |
60 | # printing its value does not cause a spurious failure. We do the | |
61 | # signedness preservation test later. | |
62 | 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)"] { | |
63 | gdb_suppress_tests; | |
64 | } | |
65 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #2"] { | |
66 | gdb_suppress_tests; | |
67 | } | |
68 | 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)"] { | |
69 | gdb_suppress_tests; | |
70 | } | |
71 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #3"] { | |
72 | gdb_suppress_tests; | |
73 | } | |
74 | 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)"] { | |
75 | gdb_suppress_tests; | |
76 | } | |
77 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #4"] { | |
78 | gdb_suppress_tests; | |
79 | } | |
80 | 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)"] { | |
81 | gdb_suppress_tests; | |
82 | } | |
83 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #5"] { | |
84 | gdb_suppress_tests; | |
85 | } | |
86 | 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)"] { | |
87 | gdb_suppress_tests; | |
88 | } | |
89 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #6"] { | |
90 | gdb_suppress_tests; | |
91 | } | |
92 | 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)"] { | |
93 | gdb_suppress_tests | |
94 | } | |
95 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #7"] { | |
96 | gdb_suppress_tests | |
97 | } | |
98 | 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)"] { | |
99 | gdb_suppress_tests | |
100 | } | |
101 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #8"] { | |
102 | gdb_suppress_tests | |
103 | } | |
104 | 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)"] { | |
105 | gdb_suppress_tests | |
106 | } | |
107 | if [gdb_test "cont" "Break.*break1 \\(\\) at .*$srcfile:$decimal.*" "continuing to break1 #9"] { | |
108 | gdb_suppress_tests | |
109 | } | |
110 | 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)"] { | |
111 | gdb_suppress_tests | |
112 | } | |
113 | # Hmmmm? | |
114 | gdb_stop_suppressing_tests; | |
115 | } | |
116 | ||
117 | ||
118 | # | |
119 | # Test bitfield containment. | |
120 | # Fill alternating fields with all 1's and verify that none of the bits | |
121 | # "bleed over" to the other fields. | |
122 | # | |
123 | ||
124 | proc bitfield_containment {} { | |
125 | global decimal | |
126 | global hex | |
127 | global gdb_prompt | |
128 | global srcfile | |
129 | ||
130 | delete_breakpoints | |
131 | ||
132 | if { ![runto break2] } { | |
133 | gdb_suppress_tests | |
134 | } | |
135 | ||
136 | 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"] { | |
137 | gdb_suppress_tests | |
138 | } | |
139 | ||
140 | if [gdb_test "cont" "Break.*break2 \\(\\) at .*$srcfile:$decimal.*" "continuing to break2"] { | |
141 | gdb_suppress_tests | |
142 | } | |
143 | ||
144 | # If program is compiled with Sun CC, then these print out as their | |
145 | # actual sizes; if compiled with gcc, they print out as 0xffffffff | |
146 | # (which strikes me as bogus, but accept it at least for now). | |
147 | 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"] { | |
148 | gdb_suppress_tests | |
149 | } | |
150 | gdb_stop_suppressing_tests; | |
151 | } | |
152 | ||
153 | # Test unsigned bitfields for unsignedness and range. | |
154 | # Fill the unsigned fields with the maximum positive value and verify that | |
155 | # the values are printed correctly. | |
156 | ||
157 | proc bitfield_unsignedness {} { | |
158 | global decimal | |
159 | global hex | |
160 | global gdb_prompt | |
161 | global srcfile | |
162 | ||
163 | delete_breakpoints | |
164 | ||
165 | if { ![runto break3] } { | |
166 | gdb_suppress_tests | |
167 | } | |
168 | ||
169 | 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"] { | |
170 | gdb_suppress_tests | |
171 | } | |
172 | gdb_stop_suppressing_tests; | |
173 | } | |
174 | ||
175 | # | |
176 | # Test signed bitfields for signedness and range. | |
177 | # Fill the signed fields with the maximum positive value, then the maximally | |
178 | # negative value, then -1, and verify in each case that the values are | |
179 | # printed correctly. | |
180 | # | |
181 | ||
182 | proc bitfield_signedness {} { | |
183 | global decimal | |
184 | global hex | |
185 | global gdb_prompt | |
186 | global srcfile | |
187 | ||
188 | delete_breakpoints | |
189 | ||
190 | if { ! [runto break4] } { | |
191 | gdb_suppress_tests | |
192 | } | |
193 | ||
194 | 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"] { | |
195 | gdb_suppress_tests | |
196 | } | |
197 | ||
198 | if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #1"] { | |
199 | gdb_suppress_tests | |
200 | } | |
201 | ||
202 | # Determine if the target has signed bitfields so we can xfail the | |
203 | # the signed bitfield tests if it doesn't. | |
204 | send_gdb "print i\n" | |
205 | gdb_expect { | |
206 | -re ".* = -256.*$gdb_prompt $" { | |
207 | pass "determining signed-ness of bitfields" | |
208 | } | |
209 | -re ".* = 256.*$gdb_prompt $" { | |
210 | pass "determining signed-ness of bitfields" | |
211 | setup_xfail "*-*-*" | |
212 | } | |
213 | -re ".*$gdb_prompt $" { | |
214 | fail "determining signed-ness of bitfields" | |
215 | gdb_suppress_tests | |
216 | } | |
217 | default { | |
218 | fail "determining signed-ness of bitfields" ; | |
219 | gdb_suppress_tests; | |
220 | } | |
221 | } | |
222 | ||
223 | 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"] { | |
224 | gdb_suppress_tests | |
225 | } | |
226 | ||
227 | if [gdb_test "cont" "Break.*break4 \\(\\) at .*$srcfile:$decimal.*" "continuing to break4 #2"] { | |
228 | gdb_suppress_tests | |
229 | } | |
230 | ||
231 | 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"] { | |
232 | gdb_suppress_tests | |
233 | } | |
234 | # Hmmmm??? | |
235 | gdb_stop_suppressing_tests; | |
236 | } | |
237 | ||
238 | gdb_start | |
239 | gdb_reinitialize_dir $srcdir/$subdir | |
240 | gdb_load ${binfile} | |
241 | ||
242 | send_gdb "set print sevenbit-strings\n" ; gdb_expect -re "$gdb_prompt $" | |
243 | ||
244 | bitfield_uniqueness | |
245 | if [istarget "mips-idt-*"] then { | |
246 | # Restart because IDT/SIM runs out of file descriptors. | |
247 | gdb_exit | |
248 | gdb_start | |
249 | gdb_reinitialize_dir $srcdir/$subdir | |
250 | gdb_load ${binfile} | |
251 | } | |
252 | bitfield_containment | |
253 | if [istarget "mips-idt-*"] then { | |
254 | # Restart because IDT/SIM runs out of file descriptors. | |
255 | gdb_exit | |
256 | gdb_start | |
257 | gdb_reinitialize_dir $srcdir/$subdir | |
258 | gdb_load ${binfile} | |
259 | } | |
260 | bitfield_unsignedness | |
261 | if [istarget "mips-idt-*"] then { | |
262 | # Restart because IDT/SIM runs out of file descriptors. | |
263 | gdb_exit | |
264 | gdb_start | |
265 | gdb_reinitialize_dir $srcdir/$subdir | |
266 | gdb_load ${binfile} | |
267 | } | |
268 | bitfield_signedness |