1 # Copyright
(C
) 2000, 2002, 2003, 2007 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 # Scan the OUTPUT_FILE
for a pattern.
If it is present and POSITIVE
23 # is non
-zero
, or it is not present and POSITIVE is zero
, the test
24 # passes. The ORIG_ARGS is the list of arguments provided by dg
-final
25 # to scan
-assembler. The first element in ORIG_ARGS is the regular
26 # expression to look
for in the file. The second element
, if present
,
27 # is a DejaGNU target selector.
29 proc dg
-scan
{ name positive testcase output_file orig_args
} {
30 if { [llength $orig_args
] < 1 } {
31 error
"$name: too few arguments"
34 if { [llength $orig_args
] > 2 } {
35 error
"$name: too many arguments"
38 if { [llength $orig_args
] >= 2 } {
39 switch [dg
-process
-target
[lindex $orig_args
1]] {
42 "F" { setup_xfail "*-*-*" }
47 if { [is_remote host
] } {
48 remote_upload host
"$output_file"
50 set fd
[open $output_file r
]
54 set pattern
[lindex $orig_args
0]
55 set printable_pattern
[string map
{\t \\t
\n \\n
\r \\r
\\ \\\\} $pattern
]
57 set match
[regexp
-- $pattern $
text]
58 if { $match
== $positive
} {
59 pass
"$testcase $name $printable_pattern"
61 fail
"$testcase $name $printable_pattern"
65 # Look
for a pattern in the .s file produced by the compiler. See
66 # dg
-scan
for details.
68 proc scan
-assembler
{ args } {
70 set output_file
"[file rootname [file tail $testcase]].s"
72 dg
-scan
"scan-assembler" 1 $testcase $output_file $args
75 # Check that a pattern is not present in the .s file produced by the
76 # compiler. See dg
-scan
for details.
78 proc scan
-assembler
-not
{ args } {
80 set output_file
"[file rootname [file tail $testcase]].s"
82 dg
-scan
"scan-assembler-not" 0 $testcase $output_file $args
85 #
Return the scan
for the assembly
for hidden visibility.
87 proc hidden
-scan
-for { symbol
} {
89 set objformat
[gcc_target_object_format
]
92 elf
{ return "hidden\[ \t_\]*$symbol" }
93 mach
-o
{ return "private_extern\[ \t_\]*_?$symbol" }
100 # Check that a symbol is defined as a hidden symbol in the .s file
101 # produced by the compiler.
103 proc scan
-hidden
{ args } {
104 upvar
2 name testcase
105 set output_file
"[file rootname [file tail $testcase]].s"
107 set symbol
[lindex $
args 0]
109 set hidden_scan
[hidden
-scan
-for $symbol
]
111 set args [lreplace $
args 0 0 "$hidden_scan"]
113 dg
-scan
"scan-hidden" 1 $testcase $output_file $args
116 # Check that a symbol is not defined as a hidden symbol in the .s file
117 # produced by the compiler.
119 proc scan
-not
-hidden
{ args } {
120 upvar
2 name testcase
121 set output_file
"[file rootname [file tail $testcase]].s"
123 set symbol
[lindex $
args 0]
124 set hidden_scan
[hidden
-scan
-for $symbol
]
126 set args [lreplace $
args 0 0 "$hidden_scan"]
128 dg
-scan
"scan-not-hidden" 0 $testcase $output_file $args
131 # Look
for a pattern in OUTPUT_FILE. See dg
-scan
for details.
133 proc scan
-file
{ output_file
args } {
134 upvar
2 name testcase
135 dg
-scan
"scan-file" 1 $testcase $output_file $args
138 # Check that a pattern is not present in the OUTPUT_FILE. See dg
-scan
141 proc scan
-file
-not
{ output_file
args } {
142 upvar
2 name testcase
143 dg
-scan
"scan-file-not" 0 $testcase $output_file $args
146 #
Call pass
if pattern is present given number of times
, otherwise fail.
147 proc scan
-assembler
-times
{ args } {
148 if { [llength $
args] < 2 } {
149 error
"scan-assembler: too few arguments"
152 if { [llength $
args] > 3 } {
153 error
"scan-assembler: too many arguments"
156 if { [llength $
args] >= 3 } {
157 switch [dg
-process
-target
[lindex $
args 2]] {
160 "F" { setup_xfail "*-*-*" }
165 # This assumes that we are two frames down from dg
-test
, and that
166 # it still stores the filename of the testcase in a local
variable "name".
167 # A cleaner solution would require a new dejagnu release.
168 upvar
2 name testcase
170 # This must match the rule in gcc
-dg.exp.
171 set output_file
"[file rootname [file tail $testcase]].s"
173 set fd
[open $output_file r
]
177 if { [llength
[regexp
-inline
-all
-- [lindex $
args 0] $
text]] == [lindex $
args 1]} {
178 pass
"$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
180 fail
"$testcase scan-assembler-times [lindex $args 0] [lindex $args 1]"
184 # Utility
for scanning demangled compiler result
, invoked via dg
-final.
185 #
Call pass
if pattern is present
, otherwise fail.
186 proc scan
-assembler
-dem
{ args } {
190 if { [llength $
args] < 1 } {
191 error
"scan-assembler-dem: too few arguments"
194 if { [llength $
args] > 2 } {
195 error
"scan-assembler-dem: too many arguments"
198 if { [llength $
args] >= 2 } {
199 switch [dg
-process
-target
[lindex $
args 1]] {
202 "F" { setup_xfail "*-*-*" }
207 # Find c
++filt like we find g
++ in g
++.exp.
208 if ![info exists cxxfilt
] {
209 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
210 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
211 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
212 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
213 [transform c
++filt
]]]]
214 verbose
-log "c++filt is $cxxfilt"
217 upvar
2 name testcase
218 set output_file
"[file rootname [file tail $testcase]].s"
220 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
221 set text [lindex $output
1]
223 if [regexp
-- [lindex $
args 0] $
text] {
224 pass
"$testcase scan-assembler-dem [lindex $args 0]"
226 fail
"$testcase scan-assembler-dem [lindex $args 0]"
230 #
Call pass
if demangled pattern is not present
, otherwise fail.
231 proc scan
-assembler
-dem
-not
{ args } {
235 if { [llength $
args] < 1 } {
236 error
"scan-assembler-dem-not: too few arguments"
239 if { [llength $
args] > 2 } {
240 error
"scan-assembler-dem-not: too many arguments"
243 if { [llength $
args] >= 2 } {
244 switch [dg
-process
-target
[lindex $
args 1]] {
247 "F" { setup_xfail "*-*-*" }
252 # Find c
++filt like we find g
++ in g
++.exp.
253 if ![info exists cxxfilt
] {
254 set cxxfilt
[findfile $base_dir
/..
/..
/..
/binutils
/cxxfilt \
255 $base_dir
/..
/..
/..
/binutils
/cxxfilt \
256 [findfile $base_dir
/..
/..
/c
++filt $base_dir
/..
/..
/c
++filt \
257 [findfile $base_dir
/c
++filt $base_dir
/c
++filt \
258 [transform c
++filt
]]]]
259 verbose
-log "c++filt is $cxxfilt"
262 upvar
2 name testcase
263 set output_file
"[file rootname [file tail $testcase]].s"
265 set output
[remote_exec host
"$cxxfilt" "" "$output_file"]
266 set text [lindex $output
1]
268 if ![regexp
-- [lindex $
args 0] $
text] {
269 pass
"$testcase scan-assembler-dem-not [lindex $args 0]"
271 fail
"$testcase scan-assembler-dem-not [lindex $args 0]"