| 1 |
# Copyright (C) 1993-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, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 |
|
| 17 |
# Please email any bugs, comments, and/or additions to this file to: |
| 18 |
# [email protected] |
| 19 |
|
| 20 |
# This file was written by Rob Savoye <[email protected]> |
| 21 |
# and rewritten by Ian Lance Taylor <[email protected]> |
| 22 |
|
| 23 |
if ![is_remote host] { |
| 24 |
if {[which $OBJDUMP] == 0} then { |
| 25 |
perror "$OBJDUMP does not exist" |
| 26 |
return |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
send_user "Version [binutil_version $OBJDUMP]" |
| 31 |
|
| 32 |
# Simple test of objdump -i |
| 33 |
|
| 34 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -i"] |
| 35 |
|
| 36 |
set cpus_expected [list] |
| 37 |
lappend cpus_expected aarch64 alpha am33-2 arc ARC700 ARCv2 arm cris |
| 38 |
lappend cpus_expected d10v d30v fr30 fr500 fr550 h8 hppa i386 iamcu ip2022 |
| 39 |
lappend cpus_expected m16c m32c m32r m68hc11 m68hc12 m68k MCore mep c5 h1 MicroBlaze |
| 40 |
lappend cpus_expected mips mn10200 mn10300 ms1 msp MSP430 nds32 n1h_v3 ns32k |
| 41 |
lappend cpus_expected or1k or1knd pj powerpc pyramid riscv romp rs6000 s390 sh sparc |
| 42 |
lappend cpus_expected tic54x tilegx tms320c30 tms320c4x tms320c54x |
| 43 |
lappend cpus_expected v850 vax x86-64 xscale xtensa z8k z8001 z8002 |
| 44 |
|
| 45 |
# Make sure the target CPU shows up in the list. |
| 46 |
lappend cpus_expected ${target_cpu} |
| 47 |
|
| 48 |
# Create regexp |
| 49 |
set cpus_regex "([join $cpus_expected | ])" |
| 50 |
|
| 51 |
verbose -log "CPU regex: $cpus_regex" |
| 52 |
|
| 53 |
set want "BFD header file version.*srec\[^\n\]*\n\[^\n\]*header \[^\n\]*endian\[^\n\]*, data \[^\n\]*endian.*$cpus_regex" |
| 54 |
|
| 55 |
if [regexp $want $got] then { |
| 56 |
pass "objdump -i" |
| 57 |
} else { |
| 58 |
fail "objdump -i" |
| 59 |
} |
| 60 |
|
| 61 |
set obj o |
| 62 |
if { [istarget "*-*-vms"] } then { |
| 63 |
set obj obj |
| 64 |
} |
| 65 |
|
| 66 |
# The remaining tests require a test file. |
| 67 |
|
| 68 |
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}]} then { |
| 69 |
fail "objdump (assembling bintest.s)" |
| 70 |
return |
| 71 |
} |
| 72 |
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest2.${obj}]} then { |
| 73 |
fail "objdump (assembling)" |
| 74 |
return |
| 75 |
} |
| 76 |
if [is_remote host] { |
| 77 |
set testfile [remote_download host tmpdir/bintest.${obj}] |
| 78 |
set testfile2 [remote_download host tmpdir/bintest2.${obj}] |
| 79 |
} else { |
| 80 |
set testfile tmpdir/bintest.${obj} |
| 81 |
set testfile2 tmpdir/bintest2.${obj} |
| 82 |
} |
| 83 |
|
| 84 |
# $testarchive exists only if it is supported. |
| 85 |
set testarchive tmpdir/bintest.a |
| 86 |
remote_file host delete $testarchive |
| 87 |
set got [binutils_run $AR "rc tmpdir/bintest.a $testfile2"] |
| 88 |
if ![string match "" $got] then { |
| 89 |
fail "bintest.a" |
| 90 |
remote_file host delete tmpdir/bintest.a |
| 91 |
} elseif [is_remote host] { |
| 92 |
set testarchive [remote_download host tmpdir/bintest.a] |
| 93 |
} |
| 94 |
remote_file host delete tmpdir/bintest2.${obj} |
| 95 |
|
| 96 |
# Test objdump -f |
| 97 |
|
| 98 |
proc test_objdump_f { testfile dumpfile } { |
| 99 |
global OBJDUMP |
| 100 |
global OBJDUMPFLAGS |
| 101 |
global cpus_regex |
| 102 |
|
| 103 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"] |
| 104 |
|
| 105 |
set want "${dumpfile}.*:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS" |
| 106 |
|
| 107 |
if ![regexp $want $got] then { |
| 108 |
fail "objdump -f ($testfile, $dumpfile)" |
| 109 |
} else { |
| 110 |
pass "objdump -f ($testfile, $dumpfile)" |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
test_objdump_f $testfile $testfile |
| 115 |
if { [ remote_file host exists $testarchive ] } then { |
| 116 |
test_objdump_f $testarchive bintest2.${obj} |
| 117 |
} |
| 118 |
|
| 119 |
# Test objdump -h |
| 120 |
|
| 121 |
proc test_objdump_h { testfile dumpfile } { |
| 122 |
global OBJDUMP |
| 123 |
global OBJDUMPFLAGS |
| 124 |
|
| 125 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"] |
| 126 |
|
| 127 |
set want "${dumpfile}.*:\[ \]*file format.*Sections.*\[0-9\]+\[ \]+\[^ \]*(text|TEXT|P|\\\$CODE\\\$)\[^ \]*\[ \]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ \]+\[^ \]*(\\.data|DATA|D_1)\[^ \]*\[ \]*(\[0-9a-fA-F\]+)" |
| 128 |
|
| 129 |
if ![regexp $want $got all text_name text_size data_name data_size] then { |
| 130 |
fail "objdump -h ($testfile, $dumpfile)" |
| 131 |
} else { |
| 132 |
verbose "text name is $text_name size is $text_size" |
| 133 |
verbose "data name is $data_name size is $data_size" |
| 134 |
set ets 8 |
| 135 |
set eds 4 |
| 136 |
# The [ti]c4x target has the property sizeof(char)=sizeof(long)=1 |
| 137 |
if [istarget *c4x*-*-*] then { |
| 138 |
set ets 2 |
| 139 |
set eds 1 |
| 140 |
} |
| 141 |
# c54x section sizes are in bytes, not octets; adjust accordingly |
| 142 |
if [istarget *c54x*-*-*] then { |
| 143 |
set ets 4 |
| 144 |
set eds 2 |
| 145 |
} |
| 146 |
if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then { |
| 147 |
send_log "sizes too small\n" |
| 148 |
fail "objdump -h ($testfile, $dumpfile)" |
| 149 |
} else { |
| 150 |
pass "objdump -h ($testfile, $dumpfile)" |
| 151 |
} |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
test_objdump_h $testfile $testfile |
| 156 |
if { [ remote_file host exists $testarchive ] } then { |
| 157 |
test_objdump_h $testarchive bintest2.${obj} |
| 158 |
} |
| 159 |
|
| 160 |
# Test objdump -t |
| 161 |
|
| 162 |
proc test_objdump_t { testfile} { |
| 163 |
global OBJDUMP |
| 164 |
global OBJDUMPFLAGS |
| 165 |
|
| 166 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"] |
| 167 |
|
| 168 |
if [info exists vars] then { unset vars } |
| 169 |
while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} { |
| 170 |
set vars($symbol) 1 |
| 171 |
set got $rest |
| 172 |
} |
| 173 |
|
| 174 |
if {![info exists vars(text_symbol)] \ |
| 175 |
|| ![info exists vars(data_symbol)] \ |
| 176 |
|| ![info exists vars(common_symbol)] \ |
| 177 |
|| ![info exists vars(external_symbol)]} then { |
| 178 |
fail "objdump -t ($testfile)" |
| 179 |
} else { |
| 180 |
pass "objdump -t ($testfile)" |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
test_objdump_t $testfile |
| 185 |
if { [ remote_file host exists $testarchive ] } then { |
| 186 |
test_objdump_t $testarchive |
| 187 |
} |
| 188 |
|
| 189 |
# Test objdump -r |
| 190 |
|
| 191 |
proc test_objdump_r { testfile dumpfile } { |
| 192 |
global OBJDUMP |
| 193 |
global OBJDUMPFLAGS |
| 194 |
|
| 195 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"] |
| 196 |
|
| 197 |
set want "${dumpfile}.*:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol" |
| 198 |
|
| 199 |
if [regexp $want $got] then { |
| 200 |
pass "objdump -r ($testfile, $dumpfile)" |
| 201 |
} else { |
| 202 |
fail "objdump -r ($testfile, $dumpfile)" |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
test_objdump_r $testfile $testfile |
| 207 |
if { [ remote_file host exists $testarchive ] } then { |
| 208 |
test_objdump_r $testarchive bintest2.${obj} |
| 209 |
} |
| 210 |
|
| 211 |
# Test objdump -d |
| 212 |
proc test_objdump_d { testfile dumpfile } { |
| 213 |
global OBJDUMP |
| 214 |
global OBJDUMPFLAGS |
| 215 |
|
| 216 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -d $testfile"] |
| 217 |
|
| 218 |
set want "${dumpfile}.*:.*Disassembly of section" |
| 219 |
if ![regexp $want $got] then { |
| 220 |
fail "objdump -d $testfile: No disassembly title" |
| 221 |
return |
| 222 |
} |
| 223 |
|
| 224 |
set want "${dumpfile}.*:.*00+0 <text_symbol>" |
| 225 |
if ![regexp $want $got] then { |
| 226 |
fail "objdump -d $testfile: Missing symbol name and address" |
| 227 |
return |
| 228 |
} |
| 229 |
|
| 230 |
set want "${dumpfile}.*:.*00+. <text_symbol2>" |
| 231 |
if ![regexp $want $got] then { |
| 232 |
fail "objdump -d $testfile: Missing second symbol" |
| 233 |
return |
| 234 |
} |
| 235 |
|
| 236 |
set want "${dumpfile}.*:.*00+. <text_symbol3>" |
| 237 |
if ![regexp $want $got] then { |
| 238 |
fail "objdump -d $testfile: Missing third symbol" |
| 239 |
return |
| 240 |
} |
| 241 |
|
| 242 |
pass "objdump -d $testfile" |
| 243 |
} |
| 244 |
|
| 245 |
test_objdump_d $testfile $testfile |
| 246 |
if { [ remote_file host exists $testarchive ] } then { |
| 247 |
test_objdump_d $testarchive bintest2.${obj} |
| 248 |
} |
| 249 |
|
| 250 |
# Test objdump --disassemble=<symbol> |
| 251 |
proc test_objdump_d_sym { testfile dumpfile } { |
| 252 |
global OBJDUMP |
| 253 |
global OBJDUMPFLAGS |
| 254 |
|
| 255 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=text_symbol2 $testfile"] |
| 256 |
|
| 257 |
set want "$dumpfile:.*Disassembly of section" |
| 258 |
if ![regexp $want $got] then { |
| 259 |
fail "objdump --disassemble=text_symbol2 $testfile: No disassembly title" |
| 260 |
return |
| 261 |
} |
| 262 |
|
| 263 |
set want "$dumpfile:.*00+0 <text_symbol>" |
| 264 |
if [regexp $want $got] then { |
| 265 |
fail "objdump --disassemble=text_symbol2 $testfile: First symbol displayed, when it should be absent" |
| 266 |
return |
| 267 |
} |
| 268 |
|
| 269 |
set want "$dumpfile:.*00+. <text_symbol2>" |
| 270 |
if ![regexp $want $got] then { |
| 271 |
fail "objdump --disassemble=text_symbol2 $testfile: Missing second symbol" |
| 272 |
return |
| 273 |
} |
| 274 |
|
| 275 |
set want "$dumpfile:.*00+. <text_symbol3>" |
| 276 |
if [regexp $want $got] then { |
| 277 |
fail "objdump --disassemble=text_symbol2 $testfile: Third symbol displayed when it should be absent" |
| 278 |
return |
| 279 |
} |
| 280 |
|
| 281 |
pass "objdump --disassemble=text_symbol2 $testfile" |
| 282 |
} |
| 283 |
|
| 284 |
test_objdump_d_sym $testfile $testfile |
| 285 |
|
| 286 |
proc test_objdump_d_func_sym { testfile dumpfile } { |
| 287 |
global OBJDUMP |
| 288 |
global OBJDUMPFLAGS |
| 289 |
|
| 290 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=func --disassemble-zeroes $testfile"] |
| 291 |
|
| 292 |
set want "$dumpfile:.*Disassembly of section" |
| 293 |
if ![regexp $want $got] then { |
| 294 |
fail "objdump --disassemble=func $testfile: No disassembly title" |
| 295 |
return |
| 296 |
} |
| 297 |
|
| 298 |
set want "$dumpfile:.*00+0 <start_of_text>" |
| 299 |
if [regexp $want $got] then { |
| 300 |
fail "objdump --disassemble=func $testfile: First symbol displayed, when it should be absent" |
| 301 |
return |
| 302 |
} |
| 303 |
|
| 304 |
set want "$dumpfile:.*00+. <func>" |
| 305 |
if ![regexp $want $got] then { |
| 306 |
fail "objdump --disassemble=func $testfile: Disassembly does not start at function symbol" |
| 307 |
return |
| 308 |
} |
| 309 |
|
| 310 |
set want "$dumpfile:.*00+. <global_non_func_sym>" |
| 311 |
if ![regexp $want $got] then { |
| 312 |
fail "objdump --disassemble=func $testfile: Non function symbol not displayed" |
| 313 |
return |
| 314 |
} |
| 315 |
|
| 316 |
set want "$dumpfile:.*00+. <next_func>" |
| 317 |
if [regexp $want $got] then { |
| 318 |
fail "objdump --disassemble=func $testfile: Disassembly did not stop at the next function" |
| 319 |
return |
| 320 |
} |
| 321 |
|
| 322 |
pass "objdump --disassemble=func $testfile" |
| 323 |
} |
| 324 |
|
| 325 |
proc test_objdump_d_non_func_sym { testfile dumpfile } { |
| 326 |
global OBJDUMP |
| 327 |
global OBJDUMPFLAGS |
| 328 |
|
| 329 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=global_non_func_sym $testfile"] |
| 330 |
|
| 331 |
set want "$dumpfile:.*Disassembly of section" |
| 332 |
if ![regexp $want $got] then { |
| 333 |
fail "objdump --disassemble=non_func $testfile: No disassembly title" |
| 334 |
return |
| 335 |
} |
| 336 |
|
| 337 |
set want "$dumpfile:.*00+0 <start_of_text>" |
| 338 |
if [regexp $want $got] then { |
| 339 |
fail "objdump --disassemble=non_func $testfile: First symbol displayed, when it should be absent" |
| 340 |
return |
| 341 |
} |
| 342 |
|
| 343 |
set want "$dumpfile:.*00+. <global_non_func_sym>" |
| 344 |
if ![regexp $want $got] then { |
| 345 |
fail "objdump --disassemble=non_func $testfile: Non function symbol not displayed" |
| 346 |
return |
| 347 |
} |
| 348 |
|
| 349 |
set want "$dumpfile:.*00+. <local_non_func_sym>" |
| 350 |
if [regexp $want $got] then { |
| 351 |
fail "objdump --disassemble=non_func $testfile: Disassembly did not stop at the next symbol" |
| 352 |
return |
| 353 |
} |
| 354 |
|
| 355 |
pass "objdump --disassemble=non_func $testfile" |
| 356 |
} |
| 357 |
|
| 358 |
# Extra test for ELF format - check that --disassemble=func disassembles |
| 359 |
# all of func, and does not stop at the next symbol. |
| 360 |
if { [is_elf_format] } then { |
| 361 |
|
| 362 |
if {![binutils_assemble $srcdir/$subdir/disasm.s tmpdir/disasm.${obj}]} then { |
| 363 |
fail "objdump --disassemble=func (assembling disasm.s)" |
| 364 |
} else { |
| 365 |
if [is_remote host] { |
| 366 |
set elftestfile [remote_download host tmpdir/disasm.${obj}] |
| 367 |
} else { |
| 368 |
set elftestfile tmpdir/disasm.${obj} |
| 369 |
} |
| 370 |
|
| 371 |
test_objdump_d_func_sym $elftestfile $elftestfile |
| 372 |
test_objdump_d_non_func_sym $elftestfile $elftestfile |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
|
| 377 |
# Test objdump -s |
| 378 |
|
| 379 |
proc test_objdump_s { testfile dumpfile } { |
| 380 |
global OBJDUMP |
| 381 |
global OBJDUMPFLAGS |
| 382 |
|
| 383 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"] |
| 384 |
|
| 385 |
set want "${dumpfile}.*:\[ \]*file format.*Contents.*(text|TEXT|P|\\\$CODE\\\$)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000001|01000000|00000100).*Contents.*(data|DATA|D_1)\[^0-9\]*\[ \]*\[0-9a-fA-F\]*\[ \]*(00000002|02000000|00000200)" |
| 386 |
|
| 387 |
if [regexp $want $got] then { |
| 388 |
pass "objdump -s ($testfile, $dumpfile)" |
| 389 |
} else { |
| 390 |
fail "objdump -s ($testfile, $dumpfile)" |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
test_objdump_s $testfile $testfile |
| 395 |
if { [ remote_file host exists $testarchive ] } then { |
| 396 |
test_objdump_s $testarchive bintest2.${obj} |
| 397 |
} |
| 398 |
|
| 399 |
# Test objdump -s on a file that contains a compressed .debug section |
| 400 |
|
| 401 |
if { ![is_elf_format] } then { |
| 402 |
unsupported "objdump compressed debug" |
| 403 |
} elseif { ![binutils_assemble $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.${obj}] } then { |
| 404 |
fail "objdump compressed debug" |
| 405 |
} else { |
| 406 |
if [is_remote host] { |
| 407 |
set compressed_testfile [remote_download host tmpdir/dw2-compressed.${obj}] |
| 408 |
} else { |
| 409 |
set compressed_testfile tmpdir/dw2-compressed.${obj} |
| 410 |
} |
| 411 |
|
| 412 |
set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"] |
| 413 |
|
| 414 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 415 |
fail "objdump -s -j .zdebug_abbrev (reason: unexpected output)" |
| 416 |
send_log $got |
| 417 |
send_log "\n" |
| 418 |
} |
| 419 |
|
| 420 |
if { [regexp_diff objdump.out $srcdir/$subdir/objdump.s] } then { |
| 421 |
fail "objdump -s -j .zdebug_abbrev" |
| 422 |
} else { |
| 423 |
pass "objdump -s -j .zdebug_abbrev" |
| 424 |
} |
| 425 |
|
| 426 |
# Test objdump -W on a file that contains some compressed .debug sections |
| 427 |
|
| 428 |
set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -W $compressed_testfile" "" "/dev/null" "objdump.out"] |
| 429 |
|
| 430 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 431 |
fail "objdump -W (reason: unexpected output)" |
| 432 |
send_log $got |
| 433 |
send_log "\n" |
| 434 |
} |
| 435 |
|
| 436 |
if { [regexp_diff objdump.out $srcdir/$subdir/objdump.W] } then { |
| 437 |
fail "objdump -W" |
| 438 |
} else { |
| 439 |
pass "objdump -W" |
| 440 |
} |
| 441 |
} |
| 442 |
|
| 443 |
# Test objdump -WL on a file that contains line information for multiple files and search directories. |
| 444 |
# Not supported on mcore and moxie targets because they do not (yet) support the generation |
| 445 |
# of DWARF2 line debug information. |
| 446 |
|
| 447 |
if { ![is_elf_format] |
| 448 |
|| [istarget "hppa64*-*-hpux*"] |
| 449 |
|| [istarget "ia64*-*-*"] |
| 450 |
|| [istarget "mcore-*-*"] |
| 451 |
|| [istarget "moxie-*-*"] |
| 452 |
} then { |
| 453 |
unsupported "objump decode line" |
| 454 |
} else { |
| 455 |
if { [istarget "or1k*-*-*"] } then { |
| 456 |
set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-1.S |
| 457 |
} else { |
| 458 |
set decodedline_testsrc $srcdir/$subdir/dw2-decodedline.S |
| 459 |
} |
| 460 |
if { ![binutils_assemble $decodedline_testsrc tmpdir/dw2-decodedline.${obj}] } then { |
| 461 |
fail "objdump decoded line" |
| 462 |
} |
| 463 |
|
| 464 |
if [is_remote host] { |
| 465 |
set decodedline_testfile [remote_download host tmpdir/dw2-decodedline.${obj}] |
| 466 |
} else { |
| 467 |
set decodedline_testfile tmpdir/dw2-decodedline.${obj} |
| 468 |
} |
| 469 |
|
| 470 |
set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -WL $decodedline_testfile" "" "/dev/null" "objdump.out"] |
| 471 |
|
| 472 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 473 |
fail "objdump -WL (reason: unexpected output)" |
| 474 |
send_log $got |
| 475 |
send_log "\n" |
| 476 |
} |
| 477 |
|
| 478 |
if { [regexp_diff objdump.out $srcdir/$subdir/objdump.WL] } then { |
| 479 |
fail "objdump -WL" |
| 480 |
} else { |
| 481 |
pass "objdump -WL" |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
# Test objdump -W on a file containing debug_ranges information. |
| 486 |
|
| 487 |
if { ![is_elf_format] } then { |
| 488 |
unsupported "objdump debug_ranges test" |
| 489 |
} elseif { ![binutils_assemble $srcdir/$subdir/dw2-ranges.S tmpdir/dw2-ranges.${obj}] } then { |
| 490 |
fail "objdump debug_ranges test" |
| 491 |
} else { |
| 492 |
if [is_remote host] { |
| 493 |
set ranges_testfile [remote_download host tmpdir/dw2-ranges.${obj}] |
| 494 |
} else { |
| 495 |
set ranges_testfile tmpdir/dw2-ranges.${obj} |
| 496 |
} |
| 497 |
|
| 498 |
set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=Ranges $ranges_testfile" "" "/dev/null" "objdump.out"] |
| 499 |
|
| 500 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 501 |
fail "objdump -W for debug_ranges (reason: unexpected output)" |
| 502 |
send_log $got |
| 503 |
send_log "\n" |
| 504 |
} |
| 505 |
|
| 506 |
setup_xfail "msp430-*-*" "nds32*-*-*" |
| 507 |
if { [regexp_diff objdump.out $srcdir/$subdir/dw2-ranges.W] } then { |
| 508 |
fail "objdump -W for debug_ranges" |
| 509 |
} else { |
| 510 |
pass "objdump -W for debug_ranges" |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
proc test_build_id_debuglink {} { |
| 515 |
global srcdir |
| 516 |
global subdir |
| 517 |
global env |
| 518 |
global STRIP |
| 519 |
global OBJCOPY |
| 520 |
global OBJDUMP |
| 521 |
global CFLAGS_FOR_TARGET |
| 522 |
|
| 523 |
set test "build-id-debuglink" |
| 524 |
|
| 525 |
# Use a fixed build-id. |
| 526 |
if { [info exists CFLAGS_FOR_TARGET] } { |
| 527 |
set save_CFLAGS_FOR_TARGET $CFLAGS_FOR_TARGET |
| 528 |
} |
| 529 |
set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01" |
| 530 |
|
| 531 |
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { |
| 532 |
unsupported "$test (build)" |
| 533 |
return |
| 534 |
} |
| 535 |
|
| 536 |
if { [info exists save_CFLAGS_FOR_TARGET] } { |
| 537 |
set CFLAGS_FOR_TARGET $save_CFLAGS_FOR_TARGET |
| 538 |
} else { |
| 539 |
unset CFLAGS_FOR_TARGET |
| 540 |
} |
| 541 |
|
| 542 |
if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog -o tmpdir/testprog.strip"] != "" } { |
| 543 |
fail "$test (strip debug info)" |
| 544 |
return |
| 545 |
} |
| 546 |
|
| 547 |
if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog tmpdir/testprog.debug"] != "" } { |
| 548 |
fail "$test (create separate debug info file)" |
| 549 |
return |
| 550 |
} |
| 551 |
|
| 552 |
set got [remote_exec host "mkdir -p .build-id/12" ] |
| 553 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 554 |
fail "$test (make debug directory)" |
| 555 |
return |
| 556 |
} |
| 557 |
|
| 558 |
set got [remote_exec host "cp tmpdir/testprog.debug .build-id/12/345678abcdef01.debug"] |
| 559 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 560 |
fail "$test (copy debug info into debug directory)" |
| 561 |
return |
| 562 |
} |
| 563 |
|
| 564 |
set got [remote_exec host "$OBJDUMP -Sl tmpdir/testprog.strip" "" "/dev/null" "tmpdir/testprog.strip.dump"] |
| 565 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 566 |
fail "$test (post strip dump)" |
| 567 |
return |
| 568 |
} |
| 569 |
|
| 570 |
set src2 tmpdir/testprog.strip.dump |
| 571 |
verbose " grep -e testprog.c ${src2}" |
| 572 |
set status [remote_exec build grep "-e testprog.c ${src2}"] |
| 573 |
set exec_output [lindex $status 1] |
| 574 |
set exec_output [prune_warnings $exec_output] |
| 575 |
if [string match "" $exec_output] then { |
| 576 |
send_log "$exec_output\n" |
| 577 |
verbose "$exec_output" 1 |
| 578 |
fail "$test (grepping for source file name in disassembly output)" |
| 579 |
} else { |
| 580 |
pass "$test" |
| 581 |
# Cleanup... |
| 582 |
set got [remote_exec host "rm .build-id/12/345678abcdef01.debug"] |
| 583 |
set got [remote_exec host "rmdir -p .build-id/12" ] |
| 584 |
set got [remote_exec host "rm tmpdir/testprog.strip.dump"] |
| 585 |
set got [remote_exec host "rm tmpdir/testprog.debug"] |
| 586 |
set got [remote_exec host "rm tmpdir/testprog.strip"] |
| 587 |
} |
| 588 |
} |
| 589 |
|
| 590 |
if {[is_elf_format]} then { |
| 591 |
test_build_id_debuglink |
| 592 |
} |
| 593 |
|
| 594 |
# Test objdump -Wk on a file containing debug links. |
| 595 |
|
| 596 |
if { [is_elf_format] } then { |
| 597 |
set testsrc $srcdir/$subdir/debuglink.s |
| 598 |
|
| 599 |
if { ![binutils_assemble $testsrc tmpdir/debuglink.${obj}] } then { |
| 600 |
fail "objdump -Wk (reason: could not assemble source)" |
| 601 |
} |
| 602 |
|
| 603 |
if [is_remote host] { |
| 604 |
set testfile [remote_download host tmpdir/debuglink.${obj}] |
| 605 |
} else { |
| 606 |
set testfile tmpdir/debuglink.${obj} |
| 607 |
} |
| 608 |
|
| 609 |
set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -Wk $testfile" "" "/dev/null" "objdump.out"] |
| 610 |
|
| 611 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 612 |
fail "objdump -Wk (reason: unexpected output)" |
| 613 |
send_log $got |
| 614 |
send_log "\n" |
| 615 |
} |
| 616 |
|
| 617 |
if { [regexp_diff objdump.out $srcdir/$subdir/objdump.Wk] } then { |
| 618 |
fail "objdump -Wk" |
| 619 |
} else { |
| 620 |
pass "objdump -Wk" |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
# Very similar to proc test_build_id_debuglink except this time we |
| 626 |
# display some of the contents of the separate debug info file. |
| 627 |
|
| 628 |
proc test_follow_debuglink { options dumpfile } { |
| 629 |
global srcdir |
| 630 |
global subdir |
| 631 |
global OBJDUMP |
| 632 |
global obj |
| 633 |
|
| 634 |
set test "follow-debuglink ($options)" |
| 635 |
|
| 636 |
if {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.${obj}]} then { |
| 637 |
fail "$test (reason: assemble first source file)" |
| 638 |
return |
| 639 |
} |
| 640 |
|
| 641 |
if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then { |
| 642 |
fail "$test (reason: assemble second source file)" |
| 643 |
return |
| 644 |
} |
| 645 |
|
| 646 |
if ![is_remote host] { |
| 647 |
set tempfile tmpdir/debuglink.${obj} |
| 648 |
} else { |
| 649 |
set tempfile [remote_download host tmpdir/linkdebug.debug] |
| 650 |
set tempfile [remote_download host tmpdir/debuglink.${obj}] |
| 651 |
} |
| 652 |
|
| 653 |
set got [remote_exec host "$OBJDUMP $options $tempfile" "" "/dev/null" "tmpdir/objdump.out"] |
| 654 |
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then { |
| 655 |
fail "$test (reason: unexpected error output from objdump)" |
| 656 |
return |
| 657 |
} |
| 658 |
|
| 659 |
if { [regexp_diff tmpdir/objdump.out $srcdir/$subdir/$dumpfile] } then { |
| 660 |
fail $test |
| 661 |
verbose "output is \n[file_contents objdump.out]" 2 |
| 662 |
return |
| 663 |
} |
| 664 |
|
| 665 |
pass $test |
| 666 |
|
| 667 |
# Tidy up |
| 668 |
set got [remote_exec host "rm tmpdir/objdump.out"] |
| 669 |
set got [remote_exec host "rm $tempfile"] |
| 670 |
set got [remote_exec host "rm tmpdir/linkdebug.debug"] |
| 671 |
} |
| 672 |
|
| 673 |
if {[is_elf_format]} then { |
| 674 |
test_follow_debuglink "--dwarf=follow-links --dwarf=info --dwarf=str" objdump.WK2 |
| 675 |
test_follow_debuglink "--dwarf=follow-links --headers --wide" objdump.WK3 |
| 676 |
} |
| 677 |
|
| 678 |
# Test objdump output with start and stop address limits for the specified |
| 679 |
# dump option |
| 680 |
|
| 681 |
proc test_objdump_limited { testfile dopt want start stop } { |
| 682 |
global OBJDUMP |
| 683 |
global OBJDUMPFLAGS |
| 684 |
|
| 685 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS $dopt --start-address 0x$start --stop-address 0x$stop $testfile"] |
| 686 |
|
| 687 |
if [regexp $want $got] then { |
| 688 |
pass "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)" |
| 689 |
} else { |
| 690 |
fail "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)" |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
# Test objdump -d --start-address M --stop-address N |
| 695 |
|
| 696 |
proc test_objdump_disas_limited { testfile text start stop } { |
| 697 |
set want "$testfile:\[ \]*file format.*Disassembly of section $text:\n.*\[ \]*$start:.*" |
| 698 |
test_objdump_limited $testfile -d $want $start $stop |
| 699 |
} |
| 700 |
|
| 701 |
# Test objdump -s --start-address M --stop-address N |
| 702 |
|
| 703 |
proc test_objdump_content_limited { testfile text start stop } { |
| 704 |
set want "$testfile:\[ \]*file format.*Contents of section $text:\n\[ \]*$start .*" |
| 705 |
test_objdump_limited $testfile -s $want $start $stop |
| 706 |
} |
| 707 |
|
| 708 |
# Test objdump with --start-address and --stop-address options for higher |
| 709 |
# address ranges which may be sign-extended on targets that treat addresses |
| 710 |
# as signed. We only check that objdump produces some dump output at the |
| 711 |
# specified start address as a proxy for correct enforcement of the |
| 712 |
# start/stop limits. |
| 713 |
|
| 714 |
if {[is_elf_format]} then { |
| 715 |
set sect_names [get_standard_section_names] |
| 716 |
if { $sect_names != "" } { |
| 717 |
set text [lindex $sect_names 0] |
| 718 |
} else { |
| 719 |
set text ".text" |
| 720 |
} |
| 721 |
# generate a copy of the test object with .text repositioned |
| 722 |
if { [binutils_run $OBJCOPY "--change-section-address $text=0x80000000 tmpdir/bintest.${obj} tmpdir/bintest_signed.${obj}"] != "" } { |
| 723 |
fail "Failed to reposition $text to 0x80000000 (tmpdir/bintest.${obj} -> tmpdir/bintest_signed.${obj})" |
| 724 |
return |
| 725 |
} |
| 726 |
|
| 727 |
if [is_remote host] { |
| 728 |
set testfile3 [remote_download host tmpdir/bintest_signed.${obj}] |
| 729 |
} else { |
| 730 |
set testfile3 tmpdir/bintest_signed.${obj} |
| 731 |
} |
| 732 |
|
| 733 |
test_objdump_content_limited $testfile3 $text "80000004" "80000008" |
| 734 |
test_objdump_disas_limited $testfile3 $text "80000004" "80000008" |
| 735 |
remote_file host delete $testfile3 |
| 736 |
} |
| 737 |
|
| 738 |
# Test objdump on .NET assemblies (PE files) |
| 739 |
|
| 740 |
proc test_objdump_dotnet_assemblies {} { |
| 741 |
global OBJDUMP |
| 742 |
global base_dir |
| 743 |
|
| 744 |
set test "dotnet-assemblies" |
| 745 |
|
| 746 |
set got [binutils_run "$base_dir/testsuite/gentestdlls" "tmpdir pei-i386 pei-x86-64"] |
| 747 |
set want "wrote linux-pei-x86-64.dll" |
| 748 |
# The test program is hardcoded to generate valid dlls on any target |
| 749 |
if ![regexp $want $got] then { |
| 750 |
fail "$test" |
| 751 |
} |
| 752 |
|
| 753 |
# First test an ordinary x86 PE format DLL. |
| 754 |
set test "dotnet-assemblies (ordinary x86 DLL)" |
| 755 |
set want "file format pei-i386" |
| 756 |
set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-i386.dll"] |
| 757 |
if ![regexp $want $got] then { |
| 758 |
if [regexp "file format not recognized" $got] then { |
| 759 |
# If the target does not recognize vanilla x86 PE format files |
| 760 |
# then it cannot be expected to recognize .NET assemblies. But |
| 761 |
# this means that these tests are unsupported, rather than failures. |
| 762 |
unsupported $test |
| 763 |
} else { |
| 764 |
fail "$test" |
| 765 |
} |
| 766 |
# In either case, if cannot pass this test, then |
| 767 |
# there is no point in running any further tests. |
| 768 |
return |
| 769 |
} |
| 770 |
pass $test |
| 771 |
|
| 772 |
# Next check a 32-bit .NET DLL. |
| 773 |
set test "dotnet-assemblies (32-bit .NET)" |
| 774 |
set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-i386.dll"] |
| 775 |
if ![regexp $want $got] then { |
| 776 |
fail "$test" |
| 777 |
} else { |
| 778 |
pass $test |
| 779 |
} |
| 780 |
|
| 781 |
# Next check an ordrinary x86_64 PE format DLL. |
| 782 |
set test "dotnet-assemblies (ordinary x86_64 DLL)" |
| 783 |
set want "file format pei-x86-64" |
| 784 |
set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-x86-64.dll"] |
| 785 |
if ![regexp $want $got] then { |
| 786 |
if [regexp "file format not recognized" $got] then { |
| 787 |
# If the target does not support 64-bit PE format |
| 788 |
# files, then the following tests are unsupported. |
| 789 |
unsupported $test |
| 790 |
} else { |
| 791 |
fail "$test" |
| 792 |
} |
| 793 |
return |
| 794 |
} |
| 795 |
pass $test |
| 796 |
|
| 797 |
# Finally check a 64-bit .NET DLL. |
| 798 |
set test "dotnet-assemblies (64-bit)" |
| 799 |
set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-x86-64.dll"] |
| 800 |
if ![regexp $want $got] then { |
| 801 |
fail "$test" |
| 802 |
} else { |
| 803 |
pass $test |
| 804 |
} |
| 805 |
} |
| 806 |
|
| 807 |
test_objdump_dotnet_assemblies |
| 808 |
|
| 809 |
# Test objdump -S |
| 810 |
|
| 811 |
proc test_objdump_S { } { |
| 812 |
global srcdir |
| 813 |
global subdir |
| 814 |
global OBJDUMP |
| 815 |
global OBJDUMPFLAGS |
| 816 |
|
| 817 |
set test "objdump -S" |
| 818 |
|
| 819 |
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog executable debug] != "" } { |
| 820 |
unsupported "$test (build)" |
| 821 |
return |
| 822 |
} |
| 823 |
|
| 824 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -D -S tmpdir/testprog"] |
| 825 |
|
| 826 |
set want "static int local = 2" |
| 827 |
|
| 828 |
if [regexp $want $got] then { |
| 829 |
pass $test |
| 830 |
} else { |
| 831 |
fail $test |
| 832 |
} |
| 833 |
|
| 834 |
set test "objdump --source-comment" |
| 835 |
|
| 836 |
set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble-all --source-comment=// tmpdir/testprog"] |
| 837 |
|
| 838 |
set want "//static int local = 2" |
| 839 |
|
| 840 |
if [regexp $want $got] then { |
| 841 |
pass $test |
| 842 |
} else { |
| 843 |
fail $test |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
test_objdump_S |
| 848 |
|
| 849 |
# Options which are not tested: -a -D -R -T -x -l --stabs |
| 850 |
# I don't see any generic way to test any of these other than -a. |
| 851 |
# Tests could be written for specific targets, and that should be done |
| 852 |
# if specific problems are found. |