1 # Copyright (C) 2000-2020 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 dump output, used by gcc-dg.exp and
20 # This is largely borrowed from scanasm.exp.
22 # Extract the constant part of the dump file suffix from the regexp.
23 # Argument 0 is the regular expression.
24 proc dump-suffix { arg } {
25 set idx [expr [string first "." $arg] + 1]
26 return [string range $arg $idx end]
29 # Construct the dumpbase.
30 # Argument 0 is the src file
31 # Argument 1 is the dump base suffix
32 proc dump-base { args } {
33 set src [lindex $args 0]
34 set dumpbase_suf [lindex $args 1]
36 if { [string length $dumpbase_suf] != 0 } {
37 regsub {[.][^.]*$} $src $dumpbase_suf dumpbase
42 # Utility for scanning compiler result, invoked via dg-final.
43 # Call pass if pattern is present, otherwise fail.
45 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
46 # Argument 1 is the regexp to match.
47 # Argument 2 is the suffix for the dump file
48 # Argument 3 is the suffix of the dump base
49 # Argument 4 handles expected failures and the like
50 proc scan-dump { args } {
52 if { [llength $args] >= 5 } {
53 switch [dg-process-target [lindex $args 4]] {
56 "F" { setup_xfail "*-*-*" }
61 set testcase [testname-for-summary]
62 # The name might include a list of options; extract the file name.
63 set filename [lindex $testcase 0]
65 set printable_pattern [make_pattern_printable [lindex $args 1]]
66 set suf [dump-suffix [lindex $args 2]]
67 set testname "$testcase scan-[lindex $args 0]-dump $suf \"$printable_pattern\""
68 set src [file tail $filename]
69 set dumpbase [dump-base $src [lindex $args 3]]
70 set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
71 if { $output_file == "" } {
72 verbose -log "$testcase: dump file does not exist"
73 unresolved "$testname"
77 set fd [open $output_file r]
81 if [regexp -- [lindex $args 1] $text] {
88 # Call pass if pattern is present given number of times, otherwise fail.
89 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
90 # Argument 1 is the regexp to match.
91 # Argument 2 is number of times the regexp must be found
92 # Argument 3 is the suffix for the dump file
93 # Argument 4 is the suffix of the dump base
94 # Argument 5 handles expected failures and the like
95 proc scan-dump-times { args } {
97 if { [llength $args] >= 6 } {
98 switch [dg-process-target [lindex $args 5]] {
101 "F" { setup_xfail "*-*-*" }
106 set testcase [testname-for-summary]
107 # The name might include a list of options; extract the file name.
108 set filename [lindex $testcase 0]
109 set times [lindex $args 2]
110 set suf [dump-suffix [lindex $args 3]]
111 set printable_pattern [make_pattern_printable [lindex $args 1]]
112 set testname "$testcase scan-[lindex $args 0]-dump-times $suf \"$printable_pattern\" [lindex $args 2]"
113 set src [file tail $filename]
114 set dumpbase [dump-base $src [lindex $args 4]]
115 set output_file "[glob -nocomplain $dumpbase.[lindex $args 3]]"
116 if { $output_file == "" } {
117 verbose -log "$testcase: dump file does not exist"
118 unresolved "$testname"
122 set fd [open $output_file r]
126 set result_count [llength [regexp -inline -all -- [lindex $args 1] $text]]
127 if {$result_count == $times} {
130 verbose -log "$testcase: pattern found $result_count times"
135 # Call pass if pattern is not present, otherwise fail.
137 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
138 # Argument 1 is the regexp to match.
139 # Argument 2 is the suffix for the dump file
140 # Argument 3 is the suffix of the dump base
141 # Argument 4 handles expected failures and the like
142 proc scan-dump-not { args } {
144 if { [llength $args] >= 5 } {
145 switch [dg-process-target [lindex $args 4]] {
148 "F" { setup_xfail "*-*-*" }
153 set testcase [testname-for-summary]
154 # The name might include a list of options; extract the file name.
155 set filename [lindex $testcase 0]
156 set printable_pattern [make_pattern_printable [lindex $args 1]]
157 set suf [dump-suffix [lindex $args 2]]
158 set testname "$testcase scan-[lindex $args 0]-dump-not $suf \"$printable_pattern\""
159 set src [file tail $filename]
160 set dumpbase [dump-base $src [lindex $args 3]]
161 set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
162 if { $output_file == "" } {
163 verbose -log "$testcase: dump file does not exist"
164 unresolved "$testname"
168 set fd [open $output_file r]
172 if ![regexp -- [lindex $args 1] $text] {
179 # Utility for scanning demangled compiler result, invoked via dg-final.
180 # Call pass if pattern is present, otherwise fail.
182 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
183 # Argument 1 is the regexp to match.
184 # Argument 2 is the suffix for the dump file
185 # Argument 3 is the suffix of the dump base
186 # Argument 4 handles expected failures and the like
187 proc scan-dump-dem { args } {
191 if { [llength $args] >= 5 } {
192 switch [dg-process-target [lindex $args 4]] {
195 "F" { setup_xfail "*-*-*" }
200 # Find c++filt like we find g++ in g++.exp.
201 if ![info exists cxxfilt] {
202 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
203 $base_dir/../../../binutils/cxxfilt \
204 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
205 [findfile $base_dir/c++filt $base_dir/c++filt \
206 [transform c++filt]]]]
207 verbose -log "c++filt is $cxxfilt"
210 set testcase [testname-for-summary]
211 # The name might include a list of options; extract the file name.
212 set filename [lindex $testcase 0]
213 set printable_pattern [make_pattern_printable [lindex $args 1]]
214 set suf [dump-suffix [lindex $args 2]]
215 set testname "$testcase scan-[lindex $args 0]-dump-dem $suf \"$printable_pattern\""
216 set src [file tail $filename]
217 set dumpbase [dump-base $src [lindex $args 3]]
218 set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
219 if { $output_file == "" } {
220 verbose -log "$testcase: dump file does not exist"
221 unresolved "$testname"
225 set fd [open "| $cxxfilt < $output_file" r]
229 if [regexp -- [lindex $args 1] $text] {
236 # Call pass if demangled pattern is not present, otherwise fail.
238 # Argument 0 is the type of dump we are searching (rtl, tree, ipa)
239 # Argument 1 is the regexp to match.
240 # Argument 2 is the suffix for the dump file
241 # Argument 3 is the suffix of the dump base
242 # Argument 4 handles expected failures and the like
243 proc scan-dump-dem-not { args } {
247 if { [llength $args] >= 5 } {
248 switch [dg-process-target [lindex $args 4]] {
251 "F" { setup_xfail "*-*-*" }
256 # Find c++filt like we find g++ in g++.exp.
257 if ![info exists cxxfilt] {
258 set cxxfilt [findfile $base_dir/../../../binutils/cxxfilt \
259 $base_dir/../../../binutils/cxxfilt \
260 [findfile $base_dir/../../c++filt $base_dir/../../c++filt \
261 [findfile $base_dir/c++filt $base_dir/c++filt \
262 [transform c++filt]]]]
263 verbose -log "c++filt is $cxxfilt"
266 set testcase [testname-for-summary]
267 # The name might include a list of options; extract the file name.
268 set filename [lindex $testcase 0]
269 set printable_pattern [make_pattern_printable [lindex $args 1]
270 set suf [dump-suffix [lindex $args 2]]
271 set testname "$testcase scan-[lindex $args 0]-dump-dem-not $suf \"$printable_pattern\""
272 set src [file tail $filename]
273 set dumpbase [dump-base $src [lindex $args 3]]
274 set output_file "[glob -nocomplain $dumpbase.[lindex $args 2]]"
275 if { $output_file == "" } {
276 verbose -log "$testcase: dump file does not exist"
277 unresolved "$testname"
281 set fd [open "| $cxxfilt < $output_file" r]
285 if ![regexp -- [lindex $args 1] $text] {