1# Copyright 2014-2023 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# Some coverage testing of DWARF operators for the compiler 17# integration. 18 19load_lib compile-support.exp 20load_lib dwarf.exp 21 22# This test can only be run on targets which support DWARF-2 and use gas. 23if {![dwarf2_support]} { 24 return 0 25} 26 27standard_testfile .c -dbg.S 28 29# 30# A port of the pr10770.c test code to the DWARF assembler format. 31# 32 33set assert_tos_non0 { 34 bra 3 35 skip -3 36} 37 38set assert_tos_0 [subst { 39 lit0 40 eq 41 $assert_tos_non0 42}] 43 44set program [subst { 45 lit0 46 nop 47 $assert_tos_0 48 lit1 49 const1u 1 50 eq 51 $assert_tos_non0 52 lit16 53 const2u 16 54 eq 55 $assert_tos_non0 56 lit31 57 const4u 31 58 ne 59 $assert_tos_0 60 lit1 61 neg 62 const1s -1 63 eq 64 $assert_tos_non0 65 lit16 66 neg 67 const2s -16 68 ne 69 $assert_tos_0 70 lit31 71 const4s -31 72 neg 73 ne 74 $assert_tos_0 75 lit7 76 dup 77 plus_uconst 2 78 lit9 79 eq 80 $assert_tos_non0 81 lit7 82 eq 83 $assert_tos_non0 84 lit20 85 lit1 86 drop 87 lit20 88 eq 89 $assert_tos_non0 90 lit17 91 lit19 92 over 93 lit17 94 eq 95 $assert_tos_non0 96 lit19 97 eq 98 $assert_tos_non0 99 lit17 100 eq 101 $assert_tos_non0 102 lit1 103 lit2 104 lit3 105 lit4 106 pick 2 107 lit2 108 eq 109 $assert_tos_non0 110 lit4 111 eq 112 $assert_tos_non0 113 lit3 114 eq 115 $assert_tos_non0 116 pick 0 117 lit2 118 eq 119 $assert_tos_non0 120 lit2 121 eq 122 $assert_tos_non0 123 lit1 124 eq 125 $assert_tos_non0 126 lit6 127 lit12 128 swap 129 lit6 130 eq 131 $assert_tos_non0 132 lit12 133 eq 134 $assert_tos_non0 135 lit7 136 lit8 137 lit9 138 rot 139 lit8 140 eq 141 $assert_tos_non0 142 lit7 143 eq 144 $assert_tos_non0 145 lit9 146 eq 147 $assert_tos_non0 148 lit7 149 abs 150 lit7 151 eq 152 $assert_tos_non0 153 const1s -123 154 abs 155 const1u 123 156 eq 157 $assert_tos_non0 158 lit3 159 lit6 160 and 161 lit2 162 eq 163 $assert_tos_non0 164 lit3 165 lit6 166 or 167 lit7 168 eq 169 $assert_tos_non0 170 lit17 171 lit2 172 minus 173 lit15 174 eq 175 $assert_tos_non0 176 # Divide is signed truncating toward zero. 177 const1s -6 178 const1s -2 179 div 180 lit3 181 eq 182 $assert_tos_non0 183 const1s -7 184 const1s 3 185 div 186 const1s -2 187 eq 188 $assert_tos_non0 189 # Modulo is unsigned. 190 const1s -6 191 const1s -4 192 mod 193 const1s -6 194 eq 195 $assert_tos_non0 196 const1s -6 197 lit4 198 mod 199 lit2 200 eq 201 $assert_tos_non0 202 lit6 203 const1s -4 204 mod 205 lit6 206 eq 207 $assert_tos_non0 208 # Signed modulo can be implemented using 'over over div mul minus'. 209 const1s -6 210 const1s -4 211 over 212 over 213 div 214 mul 215 minus 216 const1s -2 217 eq 218 $assert_tos_non0 219 const1s -7 220 lit3 221 over 222 over 223 div 224 mul 225 minus 226 const1s -1 227 eq 228 $assert_tos_non0 229 lit7 230 const1s -3 231 over 232 over 233 div 234 mul 235 minus 236 lit1 237 eq 238 $assert_tos_non0 239 lit16 240 lit31 241 plus_uconst 1 242 mul 243 const2u 512 244 eq 245 $assert_tos_non0 246 lit5 247 not 248 lit31 249 and 250 lit26 251 eq 252 $assert_tos_non0 253 lit12 254 lit31 255 plus 256 const1u 43 257 eq 258 $assert_tos_non0 259 const1s -6 260 lit2 261 plus 262 const1s -4 263 eq 264 $assert_tos_non0 265 const1s -6 266 plus_uconst 3 267 const1s -3 268 eq 269 $assert_tos_non0 270 lit16 271 lit4 272 shl 273 const2u 256 274 eq 275 $assert_tos_non0 276 lit16 277 lit3 278 shr 279 lit2 280 eq 281 $assert_tos_non0 282 const1s -16 283 lit3 284 shra 285 const1s -2 286 eq 287 $assert_tos_non0 288 lit3 289 lit6 290 xor 291 lit5 292 eq 293 $assert_tos_non0 294 lit3 295 lit6 296 le 297 $assert_tos_non0 298 lit3 299 lit3 300 le 301 $assert_tos_non0 302 lit6 303 lit3 304 le 305 $assert_tos_0 306 lit3 307 lit6 308 lt 309 $assert_tos_non0 310 lit3 311 lit3 312 lt 313 $assert_tos_0 314 lit6 315 lit3 316 lt 317 $assert_tos_0 318 lit3 319 lit6 320 ge 321 $assert_tos_0 322 lit3 323 lit3 324 ge 325 $assert_tos_non0 326 lit6 327 lit3 328 ge 329 $assert_tos_non0 330 lit3 331 lit6 332 gt 333 $assert_tos_0 334 lit3 335 lit3 336 gt 337 $assert_tos_0 338 lit6 339 lit3 340 gt 341 $assert_tos_non0 342 const1s -6 343 lit1 344 shr 345 lit0 346 gt 347 $assert_tos_non0 348 const1s -6 349 lit1 350 shra 351 lit0 352 lt 353 $assert_tos_non0 354 # Finally some result. 355 addr ptr 356}] 357 358if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { 359 return -1 360} 361 362# Make some DWARF for the test. 363set asm_file [standard_output_file $srcfile2] 364Dwarf::assemble $asm_file { 365 366 # Find start, end, and length of "func". 367 get_func_info func 368 369 # Creating a CU with 4-byte addresses lets this test link on both 370 # 32- and 64-bit machines. 371 cu { addr_size 4 } { 372 373 declare_labels int_label 374 375 compile_unit { 376 {name file1.txt} 377 {language @DW_LANG_C} 378 {low_pc $func_start addr} 379 {high_pc $func_end addr} 380 } { 381 global program 382 383 int_label: base_type { 384 {name int} 385 {byte_size 4 sdata} 386 {encoding @DW_ATE_signed} 387 } 388 389 subprogram { 390 {external 1 flag} 391 {name func} 392 {low_pc $func_start addr} 393 {high_pc $func_end addr} 394 } { 395 formal_parameter { 396 {name param} 397 {variable_parameter 1 flag} 398 {type :$int_label} 399 {location $program SPECIAL_expr} 400 } 401 402 formal_parameter { 403 {name optimized_out} 404 {variable_parameter 1 flag} 405 {type :$int_label} 406 } 407 } 408 } 409 } 410} 411 412if { [prepare_for_testing "failed to prepare" ${testfile} \ 413 [list $srcfile $asm_file] {nodebug}] } { 414 return -1 415} 416 417if ![runto func] { 418 return -1 419} 420 421if {[skip_compile_feature_untested]} { 422 return -1 423} 424 425# If we have a bug, this will hang. 426gdb_test_no_output "compile code (void) param" 427 428# We can't access optimized-out variables, but their presence should 429# not affect compilations that don't refer to them. 430gdb_test "compile code optimized_out" \ 431 ".*optimized out.*Compilation failed." 432