-# Copyright (C) 1999 Free Software Foundation, Inc.
+# Copyright 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc.
# 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
# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu
-# Written by Nick Clifto <nickc@cygnus.com>
+# Written by Nick Clifton <nickc@cygnus.com>
# Based on scripts written by Ian Lance Taylor <ian@cygnus.com>
# and Ken Raeburn <raeburn@cygnus.com>.
set end_2 1
set diff_pass 1
break
+ } elseif [ string match "#..." $line_b ] {
+ if { [gets $file_b line_b] == $eof } {
+ set end_2 1
+ break
+ }
+ verbose "looking for \"^$line_b$\"" 3
+ while { ![regexp "^$line_b$" "$line_a"] } {
+ verbose "skipping \"$line_a\"" 3
+ if { [gets $file_a line_a] == $eof } {
+ set end_1 1
+ break
+ }
+ }
+ break
}
if { [gets $file_b line_b] == $eof } {
set end_2 1
send_log "regexp_diff match failure\n"
send_log "regexp \"^$line_b$\"\nline \"$line_a\"\n"
set differences 1
- break
}
}
}
return $differences
}
+# 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"
+ catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
+
+ if ![string match "" $got] then {
+ 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
+}
+
# 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
-# of the regexp_file.
+# of the regexp_file-readelf_size if it exists, else regexp_file.
proc readelf_test { options binary_file regexp_file xfails } {
global READELF
global READELFFLAGS
+ global readelf_size
global srcdir
global subdir
- send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out"
+ send_log "exec $READELF $READELFFLAGS $options $binary_file > readelf.out\n"
catch "exec $READELF $READELFFLAGS $options $binary_file > readelf.out" got
- if { [llength $xfails] != 0 } then {
- setup_xfail $xfails
+ foreach xfail $xfails {
+ setup_xfail $xfail
}
-
+
if ![string match "" $got] then {
+ fail "readelf $options (reason: unexpected output)"
send_log $got
- fail "readelf $options"
+ send_log "\n"
return
}
+ set target_machine ""
+ if [istarget "mips*-*-*"] then {
+ if { [istarget "mips*-*-*linux*"] } then {
+ set target_machine tmips
+ } else {
+ set target_machine mips
+ }
+ }
+
+ 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 {
+ set regexp_file $regexp_file-$readelf_size
+ }
+
if { [regexp_diff readelf.out $srcdir/$subdir/$regexp_file] } then {
fail "readelf $options"
verbose "output is \n[file_contents readelf.out]" 2
pass "readelf $options"
}
+# 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.
+ set tempfile [remote_download host tmpdir/testprog.o]
+ # Run "readelf -wi" on it.
+ send_log "exec $READELF $READELFFLAGS -wi $tempfile > readelf.out\n"
+ catch "exec $READELF $READELFFLAGS -wi $tempfile > readelf.out" got
-# Only ELF based toolchains need readelf.
-# For now be paranoid and assume that if ELF is not mentioned
-# in the target string, then the target is not an ELF based port.
+ # Upload the results.
+ set output [remote_upload host readelf.out]
+
+ file_on_host delete $tempfile
+
+ # Strip any superflous warnings.
+ set got [prune_readelf_wi_warnings $got]
-if ![istarget "*-*elf"] then {
- verbose "$READELF is only intenteded for ELF targets" 2
+ if ![string match "" $got] then {
+ fail "readelf $options (reason: unexpected output)"
+ 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).*"
+ ".*\(DW_OP_addr: 0\).*"
+ }
+
+ 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
+ }
+ }
+
+ file_on_host delete $output
+
+ # All done.
+ pass "readelf -wi"
+}
+
+
+# Exclude non-ELF targets.
+if ![is_elf_format] {
+ verbose "$READELF is only intended for ELF targets" 2
return
}
send_user "Version [binutil_version $READELF]"
-# Assemle the test file.
+# Assemble the test file.
if {![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o]} then {
perror "unresolved 1"
unresolved "readelf - failed to assemble"
}
if ![is_remote host] {
- set tempfile tmpdir/bintest.o;
+ set tempfile tmpdir/bintest.o
} else {
set tempfile [remote_download host tmpdir/bintest.o]
}
-# Run the tests
-readelf_test -h $tempfile readelf.h {}
-
-# The v850 fails the next two tests because it creates two special
-# sections of its own: .call_table_data and .call_table_text
-# The regexp scripts are not expecting these sections...
+# First, determine the size, so specific output matchers can be used.
+readelf_find_size $tempfile
-readelf_test -S $tempfile readelf.s {v850*-*-*}
-readelf_test -s $tempfile readelf.ss {v850*-*-*}
+# Run the tests.
+readelf_test -h $tempfile readelf.h {}
+readelf_test -S $tempfile readelf.s {}
+readelf_test -s $tempfile readelf.ss {}
readelf_test -r $tempfile readelf.r {}
-
-# Compile the second test file.
-if { [target_compile $srcdir/$subdir/testprog.c tmpdir/testprog.o object debug] != "" } {
- untested "readelf -w"
- return
-}
-
-if [is_remote host] {
- set tempfile [remote_download host tmpdir/testprog.o];
-} else {
- set tempfile tmpdir/testprog.o
-}
-
-# The xfail targets here do not default to DWARF2 format debug information
-# The symptom is that the output of 'readelf -wi' is empty.
-
-readelf_test -wi $tempfile readelf.wi {v850*-*-*}
+readelf_wi_test