]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - 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
CommitLineData
250d07de 1# Copyright (C) 1993-2021 Free Software Foundation, Inc.
252b5132
RH
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
32866df7 5# the Free Software Foundation; either version 3 of the License, or
252b5132 6# (at your option) any later version.
65951855 7#
252b5132
RH
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.
65951855 12#
252b5132
RH
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
b43b5d5f 15# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-dejagnu@prep.ai.mit.edu
19
20# This file was written by Rob Savoye <rob@cygnus.com>
21# and extended by Ian Lance Taylor <ian@cygnus.com>
22
f3097f33
RS
23proc load_common_lib { name } {
24 load_lib $name
25}
26
27load_common_lib binutils-common.exp
28
252b5132
RH
29proc binutil_version { prog } {
30 if ![is_remote host] {
8d263650 31 set path [which $prog]
252b5132
RH
32 if {$path == 0} then {
33 perror "$prog can't be run, file not found."
34 return ""
35 }
36 } else {
37 set path $prog
38 }
8d263650
BE
39 set state [remote_exec host $prog --version]
40 set tmp "[lindex $state 1]\n"
252b5132
RH
41 # Should find a way to discard constant parts, keep whatever's
42 # left, so the version string could be almost anything at all...
43 regexp "\[^\n\]* (cygnus-|)(\[-0-9.a-zA-Z-\]+)\[\r\n\].*" "$tmp" version cyg number
44 if ![info exists number] then {
45 return "$path (no version number)\n"
46 }
47 return "$path $number\n"
48}
49
50#
51# default_binutils_run
52# run a program, returning the output
53# sets binutils_run_failed if the program does not exist
78c88364 54# sets binutils_run_status to the exit status of the program
252b5132
RH
55#
56proc default_binutils_run { prog progargs } {
57 global binutils_run_failed
78c88364 58 global binutils_run_status
252b5132
RH
59 global host_triplet
60
61 set binutils_run_failed 0
78c88364
MR
62 if [info exists binutils_run_status] {
63 unset binutils_run_status
64 }
252b5132
RH
65
66 if ![is_remote host] {
67 if {[which $prog] == 0} then {
68 perror "$prog does not exist"
69 set binutils_run_failed 1
70 return ""
71 }
72 }
73
96037eb0
NC
74 # For objdump, automatically translate standard section
75 # names to the targets one, if they are different.
76 set sect_names [get_standard_section_names]
77 if { $sect_names != "" && [string match "*objdump" $prog] } {
78 regsub -- "-j \\.text" $progargs "-j [lindex $sect_names 0]" progargs
79 regsub -- "-j \\.data" $progargs "-j [lindex $sect_names 1]" progargs
80 regsub -- "-j \\.bss" $progargs "-j [lindex $sect_names 2]" progargs
81 }
82
9e7ed8b0
JDA
83 # Gotta quote dollar-signs because they get mangled by the
84 # shell otherwise. Since get_standard_section_names returns
85 # quoted section names, we first remove the original quote
86 # and then requote.
87 regsub -all {\\\$} "$progargs" {$} progargs
88 regsub -all {\$} "$progargs" {\$} progargs
89
252b5132
RH
90 send_log "$prog $progargs\n"
91 verbose "$prog $progargs"
92
252b5132 93 set state [remote_exec host $prog $progargs]
78c88364 94 set binutils_run_status [lindex $state 0]
8d263650 95 set exec_output [prune_warnings [lindex $state 1]]
252b5132
RH
96 if {![string match "" $exec_output]} then {
97 send_log "$exec_output\n"
98 verbose "$exec_output"
da28e1e1
L
99 } else {
100 if { [lindex $state 0] != 0 } {
101 set exec_output "$prog exited with status [lindex $state 0]"
102 send_log "$exec_output\n"
103 verbose "$exec_output"
104 }
252b5132
RH
105 }
106 return $exec_output
107}
108
109#
368886ac 110# default_binutils_assemble_flags
252b5132
RH
111# assemble a file
112#
368886ac 113proc default_binutils_assemble_flags { source object asflags } {
252b5132
RH
114 global srcdir
115 global host_triplet
116
117 # The HPPA assembler syntax is a little different than most, to make
118 # the test source file assemble we need to run it through sed.
119 #
120 # This is a hack in that it won't scale well if other targets need
121 # similar transformations to assemble. We'll generalize the hack
122 # if/when other targets need similar handling.
0b1352e0
AM
123 if { [istarget "hppa*-*-*"] \
124 && ![istarget "*-*-linux*"] \
125 && ![istarget "*-*-netbsd*" ] } {
12c616f1
AM
126 set sed_file $srcdir/config/hppa.sed
127 send_log "sed -f $sed_file < $source > asm.s\n"
128 verbose "sed -f $sed_file < $source > asm.s"
8d263650 129 catch "exec sed -f $sed_file < $source > asm.s"
252b5132
RH
130 set source asm.s
131 }
132
368886ac 133 set exec_output [target_assemble $source $object $asflags]
252b5132
RH
134 set exec_output [prune_warnings $exec_output]
135
136 if [string match "" $exec_output] {
137 return 1
138 } else {
139 send_log "$exec_output\n"
140 verbose "$exec_output"
252b5132
RH
141 return 0
142 }
143}
9ce701e2 144
0fd555c4
NC
145#
146# exe_ext
147# Returns target executable extension, if any.
148#
149proc exe_ext {} {
99ad8390 150 if { [istarget *-*-mingw*] || [istarget *-*-cygwin*] } {
0fd555c4
NC
151 return ".exe"
152 } else {
153 return ""
154 }
155}
af3c5dea 156
af3c5dea
L
157proc verbose_eval { expr { level 1 } } {
158 global verbose
159 if $verbose>$level then { eval verbose "$expr" $level }
160}