1 # Copyright
(C
) 2000-2015 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 set output_file
"[file rootname [file tail $testcase]].s"
82 dg
-scan
"scan-assembler" 1 $testcase $output_file $args
85 force_conventional_output_for scan
-assembler
87 # Check that a pattern is not present in the .s file produced by the
88 # compiler. See dg
-scan
for details.
90 proc scan
-assembler
-not
{ args } {
91 set testcase
[testname
-for-summary
]
92 set output_file
"[file rootname [file tail $testcase]].s"
94 dg
-scan
"scan-assembler-not" 0 $testcase $output_file $args
97 force_conventional_output_for scan
-assembler
-not
99 #
Return the scan
for the assembly
for hidden visibility.
101 proc hidden
-scan
-for { symbol
} {
103 set objformat
[gcc_target_object_format
]
106 elf
{ return "hidden\[ \t_\]*$symbol" }
107 mach
-o
{ return "private_extern\[ \t_\]*_?$symbol" }
108 default
{ return "" }
114 # Check that a symbol is defined as a hidden symbol in the .s file
115 # produced by the compiler.
117 proc scan
-hidden
{ args } {
118 set testcase
[testname
-for-summary
]
119 set output_file
"[file rootname [file tail $testcase]].s"
121 set symbol
[lindex $
args 0]
123 set hidden_scan
[hidden
-scan
-for $symbol
]
125 set args [lreplace $
args 0 0 "$hidden_scan"]
127 dg
-scan
"scan-hidden" 1 $testcase $output_file $args
130 # Check that a symbol is not defined as a hidden symbol in the .s file
131 # produced by the compiler.
133 proc scan
-not
-hidden
{ args } {
134 set testcase
[testname
-for-summary
]
135 set output_file
"[file rootname [file tail $testcase]].s"
137 set symbol
[lindex $
args 0]
138 set hidden_scan
[hidden
-scan
-for $symbol
]
140 set args [lreplace $
args 0 0 "$hidden_scan"]
142 dg
-scan
"scan-not-hidden" 0 $testcase $output_file $args
145 # Look
for a pattern in OUTPUT_FILE. See dg
-scan
for details.
147 proc scan
-file
{ output_file
args } {
148 set testcase
[testname
-for-summary
]
149 dg
-scan
"scan-file" 1 $testcase $output_file $args
152 # Check that a pattern is not present in the OUTPUT_FILE. See dg
-scan
155 proc scan
-file
-not
{ output_file
args } {
156 set testcase
[testname
-for-summary
]
157 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
160 # Look
for a pattern in the .su file produced by the compiler. See
161 # dg
-scan
for details.
163 proc scan
-stack
-usage
{ args } {
164 set testcase
[testname
-for-summary
]
165 set output_file
"[file rootname [file tail $testcase]].su"
167 dg
-scan
"scan-file" 1 $testcase $output_file $args
170 # Check that a pattern is not present in the .su file produced by the
171 # compiler. See dg
-scan
for details.
173 proc scan
-stack
-usage
-not
{ args } {
174 set testcase
[testname
-for-summary
]
175 set output_file
"[file rootname [file tail $testcase]].su"
177 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
180 #
Return the filename of the Ada spec corresponding to the
argument.
182 proc get_ada_spec_filename
{ testcase
} {
183 # The
name might
include a list of options
; extract the file
name.
184 set filename
[lindex $testcase
0]
185 set tailname
[file tail $filename
]
186 set extension
[string trimleft
[file extension $tailname
] {.
}]
187 regsub
-all
{\
-} [file rootname $tailname
] {_
} rootname
189 return [string tolower
"${rootname}_${extension}.ads"]
192 # Look
for a pattern in the .ads file produced by the compiler. See
193 # dg
-scan
for details.
195 proc scan
-ada
-spec
{ args } {
196 set testcase
[testname
-for-summary
]
197 set output_file
"[get_ada_spec_filename $testcase]"
199 dg
-scan
"scan-file" 1 $testcase $output_file $args
202 # Check that a pattern is not present in the .ads file produced by the
203 # compiler. See dg
-scan
for details.
205 proc scan
-ada
-spec
-not
{ args } {
206 set testcase
[testname
-for-summary
]
207 set output_file
"[get_ada_spec_filename $testcase]"
209 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
212 #
Call pass
if pattern is present given number of times
, otherwise fail.
213 proc scan
-assembler
-times
{ args } {
214 if { [llength $
args] < 2 } {
215 error
"scan-assembler: too few arguments"
218 if { [llength $
args] > 3 } {
219 error
"scan-assembler: too many arguments"
222 if { [llength $
args] >= 3 } {
223 switch [dg
-process
-target
[lindex $
args 2]] {
226 "F" { setup_xfail "*-*-*" }
231 set testcase
[testname
-for-summary
]
232 set pattern
[lindex $
args 0]
233 set pp_pattern
[make_pattern_printable $pattern
]
235 # This must match the rule in gcc
-dg.exp.
236 set output_file
"[file rootname [file tail $testcase]].s"
238 set files
[glob
-nocomplain $output_file
]
239 if { $files
== "" } {
240 verbose
-log "$testcase: output file does not exist"
241 unresolved
"$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
245 set fd
[open $output_file r
]
249 if { [llength
[regexp
-inline
-all
-- $pattern $
text]] == [lindex $
args 1]} {
250 pass
"$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
252 fail
"$testcase scan-assembler-times $pp_pattern [lindex $args 1]"
256 force_conventional_output_for scan
-assembler
-times
258 # Utility
for scanning demangled compiler result
, invoked via dg
-final.
259 #
Call pass
if pattern is present
, otherwise fail.
260 proc scan
-assembler
-dem
{ args } {
264 if { [llength $
args] < 1 } {
265 error
"scan-assembler-dem: too few arguments"
268 if { [llength $
args] > 2 } {
269 error
"scan-assembler-dem: too many arguments"
272 if { [llength $
args] >= 2 } {
273 switch [dg
-process
-target
[lindex $
args 1]] {
276 "F" { setup_xfail "*-*-*" }
281 # Find c
++filt like we find g
++ in g
++.exp.
282 if ![info exists cxxfilt
] {
283 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
284 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
285 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
286 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
287 [transform c
++filt
]]]]
288 verbose
-log "c++filt is $cxxfilt"
291 set testcase
[testname
-for-summary
]
292 set pattern
[lindex $
args 0]
293 set pp_pattern
[make_pattern_printable $pattern
]
294 set output_file
"[file rootname [file tail $testcase]].s"
296 set files
[glob
-nocomplain $output_file
]
297 if { $files
== "" } {
298 verbose
-log "$testcase: output file does not exist"
299 unresolved
"$testcase scan-assembler-dem $pp_pattern"
303 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
304 set text [lindex $output
1]
306 if [regexp
-- $pattern $
text] {
307 pass
"$testcase scan-assembler-dem $pp_pattern"
309 fail
"$testcase scan-assembler-dem $pp_pattern"
313 #
Call pass
if demangled pattern is not present
, otherwise fail.
314 proc scan
-assembler
-dem
-not
{ args } {
318 if { [llength $
args] < 1 } {
319 error
"scan-assembler-dem-not: too few arguments"
322 if { [llength $
args] > 2 } {
323 error
"scan-assembler-dem-not: too many arguments"
326 if { [llength $
args] >= 2 } {
327 switch [dg
-process
-target
[lindex $
args 1]] {
330 "F" { setup_xfail "*-*-*" }
335 # Find c
++filt like we find g
++ in g
++.exp.
336 if ![info exists cxxfilt
] {
337 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
338 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
339 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
340 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
341 [transform c
++filt
]]]]
342 verbose
-log "c++filt is $cxxfilt"
345 set testcase
[testname
-for-summary
]
346 set pattern
[lindex $
args 0]
347 set pp_pattern
[make_pattern_printable $pattern
]
348 set output_file
"[file rootname [file tail $testcase]].s"
350 set files
[glob
-nocomplain $output_file
]
351 if { $files
== "" } {
352 verbose
-log "$testcase: output file does not exist"
353 unresolved
"$testcase scan-assembler-dem-not $pp_pattern"
357 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
358 set text [lindex $output
1]
360 if ![regexp
-- $pattern $
text] {
361 pass
"$testcase scan-assembler-dem-not $pp_pattern"
363 fail
"$testcase scan-assembler-dem-not $pp_pattern"
367 #
Call pass
if object size is ok
, otherwise fail.
368 # example
: /* { dg
-final
{ object
-size
text <= 54 } } */
369 proc object
-size
{ args } {
373 if { [llength $
args] < 3 } {
374 error
"object-size: too few arguments"
377 if { [llength $
args] > 4 } {
378 error
"object-size: too many arguments"
381 if { [llength $
args] >= 4 } {
382 switch [dg
-process
-target
[lindex $
args 3]] {
385 "F" { setup_xfail "*-*-*" }
390 # Find size like we find g
++ in g
++.exp.
391 if ![info exists size
] {
392 set size
[findfile $base_dir
/..
/..
/..
/binutils
/size \
393 $base_dir
/..
/..
/..
/binutils
/size \
394 [findfile $base_dir
/..
/..
/size $base_dir
/..
/..
/size \
395 [findfile $base_dir
/size $base_dir
/size \
397 verbose
-log "size is $size"
400 set testcase
[testname
-for-summary
]
401 set what
[lindex $
args 0]
402 set where
[lsearch
{ text data bss
total } $what
]
403 if { $where
== -1 } {
404 error
"object-size: illegal argument: $what"
407 set cmp
[lindex $
args 1]
408 if { [lsearch
{ < > <= >= == != } $cmp
] == -1 } {
409 error
"object-size: illegal argument: $cmp"
412 set with
[lindex $
args 2]
413 if ![string is
integer $with
] {
414 error
"object-size: illegal argument: $with"
418 set output_file
"[file rootname [file tail $testcase]].o"
419 if ![file_on_host
exists $output_file
] {
420 verbose
-log "$testcase: $output_file does not exist"
421 unresolved
"$testcase object-size $what $cmp $with"
424 set output
[remote_exec host
"$size" "$output_file"]
425 set status [lindex $output
0]
426 if { $
status != 0 } {
427 verbose
-log "$testcase object-size: $size failed"
428 unresolved
"$testcase object-size $what $cmp $with"
432 set text [lindex $output
1]
433 set lines
[split $
text "\n"]
435 set line0
[lindex $lines
0]
436 if ![regexp
{^\s
*text\s
+data\s
+bss\s
+dec\s
+hex\s
+filename\s
*$
} $line0
] {
437 verbose
-log "$testcase object-size: $size did not produce expected first line: $line0"
438 unresolved
"$testcase object-size $what $cmp $with"
442 set line1
[lindex $lines
1]
443 if ![regexp
{^\s
*\d
+\s
+\d
+\s
+\d
+\s
+\d
+\s
+[\da
-fA
-F
]+\s
+} $line1
] {
444 verbose
-log "$testcase object-size: $size did not produce expected second line: $line1"
445 unresolved
"$testcase object-size $what $cmp $with"
449 set actual
[lindex $line1 $where
]
450 verbose
-log "$what size is $actual"
452 if [expr $actual $cmp $with
] {
453 pass
"$testcase object-size $what $cmp $with"
455 fail
"$testcase object-size $what $cmp $with"
459 # Utility
for testing that a function is defined
on the current line.
460 #
Call pass
if so
, otherwise fail. Invoked directly
; the file must
461 # have been compiled with
-g
-dA.
463 #
Argument 0 is the current line
, passed implicitly by dejagnu
464 #
Argument 1 is the function to check
465 #
Argument 2 handles expected failures and the like
466 #
Argument 3 is
"." to match the current line, or an integer to match
468 proc dg
-function
-on-line
{ args } {
469 # Upvar from dg
-final
:
470 upvar dg
-final
-code final
-code
472 set line
[lindex $
args 0]
473 set symbol
[lindex $
args 1]
474 set failures
[lindex $
args 2]
476 if { [llength $
args] >= 4 } {
477 switch [lindex $
args 3] {
479 "default" { set line [lindex $args 3] }
483 if { [istarget hppa
*-*-*] } {
484 set pattern
[format
{\t;[^
:]+:%d
\n(\t[^
\t]+\n)+%s
:\n\t.PROC
} \
486 } elseif
{ [istarget mips
*-*-*] } {
487 set pattern
[format
{\t\.loc
[0-9]+ %d
0( [^
\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} \
488 $line $symbol $symbol $symbol
]
489 } elseif
{ [istarget microblaze
*-*-*] } {
490 set pattern
[format
{:%d
\n\$.
*:\n\t\.ent
\t%s
\n\t\.type
\t%s
, @function
\n%s
:\n} \
491 $line $symbol $symbol $symbol
]
493 set pattern
[format
{%s
:[^
\t]*(\t.
(fnstart|frame|mask|file
)[^
\t]*)*\t[^
:]+:%d
\n} \
497 # The lack of spaces around $pattern is important
, since they
'd
498 # become part of the regex scan-assembler tries to match.
499 set cmd "scan-assembler {$pattern}"
500 if { [llength $args] >= 3 } {
501 set cmd "$cmd {$failures}"
504 append final-code "$cmd\n"
507 # Look for a pattern in the .exe.ltrans0.s file produced by the
508 # compiler. See dg-scan for details.
510 proc scan-lto-assembler { args } {
511 set testcase [testname-for-summary]
512 set output_file "[file rootname [file tail $testcase]].exe.ltrans0.s"
513 verbose "output_file: $output_file"
514 dg-scan "scan-assembler" 1 $testcase $output_file $args