1 # Copyright 2016-2024 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 load_lib dwarf.exp 16 17 # This test can only be run on targets which support DWARF-2 and use gas. 18 require dwarf2_support 19 20 standard_testfile dw2-fixed-point.c dw2-fixed-point-dw.S 21 22 # Make some DWARF for the test. 23 set asm_file [standard_output_file $srcfile2] 24 Dwarf::assemble $asm_file { 25 cu {} { 26 DW_TAG_compile_unit { 27 {DW_AT_language @DW_LANG_Ada95} 28 {DW_AT_name pck.ads} 29 {DW_AT_comp_dir /tmp} 30 } { 31 declare_labels fp1_base_type fp2_base_type fp3_small \ 32 fp3_base_type fp1_range_type 33 34 fp1_base_type: DW_TAG_base_type { 35 {DW_AT_byte_size 1 DW_FORM_sdata} 36 {DW_AT_encoding @DW_ATE_signed_fixed} 37 {DW_AT_name pck__fp1_type} 38 {DW_AT_binary_scale -4 DW_FORM_sdata} 39 } 40 41 DW_TAG_variable { 42 {DW_AT_name pck__fp1_var} 43 {DW_AT_type :$fp1_base_type} 44 {DW_AT_location { 45 DW_OP_addr [gdb_target_symbol pck__fp1_var] 46 } SPECIAL_expr} 47 {external 1 flag} 48 } 49 50 DW_TAG_variable { 51 {DW_AT_name pck__fp1_var2} 52 {DW_AT_type :$fp1_base_type} 53 {DW_AT_location { 54 DW_OP_addr [gdb_target_symbol pck__fp1_var2] 55 } SPECIAL_expr} 56 {external 1 flag} 57 } 58 59 fp2_base_type: DW_TAG_base_type { 60 {DW_AT_byte_size 1 DW_FORM_sdata} 61 {DW_AT_encoding @DW_ATE_signed_fixed} 62 {DW_AT_name pck__fp2_type} 63 {DW_AT_decimal_scale -2 DW_FORM_sdata} 64 } 65 66 DW_TAG_variable { 67 {DW_AT_name pck__fp2_var} 68 {DW_AT_type :$fp2_base_type} 69 {DW_AT_location { 70 DW_OP_addr [gdb_target_symbol pck__fp2_var] 71 } SPECIAL_expr} 72 {external 1 flag} 73 } 74 75 fp3_small: DW_TAG_constant { 76 {DW_AT_GNU_numerator 1 DW_FORM_data1} 77 {DW_AT_GNU_denominator 30 DW_FORM_sdata} 78 } 79 80 fp3_base_type: DW_TAG_base_type { 81 {DW_AT_byte_size 1 DW_FORM_sdata} 82 {DW_AT_encoding @DW_ATE_signed_fixed} 83 {DW_AT_name pck__fp3_type} 84 {DW_AT_small :$fp3_small} 85 } 86 87 DW_TAG_variable { 88 {DW_AT_name pck__fp3_var} 89 {DW_AT_type :$fp3_base_type} 90 {DW_AT_location { 91 DW_OP_addr [gdb_target_symbol pck__fp3_var] 92 } SPECIAL_expr} 93 {external 1 flag} 94 } 95 96 fp1_range_type: DW_TAG_subrange_type { 97 {DW_AT_lower_bound 0xf0 DW_FORM_data1} 98 {DW_AT_upper_bound 0x10 DW_FORM_data1} 99 {DW_AT_name foo__fp1_range_type} 100 {DW_AT_type :$fp1_base_type} 101 } 102 103 DW_TAG_variable { 104 {DW_AT_name pck__fp1_range_var} 105 {DW_AT_type :$fp1_range_type} 106 {DW_AT_location { 107 DW_OP_addr [gdb_target_symbol pck__fp1_range_var] 108 } SPECIAL_expr} 109 {external 1 flag} 110 } 111 } 112 } 113 } 114 115 if { [prepare_for_testing ${testfile}.exp ${testfile} \ 116 [list $srcfile $asm_file] {nodebug}] } { 117 return -1 118 } 119 120 if ![runto_main] { 121 return -1 122 } 123 124 # Do the testing in Ada mode, since this is the language for which 125 # this feature has been implemented, and where we know the language 126 # has the concept of fixed-point types. 127 gdb_test_no_output "set lang ada" 128 129 gdb_test "print pck.fp1_var" \ 130 " = 0.25" 131 132 gdb_test "print /x pck.fp1_var" \ 133 " = 0x0" 134 135 gdb_test "print pck.fp2_var" \ 136 " = -0.01" 137 138 gdb_test "print /x pck.fp2_var" \ 139 " = 0x0" 140 141 gdb_test "print pck.fp3_var" \ 142 " = 0.1" 143 144 gdb_test "print /x pck.fp3_var" \ 145 " = 0x0" 146 147 gdb_test "print pck.fp1_range_var" \ 148 " = 1" 149 150 gdb_test "print /x pck.fp1_range_var" \ 151 " = 0x1" 152 153 gdb_test "print pck.fp1_var + 0.25" \ 154 " = 0.5" 155 156 gdb_test "print pck.fp2_var - pck.fp2_var" \ 157 " = 0" 158 159 gdb_test "print pck.fp3_var * 1" \ 160 " = 0.1" 161 162 gdb_test "print pck.fp3_var / pck.fp3_var" \ 163 " = 1" 164 165 gdb_test "print pck.fp3_var / 0" \ 166 "Division by zero" 167 168 gdb_test "print pck.fp1_range_var - 0.5" \ 169 " = 0.5" 170 171 gdb_test "print -pck.fp1_var" \ 172 " = -0.25" 173 174 gdb_test "print pck.fp1_var = pck.fp1_var" \ 175 " = true" 176 177 gdb_test "print pck.fp1_var = pck.fp1_var2" \ 178 " = false" 179 180 gdb_test "print pck.fp1_var /= pck.fp1_var" \ 181 " = false" 182 183 gdb_test "print pck.fp1_var /= pck.fp1_var2" \ 184 " = true" 185 186 gdb_test "print pck.fp1_var < pck.fp1_var" \ 187 " = false" 188 189 gdb_test "print pck.fp1_var < pck.fp1_var2" \ 190 " = true" 191 192 gdb_test "print pck.fp1_var <= pck.fp1_var2" \ 193 " = true" 194 195 gdb_test "print pck.fp1_var <= pck.fp1_var" \ 196 " = true" 197 198 gdb_test "print pck.fp1_var > pck.fp1_var2" \ 199 " = false" 200 201 gdb_test "print pck.fp1_var2 > pck.fp1_var" \ 202 " = true" 203 204 gdb_test "print pck.fp1_var >= pck.fp1_var" \ 205 " = true" 206 207 gdb_test "print pck.fp1_var >= pck.fp1_var2" \ 208 " = false" 209 210 # Same as above, but with litterals... 211 212 gdb_test "print pck.fp1_var = 0.25" \ 213 " = true" 214 215 gdb_test "print pck.fp1_var = 0.5" \ 216 " = false" 217 218 gdb_test "print pck.fp1_var = 1" \ 219 " = false" 220 221 gdb_test "print pck.fp1_var /= 0.25" \ 222 " = false" 223 224 gdb_test "print pck.fp1_var /= 0.5" \ 225 " = true" 226 227 gdb_test "print pck.fp1_var /= 1" \ 228 " = true" 229 230 gdb_test "print pck.fp1_var < 0.25" \ 231 " = false" 232 233 gdb_test "print pck.fp1_var < 0.5" \ 234 " = true" 235 236 gdb_test "print pck.fp1_var < 1" \ 237 " = true" 238 239 gdb_test "print pck.fp1_var <= 0.25" \ 240 " = true" 241 242 gdb_test "print pck.fp1_var <= 0.5" \ 243 " = true" 244 245 gdb_test "print pck.fp1_var <= 1" \ 246 " = true" 247 248 gdb_test "print pck.fp1_var > 0.25" \ 249 " = false" 250 251 gdb_test "print pck.fp1_var > 0.5" \ 252 " = false" 253 254 gdb_test "print pck.fp1_var > 1" \ 255 " = false" 256 257 gdb_test "print pck.fp1_var >= 0.25" \ 258 " = true" 259 260 gdb_test "print pck.fp1_var >= 0.5" \ 261 " = false" 262 263 gdb_test "print pck.fp1_var >= 1" \ 264 " = false" 265 266 267 # Set the language to LANG and do a ptype test on pck__fp1_var, 268 # pck__fp2_var and pck__fp3_var, verifying that the output matches 269 # FP1_RE, FP2_RE, FP2_RE (resp.). 270 271 proc do_ptype_test {lang fp1_re fp2_re fp3_re fp1_range_re} { 272 with_test_prefix "lang=$lang" { 273 gdb_test_no_output "set language $lang" \ 274 "set language to $lang for ptype test" 275 276 gdb_test "ptype pck__fp1_var" $fp1_re 277 278 gdb_test "ptype pck__fp2_var" $fp2_re 279 280 gdb_test "ptype pck__fp3_var" $fp3_re 281 282 gdb_test "ptype pck__fp1_range_var" $fp1_range_re 283 } 284 } 285 286 do_ptype_test "ada" \ 287 " = <1-byte fixed point \\(small = 1/16\\)>" \ 288 " = <1-byte fixed point \\(small = 1/100\\)>" \ 289 " = <1-byte fixed point \\(small = 1/30\\)>" \ 290 " = <1-byte fixed point \\(small = 1/16\\)>" 291 292 foreach lang [list "c" "d" "go" "objective-c" "opencl" ] { 293 do_ptype_test $lang \ 294 " = 1-byte fixed point \\(small = 1/16\\)" \ 295 " = 1-byte fixed point \\(small = 1/100\\)" \ 296 " = 1-byte fixed point \\(small = 1/30\\)" \ 297 " = <range type>" 298 } 299 300 do_ptype_test "fortran" \ 301 " = pck__fp1_type" \ 302 " = pck__fp2_type" \ 303 " = pck__fp3_type" \ 304 " = <range type>" 305 306 do_ptype_test "modula-2" \ 307 " = pck__fp1_type" \ 308 " = pck__fp2_type" \ 309 " = pck__fp3_type" \ 310 " = \\\[1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)\\\]" 311 312 do_ptype_test "pascal" \ 313 " = pck__fp1_type" \ 314 " = pck__fp2_type" \ 315 " = pck__fp3_type" \ 316 " = 1-byte fixed point \\(small = 1/16\\)\\.\\.1-byte fixed point \\(small = 1/16\\)" 317 318