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