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