import (
"cmd/internal/obj"
"cmd/internal/src"
- "crypto/sha1"
- "fmt"
"os"
"strconv"
- "strings"
)
// A Config holds readonly compilation information.
func (c *Config) Warnl(pos src.XPos, msg string, args ...interface{}) { c.fe.Warnl(pos, msg, args...) }
func (c *Config) Debug_checknil() bool { return c.fe.Debug_checknil() }
func (c *Config) Debug_wb() bool { return c.fe.Debug_wb() }
-
-func (f *Func) logDebugHashMatch(evname, name string) {
- if f.logfiles == nil {
- f.logfiles = make(map[string]*os.File)
- }
- file := f.logfiles[evname]
- if file == nil {
- file = os.Stdout
- tmpfile := os.Getenv("GSHS_LOGFILE")
- if tmpfile != "" {
- var ok error
- file, ok = os.Create(tmpfile)
- if ok != nil {
- f.Fatalf("could not open hash-testing logfile %s", tmpfile)
- }
- }
- f.logfiles[evname] = file
- }
- s := fmt.Sprintf("%s triggered %s\n", evname, name)
- file.WriteString(s)
- file.Sync()
-}
-
-// DebugHashMatch returns true if environment variable evname
-// 1) is empty (this is a special more-quickly implemented case of 3)
-// 2) is "y" or "Y"
-// 3) is a suffix of the sha1 hash of name
-// 4) is a suffix of the environment variable
-// fmt.Sprintf("%s%d", evname, n)
-// provided that all such variables are nonempty for 0 <= i <= n
-// Otherwise it returns false.
-// When true is returned the message
-// "%s triggered %s\n", evname, name
-// is printed on the file named in environment variable
-// GSHS_LOGFILE
-// or standard out if that is empty or there is an error
-// opening the file.
-func (f *Func) DebugHashMatch(evname, name string) bool {
- evhash := os.Getenv(evname)
- if evhash == "" {
- return true // default behavior with no EV is "on"
- }
- if evhash == "y" || evhash == "Y" {
- f.logDebugHashMatch(evname, name)
- return true
- }
- if evhash == "n" || evhash == "N" {
- return false
- }
- // Check the hash of the name against a partial input hash.
- // We use this feature to do a binary search to
- // find a function that is incorrectly compiled.
- hstr := ""
- for _, b := range sha1.Sum([]byte(name)) {
- hstr += fmt.Sprintf("%08b", b)
- }
-
- if strings.HasSuffix(hstr, evhash) {
- f.logDebugHashMatch(evname, name)
- return true
- }
-
- // Iteratively try additional hashes to allow tests for multi-point
- // failure.
- for i := 0; true; i++ {
- ev := fmt.Sprintf("%s%d", evname, i)
- evv := os.Getenv(ev)
- if evv == "" {
- break
- }
- if strings.HasSuffix(hstr, evv) {
- f.logDebugHashMatch(ev, name)
- return true
- }
- }
- return false
-}
-
-func DebugNameMatch(evname, name string) bool {
- return os.Getenv(evname) == name
-}
import (
"cmd/internal/src"
+ "crypto/sha1"
"fmt"
"math"
"os"
f.cachedSdom = nil
f.cachedLoopnest = nil
}
+
+// DebugHashMatch returns true if environment variable evname
+// 1) is empty (this is a special more-quickly implemented case of 3)
+// 2) is "y" or "Y"
+// 3) is a suffix of the sha1 hash of name
+// 4) is a suffix of the environment variable
+// fmt.Sprintf("%s%d", evname, n)
+// provided that all such variables are nonempty for 0 <= i <= n
+// Otherwise it returns false.
+// When true is returned the message
+// "%s triggered %s\n", evname, name
+// is printed on the file named in environment variable
+// GSHS_LOGFILE
+// or standard out if that is empty or there is an error
+// opening the file.
+func (f *Func) DebugHashMatch(evname, name string) bool {
+ evhash := os.Getenv(evname)
+ if evhash == "" {
+ return true // default behavior with no EV is "on"
+ }
+ if evhash == "y" || evhash == "Y" {
+ f.logDebugHashMatch(evname, name)
+ return true
+ }
+ if evhash == "n" || evhash == "N" {
+ return false
+ }
+ // Check the hash of the name against a partial input hash.
+ // We use this feature to do a binary search to
+ // find a function that is incorrectly compiled.
+ hstr := ""
+ for _, b := range sha1.Sum([]byte(name)) {
+ hstr += fmt.Sprintf("%08b", b)
+ }
+
+ if strings.HasSuffix(hstr, evhash) {
+ f.logDebugHashMatch(evname, name)
+ return true
+ }
+
+ // Iteratively try additional hashes to allow tests for multi-point
+ // failure.
+ for i := 0; true; i++ {
+ ev := fmt.Sprintf("%s%d", evname, i)
+ evv := os.Getenv(ev)
+ if evv == "" {
+ break
+ }
+ if strings.HasSuffix(hstr, evv) {
+ f.logDebugHashMatch(ev, name)
+ return true
+ }
+ }
+ return false
+}
+
+func (f *Func) logDebugHashMatch(evname, name string) {
+ if f.logfiles == nil {
+ f.logfiles = make(map[string]*os.File)
+ }
+ file := f.logfiles[evname]
+ if file == nil {
+ file = os.Stdout
+ tmpfile := os.Getenv("GSHS_LOGFILE")
+ if tmpfile != "" {
+ var ok error
+ file, ok = os.Create(tmpfile)
+ if ok != nil {
+ f.Fatalf("could not open hash-testing logfile %s", tmpfile)
+ }
+ }
+ f.logfiles[evname] = file
+ }
+ s := fmt.Sprintf("%s triggered %s\n", evname, name)
+ file.WriteString(s)
+ file.Sync()
+}
+
+func DebugNameMatch(evname, name string) bool {
+ return os.Getenv(evname) == name
+}