@@ -73,29 +73,37 @@ func testAddr2Line(t *testing.T, exepath, addr string) {
73
73
if err != nil {
74
74
t .Fatalf ("Stat failed: %v" , err )
75
75
}
76
+
76
77
// Debug paths are stored slash-separated, so convert to system-native.
77
78
srcPath = filepath .FromSlash (srcPath )
78
79
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 ) {
84
91
fi2 , err = os .Stat (runtime .GOROOT () + strings .TrimPrefix (srcPath , gorootFinal ))
85
92
}
86
93
}
94
+
87
95
if err != nil {
88
96
t .Fatalf ("Stat failed: %v" , err )
89
97
}
90
98
if ! os .SameFile (fi1 , fi2 ) {
91
99
t .Fatalf ("addr2line_test.go and %s are not same file" , srcPath )
92
100
}
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 )
95
103
}
96
104
}
97
105
98
- // This is line 98 . The test depends on that.
106
+ // This is line 106 . The test depends on that.
99
107
func TestAddr2Line (t * testing.T ) {
100
108
testenv .MustHaveGoBuild (t )
101
109
0 commit comments