Commit | Line | Data |
---|---|---|
88b9d363 | 1 | # Copyright 1992-2022 Free Software Foundation, Inc. |
c8170782 PH |
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 |
c8170782 | 6 | # (at your option) any later version. |
e22f8b7c | 7 | # |
c8170782 PH |
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 | # |
c8170782 | 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/>. |
c8170782 PH |
15 | |
16 | # This file was adapted from bitfields.exp by Paul Hilfinger | |
17 | # (Hilfinger@gnat.com) | |
18 | ||
19 | # | |
20 | # Tests for bit-fields that do not fit in type (unsigned) int, but do fit | |
21 | # in type (unsigned) long long. We perform essentially the same tests as | |
22 | # in bitfields.c, which considers only bit-fields that are <= 9 bits long. | |
23 | # | |
24 | ||
c8170782 | 25 | |
a64d2530 TT |
26 | standard_testfile .c |
27 | ||
c8170782 | 28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
84c93cd5 | 29 | untested "failed to compile" |
b60f0898 | 30 | return -1 |
c8170782 PH |
31 | } |
32 | ||
33 | set has_signed_bitfields 1 | |
34 | ||
35 | # | |
36 | # Continue to expected breakpoint at FUNCTION. Append TAG to make pass/fail | |
37 | # messages (to make them unique). Suppress tests on failure. | |
38 | # | |
39 | proc continue_test { function tag } { | |
40 | global decimal | |
41 | global srcfile | |
42 | ||
0ac85db5 | 43 | gdb_test "cont" "Break.*$function \\(\\) at .*$srcfile:$decimal.*" "continuing to $function $tag" |
c8170782 PH |
44 | } |
45 | ||
46 | # | |
47 | # Start next test by running to tester and then to FUNCTION. Suppresses | |
48 | # tests on failure. | |
49 | # | |
50 | proc start_test { function } { | |
51 | delete_breakpoints | |
0ac85db5 | 52 | gdb_test "break tester" ".*" "break tester prior to $function" |
c8170782 | 53 | continue_test "tester" "prior to $function" |
0ac85db5 | 54 | gdb_breakpoint $function |
c8170782 PH |
55 | continue_test $function "#0" |
56 | } | |
57 | ||
58 | ||
59 | # | |
60 | # Test bitfield locating and uniqueness. | |
61 | # For each member, set that member to 1 and verify that the member (and only | |
62 | # that member) is 1, then reset it back to 0. | |
63 | # | |
64 | ||
65 | proc bitfield_uniqueness {} { | |
66 | global decimal | |
67 | global hex | |
68 | global gdb_prompt | |
69 | global srcfile | |
70 | ||
71 | start_test break1 | |
0ac85db5 SM |
72 | |
73 | gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 1, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.s1 = 1" | |
c8170782 | 74 | continue_test break1 "#1" |
0ac85db5 | 75 | gdb_test "print flags" ".*u1 = 1, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u1 = 1" |
c8170782 | 76 | continue_test break1 "#2" |
0ac85db5 | 77 | gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 1, s3 = 0.*" "bitfield uniqueness; flags.s2 = 1" |
c8170782 | 78 | continue_test break1 "#3" |
0ac85db5 | 79 | gdb_test "print flags" ".*u1 = 0, u2 = 1, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u2 = 1" |
c8170782 | 80 | continue_test break1 "#4" |
0ac85db5 | 81 | gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 1.*" "bitfield uniqueness; flags.s3 = 1" |
c8170782 | 82 | continue_test break1 "#5" |
0ac85db5 | 83 | gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 1, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u3 = 1" |
c8170782 PH |
84 | } |
85 | ||
86 | ||
87 | # | |
88 | # Test bitfield containment. | |
89 | # Fill alternating fields with all 1's and verify that none of the bits | |
90 | # "bleed over" to the other fields. | |
91 | # | |
92 | ||
93 | proc bitfield_containment {} { | |
94 | global decimal | |
95 | global hex | |
96 | global gdb_prompt | |
97 | global srcfile | |
98 | ||
99 | start_test break2 | |
100 | ||
101 | # If program is compiled with Sun CC, signed fields print out as their | |
102 | # actual sizes; if compiled with gcc, they print out as 0xffffffff. | |
0ac85db5 | 103 | gdb_test "print/x flags" "= {u1 = 0x7fff, u2 = 0x0, u3 = 0xffff, s1 = 0x0, s2 = 0x(1ffffffff|f*), s3 = 0x0}" "bitfield containment; flags.u1, flags.u3, and flags.s3 to all 1s" |
c8170782 PH |
104 | |
105 | continue_test break2 "#1" | |
106 | ||
0ac85db5 | 107 | gdb_test "print/x flags" "= {u1 = 0x0, u2 = 0x1ffffffff, u3 = 0x0, s1 = 0x(7fff|f*), s2 = 0x0, s3 = 0xf*}" "bitfield containment; flags.u2, flags.s1, flags.s2 to all 1s" |
c8170782 PH |
108 | } |
109 | ||
110 | # Test unsigned bitfields for unsignedness and range. | |
111 | # Fill the unsigned fields with the maximum positive value and verify that | |
112 | # the values are printed correctly. | |
113 | ||
114 | proc bitfield_unsignedness {} { | |
115 | global decimal | |
116 | global hex | |
117 | global gdb_prompt | |
118 | global srcfile | |
119 | ||
120 | start_test break3 | |
121 | ||
0ac85db5 | 122 | gdb_test "print flags" ".*u1 = 32767, u2 = 8589934591, u3 = 65535, s1 = 0, s2 = 0, s3 = 0.*" "maximum unsigned bitfield values" |
c8170782 PH |
123 | } |
124 | ||
125 | # | |
126 | # Test signed bitfields for signedness and range. | |
127 | # Fill the signed fields with the maximum positive value, then the maximally | |
128 | # negative value, then -1, and verify in each case that the values are | |
129 | # printed correctly. | |
130 | # | |
131 | ||
132 | proc bitfield_signedness {} { | |
133 | global decimal | |
134 | global hex | |
135 | global gdb_prompt | |
136 | global srcfile | |
137 | global has_signed_bitfields | |
138 | ||
139 | start_test break4 | |
140 | ||
0ac85db5 | 141 | gdb_test "print flags" "= {.*u1 = 0, u2 = 0, u3 = 0, s1 = 16383, s2 = 4294967295, s3 = 32767.*}" "maximum signed bitfield values" |
c8170782 PH |
142 | |
143 | continue_test break4 "#1" | |
144 | ||
145 | # Determine if the target has signed bitfields so we can skip | |
146 | # the signed bitfield tests if it doesn't. | |
147 | set test "determining signed-ness of bitfields" | |
148 | set has_signed_bitfields 0 | |
149 | gdb_test_multiple "print i" $test { | |
150 | -re ".* = -32768.*$gdb_prompt $" { | |
151 | set has_signed_bitfields 1 | |
152 | pass "determining signed-ness of bitfields" | |
153 | } | |
154 | -re ".* = 32768.*$gdb_prompt $" { | |
155 | pass "determining signed-ness of bitfields" | |
156 | } | |
157 | -re ".*$gdb_prompt $" { | |
158 | fail "determining signed-ness of bitfields" | |
c8170782 PH |
159 | } |
160 | } | |
161 | ||
162 | set test "most negative signed bitfield values" | |
163 | if $has_signed_bitfields then { | |
0ac85db5 | 164 | gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -16384, s2 = -4294967296, s3 = -32768.*" $test |
c8170782 PH |
165 | } else { |
166 | unsupported $test | |
167 | } | |
168 | ||
169 | continue_test break4 "#2" | |
170 | ||
171 | set test "signed bitfields containing -1" | |
172 | if $has_signed_bitfields then { | |
0ac85db5 | 173 | gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -1, s2 = -1, s3 = -1.*" $test |
c8170782 PH |
174 | } else { |
175 | unsupported $test | |
176 | } | |
c8170782 PH |
177 | } |
178 | ||
179 | ||
180 | # Test setting of long long bit fields from within GDB. | |
181 | ||
182 | proc bitfield_set {} { | |
183 | global decimal | |
184 | global hex | |
185 | global gdb_prompt | |
186 | global srcfile | |
187 | global has_signed_bitfields | |
188 | ||
189 | start_test break5 | |
190 | ||
191 | set big_set_failed 0 | |
192 | set test "set long long unsigned bitfield" | |
193 | gdb_test_multiple "print flags.u2 = 0x100000000" $test { | |
194 | -re "warning: Value does not fit.*$gdb_prompt $" { | |
195 | fail "$test" | |
c8170782 PH |
196 | } |
197 | -re "= 4294967296.*$gdb_prompt $" { | |
198 | pass "$test" | |
199 | } | |
200 | } | |
201 | ||
202 | set test "set long long signed bitfield positive" | |
203 | gdb_test_multiple "print flags.s2 = 0x80000000" $test { | |
204 | -re "warning: Value does not fit.*$gdb_prompt $" { | |
205 | fail "$test" | |
c8170782 PH |
206 | } |
207 | -re "= 2147483648.*$gdb_prompt $" { | |
208 | pass "$test" | |
209 | } | |
210 | } | |
211 | ||
0ac85db5 | 212 | gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = 2147483648, s3 = 0.*" "long long bitfield values after set" |
c8170782 PH |
213 | |
214 | set test "set long long signed bitfield negative" | |
215 | if $has_signed_bitfields then { | |
216 | gdb_test_multiple "print flags.s2 = -1" $test { | |
217 | -re "warning: Value does not fit.*$gdb_prompt $" { | |
218 | fail "$test" | |
c8170782 PH |
219 | } |
220 | -re "= -1.*$gdb_prompt $" { | |
221 | pass "$test" | |
222 | } | |
223 | } | |
224 | } else { | |
225 | unsupported $test | |
226 | } | |
227 | ||
228 | set test "long long bitfield values after set negative" | |
229 | if $has_signed_bitfields then { | |
0ac85db5 | 230 | gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = -1, s3 = 0.*" $test |
c8170782 PH |
231 | } else { |
232 | unsupported $test | |
233 | } | |
c8170782 PH |
234 | } |
235 | ||
a64d2530 | 236 | clean_restart ${binfile} |
c8170782 | 237 | |
6acb16a2 | 238 | gdb_test_no_output "set print sevenbit-strings" |
c8170782 PH |
239 | runto_main |
240 | ||
241 | bitfield_uniqueness | |
242 | bitfield_containment | |
243 | bitfield_unsignedness | |
244 | bitfield_signedness | |
245 | bitfield_set | |
246 |