Skip to content

Commit 6796a7f

Browse files
author
Bryan C. Mills
committed
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 <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 35e413c commit 6796a7f

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/cmd/addr2line/addr2line_test.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,37 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
7373
if err != nil {
7474
t.Fatalf("Stat failed: %v", err)
7575
}
76+
7677
// Debug paths are stored slash-separated, so convert to system-native.
7778
srcPath = filepath.FromSlash(srcPath)
7879
fi2, err := os.Stat(srcPath)
79-
if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" && strings.HasPrefix(srcPath, gorootFinal) {
80-
if os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2)) {
81-
// srcPath has had GOROOT_FINAL substituted for GOROOT, and it doesn't
82-
// match the actual file. GOROOT probably hasn't been moved to its final
83-
// location yet, so try the original location instead.
80+
81+
// If GOROOT_FINAL is set and srcPath is not the file we expect, perhaps
82+
// srcPath has had GOROOT_FINAL substituted for GOROOT and GOROOT hasn't been
83+
// moved to its final location yet. If so, try the original location instead.
84+
if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" &&
85+
(os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2))) {
86+
// srcPath is clean, but GOROOT_FINAL itself might not be.
87+
// (See https://golang.org/issue/41447.)
88+
gorootFinal = filepath.Clean(gorootFinal)
89+
90+
if strings.HasPrefix(srcPath, gorootFinal) {
8491
fi2, err = os.Stat(runtime.GOROOT() + strings.TrimPrefix(srcPath, gorootFinal))
8592
}
8693
}
94+
8795
if err != nil {
8896
t.Fatalf("Stat failed: %v", err)
8997
}
9098
if !os.SameFile(fi1, fi2) {
9199
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
92100
}
93-
if srcLineNo != "99" {
94-
t.Fatalf("line number = %v; want 99", srcLineNo)
101+
if srcLineNo != "107" {
102+
t.Fatalf("line number = %v; want 107", srcLineNo)
95103
}
96104
}
97105

98-
// This is line 98. The test depends on that.
106+
// This is line 106. The test depends on that.
99107
func TestAddr2Line(t *testing.T) {
100108
testenv.MustHaveGoBuild(t)
101109

0 commit comments

Comments
 (0)