Use unsuspend_all_lwps
[deliverable/binutils-gdb.git] / binutils / testsuite / lib / binutils-common.exp
CommitLineData
6f2750fe 1# Copyright (C) 1993-2016 Free Software Foundation, Inc.
f3097f33
RS
2#
3# This file is part of the GNU Binutils.
4#
5# This file is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18# MA 02110-1301, USA.
19
20# True if the object format is known to be ELF.
21#
22proc is_elf_format {} {
b3066ae8
AM
23 # config.sub for these targets curiously transforms a target doublet
24 # ending in -elf to -none. eg. m68hc12-elf to m68hc12-unknown-none
25 # They are always elf.
26 if { [istarget m68hc1*-*] || [istarget xgate-*] } {
27 return 1;
28 }
29
4a85cc09 30 if { ![istarget *-*-eabi*]
f3097f33 31 && ![istarget *-*-elf*]
4a85cc09 32 && ![istarget *-*-freebsd*]
f3097f33 33 && ![istarget *-*-gnu*]
f3097f33
RS
34 && ![istarget *-*-irix5*]
35 && ![istarget *-*-irix6*]
4a85cc09
SKS
36 && ![istarget *-*-linux*]
37 && ![istarget *-*-nacl*]
f3097f33
RS
38 && ![istarget *-*-netbsd*]
39 && ![istarget *-*-openbsd*]
4a85cc09
SKS
40 && ![istarget *-*-rtems*]
41 && ![istarget *-*-solaris2*]
42 && ![istarget *-*-sysv4*]
43 && ![istarget *-*-unixware*]
44 && ![istarget avr-*-*]
45 && ![istarget bfin-*-uclinux]
46 && ![istarget frv-*-uclinux*]
47 && ![istarget hppa*64*-*-hpux*]
48 && ![istarget ia64-*-hpux*]
49 && ![istarget sh*-*-uclinux*]
50 && ![istarget tic6x*-*-uclinux*] } {
f3097f33
RS
51 return 0
52 }
53
4a85cc09 54 if { [istarget *-*-linux*aout*]
df26367c 55 || [istarget *-*-linux*ecoff*]
f3097f33 56 || [istarget *-*-linux*oldld*]
4a85cc09 57 || [istarget *-*-rtemscoff*]
f3097f33 58 || [istarget h8500-*-rtems*]
4a85cc09
SKS
59 || [istarget i?86-*-freebsd\[12\].*]
60 || [istarget i960-*-rtems*] } {
f3097f33
RS
61 return 0
62 }
63
64 if { ![istarget *-*-netbsdelf*]
4a85cc09 65 && ( [istarget *-*-netbsd*aout*]
f3097f33
RS
66 || [istarget *-*-netbsdpe*]
67 || [istarget arm*-*-netbsd*]
68 || [istarget sparc-*-netbsd*]
69 || [istarget i*86-*-netbsd*]
70 || [istarget m68*-*-netbsd*]
71 || [istarget vax-*-netbsd*]
72 || [istarget ns32k-*-netbsd*]) } {
73 return 0
74 }
75
4a85cc09 76 if { [istarget arm-*-openbsd*]
f3097f33
RS
77 || [istarget i386-*-openbsd\[0-2\].*]
78 || [istarget i386-*-openbsd3.\[0-2\]]
79 || [istarget m68*-*-openbsd*]
80 || [istarget ns32k-*-openbsd*]
81 || [istarget sparc-*-openbsd\[0-2\].*]
82 || [istarget sparc-*-openbsd3.\[0-1\]]
83 || [istarget vax-*-openbsd*] } {
84 return 0
85 }
86
87 return 1
88}
89
90# True if the object format is known to be a.out.
91#
92proc is_aout_format {} {
93 if { [istarget *-*-netbsdelf]
94 || [istarget sparc64-*-netbsd*]
95 || [istarget sparc64-*-openbsd*] } {
96 return 0
97 }
98 if { [istarget *-*-*\[ab\]out*]
99 || [istarget *-*-linux*oldld*]
100 || [istarget *-*-bsd*]
101 || [istarget *-*-msdos*]
102 || [istarget arm-*-netbsd*]
103 || [istarget arm-*-openbsd*]
104 || [istarget arm-*-riscix*]
7e16ef34 105 || [istarget i?86-*-freebsd\[12\].*]
f3097f33
RS
106 || [istarget i?86-*-netbsd*]
107 || [istarget i?86-*-openbsd\[0-2\]*]
108 || [istarget i?86-*-openbsd3.\[0-2\]*]
109 || [istarget i?86-*-vsta]
110 || [istarget i?86-*-mach*]
111 || [istarget m68*-*-netbsd*]
112 || [istarget m68*-*-openbsd*]
113 || [istarget ns32k-*-*]
114 || [istarget pdp11-*-*]
115 || [istarget sparc*-*-sunos4*]
116 || [istarget sparc*-*-netbsd*]
117 || [istarget sparc*-*-openbsd\[0-2\]*]
118 || [istarget sparc*-*-openbsd3.\[0-1\]*]
119 || [istarget sparc*-fujitsu-none]
120 || [istarget vax-dec-ultrix*]
121 || [istarget vax-*-netbsd] } {
122 return 1
123 }
124 return 0
125}
126
127# True if the object format is known to be PE COFF.
128#
129proc is_pecoff_format {} {
130 if { ![istarget *-*-mingw*]
131 && ![istarget *-*-cygwin*]
132 && ![istarget *-*-cegcc*]
133 && ![istarget *-*-pe*] } {
134 return 0
135 }
136
137 return 1
138}
139
140# True if the object format is known to be 64-bit ELF.
141#
142proc is_elf64 { binary_file } {
143 global READELF
144 global READELFFLAGS
145
146 set readelf_size ""
147 catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
148
149 if ![string match "" $got] then {
150 return 0
151 }
152
153 if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
154 [file_contents readelf.out] nil readelf_size] } {
155 return 0
156 }
157
158 if { $readelf_size == "64" } {
159 return 1
160 }
161
162 return 0
163}
eb22018c
RS
164
165# Compare two files line-by-line. FILE_1 is the actual output and FILE_2
166# is the expected output. Ignore blank lines in either file.
167#
168# FILE_2 is a series of regexps, comments and # directives. The directives
169# are:
170#
171# #pass
172# Treat the test as a PASS if everything up till this point has
173# matched. Ignore any remaining lines in either FILE_1 or FILE_2.
174#
175# #failif
176# Reverse the sense of the test: expect differences to exist.
177#
178# #...
179# REGEXP
180# Skip all lines in FILE_1 until the first that matches REGEXP.
181#
738f4d98
MR
182# Other # lines are comments. Regexp lines starting with the `!' character
183# specify inverse matching (use `\!' for literal matching against a leading
184# `!'). Skip empty lines in both files.
eb22018c
RS
185#
186# The first optional argument is a list of regexp substitutions of the form:
187#
188# EXP1 SUBSPEC1 EXP2 SUBSPEC2 ...
189#
190# This tells the function to apply each regexp substitution EXPi->SUBSPECi
191# in order to every line of FILE_2.
192#
193# Return nonzero if differences exist.
194proc regexp_diff { file_1 file_2 args } {
195 set eof -1
196 set end_1 0
197 set end_2 0
198 set differences 0
199 set diff_pass 0
200 set fail_if_match 0
201 set ref_subst ""
202 if { [llength $args] > 0 } {
203 set ref_subst [lindex $args 0]
204 }
205 if { [llength $args] > 1 } {
206 perror "Too many arguments to regexp_diff"
207 return 1
208 }
209
210 if [file exists $file_1] then {
211 set file_a [open $file_1 r]
212 } else {
213 perror "$file_1 doesn't exist"
214 return 1
215 }
216
217 if [file exists $file_2] then {
218 set file_b [open $file_2 r]
219 } else {
220 perror "$file_2 doesn't exist"
221 close $file_a
222 return 1
223 }
224
225 verbose " Regexp-diff'ing: $file_1 $file_2" 2
226
227 while { 1 } {
228 set line_a ""
229 set line_b ""
230 while { [string length $line_a] == 0 } {
231 # Ignore blank line in FILE_1.
232 if { [gets $file_a line_a] == $eof } {
233 set end_1 1
234 break
235 }
236 }
237 while { [string length $line_b] == 0 || [string match "#*" $line_b] } {
238 if { [string match "#pass" $line_b] } {
239 set end_2 1
240 set diff_pass 1
241 break
242 } elseif { [string match "#failif" $line_b] } {
243 send_log "fail if no difference\n"
244 verbose "fail if no difference" 3
245 set fail_if_match 1
246 } elseif { [string match "#..." $line_b] } {
247 if { [gets $file_b line_b] == $eof } {
248 set end_2 1
249 set diff_pass 1
250 break
251 }
47a50e5b 252 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
253 set line_bx [string range $line_b $negated end]
254 set n [expr { $negated ? "! " : "" }]
eb22018c
RS
255 # Substitute on the reference.
256 foreach {name value} $ref_subst {
738f4d98 257 regsub -- $name $line_bx $value line_bx
eb22018c 258 }
738f4d98
MR
259 verbose "looking for $n\"^$line_bx$\"" 3
260 while { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c
RS
261 verbose "skipping \"$line_a\"" 3
262 if { [gets $file_a line_a] == $eof } {
263 set end_1 1
264 break
265 }
266 }
267 break
268 }
269 if { [gets $file_b line_b] == $eof } {
270 set end_2 1
271 break
272 }
273 }
274
275 if { $diff_pass } {
276 break
277 } elseif { $end_1 && $end_2 } {
278 break
279 } elseif { $end_1 } {
280 send_log "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1\n"
281 verbose "extra regexps in $file_2 starting with \"^$line_b$\"\nEOF from $file_1" 3
282 set differences 1
283 break
284 } elseif { $end_2 } {
285 send_log "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n"
286 verbose "extra lines in $file_1 starting with \"^$line_a$\"\nEOF from $file_2\n" 3
287 set differences 1
288 break
289 } else {
47a50e5b 290 set negated [expr { [string index $line_b 0] == "!" }]
738f4d98
MR
291 set line_bx [string range $line_b $negated end]
292 set n [expr { $negated ? "! " : "" }]
293 set s [expr { $negated ? " " : "" }]
eb22018c
RS
294 # Substitute on the reference.
295 foreach {name value} $ref_subst {
738f4d98 296 regsub -- $name $line_bx $value line_bx
eb22018c 297 }
738f4d98
MR
298 verbose "regexp $n\"^$line_bx$\"\nline \"$line_a\"" 3
299 if { [expr [regexp "^$line_bx$" "$line_a"] == $negated] } {
eb22018c 300 send_log "regexp_diff match failure\n"
738f4d98 301 send_log "regexp $n\"^$line_bx$\"\nline $s\"$line_a\"\n"
eb22018c
RS
302 verbose "regexp_diff match failure\n" 3
303 set differences 1
304 }
305 }
306 }
307
308 if { $differences == 0 && !$diff_pass && [eof $file_a] != [eof $file_b] } {
309 send_log "$file_1 and $file_2 are different lengths\n"
310 verbose "$file_1 and $file_2 are different lengths" 3
311 set differences 1
312 }
313
314 if { $fail_if_match } {
315 if { $differences == 0 } {
316 set differences 1
317 } else {
318 set differences 0
319 }
320 }
321
322 close $file_a
323 close $file_b
324
325 return $differences
326}
This page took 0.242967 seconds and 4 git commands to generate.