| 1 | # Copyright 1992-2016 Free Software Foundation, Inc. |
| 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 3 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, see <http://www.gnu.org/licenses/>. |
| 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 | |
| 25 | |
| 26 | standard_testfile .c |
| 27 | |
| 28 | if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } { |
| 29 | untested bitfields2.exp |
| 30 | return -1 |
| 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 | |
| 43 | if [gdb_test "cont" "Break.*$function \\(\\) at .*$srcfile:$decimal.*" "continuing to $function $tag"] { |
| 44 | gdb_suppress_tests |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | # |
| 49 | # Start next test by running to tester and then to FUNCTION. Suppresses |
| 50 | # tests on failure. |
| 51 | # |
| 52 | proc start_test { function } { |
| 53 | delete_breakpoints |
| 54 | if [gdb_test "break tester" ".*" "break tester prior to $function"] { |
| 55 | gdb_suppress_tests |
| 56 | } |
| 57 | continue_test "tester" "prior to $function" |
| 58 | if ![gdb_breakpoint $function] { |
| 59 | gdb_suppress_tests |
| 60 | } |
| 61 | continue_test $function "#0" |
| 62 | } |
| 63 | |
| 64 | |
| 65 | # |
| 66 | # Test bitfield locating and uniqueness. |
| 67 | # For each member, set that member to 1 and verify that the member (and only |
| 68 | # that member) is 1, then reset it back to 0. |
| 69 | # |
| 70 | |
| 71 | proc bitfield_uniqueness {} { |
| 72 | global decimal |
| 73 | global hex |
| 74 | global gdb_prompt |
| 75 | global srcfile |
| 76 | |
| 77 | start_test break1 |
| 78 | |
| 79 | if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 1, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.s1 = 1"] { |
| 80 | gdb_suppress_tests |
| 81 | } |
| 82 | continue_test break1 "#1" |
| 83 | if [gdb_test "print flags" ".*u1 = 1, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u1 = 1"] { |
| 84 | gdb_suppress_tests |
| 85 | } |
| 86 | continue_test break1 "#2" |
| 87 | if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 1, s3 = 0.*" "bitfield uniqueness; flags.s2 = 1"] { |
| 88 | gdb_suppress_tests |
| 89 | } |
| 90 | continue_test break1 "#3" |
| 91 | if [gdb_test "print flags" ".*u1 = 0, u2 = 1, u3 = 0, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u2 = 1"] { |
| 92 | gdb_suppress_tests |
| 93 | } |
| 94 | continue_test break1 "#4" |
| 95 | if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 0, s1 = 0, s2 = 0, s3 = 1.*" "bitfield uniqueness; flags.s3 = 1"] { |
| 96 | gdb_suppress_tests |
| 97 | } |
| 98 | continue_test break1 "#5" |
| 99 | if [gdb_test "print flags" ".*u1 = 0, u2 = 0, u3 = 1, s1 = 0, s2 = 0, s3 = 0.*" "bitfield uniqueness; flags.u3 = 1"] { |
| 100 | gdb_suppress_tests |
| 101 | } |
| 102 | gdb_stop_suppressing_tests |
| 103 | } |
| 104 | |
| 105 | |
| 106 | # |
| 107 | # Test bitfield containment. |
| 108 | # Fill alternating fields with all 1's and verify that none of the bits |
| 109 | # "bleed over" to the other fields. |
| 110 | # |
| 111 | |
| 112 | proc bitfield_containment {} { |
| 113 | global decimal |
| 114 | global hex |
| 115 | global gdb_prompt |
| 116 | global srcfile |
| 117 | |
| 118 | start_test break2 |
| 119 | |
| 120 | # If program is compiled with Sun CC, signed fields print out as their |
| 121 | # actual sizes; if compiled with gcc, they print out as 0xffffffff. |
| 122 | if [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"] { |
| 123 | gdb_suppress_tests |
| 124 | } |
| 125 | |
| 126 | continue_test break2 "#1" |
| 127 | |
| 128 | if [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"] { |
| 129 | gdb_suppress_tests |
| 130 | } |
| 131 | gdb_stop_suppressing_tests |
| 132 | } |
| 133 | |
| 134 | # Test unsigned bitfields for unsignedness and range. |
| 135 | # Fill the unsigned fields with the maximum positive value and verify that |
| 136 | # the values are printed correctly. |
| 137 | |
| 138 | proc bitfield_unsignedness {} { |
| 139 | global decimal |
| 140 | global hex |
| 141 | global gdb_prompt |
| 142 | global srcfile |
| 143 | |
| 144 | start_test break3 |
| 145 | |
| 146 | if [gdb_test "print flags" ".*u1 = 32767, u2 = 8589934591, u3 = 65535, s1 = 0, s2 = 0, s3 = 0.*" "maximum unsigned bitfield values"] { |
| 147 | gdb_suppress_tests |
| 148 | } |
| 149 | gdb_stop_suppressing_tests |
| 150 | } |
| 151 | |
| 152 | # |
| 153 | # Test signed bitfields for signedness and range. |
| 154 | # Fill the signed fields with the maximum positive value, then the maximally |
| 155 | # negative value, then -1, and verify in each case that the values are |
| 156 | # printed correctly. |
| 157 | # |
| 158 | |
| 159 | proc bitfield_signedness {} { |
| 160 | global decimal |
| 161 | global hex |
| 162 | global gdb_prompt |
| 163 | global srcfile |
| 164 | global has_signed_bitfields |
| 165 | |
| 166 | start_test break4 |
| 167 | |
| 168 | if [gdb_test "print flags" "= {.*u1 = 0, u2 = 0, u3 = 0, s1 = 16383, s2 = 4294967295, s3 = 32767.*}" "maximum signed bitfield values"] { |
| 169 | gdb_suppress_tests |
| 170 | } |
| 171 | |
| 172 | continue_test break4 "#1" |
| 173 | |
| 174 | # Determine if the target has signed bitfields so we can skip |
| 175 | # the signed bitfield tests if it doesn't. |
| 176 | set test "determining signed-ness of bitfields" |
| 177 | set has_signed_bitfields 0 |
| 178 | gdb_test_multiple "print i" $test { |
| 179 | -re ".* = -32768.*$gdb_prompt $" { |
| 180 | set has_signed_bitfields 1 |
| 181 | pass "determining signed-ness of bitfields" |
| 182 | } |
| 183 | -re ".* = 32768.*$gdb_prompt $" { |
| 184 | pass "determining signed-ness of bitfields" |
| 185 | } |
| 186 | -re ".*$gdb_prompt $" { |
| 187 | fail "determining signed-ness of bitfields" |
| 188 | gdb_suppress_tests |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | set test "most negative signed bitfield values" |
| 193 | if $has_signed_bitfields then { |
| 194 | if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -16384, s2 = -4294967296, s3 = -32768.*" $test ] { |
| 195 | gdb_suppress_tests |
| 196 | } |
| 197 | } else { |
| 198 | unsupported $test |
| 199 | } |
| 200 | |
| 201 | continue_test break4 "#2" |
| 202 | |
| 203 | set test "signed bitfields containing -1" |
| 204 | if $has_signed_bitfields then { |
| 205 | if [gdb_test "print flags" "u1 = 0, u2 = 0, u3 = 0, s1 = -1, s2 = -1, s3 = -1.*" $test ] { |
| 206 | gdb_suppress_tests |
| 207 | } |
| 208 | } else { |
| 209 | unsupported $test |
| 210 | } |
| 211 | |
| 212 | gdb_stop_suppressing_tests |
| 213 | } |
| 214 | |
| 215 | |
| 216 | # Test setting of long long bit fields from within GDB. |
| 217 | |
| 218 | proc bitfield_set {} { |
| 219 | global decimal |
| 220 | global hex |
| 221 | global gdb_prompt |
| 222 | global srcfile |
| 223 | global has_signed_bitfields |
| 224 | |
| 225 | start_test break5 |
| 226 | |
| 227 | set big_set_failed 0 |
| 228 | set test "set long long unsigned bitfield" |
| 229 | gdb_test_multiple "print flags.u2 = 0x100000000" $test { |
| 230 | -re "warning: Value does not fit.*$gdb_prompt $" { |
| 231 | fail "$test" |
| 232 | gdb_suppress_tests |
| 233 | } |
| 234 | -re "= 4294967296.*$gdb_prompt $" { |
| 235 | pass "$test" |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | set test "set long long signed bitfield positive" |
| 240 | gdb_test_multiple "print flags.s2 = 0x80000000" $test { |
| 241 | -re "warning: Value does not fit.*$gdb_prompt $" { |
| 242 | fail "$test" |
| 243 | gdb_suppress_tests |
| 244 | } |
| 245 | -re "= 2147483648.*$gdb_prompt $" { |
| 246 | pass "$test" |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = 2147483648, s3 = 0.*" "long long bitfield values after set"] { |
| 251 | gdb_suppress_tests |
| 252 | } |
| 253 | |
| 254 | set test "set long long signed bitfield negative" |
| 255 | if $has_signed_bitfields then { |
| 256 | gdb_test_multiple "print flags.s2 = -1" $test { |
| 257 | -re "warning: Value does not fit.*$gdb_prompt $" { |
| 258 | fail "$test" |
| 259 | gdb_suppress_tests |
| 260 | } |
| 261 | -re "= -1.*$gdb_prompt $" { |
| 262 | pass "$test" |
| 263 | } |
| 264 | } |
| 265 | } else { |
| 266 | unsupported $test |
| 267 | } |
| 268 | |
| 269 | set test "long long bitfield values after set negative" |
| 270 | if $has_signed_bitfields then { |
| 271 | if [gdb_test "print flags" "u1 = 0, u2 = 4294967296, u3 = 0, s1 = 0, s2 = -1, s3 = 0.*" $test] { |
| 272 | gdb_suppress_tests |
| 273 | } |
| 274 | } else { |
| 275 | unsupported $test |
| 276 | } |
| 277 | |
| 278 | gdb_stop_suppressing_tests |
| 279 | } |
| 280 | |
| 281 | clean_restart ${binfile} |
| 282 | |
| 283 | gdb_test_no_output "set print sevenbit-strings" |
| 284 | runto_main |
| 285 | |
| 286 | bitfield_uniqueness |
| 287 | bitfield_containment |
| 288 | bitfield_unsignedness |
| 289 | bitfield_signedness |
| 290 | bitfield_set |
| 291 | |