When a check-function-bodies test fails, it can sometimes be hard to
identify which part of a large function regexp is causing the failure.
To aid debugging these failures, find the largest initial set of lines
that matches the function, and log this separately from the remainder of
the regexp.
Additionally, add a newline before logging the function bodies, so that
the first line has the same indentation as the rest of that function.
gcc/testsuite/ChangeLog:
* lib/scanasm.exp (check_function_body): Log matching portion
of body_regexp separately.
---
I've tested this by taking working tests and deleting a line from the start,
end, or middle of the regexp, including a line from the middle of a group of
alternative sequences. In all cases the output was as expected (although less
precise when alternatives are involved).
Is this, or something similar, ok for master?
Alice
diff --git a/gcc/testsuite/lib/scanasm.exp b/gcc/testsuite/lib/scanasm.exp
index
c414d44f0f0e614fe96cdd64d51eb06758c47992..be26f16dd7dc0f0a7925d39d486e3c5b137fc8f8
100644
--- a/gcc/testsuite/lib/scanasm.exp
+++ b/gcc/testsuite/lib/scanasm.exp
@@ -983,8 +983,31 @@ proc check_function_body { functions name body_regexp } {
}
set fn_res [regexp "^$body_regexp\$" $up_functions($name)]
if { !$fn_res } {
- verbose -log "body: $body_regexp"
- verbose -log "against: $up_functions($name)"
+ # Find the longest initial set of lines in body_regexp that matches the
+ # function. Unfortunately this makes runtime quadratic in the number of
+ # lines, but failures in large check-function-body regexps are hopefully
+ # rare.
+ set ok_index [string length $body_regexp]
+ incr ok_index -1
+ while {$ok_index >= 0} {
+ set short_regexp [string range $body_regexp 0 $ok_index]
+ set match_found 0
+ # Not all initial sets of lines are valid. Ignore any broken regexps.
+ catch {
+ if { [regexp "^$short_regexp" $up_functions($name)] } {
+ set match_found 1
+ }
+ }
+ if {$match_found} {
+ break
+ }
+ set ok_index [string last "\n" $body_regexp $ok_index-1]
+ }
+ set head [string range $body_regexp 0 $ok_index]
+ set tail [string range $body_regexp $ok_index+1 end]
+ verbose -log "initial matched regexp:\n$head"
+ verbose -log "mismatch in remaining regexp:\n$tail"
+ verbose -log "against:\n$up_functions($name)"
}
return $fn_res
}