mirror of
https://github.com/golang/go
synced 2024-09-15 14:10:17 +00:00
cmd/addr2line: don't assume that GOROOT_FINAL is clean
Fixes #41447 Change-Id: I4460c1c7962d02c41622a5ea1a3c4bc3714a1873 Reviewed-on: https://go-review.googlesource.com/c/go/+/255477 Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
35e413c537
commit
6796a7fb12
|
@ -73,29 +73,37 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Stat failed: %v", err)
|
t.Fatalf("Stat failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug paths are stored slash-separated, so convert to system-native.
|
// Debug paths are stored slash-separated, so convert to system-native.
|
||||||
srcPath = filepath.FromSlash(srcPath)
|
srcPath = filepath.FromSlash(srcPath)
|
||||||
fi2, err := os.Stat(srcPath)
|
fi2, err := os.Stat(srcPath)
|
||||||
if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" && strings.HasPrefix(srcPath, gorootFinal) {
|
|
||||||
if os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2)) {
|
// If GOROOT_FINAL is set and srcPath is not the file we expect, perhaps
|
||||||
// srcPath has had GOROOT_FINAL substituted for GOROOT, and it doesn't
|
// srcPath has had GOROOT_FINAL substituted for GOROOT and GOROOT hasn't been
|
||||||
// match the actual file. GOROOT probably hasn't been moved to its final
|
// moved to its final location yet. If so, try the original location instead.
|
||||||
// location yet, so try the original location instead.
|
if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" &&
|
||||||
|
(os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2))) {
|
||||||
|
// srcPath is clean, but GOROOT_FINAL itself might not be.
|
||||||
|
// (See https://golang.org/issue/41447.)
|
||||||
|
gorootFinal = filepath.Clean(gorootFinal)
|
||||||
|
|
||||||
|
if strings.HasPrefix(srcPath, gorootFinal) {
|
||||||
fi2, err = os.Stat(runtime.GOROOT() + strings.TrimPrefix(srcPath, gorootFinal))
|
fi2, err = os.Stat(runtime.GOROOT() + strings.TrimPrefix(srcPath, gorootFinal))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Stat failed: %v", err)
|
t.Fatalf("Stat failed: %v", err)
|
||||||
}
|
}
|
||||||
if !os.SameFile(fi1, fi2) {
|
if !os.SameFile(fi1, fi2) {
|
||||||
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
|
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
|
||||||
}
|
}
|
||||||
if srcLineNo != "99" {
|
if srcLineNo != "107" {
|
||||||
t.Fatalf("line number = %v; want 99", srcLineNo)
|
t.Fatalf("line number = %v; want 107", srcLineNo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is line 98. The test depends on that.
|
// This is line 106. The test depends on that.
|
||||||
func TestAddr2Line(t *testing.T) {
|
func TestAddr2Line(t *testing.T) {
|
||||||
testenv.MustHaveGoBuild(t)
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue