1 # Copyright
(C
) 2000-2018 Free Software Foundation
, Inc.
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
5 # the Free Software Foundation
; either version
3 of the License
, or
6 #
(at your option
) any later version.
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.
13 # You should have received a copy of the GNU General Public License
14 # along with GCC
; see the file COPYING3.
If not see
15 #
<http
://www.gnu.org
/licenses
/>.
17 # Various utilities
for scanning assembler output
, used by gcc
-dg.exp and
20 # Utility
for scanning compiler result
, invoked via dg
-final.
22 # Transform newline and similar characters into their escaped form.
23 proc make_pattern_printable
{ pattern
} {
24 return [string map
{\t \\t
\n \\n
\r \\r
\\ \\\\} $pattern
]
27 # Scan the OUTPUT_FILE
for a pattern.
If it is present and POSITIVE
28 # is non
-zero
, or it is not present and POSITIVE is zero
, the test
29 # passes. The ORIG_ARGS is the list of arguments provided by dg
-final
30 # to scan
-assembler. The first element in ORIG_ARGS is the regular
31 # expression to look
for in the file. The second element
, if present
,
32 # is a DejaGNU target selector.
34 proc dg
-scan
{ name positive testcase output_file orig_args
} {
35 if { [llength $orig_args
] < 1 } {
36 error
"$name: too few arguments"
39 if { [llength $orig_args
] > 2 } {
40 error
"$name: too many arguments"
43 if { [llength $orig_args
] >= 2 } {
44 switch [dg
-process
-target
[lindex $orig_args
1]] {
47 "F" { setup_xfail "*-*-*" }
52 set pattern
[lindex $orig_args
0]
53 set printable_pattern
[make_pattern_printable $pattern
]
55 if { [is_remote host
] } {
56 remote_upload host
"$output_file"
58 set files
[glob
-nocomplain $output_file
]
60 verbose
-log "$testcase: output file does not exist"
61 unresolved
"$testcase $name $printable_pattern"
64 set fd
[open $output_file r
]
68 set match
[regexp
-- $pattern $
text]
69 if { $match
== $positive
} {
70 pass
"$testcase $name $printable_pattern"
72 fail
"$testcase $name $printable_pattern"
76 # Look
for a pattern in the .s file produced by the compiler. See
77 # dg
-scan
for details.
79 proc scan
-assembler
{ args } {
80 set testcase
[testname
-for-summary
]
81 # The
name might
include a list of options
; extract the file
name.
82 set filename
[lindex $testcase
0]
83 set output_file
"[file rootname [file tail $filename]].s"
84 dg
-scan
"scan-assembler" 1 $testcase $output_file $args
87 force_conventional_output_for scan
-assembler
89 # Check that a pattern is not present in the .s file produced by the
90 # compiler. See dg
-scan
for details.
92 proc scan
-assembler
-not
{ args } {
93 set testcase
[testname
-for-summary
]
94 # The
name might
include a list of options
; extract the file
name.
95 set filename
[lindex $testcase
0]
96 set output_file
"[file rootname [file tail $filename]].s"
98 dg
-scan
"scan-assembler-not" 0 $testcase $output_file $args
101 force_conventional_output_for scan
-assembler
-not
103 #
Return the scan
for the assembly
for hidden visibility.
105 proc hidden
-scan
-for { symbol
} {
107 set objformat
[gcc_target_object_format
]
110 coff
{ return "$symbol\[,\d\]*hidden" }
111 elf
{ return "hidden\[ \t_\]*$symbol" }
112 mach
-o
{ return "private_extern\[ \t_\]*_?$symbol" }
113 default
{ return "" }
119 # Check that a symbol is defined as a hidden symbol in the .s file
120 # produced by the compiler.
122 proc scan
-hidden
{ args } {
123 set testcase
[testname
-for-summary
]
124 # The
name might
include a list of options
; extract the file
name.
125 set filename
[lindex $testcase
0]
126 set output_file
"[file rootname [file tail $filename]].s"
128 set symbol
[lindex $
args 0]
130 set hidden_scan
[hidden
-scan
-for $symbol
]
132 set args [lreplace $
args 0 0 "$hidden_scan"]
134 dg
-scan
"scan-hidden" 1 $testcase $output_file $args
137 # Check that a symbol is not defined as a hidden symbol in the .s file
138 # produced by the compiler.
140 proc scan
-not
-hidden
{ args } {
141 set testcase
[testname
-for-summary
]
142 # The
name might
include a list of options
; extract the file
name.
143 set filename
[lindex $testcase
0]
144 set output_file
"[file rootname [file tail $filename]].s"
146 set symbol
[lindex $
args 0]
147 set hidden_scan
[hidden
-scan
-for $symbol
]
149 set args [lreplace $
args 0 0 "$hidden_scan"]
151 dg
-scan
"scan-not-hidden" 0 $testcase $output_file $args
154 # Look
for a pattern in OUTPUT_FILE. See dg
-scan
for details.
156 proc scan
-file
{ output_file
args } {
157 set testcase
[testname
-for-summary
]
158 dg
-scan
"scan-file" 1 $testcase $output_file $args
161 # Check that a pattern is not present in the OUTPUT_FILE. See dg
-scan
164 proc scan
-file
-not
{ output_file
args } {
165 set testcase
[testname
-for-summary
]
166 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
169 # Look
for a pattern in the .su file produced by the compiler. See
170 # dg
-scan
for details.
172 proc scan
-stack
-usage
{ args } {
173 set testcase
[testname
-for-summary
]
174 # The
name might
include a list of options
; extract the file
name.
175 set filename
[lindex $testcase
0]
176 set output_file
"[file rootname [file tail $filename]].su"
178 dg
-scan
"scan-file" 1 $testcase $output_file $args
181 # Check that a pattern is not present in the .su file produced by the
182 # compiler. See dg
-scan
for details.
184 proc scan
-stack
-usage
-not
{ args } {
185 set testcase
[testname
-for-summary
]
186 # The
name might
include a list of options
; extract the file
name.
187 set filename
[lindex $testcase
0]
188 set output_file
"[file rootname [file tail $filename]].su"
190 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
193 #
Return the filename of the Ada spec corresponding to the
argument.
195 proc get_ada_spec_filename
{ testcase
} {
196 # The
name might
include a list of options
; extract the file
name.
197 set filename
[lindex $testcase
0]
198 set tailname
[file tail $filename
]
199 set extension
[string trimleft
[file extension $tailname
] {.
}]
200 regsub
-all
{\
-} [file rootname $tailname
] {_
} rootname
202 return [string tolower
"${rootname}_${extension}.ads"]
205 # Look
for a pattern in the .ads file produced by the compiler. See
206 # dg
-scan
for details.
208 proc scan
-ada
-spec
{ args } {
209 set testcase
[testname
-for-summary
]
210 set output_file
"[get_ada_spec_filename $testcase]"
212 dg
-scan
"scan-file" 1 $testcase $output_file $args
215 # Check that a pattern is not present in the .ads file produced by the
216 # compiler. See dg
-scan
for details.
218 proc scan
-ada
-spec
-not
{ args } {
219 set testcase
[testname
-for-summary
]
220 set output_file
"[get_ada_spec_filename $testcase]"
222 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
225 #
Call pass
if pattern is present given number of times
, otherwise fail.
226 proc scan
-assembler
-times
{ args } {
227 if { [llength $
args] < 2 } {
228 error
"scan-assembler: too few arguments"
231 if { [llength $
args] > 3 } {
232 error
"scan-assembler: too many arguments"
235 if { [llength $
args] >= 3 } {
236 switch [dg
-process
-target
[lindex $
args 2]] {
239 "F" { setup_xfail "*-*-*" }
244 set testcase
[testname
-for-summary
]
245 # The
name might
include a list of options
; extract the file
name.
246 set filename
[lindex $testcase
0]
247 set pattern
[lindex $
args 0]
248 set times
[lindex $
args 1]
249 set pp_pattern
[make_pattern_printable $pattern
]
251 # This must match the rule in gcc
-dg.exp.
252 set output_file
"[file rootname [file tail $filename]].s"
254 set files
[glob
-nocomplain $output_file
]
255 if { $files
== "" } {
256 verbose
-log "$testcase: output file does not exist"
257 unresolved
"$testcase scan-assembler-times $pp_pattern $times"
261 set fd
[open $output_file r
]
265 set result_count
[llength
[regexp
-inline
-all
-- $pattern $
text]]
266 if {$result_count
== $times
} {
267 pass
"$testcase scan-assembler-times $pp_pattern $times"
269 fail
"$testcase scan-assembler-times $pp_pattern $times (found $result_count times)"
273 force_conventional_output_for scan
-assembler
-times
275 # Utility
for scanning demangled compiler result
, invoked via dg
-final.
276 #
Call pass
if pattern is present
, otherwise fail.
277 proc scan
-assembler
-dem
{ args } {
281 if { [llength $
args] < 1 } {
282 error
"scan-assembler-dem: too few arguments"
285 if { [llength $
args] > 2 } {
286 error
"scan-assembler-dem: too many arguments"
289 if { [llength $
args] >= 2 } {
290 switch [dg
-process
-target
[lindex $
args 1]] {
293 "F" { setup_xfail "*-*-*" }
298 # Find c
++filt like we find g
++ in g
++.exp.
299 if ![info exists cxxfilt
] {
300 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
301 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
302 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
303 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
304 [transform c
++filt
]]]]
305 verbose
-log "c++filt is $cxxfilt"
308 set testcase
[testname
-for-summary
]
309 # The
name might
include a list of options
; extract the file
name.
310 set filename
[lindex $testcase
0]
311 set pattern
[lindex $
args 0]
312 set pp_pattern
[make_pattern_printable $pattern
]
313 set output_file
"[file rootname [file tail $filename]].s"
315 set files
[glob
-nocomplain $output_file
]
316 if { $files
== "" } {
317 verbose
-log "$testcase: output file does not exist"
318 unresolved
"$testcase scan-assembler-dem $pp_pattern"
322 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
323 set text [lindex $output
1]
325 if [regexp
-- $pattern $
text] {
326 pass
"$testcase scan-assembler-dem $pp_pattern"
328 fail
"$testcase scan-assembler-dem $pp_pattern"
332 #
Call pass
if demangled pattern is not present
, otherwise fail.
333 proc scan
-assembler
-dem
-not
{ args } {
337 if { [llength $
args] < 1 } {
338 error
"scan-assembler-dem-not: too few arguments"
341 if { [llength $
args] > 2 } {
342 error
"scan-assembler-dem-not: too many arguments"
345 if { [llength $
args] >= 2 } {
346 switch [dg
-process
-target
[lindex $
args 1]] {
349 "F" { setup_xfail "*-*-*" }
354 # Find c
++filt like we find g
++ in g
++.exp.
355 if ![info exists cxxfilt
] {
356 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
357 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
358 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
359 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
360 [transform c
++filt
]]]]
361 verbose
-log "c++filt is $cxxfilt"
364 set testcase
[testname
-for-summary
]
365 # The
name might
include a list of options
; extract the file
name.
366 set filename
[lindex $testcase
0]
367 set pattern
[lindex $
args 0]
368 set pp_pattern
[make_pattern_printable $pattern
]
369 set output_file
"[file rootname [file tail $filename]].s"
371 set files
[glob
-nocomplain $output_file
]
372 if { $files
== "" } {
373 verbose
-log "$testcase: output file does not exist"
374 unresolved
"$testcase scan-assembler-dem-not $pp_pattern"
378 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
379 set text [lindex $output
1]
381 if ![regexp
-- $pattern $
text] {
382 pass
"$testcase scan-assembler-dem-not $pp_pattern"
384 fail
"$testcase scan-assembler-dem-not $pp_pattern"
388 #
Call pass
if object size is ok
, otherwise fail.
389 # example
: /* { dg
-final
{ object
-size
text <= 54 } } */
390 proc object
-size
{ args } {
394 if { [llength $
args] < 3 } {
395 error
"object-size: too few arguments"
398 if { [llength $
args] > 4 } {
399 error
"object-size: too many arguments"
402 if { [llength $
args] >= 4 } {
403 switch [dg
-process
-target
[lindex $
args 3]] {
406 "F" { setup_xfail "*-*-*" }
411 # Find size like we find g
++ in g
++.exp.
412 if ![info exists size
] {
413 set size
[findfile $base_dir
/..
/..
/..
/binutils
/size \
414 $base_dir
/..
/..
/..
/binutils
/size \
415 [findfile $base_dir
/..
/..
/size $base_dir
/..
/..
/size \
416 [findfile $base_dir
/size $base_dir
/size \
418 verbose
-log "size is $size"
421 set testcase
[testname
-for-summary
]
422 # The
name might
include a list of options
; extract the file
name.
423 set filename
[lindex $testcase
0]
424 set what
[lindex $
args 0]
425 set where
[lsearch
{ text data bss
total } $what
]
426 if { $where
== -1 } {
427 error
"object-size: illegal argument: $what"
430 set cmp
[lindex $
args 1]
431 if { [lsearch
{ < > <= >= == != } $cmp
] == -1 } {
432 error
"object-size: illegal argument: $cmp"
435 set with
[lindex $
args 2]
436 if ![string is
integer $with
] {
437 error
"object-size: illegal argument: $with"
441 set output_file
"[file rootname [file tail $filename]].o"
442 if ![file_on_host
exists $output_file
] {
443 verbose
-log "$testcase: $output_file does not exist"
444 unresolved
"$testcase object-size $what $cmp $with"
447 set output
[remote_exec host
"$size" "$output_file"]
448 set status [lindex $output
0]
449 if { $
status != 0 } {
450 verbose
-log "$testcase object-size: $size failed"
451 unresolved
"$testcase object-size $what $cmp $with"
455 set text [lindex $output
1]
456 set lines
[split $
text "\n"]
458 set line0
[lindex $lines
0]
459 if ![regexp
{^\s
*text\s
+data\s
+bss\s
+dec\s
+hex\s
+filename\s
*$
} $line0
] {
460 verbose
-log "$testcase object-size: $size did not produce expected first line: $line0"
461 unresolved
"$testcase object-size $what $cmp $with"
465 set line1
[lindex $lines
1]
466 if ![regexp
{^\s
*\d
+\s
+\d
+\s
+\d
+\s
+\d
+\s
+[\da
-fA
-F
]+\s
+} $line1
] {
467 verbose
-log "$testcase object-size: $size did not produce expected second line: $line1"
468 unresolved
"$testcase object-size $what $cmp $with"
472 set actual
[lindex $line1 $where
]
473 verbose
-log "$what size is $actual"
475 if [expr $actual $cmp $with
] {
476 pass
"$testcase object-size $what $cmp $with"
478 fail
"$testcase object-size $what $cmp $with"
482 # Utility
for testing that a function is defined
on the current line.
483 #
Call pass
if so
, otherwise fail. Invoked directly
; the file must
484 # have been compiled with
-g
-dA.
486 #
Argument 0 is the current line
, passed implicitly by dejagnu
487 #
Argument 1 is the function to check
488 #
Argument 2 handles expected failures and the like
489 #
Argument 3 is
"." to match the current line, or an integer to match
491 proc dg
-function
-on-line
{ args } {
492 # Upvar from dg
-final
:
493 upvar dg
-final
-code final
-code
495 set line
[lindex $
args 0]
496 set symbol
[lindex $
args 1]
497 set failures
[lindex $
args 2]
499 if { [llength $
args] >= 4 } {
500 switch [lindex $
args 3] {
502 "default" { set line [lindex $args 3] }
506 if { [istarget hppa
*-*-*] } {
507 set pattern
[format
{\t;[^
:]+:%d
(:[0-9]+)?
\n(\t[^
\t]+\n)+%s
:\n\t.PROC
} \
509 } elseif
{ [istarget mips
*-*-*] } {
510 set pattern
[format
{\t\.loc
[0-9]+ %d
[0-9]+( [^
\n]*)?
\n(\t.cfi_startproc
[^
\t]*\n)*\t\.
set\t(no
)?mips16
\n\t(\.
set\t(no
)?micromips
\n\t)?\.ent
\t%s
\n\t\.type
\t%s
, @function
\n%s
:\n} \
511 $line $symbol $symbol $symbol
]
512 } elseif
{ [istarget microblaze
*-*-*] } {
513 set pattern
[format
{:%d
(:[0-9]+)?
\n\$.
*:\n\t\.ent
\t%s
\n\t\.type
\t%s
, @function
\n%s
:\n} \
514 $line $symbol $symbol $symbol
]
516 set pattern
[format
{%s
:[^
\t]*(\t.
(fnstart|frame|mask|file
)[^
\t]*)*\t[^
:]+:%d
(:[0-9]+)?
\n} \
520 # The lack of spaces around $pattern is important
, since they
'd
521 # become part of the regex scan-assembler tries to match.
522 set cmd "scan-assembler {$pattern}"
523 if { [llength $args] >= 3 } {
524 set cmd "$cmd {$failures}"
527 append final-code "$cmd\n"
530 # Look for a pattern in the .exe.ltrans0.s file produced by the
531 # compiler. See dg-scan for details.
533 proc scan-lto-assembler { args } {
534 set testcase [testname-for-summary]
535 # The name might include a list of options; extract the file name.
536 set filename [lindex $testcase 0]
537 set output_file "[file rootname [file tail $filename]].exe.ltrans0.s"
538 verbose "output_file: $output_file"
539 dg-scan "scan-assembler" 1 $testcase $output_file $args