2007-07-05 16:54:46 +00:00
|
|
|
# Copyright 1999, 2000, 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2007-07-05 16:54:46 +00:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
1999-05-03 07:29:11 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2005-05-08 14:17:41 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
# Please email any bugs, comments, and/or additions to this file to:
|
|
|
|
# bug-dejagnu@prep.ai.mit.edu
|
|
|
|
|
2000-05-02 12:47:19 +00:00
|
|
|
# Written by Nick Clifton <nickc@cygnus.com>
|
1999-05-03 07:29:11 +00:00
|
|
|
# Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
|
|
|
|
# and Ken Raeburn <raeburn@cygnus.com>.
|
|
|
|
|
2007-08-30 13:47:35 +00:00
|
|
|
# Exclude non-ELF targets.
|
|
|
|
if ![is_elf_format] {
|
|
|
|
verbose "$READELF is only intended for ELF targets" 2
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
# First some helpful procedures, then the tests themselves
|
|
|
|
|
|
|
|
# Return the contents of the filename given
|
|
|
|
proc file_contents { filename } {
|
|
|
|
set file [open $filename r]
|
|
|
|
set contents [read $file]
|
|
|
|
close $file
|
|
|
|
return $contents
|
|
|
|
}
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
# Find out the size by reading the output of the EI_CLASS field.
|
|
|
|
# Similar to the test for readelf -h, but we're just looking for the
|
|
|
|
# EI_CLASS line here.
|
|
|
|
proc readelf_find_size { binary_file } {
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
|
|
|
global readelf_size
|
|
|
|
|
|
|
|
set readelf_size ""
|
|
|
|
set testname "finding out ELF size with readelf -h"
|
2007-08-28 13:21:58 +00:00
|
|
|
set got [remote_exec host "$READELF $READELFFLAGS -h $binary_file" "" "/dev/null" "readelf.out"]
|
|
|
|
if [is_remote host] then {
|
|
|
|
remote_upload host "readelf.out"
|
|
|
|
}
|
2000-06-14 01:21:35 +00:00
|
|
|
|
2007-08-28 13:21:58 +00:00
|
|
|
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]]} then {
|
2000-06-14 01:21:35 +00:00
|
|
|
send_log $got
|
|
|
|
fail $testname
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if { ! [regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
|
|
|
|
[file_contents readelf.out] nil readelf_size] } {
|
|
|
|
verbose -log "EI_CLASS field not found in output"
|
|
|
|
verbose -log "output is \n[file_contents readelf.out]"
|
|
|
|
fail $testname
|
|
|
|
return
|
|
|
|
} else {
|
|
|
|
verbose -log "ELF size is $readelf_size"
|
|
|
|
}
|
|
|
|
|
|
|
|
pass $testname
|
|
|
|
}
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
# Run an individual readelf test.
|
|
|
|
# Basically readelf is run on the binary_file with the given options.
|
|
|
|
# Readelf's output is captured and then compared against the contents
|
2000-06-14 01:21:35 +00:00
|
|
|
# of the regexp_file-readelf_size if it exists, else regexp_file.
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
proc readelf_test { options binary_file regexp_file xfails } {
|
|
|
|
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
2000-06-14 01:21:35 +00:00
|
|
|
global readelf_size
|
1999-05-03 07:29:11 +00:00
|
|
|
global srcdir
|
|
|
|
global subdir
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
|
2007-08-28 13:21:58 +00:00
|
|
|
set got [remote_exec host "$READELF $READELFFLAGS $options $binary_file" "" "/dev/null" "readelf.out"]
|
1999-05-03 07:29:11 +00:00
|
|
|
|
2000-10-19 18:04:56 +00:00
|
|
|
foreach xfail $xfails {
|
|
|
|
setup_xfail $xfail
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
2003-04-23 17:36:08 +00:00
|
|
|
|
2007-08-28 13:21:58 +00:00
|
|
|
if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
|
2003-04-23 17:36:08 +00:00
|
|
|
fail "readelf $options (reason: unexpected output)"
|
1999-05-03 07:29:11 +00:00
|
|
|
send_log $got
|
2003-04-23 17:36:08 +00:00
|
|
|
send_log "\n"
|
1999-05-03 07:29:11 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2000-11-03 01:59:12 +00:00
|
|
|
set target_machine ""
|
|
|
|
if [istarget "mips*-*-*"] then {
|
2006-08-15 18:23:11 +00:00
|
|
|
if { [istarget "mips*-*-*linux*"] || [istarget "mips*-sde-elf*"] } then {
|
2001-05-25 18:58:10 +00:00
|
|
|
set target_machine tmips
|
|
|
|
} else {
|
|
|
|
set target_machine mips
|
|
|
|
}
|
2000-11-03 01:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$readelf_size-$target_machine] } then {
|
|
|
|
set regexp_file $regexp_file-$readelf_size-$target_machine
|
|
|
|
} elseif { $target_machine != "" && [file exists $srcdir/$subdir/$regexp_file-$target_machine] } then {
|
|
|
|
set regexp_file $regexp_file-$target_machine
|
|
|
|
} elseif { [file exists $srcdir/$subdir/$regexp_file-$readelf_size] } then {
|
2000-06-14 01:21:35 +00:00
|
|
|
set regexp_file $regexp_file-$readelf_size
|
|
|
|
}
|
|
|
|
|
1999-05-03 07:29:11 +00:00
|
|
|
if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
|
|
|
|
fail "readelf $options"
|
|
|
|
verbose "output is \n[file_contents readelf.out]" 2
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pass "readelf $options"
|
|
|
|
}
|
|
|
|
|
2003-04-26 07:53:20 +00:00
|
|
|
# Simple proc to skip certain expected warning messages.
|
|
|
|
|
|
|
|
proc prune_readelf_wi_warnings { text } {
|
|
|
|
regsub -all "(^|\n)(.*Skipping unexpected symbol type.*)" $text "\\1" text
|
|
|
|
return $text
|
|
|
|
}
|
|
|
|
|
|
|
|
# Testing the "readelf -wi" option is difficult because there
|
|
|
|
# is no guaranteed order to the output, and because some ports
|
|
|
|
# will use indirect string references, whilst others will use
|
|
|
|
# direct references. So instead of having an expected output
|
|
|
|
# file, like the other readelf tests, we grep for strings that
|
|
|
|
# really ought to be there.
|
|
|
|
|
|
|
|
proc readelf_wi_test {} {
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
|
|
|
global srcdir
|
|
|
|
global subdir
|
|
|
|
|
|
|
|
# Compile the second test file.
|
|
|
|
if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
|
|
|
|
verbose "Unable to compile test file."
|
|
|
|
untested "readelf -wi"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Download it.
|
2004-05-12 03:28:46 +00:00
|
|
|
set tempfile [remote_download host tmpdir/testprog.o]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# Run "readelf -wi" on it.
|
2007-08-28 13:21:58 +00:00
|
|
|
set got [remote_exec host "$READELF $READELFFLAGS -wi $tempfile" "" "/dev/null" "readelf.out"]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# Upload the results.
|
2004-05-12 03:28:46 +00:00
|
|
|
set output [remote_upload host readelf.out]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
2004-05-12 03:28:46 +00:00
|
|
|
file_on_host delete $tempfile
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# Strip any superflous warnings.
|
2007-08-28 13:21:58 +00:00
|
|
|
set got [prune_readelf_wi_warnings [lindex $got 1]]
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
if ![string match "" $got] then {
|
2007-02-14 10:05:59 +00:00
|
|
|
fail "readelf $READELFFLAGS -wi (reason: unexpected output)"
|
2003-04-26 07:53:20 +00:00
|
|
|
send_log $got
|
|
|
|
send_log "\n"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![file size $output] then {
|
|
|
|
# If the output file is empty, then this target does not
|
|
|
|
# generate dwarf2 output. This is not a failure.
|
|
|
|
verbose "No output from 'readelf -wi'"
|
|
|
|
untested "readelf -wi"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Search for strings that should be in the output.
|
|
|
|
set sought {
|
|
|
|
".*DW_TAG_compile_unit.*"
|
|
|
|
".*DW_TAG_subprogram.*"
|
|
|
|
".*DW_TAG_base_type.*"
|
|
|
|
".*DW_AT_producer.*(GNU C|indirect string).*"
|
|
|
|
".*DW_AT_language.*ANSI C.*"
|
|
|
|
".*DW_AT_name.*(testprog.c|indirect string).*"
|
|
|
|
".*DW_AT_name.*fn.*"
|
|
|
|
".*DW_AT_name.*(main|indirect string).*"
|
2003-04-26 07:57:26 +00:00
|
|
|
".*\(DW_OP_addr: 0\).*"
|
2003-04-26 07:53:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
foreach looked_for $sought {
|
|
|
|
set lines [grep $output $looked_for]
|
|
|
|
if ![llength $lines] then {
|
|
|
|
fail "readelf -wi: missing: $looked_for"
|
|
|
|
send_log readelf.out
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-12 03:28:46 +00:00
|
|
|
file_on_host delete $output
|
2003-04-26 07:53:20 +00:00
|
|
|
|
|
|
|
# All done.
|
|
|
|
pass "readelf -wi"
|
|
|
|
}
|
1999-05-03 07:29:11 +00:00
|
|
|
|
|
|
|
|
2007-08-30 13:47:35 +00:00
|
|
|
# Test readelf's dumping abilities.
|
|
|
|
|
|
|
|
proc readelf_dump_test {} {
|
|
|
|
global READELF
|
|
|
|
global READELFFLAGS
|
|
|
|
global srcdir
|
|
|
|
global subdir
|
|
|
|
|
|
|
|
# Assemble the dump test file.
|
|
|
|
if {![binutils_assemble $srcdir/$subdir/dumptest.s tmpdir/dumptest.o]} then {
|
|
|
|
unresolved "readelf -p: failed to assemble dump test file"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
# Download it.
|
|
|
|
set tempfile [remote_download host tmpdir/dumptest.o]
|
|
|
|
|
|
|
|
# Run "readelf -p.data" on it.
|
|
|
|
set got [remote_exec host "$READELF $READELFFLAGS -p.data $tempfile" "" "/dev/null" "readelf.out"]
|
|
|
|
set got [lindex $got 1]
|
|
|
|
|
|
|
|
# Upload the results.
|
|
|
|
set output [remote_upload host readelf.out]
|
|
|
|
|
|
|
|
# Check for something going wrong.
|
|
|
|
if ![string match "" $got] then {
|
|
|
|
fail "readelf -p: unexpected output"
|
|
|
|
send_log $got
|
|
|
|
send_log "\n"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
# Search for strings that should be in the output.
|
|
|
|
set sought {
|
|
|
|
".*test_string.*"
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach looked_for $sought {
|
|
|
|
set lines [grep $output $looked_for]
|
|
|
|
if ![llength $lines] then {
|
|
|
|
fail "readelf -p: missing: $looked_for"
|
|
|
|
send_log readelf.out
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_on_host delete $tempfile
|
|
|
|
file_on_host delete $output
|
|
|
|
|
|
|
|
# All done.
|
|
|
|
pass "readelf -p"
|
|
|
|
|
|
|
|
# XXX FIXME: Add test of readelf -x here
|
1999-05-03 07:29:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ![is_remote host] {
|
|
|
|
if {[which $READELF] == 0} then {
|
|
|
|
perror "$READELF does not exist"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send_user "Version [binutil_version $READELF]"
|
|
|
|
|
2001-06-21 07:44:32 +00:00
|
|
|
# Assemble the test file.
|
1999-05-03 07:29:11 +00:00
|
|
|
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
|
2007-08-30 13:47:35 +00:00
|
|
|
perror "could not assemble test file"
|
1999-05-03 07:29:11 +00:00
|
|
|
unresolved "readelf - failed to assemble"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ![is_remote host] {
|
2004-05-12 03:28:46 +00:00
|
|
|
set tempfile tmpdir/bintest.o
|
1999-05-03 07:29:11 +00:00
|
|
|
} else {
|
|
|
|
set tempfile [remote_download host tmpdir/bintest.o]
|
|
|
|
}
|
|
|
|
|
2000-06-14 01:21:35 +00:00
|
|
|
# First, determine the size, so specific output matchers can be used.
|
|
|
|
readelf_find_size $tempfile
|
|
|
|
|
|
|
|
# Run the tests.
|
1999-05-03 07:29:11 +00:00
|
|
|
readelf_test -h $tempfile readelf.h {}
|
2000-11-03 01:59:12 +00:00
|
|
|
readelf_test -S $tempfile readelf.s {}
|
|
|
|
readelf_test -s $tempfile readelf.ss {}
|
1999-05-03 07:29:11 +00:00
|
|
|
readelf_test -r $tempfile readelf.r {}
|
|
|
|
|
2003-04-26 07:53:20 +00:00
|
|
|
readelf_wi_test
|
2007-08-30 13:47:35 +00:00
|
|
|
|
|
|
|
readelf_dump_test
|