@@ -122,11 +122,11 @@ var LoopVarHash *HashDebug // for debugging shared/private loop variable changes
122122// 6. gossahash should return a single function whose miscompilation
123123// causes the problem, and you can focus on that.
124124func DebugHashMatchPkgFunc (pkg , fn string ) bool {
125- return hashDebug .MatchPkgFunc (pkg , fn )
125+ return hashDebug .MatchPkgFunc (pkg , fn , nil )
126126}
127127
128128func DebugHashMatchPos (pos src.XPos ) bool {
129- return hashDebug .MatchPos (pos )
129+ return hashDebug .MatchPos (pos , nil )
130130}
131131
132132// HasDebugHash returns true if Flags.Gossahash is non-empty, which
@@ -247,62 +247,66 @@ func (d *HashDebug) match(hash uint64) *hashAndMask {
247247// representation of the hash of pkg and fn. If the variable is not nil,
248248// then a true result is accompanied by stylized output to d.logfile, which
249249// is used for automated bug search.
250- func (d * HashDebug ) MatchPkgFunc (pkg , fn string ) bool {
250+ func (d * HashDebug ) MatchPkgFunc (pkg , fn string , note func () string ) bool {
251251 if d == nil {
252252 return true
253253 }
254254 // Written this way to make inlining likely.
255- return d .matchPkgFunc (pkg , fn )
255+ return d .matchPkgFunc (pkg , fn , note )
256256}
257257
258- func (d * HashDebug ) matchPkgFunc (pkg , fn string ) bool {
258+ func (d * HashDebug ) matchPkgFunc (pkg , fn string , note func () string ) bool {
259259 hash := bisect .Hash (pkg , fn )
260- if d .bisect != nil {
261- if d .bisect .ShouldPrint (hash ) {
262- d .log (d .name , hash , pkg + "." + fn )
263- }
264- return d .bisect .ShouldEnable (hash )
265- }
266-
267- // TODO: Delete rest of function body when we switch to bisect-only.
268- if m := d .match (hash ); m != nil {
269- d .log (m .name , hash , pkg + "." + fn )
270- return true
271- }
272- return false
260+ return d .matchAndLog (hash , func () string { return pkg + "." + fn }, note )
273261}
274262
275263// MatchPos is similar to MatchPkgFunc, but for hash computation
276264// it uses the source position including all inlining information instead of
277265// package name and path.
278266// Note that the default answer for no environment variable (d == nil)
279267// is "yes", do the thing.
280- func (d * HashDebug ) MatchPos (pos src.XPos ) bool {
268+ func (d * HashDebug ) MatchPos (pos src.XPos , desc func () string ) bool {
281269 if d == nil {
282270 return true
283271 }
284272 // Written this way to make inlining likely.
285- return d .matchPos (Ctxt , pos )
273+ return d .matchPos (Ctxt , pos , desc )
286274}
287275
288- func (d * HashDebug ) matchPos (ctxt * obj.Link , pos src.XPos ) bool {
276+ func (d * HashDebug ) matchPos (ctxt * obj.Link , pos src.XPos , note func () string ) bool {
289277 hash := d .hashPos (ctxt , pos )
278+ return d .matchAndLog (hash , func () string { return d .fmtPos (ctxt , pos ) }, note )
279+ }
290280
281+ // matchAndLog is the core matcher. It reports whether the hash matches the pattern.
282+ // If a report needs to be printed, match prints that report to the log file.
283+ // The text func must be non-nil and should return a user-readable
284+ // representation of what was hashed. The note func may be nil; if non-nil,
285+ // it should return additional information to display to the user when this
286+ // change is selected.
287+ func (d * HashDebug ) matchAndLog (hash uint64 , text , note func () string ) bool {
291288 if d .bisect != nil {
292289 if d .bisect .ShouldPrint (hash ) {
293- d .log (d .name , hash , d .fmtPos (ctxt , pos ))
290+ var t string
291+ if ! d .bisect .MarkerOnly () {
292+ t = text ()
293+ if note != nil {
294+ if n := note (); n != "" {
295+ t += ": " + n
296+ }
297+ }
298+ }
299+ d .log (d .name , hash , t )
294300 }
295301 return d .bisect .ShouldEnable (hash )
296302 }
297303
298304 // TODO: Delete rest of function body when we switch to bisect-only.
299-
300- // Return false for explicitly excluded hashes
301305 if d .excluded (hash ) {
302306 return false
303307 }
304308 if m := d .match (hash ); m != nil {
305- d .log (m .name , hash , d . fmtPos ( ctxt , pos ))
309+ d .log (m .name , hash , text ( ))
306310 return true
307311 }
308312 return false
0 commit comments