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