Home | History | Annotate | Download | only in binutils-all
      1 #   Copyright (C) 1993-2016 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 # bug-dejagnu (at) prep.ai.mit.edu
     19 
     20 # This file was written by Rob Savoye <rob (at) cygnus.com>
     21 # and rewritten by Ian Lance Taylor <ian (at) cygnus.com>
     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 arc ARC700 ARCv2 arm cris
     38 lappend cpus_expected d10v d30v fr30 fr500 fr550 h8 hppa i386 i860 i960 iamcu ip2022
     39 lappend cpus_expected m16c m32c m32r m68hc11 m68hc12 m68k m88k 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 romp rs6000 s390 sh sparc
     42 lappend cpus_expected tahoe tic54x tic80 tilegx tms320c30 tms320c4x tms320c54x
     43 lappend cpus_expected v850 vax we32k 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 # The remaining tests require a test file.
     62 
     63 
     64 if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
     65     return
     66 }
     67 if [is_remote host] {
     68     set testfile [remote_download host tmpdir/bintest.o]
     69 } else {
     70     set testfile tmpdir/bintest.o
     71 }
     72 
     73 # Test objdump -f
     74 
     75 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -f $testfile"]
     76 
     77 set want "$testfile:\[ 	\]*file format.*architecture:\[ 	\]*${cpus_regex}.*HAS_RELOC.*HAS_SYMS"
     78 
     79 if ![regexp $want $got] then {
     80     fail "objdump -f"
     81 } else {
     82     pass "objdump -f"
     83 }
     84 
     85 # Test objdump -h
     86 
     87 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -h $testfile"]
     88 
     89 set want "$testfile:\[ 	\]*file format.*Sections.*\[0-9\]+\[ 	\]+\[^ 	\]*(text|TEXT|P|\\\$CODE\\\$)\[^ 	\]*\[ 	\]*(\[0-9a-fA-F\]+).*\[0-9\]+\[ 	\]+\[^ 	\]*(\\.data|DATA|D_1)\[^ 	\]*\[ 	\]*(\[0-9a-fA-F\]+)"
     90 
     91 if ![regexp $want $got all text_name text_size data_name data_size] then {
     92     fail "objdump -h"
     93 } else {
     94     verbose "text name is $text_name size is $text_size"
     95     verbose "data name is $data_name size is $data_size"
     96     set ets 8
     97     set eds 4
     98     # The [ti]c4x target has the property sizeof(char)=sizeof(long)=1
     99     if [istarget *c4x*-*-*] then {
    100         set ets 2
    101         set eds 1
    102     }
    103     # c54x section sizes are in bytes, not octets; adjust accordingly
    104     if [istarget *c54x*-*-*] then {
    105 	set ets 4
    106 	set eds 2
    107     }
    108     if {[expr "0x$text_size"] < $ets || [expr "0x$data_size"] < $eds} then {
    109 	send_log "sizes too small\n"
    110 	fail "objdump -h"
    111     } else {
    112 	pass "objdump -h"
    113     }
    114 }
    115 
    116 # Test objdump -t
    117 
    118 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -t $testfile"]
    119 
    120 if [info exists vars] then { unset vars }
    121 while {[regexp "(\[a-z\]*_symbol)(.*)" $got all symbol rest]} {
    122     set vars($symbol) 1
    123     set got $rest
    124 }
    125 
    126 if {![info exists vars(text_symbol)] \
    127      || ![info exists vars(data_symbol)] \
    128      || ![info exists vars(common_symbol)] \
    129      || ![info exists vars(external_symbol)]} then {
    130     fail "objdump -t"
    131 } else {
    132     pass "objdump -t"
    133 }
    134 
    135 # Test objdump -r
    136 
    137 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -r $testfile"]
    138 
    139 set want "$testfile:\[ 	\]*file format.*RELOCATION RECORDS FOR \\\[\[^\]\]*(text|TEXT|P|\\\$CODE\\\$)\[^\]\]*\\\].*external_symbol"
    140 
    141 if [regexp $want $got] then {
    142     pass "objdump -r"
    143 } else {
    144     fail "objdump -r"
    145 }
    146 
    147 # Test objdump -s
    148 
    149 set got [binutils_run $OBJDUMP "$OBJDUMPFLAGS -s $testfile"]
    150 
    151 set want "$testfile:\[ 	\]*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)"
    152 
    153 if [regexp $want $got] then {
    154     pass "objdump -s"
    155 } else {
    156     fail "objdump -s"
    157 }
    158 
    159 # Test objdump -s on a file that contains a compressed .debug section
    160 
    161 if { ![is_elf_format] } then {
    162     unsupported "objdump compressed debug"
    163 } elseif { ![binutils_assemble $srcdir/$subdir/dw2-compressed.S tmpdir/dw2-compressed.o] } then {
    164     fail "objdump compressed debug"
    165 } else {
    166     if [is_remote host] {
    167 	set compressed_testfile [remote_download host tmpdir/dw2-compressed.o]
    168     } else {
    169 	set compressed_testfile tmpdir/dw2-compressed.o
    170     }
    171 
    172     set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -s -j .zdebug_abbrev $compressed_testfile" "" "/dev/null" "objdump.out"]
    173 
    174     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    175 	fail "objdump -s -j .zdebug_abbrev (reason: unexpected output)"
    176 	send_log $got
    177 	send_log "\n"
    178     }
    179 
    180     if { [regexp_diff objdump.out $srcdir/$subdir/objdump.s] } then {
    181 	fail "objdump -s -j .zdebug_abbrev"
    182     } else {
    183 	pass "objdump -s -j .zdebug_abbrev"
    184     }
    185 
    186     # Test objdump -W on a file that contains some compressed .debug sections
    187 
    188     set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -W $compressed_testfile" "" "/dev/null" "objdump.out"]
    189 
    190     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    191 	fail "objdump -W (reason: unexpected output)"
    192 	send_log $got
    193 	send_log "\n"
    194     }
    195 
    196     if { [regexp_diff objdump.out $srcdir/$subdir/objdump.W] } then {
    197 	fail "objdump -W"
    198     } else {
    199 	pass "objdump -W"
    200     }
    201 }
    202 
    203 # Test objdump -WL on a file that contains line information for multiple files and search directories.
    204 # Not supported on mcore and moxie targets because they do not (yet) support the generation
    205 # of DWARF2 line debug information.
    206 
    207 if { ![is_elf_format]
    208      || [istarget "hppa64*-*-hpux*"]
    209      || [istarget "i370-*-*"]
    210      || [istarget "i960-*-*"]
    211      || [istarget "ia64*-*-*"]
    212      || [istarget "mcore-*-*"]
    213      || [istarget "moxie-*-*"]
    214 } then {
    215     unsupported "objump decode line"
    216 } else {
    217     if { [istarget "or1k*-*-*"] } then {
    218         set decodedline_testsrc $srcdir/$subdir/dw2-decodedline-1.S
    219     } else {
    220         set decodedline_testsrc $srcdir/$subdir/dw2-decodedline.S
    221     }
    222     if { ![binutils_assemble $decodedline_testsrc tmpdir/dw2-decodedline.o] } then {
    223 	fail "objdump decoded line"
    224     }
    225 
    226     if [is_remote host] {
    227 	set decodedline_testfile [remote_download host tmpdir/dw2-decodedline.o]
    228     } else {
    229 	set decodedline_testfile tmpdir/dw2-decodedline.o
    230     }
    231 
    232     set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS -WL $decodedline_testfile" "" "/dev/null" "objdump.out"]
    233 
    234     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    235 	fail "objdump -WL (reason: unexpected output)"
    236 	send_log $got
    237 	send_log "\n"
    238     }
    239 
    240     if { [regexp_diff objdump.out $srcdir/$subdir/objdump.WL] } then {
    241 	fail "objdump -WL"
    242     } else {
    243 	pass "objdump -WL"
    244     }
    245 }
    246 
    247 # Test objdump -W on a file containing debug_ranges information.
    248 
    249 if { ![is_elf_format] } then {
    250     unsupported "objdump debug_ranges test"
    251 } elseif { ![binutils_assemble $srcdir/$subdir/dw2-ranges.S tmpdir/dw2-ranges.o] } then {
    252     fail "objdump debug_ranges test"
    253 } else {
    254     if [is_remote host] {
    255 	set ranges_testfile [remote_download host tmpdir/dw2-ranges.o]
    256     } else {
    257 	set ranges_testfile tmpdir/dw2-ranges.o
    258     }
    259 
    260     set got [remote_exec host "$OBJDUMP $OBJDUMPFLAGS --dwarf=Ranges $ranges_testfile" "" "/dev/null" "objdump.out"]
    261 
    262     if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
    263 	fail "objdump -W for debug_ranges (reason: unexpected output)"
    264 	send_log $got
    265 	send_log "\n"
    266     }
    267 
    268     setup_xfail "msp430-*-*" "nds32*-*-*"
    269     if { [regexp_diff objdump.out $srcdir/$subdir/dw2-ranges.W] } then {
    270 	fail "objdump -W for debug_ranges"
    271     } else {
    272 	pass "objdump -W for debug_ranges"
    273     }
    274 }
    275 
    276 
    277 # Options which are not tested: -a -d -D -R -T -x -l --stabs
    278 # I don't see any generic way to test any of these other than -a.
    279 # Tests could be written for specific targets, and that should be done
    280 # if specific problems are found.
    281