]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/testsuite/lib/utils-lib.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / binutils / testsuite / lib / utils-lib.exp
index e27f21710c9e8d67f44c42bdb1d1565dd1ce12be..b644781a90c4f7f0bbb50ff7de0500937a191747 100644 (file)
@@ -1,18 +1,18 @@
-#   Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
+# Copyright (C) 1993-2021 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
-# the Free Software Foundation; either version 2 of the License, or
+# the Free Software Foundation; either version 3 of the License, or
 # (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
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 
 # Please email any bugs, comments, and/or additions to this file to:
 # bug-dejagnu@prep.ai.mit.edu
 # This file was written by Rob Savoye <rob@cygnus.com>
 # and extended by Ian Lance Taylor <ian@cygnus.com>
 
+proc load_common_lib { name } {
+    load_lib $name
+}
+
+load_common_lib binutils-common.exp
+
 proc binutil_version { prog } {
     if ![is_remote host] {
-       set path [which $prog];
+       set path [which $prog]
        if {$path == 0} then {
            perror "$prog can't be run, file not found."
            return ""
@@ -30,8 +36,8 @@ proc binutil_version { prog } {
     } else {
        set path $prog
     }
-    set state [remote_exec host $prog --version];
-    set tmp "[lindex $state 1]\n";
+    set state [remote_exec host $prog --version]
+    set tmp "[lindex $state 1]\n"
     # Should find a way to discard constant parts, keep whatever's
     # left, so the version string could be almost anything at all...
     regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
@@ -45,12 +51,17 @@ proc binutil_version { prog } {
 # default_binutils_run
 #      run a program, returning the output
 #      sets binutils_run_failed if the program does not exist
+#      sets binutils_run_status to the exit status of the program
 #
 proc default_binutils_run { prog progargs } {
     global binutils_run_failed
+    global binutils_run_status
     global host_triplet
 
     set binutils_run_failed 0
+    if [info exists binutils_run_status] {
+       unset binutils_run_status
+    }
 
     if ![is_remote host] {
        if {[which $prog] == 0} then {
@@ -60,27 +71,46 @@ proc default_binutils_run { prog progargs } {
        }
     }
 
-    send_log "$prog $progargs\n"
-    verbose "$prog $progargs"
+    # For objdump, automatically translate standard section
+    # names to the targets one, if they are different.
+    set sect_names [get_standard_section_names]
+    if { $sect_names != "" && [string match "*objdump" $prog] } {
+        regsub -- "-j \\.text" $progargs "-j [lindex $sect_names 0]" progargs
+        regsub -- "-j \\.data" $progargs "-j [lindex $sect_names 1]" progargs
+        regsub -- "-j \\.bss"  $progargs "-j [lindex $sect_names 2]" progargs
+    }
 
     # Gotta quote dollar-signs because they get mangled by the
-    # shell otherwise.
-    regsub -all "\\$" "$progargs" "\\$" progargs
+    # shell otherwise.  Since get_standard_section_names returns
+    # quoted section names, we first remove the original quote
+    # and then requote.
+    regsub -all {\\\$} "$progargs" {$} progargs
+    regsub -all {\$} "$progargs" {\$} progargs
+
+    send_log "$prog $progargs\n"
+    verbose "$prog $progargs"
 
     set state [remote_exec host $prog $progargs]
-    set exec_output [prune_warnings [lindex $state 1]];
+    set binutils_run_status [lindex $state 0]
+    set exec_output [prune_warnings [lindex $state 1]]
     if {![string match "" $exec_output]} then {
        send_log "$exec_output\n"
        verbose "$exec_output"
+    } else {
+       if { [lindex $state 0] != 0 } {
+           set exec_output "$prog exited with status [lindex $state 0]"
+           send_log "$exec_output\n"
+           verbose "$exec_output"
+       }
     }
     return $exec_output
 }
 
 #
-# default_binutils_assemble
+# default_binutils_assemble_flags
 #      assemble a file
 #
-proc default_binutils_assemble { source object } {
+proc default_binutils_assemble_flags { source object asflags } {
     global srcdir
     global host_triplet
 
@@ -90,14 +120,17 @@ proc default_binutils_assemble { source object } {
     # This is a hack in that it won't scale well if other targets need
     # similar transformations to assemble.  We'll generalize the hack
     # if/when other targets need similar handling.
-    if [istarget "hppa*-*-*" ] then {
-       send_log "sed -f $srcdir/config/hppa.sed < $source > asm.s\n"
-       verbose "sed -f $srcdir/config/hppa.sed < $source > asm.s"
-       catch "exec sed -f $srcdir/config/hppa.sed < $source > asm.s";
+    if { [istarget "hppa*-*-*"] \
+            && ![istarget "*-*-linux*"] \
+            && ![istarget "*-*-netbsd*" ] } {
+        set sed_file $srcdir/config/hppa.sed
+       send_log "sed -f $sed_file < $source > asm.s\n"
+       verbose "sed -f $sed_file < $source > asm.s"
+       catch "exec sed -f $sed_file < $source > asm.s"
        set source asm.s
     }
 
-    set exec_output [target_assemble $source $object ""];
+    set exec_output [target_assemble $source $object $asflags]
     set exec_output [prune_warnings $exec_output]
 
     if [string match "" $exec_output] {
@@ -105,57 +138,23 @@ proc default_binutils_assemble { source object } {
     } else {
        send_log "$exec_output\n"
        verbose "$exec_output"
-       perror "$source: assembly failed"
        return 0
     }
 }
 
-if ![info exists target_assemble] {
 #
-# Stolen from dejagnu/lib/target.exp--please remove after 1/1/98.
+# exe_ext
+#      Returns target executable extension, if any.
 #
-uplevel #0 {
-    proc target_assemble { source destfile flags } {
-       return [default_target_assemble $source $destfile $flags];
+proc exe_ext {} {
+    if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
+        return ".exe"
+    } else {
+        return ""
     }
-
-    proc default_target_assemble { source destfile flags } {
-       global AS_FOR_TARGET;
-       global ASFLAGS_FOR_TARGET;
-
-       if [info exists AS_FOR_TARGET] {
-           set AS "$AS_FOR_TARGET";
-       } else {
-           if ![board_info target exists assembler] {
-               set AS [find_gas];
-           } else {
-               set AS [board_info target assembler];
-           }
-       }
-
-       if [info exists ASFLAGS_FOR_TARGET] {
-           append flags " $ASFLAGS_FOR_TARGET";
-       }
-
-       if [is_remote host] {
-           set source [remote_download host $source];
-           set dest "a.out"
-       } else {
-           set dest $destfile
-       }
-       set status [remote_exec host "$AS $source $flags -o $dest"]
-       if [is_remote host] {
-           remote_upload host $dest $destfile
-       }
-
-       set comp_output [prune_warnings [lindex $status 1]];
-       if { [lindex $status 0] != 0 } {
-           verbose -log "assembler exited with status [lindex $status 0]";
-       }
-       if { [lindex $status 1] != "" } {
-           verbose -log "assembler output is:\n[lindex $status 1]" 2;
-       }
-       return ${comp_output};
-}
 }
+
+proc verbose_eval { expr { level 1 } } {
+    global verbose
+    if $verbose>$level then { eval verbose "$expr" $level }
 }