1 # Copyright (C) 1993-2024 Free Software Foundation, Inc.
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.
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.
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.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # This file was written by Rob Savoye <rob@cygnus.com>
21 # and rewritten by Ian Lance Taylor <ian@cygnus.com>
23 if ![is_remote host] {
24 if {[which $OBJDUMP] == 0} then {
25 perror "$OBJDUMP does not exist"
30 send_user "Version [binutil_version $OBJDUMP]"
32 # Simple test of objdump -i
34 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -i"]
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 lappend cpus_expected Loongarch64 Loongarch32
46 # Make sure the target CPU shows up in the list.
47 lappend cpus_expected ${target_cpu}
50 set cpus_regex "([join $cpus_expected | ])"
52 verbose -log "CPU regex: $cpus_regex"
54 set want "BFD header file version.*srec\[^\n\]*\n\[^\n\]*header \[^\n\]*endian\[^\n\]*, data \[^\n\]*endian.*$cpus_regex"
56 if [regexp $want $got] then {
63 if { [istarget "*-*-vms"] } then {
68 # The remaining tests require a test file.
70 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}]} then {
71 fail "objdump (assembling bintest.s)"
74 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest2.${obj}]} then {
75 fail "objdump (assembling)"
79 set testfile [remote_download host tmpdir/bintest.${obj}]
80 set testfile2 [remote_download host tmpdir/bintest2.${obj}]
82 set testfile tmpdir/bintest.${obj}
83 set testfile2 tmpdir/bintest2.${obj}
86 # $testarchive exists only if it is supported.
87 set testarchive tmpdir/bintest.a
88 remote_file host delete $testarchive
89 set got [binutils_run $AR "rc tmpdir/bintest.a $testfile2"]
90 if ![string match "" $got] then {
92 remote_file host delete tmpdir/bintest.a
93 } elseif [is_remote host] {
94 set testarchive [remote_download host tmpdir/bintest.a]
96 remote_file host delete tmpdir/bintest2.${obj}
100 proc test_objdump_f { testfile dumpfile } {
105 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"]
107 set want "${dumpfile}.*:\[ \]*file format.*architecture:\[ \]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS"
109 if ![regexp $want $got] then {
110 fail "objdump -f ($testfile, $dumpfile)"
112 pass "objdump -f ($testfile, $dumpfile)"
116 test_objdump_f $testfile $testfile
117 if { [ remote_file host exists $testarchive ] } then {
118 test_objdump_f $testarchive bintest2.${obj}
123 proc test_objdump_h { testfile dumpfile } {
127 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"]
129 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\]+)"
131 if ![regexp $want $got all text_name text_size data_name data_size] then {
132 fail "objdump -h ($testfile, $dumpfile)"
134 verbose "text name is $text_name size is $text_size"
135 verbose "data name is $data_name size is $data_size"
138 # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1
139 if [istarget *c4x*-*-*] then {
143 # c54x section sizes are in bytes, not octets; adjust accordingly
144 if [istarget *c54x*-*-*] then {
148 if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then {
149 send_log "sizes too small\n"
150 fail "objdump -h ($testfile, $dumpfile)"
152 pass "objdump -h ($testfile, $dumpfile)"
157 test_objdump_h $testfile $testfile
158 if { [ remote_file host exists $testarchive ] } then {
159 test_objdump_h $testarchive bintest2.${obj}
164 proc test_objdump_t { testfile} {
168 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"]
170 if [info exists vars] then { unset vars }
171 while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} {
176 if {![info exists vars(text_symbol)] \
177 || ![info exists vars(data_symbol)] \
178 || ![info exists vars(common_symbol)] \
179 || ![info exists vars(external_symbol)]} then {
180 fail "objdump -t ($testfile)"
182 pass "objdump -t ($testfile)"
186 test_objdump_t $testfile
187 if { [ remote_file host exists $testarchive ] } then {
188 test_objdump_t $testarchive
193 proc test_objdump_r { testfile dumpfile } {
197 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"]
199 set want "${dumpfile}.*:\[ \]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol"
201 if [regexp $want $got] then {
202 pass "objdump -r ($testfile, $dumpfile)"
204 fail "objdump -r ($testfile, $dumpfile)"
208 test_objdump_r $testfile $testfile
209 if { [ remote_file host exists $testarchive ] } then {
210 test_objdump_r $testarchive bintest2.${obj}
214 proc test_objdump_d { testfile dumpfile } {
218 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -d $testfile"]
220 set want "${dumpfile}.*:.*Disassembly of section"
221 if ![regexp $want $got] then {
222 fail "objdump -d $testfile: No disassembly title"
226 set want "${dumpfile}.*:.*00+0 <text_symbol>"
227 if ![regexp $want $got] then {
228 fail "objdump -d $testfile: Missing symbol name and address"
232 set want "${dumpfile}.*:.*00+. <text_symbol2>"
233 if ![regexp $want $got] then {
234 fail "objdump -d $testfile: Missing second symbol"
238 set want "${dumpfile}.*:.*00+. <text_symbol3>"
239 if ![regexp $want $got] then {
240 fail "objdump -d $testfile: Missing third symbol"
244 pass "objdump -d $testfile"
247 test_objdump_d $testfile $testfile
248 if { [ remote_file host exists $testarchive ] } then {
249 test_objdump_d $testarchive bintest2.${obj}
252 # Test objdump --disassemble=<symbol>
253 proc test_objdump_d_sym { testfile dumpfile } {
257 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=text_symbol2 $testfile"]
259 set want "$dumpfile:.*Disassembly of section"
260 if ![regexp $want $got] then {
261 fail "objdump --disassemble=text_symbol2 $testfile: No disassembly title"
265 set want "$dumpfile:.*00+0 <text_symbol>"
266 if [regexp $want $got] then {
267 fail "objdump --disassemble=text_symbol2 $testfile: First symbol displayed, when it should be absent"
271 set want "$dumpfile:.*00+. <text_symbol2>"
272 if ![regexp $want $got] then {
273 fail "objdump --disassemble=text_symbol2 $testfile: Missing second symbol"
277 set want "$dumpfile:.*00+. <text_symbol3>"
278 if [regexp $want $got] then {
279 fail "objdump --disassemble=text_symbol2 $testfile: Third symbol displayed when it should be absent"
283 pass "objdump --disassemble=text_symbol2 $testfile"
286 test_objdump_d_sym $testfile $testfile
288 proc test_objdump_d_func_sym { testfile dumpfile } {
292 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=func --disassemble-zeroes $testfile"]
294 set want "$dumpfile:.*Disassembly of section"
295 if ![regexp $want $got] then {
296 fail "objdump --disassemble=func $testfile: No disassembly title"
300 set want "$dumpfile:.*00+0 <start_of_text>"
301 if [regexp $want $got] then {
302 fail "objdump --disassemble=func $testfile: First symbol displayed, when it should be absent"
306 set want "$dumpfile:.*00+. <func>"
307 if ![regexp $want $got] then {
308 fail "objdump --disassemble=func $testfile: Disassembly does not start at function symbol"
312 set want "$dumpfile:.*00+. <global_non_func_sym>"
313 if ![regexp $want $got] then {
314 fail "objdump --disassemble=func $testfile: Non function symbol not displayed"
318 set want "$dumpfile:.*00+. <next_func>"
319 if [regexp $want $got] then {
320 fail "objdump --disassemble=func $testfile: Disassembly did not stop at the next function"
324 pass "objdump --disassemble=func $testfile"
327 proc test_objdump_d_non_func_sym { testfile dumpfile } {
331 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble=global_non_func_sym $testfile"]
333 set want "$dumpfile:.*Disassembly of section"
334 if ![regexp $want $got] then {
335 fail "objdump --disassemble=non_func $testfile: No disassembly title"
339 set want "$dumpfile:.*00+0 <start_of_text>"
340 if [regexp $want $got] then {
341 fail "objdump --disassemble=non_func $testfile: First symbol displayed, when it should be absent"
345 set want "$dumpfile:.*00+. <global_non_func_sym>"
346 if ![regexp $want $got] then {
347 fail "objdump --disassemble=non_func $testfile: Non function symbol not displayed"
351 set want "$dumpfile:.*00+. <local_non_func_sym>"
352 if [regexp $want $got] then {
353 fail "objdump --disassemble=non_func $testfile: Disassembly did not stop at the next symbol"
357 pass "objdump --disassemble=non_func $testfile"
360 # Extra test for ELF format - check that --disassemble=func disassembles
361 # all of func, and does not stop at the next symbol.
362 if { [is_elf_format] } then {
364 if {![binutils_assemble $srcdir/$subdir/disasm.s tmpdir/disasm.${obj}]} then {
365 fail "objdump --disassemble=func (assembling disasm.s)"
367 if [is_remote host] {
368 set elftestfile [remote_download host tmpdir/disasm.${obj}]
370 set elftestfile tmpdir/disasm.${obj}
373 test_objdump_d_func_sym $elftestfile $elftestfile
374 test_objdump_d_non_func_sym $elftestfile $elftestfile
378 proc test_objdump_d_show_all_symbols { testfile dumpfile } {
382 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -d --show-all-symbols $testfile"]
384 set want "${dumpfile}.*:.*00+0 <text_symbol>"
385 if ![regexp $want $got] then {
386 fail "objdump -d --show-all-symbols $testfile: Missing 'text_symbol'"
390 set want "${dumpfile}.*:.*00+0 <static_text_symbol>"
391 if ![regexp $want $got] then {
392 fail "objdump -d --show-all-symbols $testfile: Missing 'static_text_symbol'"
396 pass "objdump -d --show-all-symbols $testfile"
399 # The AIX and ECOFF assemblers default to makeing symbols local, not global.
400 # So they do not show up in this test.
401 setup_xfail "*-*-*aix*"
402 setup_xfail "*-*-*ecoff"
403 test_objdump_d_show_all_symbols $testfile $testfile
407 proc test_objdump_s { testfile dumpfile } {
411 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"]
413 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)"
415 if [regexp $want $got] then {
416 pass "objdump -s ($testfile, $dumpfile)"
418 fail "objdump -s ($testfile, $dumpfile)"
422 test_objdump_s $testfile $testfile
423 if { [ remote_file host exists $testarchive ] } then {
424 test_objdump_s $testarchive bintest2.${obj}
427 # Test objdump -s on a file that contains a compressed .debug section
429 if { ![is_elf_format] } then {
430 unsupported "objdump compressed debug"
431 } elseif { ![binutils_assemble $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.${obj}] } then {
432 fail "objdump compressed debug"
434 if [is_remote host] {
435 set compressed_testfile [remote_download host tmpdir/dw2-compressed.${obj}]
437 set compressed_testfile tmpdir/dw2-compressed.${obj}
440 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"]
442 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
443 fail "objdump -s -j .zdebug_abbrev (reason: unexpected output)"
448 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.s] } then {
449 fail "objdump -s -j .zdebug_abbrev"
451 pass "objdump -s -j .zdebug_abbrev"
454 # Test objdump -W on a file that contains some compressed .debug sections
456 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -W $compressed_testfile" "" "/dev/null" "objdump.out"]
458 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
459 fail "objdump -W (reason: unexpected output)"
464 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.W] } then {
470 # Test objdump -Z -s on a file that contains some compressed .debug sections
472 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -Z -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"]
474 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
475 fail "objdump -Z -s (reason: unexpected output)"
480 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.Zs] } then {
487 # Test objdump -WL on a file that contains line information for multiple files and search directories.
488 # Not supported on mcore and moxie targets because they do not (yet) support the generation
489 # of DWARF2 line debug information.
491 if { ![is_elf_format]
492 || [istarget "hppa64*-*-hpux*"]
493 || [istarget "ia64*-*-*"]
494 || [istarget "mcore-*-*"]
495 || [istarget "moxie-*-*"]
497 unsupported "objump decode line"
499 if { [istarget "or1k*-*-*"] } then {
500 set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-1.S
501 } elseif { [istarget "kvx*-*-*"] } {
502 set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-2.S
504 set decodedline_testsrc $srcdir/$subdir/dw2-decodedline.S
506 if { ![binutils_assemble $decodedline_testsrc tmpdir/dw2-decodedline.${obj}] } then {
507 fail "objdump decoded line"
510 if [is_remote host] {
511 set decodedline_testfile [remote_download host tmpdir/dw2-decodedline.${obj}]
513 set decodedline_testfile tmpdir/dw2-decodedline.${obj}
516 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -WL $decodedline_testfile" "" "/dev/null" "objdump.out"]
518 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
519 fail "objdump -WL (reason: unexpected output)"
524 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.WL] } then {
531 # Test objdump -W on a file containing debug_ranges information.
533 if { ![is_elf_format] } then {
534 unsupported "objdump debug_ranges test"
535 } elseif { ![binutils_assemble $srcdir/$subdir/dw2-ranges.S tmpdir/dw2-ranges.${obj}] } then {
536 fail "objdump debug_ranges test"
538 if [is_remote host] {
539 set ranges_testfile [remote_download host tmpdir/dw2-ranges.${obj}]
541 set ranges_testfile tmpdir/dw2-ranges.${obj}
544 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=Ranges $ranges_testfile" "" "/dev/null" "objdump.out"]
546 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
547 fail "objdump -W for debug_ranges (reason: unexpected output)"
552 setup_xfail "msp430-*-*"
553 if { [regexp_diff objdump.out $srcdir/$subdir/dw2-ranges.W] } then {
554 fail "objdump -W for debug_ranges"
556 pass "objdump -W for debug_ranges"
560 # Test objdump -Wi on a file containing dwarf-5 encodings information.
562 if { ![is_elf_format] } then {
563 unsupported "objdump DW_OP_* test"
564 } elseif { ![binutils_assemble $srcdir/$subdir/dw5-op.S tmpdir/dw5-op.${obj}] } then {
565 fail "objdump DW_OP_* test"
567 if [is_remote host] {
568 set op_testfile [remote_download host tmpdir/dw5-op.${obj}]
570 set op_testfile tmpdir/dw5-op.${obj}
573 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -Wi $op_testfile" "" "/dev/null" "objdump.out"]
575 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
576 fail "objdump -Wi (reason: unexpected output)"
581 set got [remote_exec host "tail -n +4 objdump.out" "" "/dev/null" "objdump.out"]
582 set output [remote_upload host objdump.out]
584 if ![file size $output] then {
585 # If the output file is empty, then this target does not
586 # generate dwarf2 output. This is not a failure.
587 verbose "No output from 'objdump -Wi'"
588 untested "objdump -Wi"
592 if { [regexp_diff objdump.out $srcdir/$subdir/dw5-op.W] } then {
593 fail "objdump -Wi for DW_OP_*"
595 pass "objdump -Wi for DW_OP_*"
598 file_on_host delete $output
601 proc test_build_id_debuglink {option} {
608 global CFLAGS_FOR_TARGET
611 set test "build-id-debuglink ($option)"
613 # Use a fixed build-id.
614 if { [info exists CFLAGS_FOR_TARGET] } {
615 set save_CFLAGS_FOR_TARGET $CFLAGS_FOR_TARGET
617 set CFLAGS_FOR_TARGET "-g -Wl,--build-id=0x12345678abcdef01,--compress-debug-sections=$option"
619 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog${exe} executable debug] != "" } {
620 unsupported "$test (build)"
624 if { [info exists save_CFLAGS_FOR_TARGET] } {
625 set CFLAGS_FOR_TARGET $save_CFLAGS_FOR_TARGET
627 unset CFLAGS_FOR_TARGET
630 if { [binutils_run $STRIP "--strip-debug --remove-section=.comment tmpdir/testprog${exe} -o tmpdir/testprog.strip"] != "" } {
631 fail "$test (strip debug info)"
635 if { [binutils_run $OBJCOPY "--only-keep-debug tmpdir/testprog${exe} tmpdir/testprog.debug"] != "" } {
636 fail "$test (create separate debug info file)"
640 set got [remote_exec host "mkdir -p .build-id/12" ]
641 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
642 fail "$test (make debug directory)"
646 set got [remote_exec host "cp tmpdir/testprog.debug .build-id/12/345678abcdef01.debug"]
647 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
648 fail "$test (copy debug info into debug directory)"
652 set got [remote_exec host "$OBJDUMP -Sl tmpdir/testprog.strip" "" "/dev/null" "tmpdir/testprog.strip.dump"]
653 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
654 fail "$test (post strip dump)"
658 set src2 tmpdir/testprog.strip.dump
659 verbose " grep -e testprog.c ${src2}"
660 set status [remote_exec build grep "-e testprog.c ${src2}"]
661 set exec_output [lindex $status 1]
662 set exec_output [prune_warnings $exec_output]
663 if [string match "" $exec_output] then {
664 send_log "$exec_output\n"
665 verbose "$exec_output" 1
666 fail "$test (grepping for source file name in disassembly output)"
670 set got [remote_exec host "rm .build-id/12/345678abcdef01.debug"]
671 set got [remote_exec host "rmdir -p .build-id/12" ]
672 set got [remote_exec host "rm tmpdir/testprog.strip.dump"]
673 set got [remote_exec host "rm tmpdir/testprog.debug"]
674 set got [remote_exec host "rm tmpdir/testprog.strip"]
678 if {[is_elf_format]} then {
679 test_build_id_debuglink none
680 test_build_id_debuglink zlib
683 # Test objdump -Wk on a file containing debug links.
685 if { [is_elf_format] } then {
686 set testsrc $srcdir/$subdir/debuglink.s
688 if { ![binutils_assemble $testsrc tmpdir/debuglink.${obj}] } then {
689 fail "objdump -Wk (reason: could not assemble source)"
692 if [is_remote host] {
693 set testfile [remote_download host tmpdir/debuglink.${obj}]
695 set testfile tmpdir/debuglink.${obj}
698 set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -Wk -WN $testfile" "" "/dev/null" "objdump.out"]
700 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
701 fail "objdump -Wk (reason: unexpected output)"
706 if { [regexp_diff objdump.out $srcdir/$subdir/objdump.Wk] } then {
707 fail "objdump -Wk (reason: output does not match expectations)"
714 # Very similar to proc test_build_id_debuglink except this time we
715 # display some of the contents of the separate debug info file.
717 proc test_follow_debuglink { options dumpfile } {
723 set test "follow-debuglink ($options)"
725 if {![binutils_assemble $srcdir/$subdir/debuglink.s tmpdir/debuglink.${obj}]} then {
726 fail "$test (reason: assemble first source file)"
730 if {![binutils_assemble $srcdir/$subdir/linkdebug.s tmpdir/linkdebug.debug]} then {
731 fail "$test (reason: assemble second source file)"
735 if ![is_remote host] {
736 set tempfile tmpdir/debuglink.${obj}
738 set tempfile [remote_download host tmpdir/linkdebug.debug]
739 set tempfile [remote_download host tmpdir/debuglink.${obj}]
742 set got [remote_exec host "$OBJDUMP $options $tempfile" "" "/dev/null" "tmpdir/objdump.out"]
743 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
744 fail "$test (reason: unexpected error output from objdump)"
748 if { [regexp_diff tmpdir/objdump.out $srcdir/$subdir/$dumpfile] } then {
750 verbose "output is \n[file_contents objdump.out]" 2
757 set got [remote_exec host "rm tmpdir/objdump.out"]
758 set got [remote_exec host "rm $tempfile"]
759 set got [remote_exec host "rm tmpdir/linkdebug.debug"]
762 if {[is_elf_format]} then {
763 test_follow_debuglink "--process-links --dwarf=info --dwarf=str" objdump.WK2
764 test_follow_debuglink "--process-links --headers --wide" objdump.WK3
767 # Test objdump output with start and stop address limits for the specified
770 proc test_objdump_limited { testfile dopt want start stop } {
774 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS $dopt --start-address 0x$start --stop-address 0x$stop $testfile"]
776 if [regexp $want $got] then {
777 pass "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)"
779 fail "objdump $dopt --start-address 0x$start --stop-address 0x$stop ($testfile)"
783 # Test objdump -d --start-address M --stop-address N
785 proc test_objdump_disas_limited { testfile text start stop } {
786 set want "$testfile:\[ \]*file format.*Disassembly of section $text:\n.*\[ \]*$start:.*"
787 test_objdump_limited $testfile -d $want $start $stop
790 # Test objdump -s --start-address M --stop-address N
792 proc test_objdump_content_limited { testfile text start stop } {
793 set want "$testfile:\[ \]*file format.*Contents of section $text:\n\[ \]*$start .*"
794 test_objdump_limited $testfile -s $want $start $stop
797 # Test objdump with --start-address and --stop-address options for higher
798 # address ranges which may be sign-extended on targets that treat addresses
799 # as signed. We only check that objdump produces some dump output at the
800 # specified start address as a proxy for correct enforcement of the
803 if {[is_elf_format]} then {
804 set sect_names [get_standard_section_names]
805 if { $sect_names != "" } {
806 set text [lindex $sect_names 0]
810 # generate a copy of the test object with .text repositioned
811 if { [binutils_run $OBJCOPY "--change-section-address $text=0x80000000 tmpdir/bintest.${obj} tmpdir/bintest_signed.${obj}"] != "" } {
812 fail "Failed to reposition $text to 0x80000000 (tmpdir/bintest.${obj} -> tmpdir/bintest_signed.${obj})"
816 if [is_remote host] {
817 set testfile3 [remote_download host tmpdir/bintest_signed.${obj}]
819 set testfile3 tmpdir/bintest_signed.${obj}
822 test_objdump_content_limited $testfile3 $text "80000004" "80000008"
823 test_objdump_disas_limited $testfile3 $text "80000004" "80000008"
824 remote_file host delete $testfile3
827 # Test objdump on .NET assemblies (PE files)
829 proc test_objdump_dotnet_assemblies {} {
833 set test "dotnet-assemblies"
835 # If gentestdlls isn't available, skip instead of crashing below.
836 if ![file exists $base_dir/testsuite/gentestdlls] {
841 set got [binutils_run "$base_dir/testsuite/gentestdlls" "tmpdir pei-i386 pei-x86-64"]
842 set want "wrote linux-pei-x86-64.dll"
843 # The test program is hardcoded to generate valid dlls on any target
844 if ![regexp $want $got] then {
848 # First test an ordinary x86 PE format DLL.
849 set test "dotnet-assemblies (ordinary x86 DLL)"
850 set want "file format pei-i386"
851 set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-i386.dll"]
852 if ![regexp $want $got] then {
853 if [regexp "file format not recognized" $got] then {
854 # If the target does not recognize vanilla x86 PE format files
855 # then it cannot be expected to recognize .NET assemblies. But
856 # this means that these tests are unsupported, rather than failures.
861 # In either case, if cannot pass this test, then
862 # there is no point in running any further tests.
867 # Next check a 32-bit .NET DLL.
868 set test "dotnet-assemblies (32-bit .NET)"
869 set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-i386.dll"]
870 if ![regexp $want $got] then {
876 # Next check an ordrinary x86_64 PE format DLL.
877 set test "dotnet-assemblies (ordinary x86_64 DLL)"
878 set want "file format pei-x86-64"
879 set got [binutils_run $OBJDUMP "-x tmpdir/simple-pei-x86-64.dll"]
880 if ![regexp $want $got] then {
881 if [regexp "file format not recognized" $got] then {
882 # If the target does not support 64-bit PE format
883 # files, then the following tests are unsupported.
892 # Finally check a 64-bit .NET DLL.
893 set test "dotnet-assemblies (64-bit)"
894 set got [binutils_run $OBJDUMP "-x tmpdir/linux-pei-x86-64.dll"]
895 if ![regexp $want $got] then {
902 test_objdump_dotnet_assemblies
906 proc test_objdump_S { } {
913 set test "objdump -S"
915 if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog${exe} executable debug] != "" } {
916 unsupported "$test (build)"
920 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -D -S tmpdir/testprog${exe}"]
922 set want "static int local = 2"
924 if [regexp $want $got] then {
930 set test "objdump --source-comment"
932 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --disassemble-all --source-comment=// tmpdir/testprog${exe}"]
934 set want "//static int local = 2"
936 if [regexp $want $got] then {
945 # Test objdump --private
946 proc test_objdump_P {} {
953 set test "objdump -P"
955 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}]} then {
956 unsupported "$test (build)"
960 if [is_remote host] {
961 set testfile [remote_download host tmpdir/bintest.${obj}]
963 set testfile tmpdir/bintest.${obj}
966 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -P header $testfile"]
968 # FIXME: We should probably test the output further than this...
969 set want "Machine Num"
971 if [regexp $want $got] then {
972 pass "$test (dump headers)"
974 fail "$test (dump headers)"
977 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS --private=sections $testfile"]
979 # FIXME: We should probably test the output further than this...
980 set want "EXECUTE,READ"
982 if [regexp $want $got] then {
983 pass "$test (dump sections)"
985 fail "$test (dump sections)"
988 # remote_file host delete $testfile
991 # Test objdump --private of a PE format file.
992 if { [istarget "*-*-pe*"]
993 || [istarget "*-*-cygwin*"]
994 || [istarget "*-*-mingw*"]
999 # Options which are not tested: -a -D -R -T -x -l --stabs
1000 # I don't see any generic way to test any of these other than -a.
1001 # Tests could be written for specific targets, and that should be done
1002 # if specific problems are found.