Skip to content

Commit caafb50

Browse files
cherrymuigopherbot
authored andcommitted
[release-branch.go1.21] runtime: don't print "unexpected SPWRITE" when printing traceback
The system stack often starts with a stack transition function like "systemstack" or "mcall", which is marked as SPWRITE. When unwinding a system stack for printing, we want the traceback stop at the stack switching frame, but not print the "unexpected SPWRITE" message. Previously before CL 525835, we don't print the "unexpected SPWRITE" message if unwindPrintErrors is set, i.e. printing a stack trace. This CL restores this behavior. Another possibility is not printing the message only on the system stack. We don't expect a stack transition function to appear in a user G. Fixes #64935. Change-Id: I173e89ead2cd4fbf1f0f8cca225f28718b5baebe Reviewed-on: https://go-review.googlesource.com/c/go/+/531815 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> (cherry picked from commit 15a274b) Reviewed-on: https://go-review.googlesource.com/c/go/+/553476 Reviewed-by: Cherry Mui <[email protected]> Auto-Submit: Dmitri Shuralyov <[email protected]> TryBot-Bypass: Dmitri Shuralyov <[email protected]>
1 parent cc85462 commit caafb50

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/runtime/crash_unix_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ func TestPanicSystemstack(t *testing.T) {
214214
if nUser != 2 || nSys != 2 {
215215
t.Fatalf("want %d user stack frames in %s and %d system stack frames in %s, got %d and %d:\n%s", 2, userFunc, 2, sysFunc, nUser, nSys, string(tb))
216216
}
217+
218+
// Traceback should not contain "unexpected SPWRITE" when
219+
// unwinding the system stacks.
220+
if bytes.Contains(tb, []byte("unexpected SPWRITE")) {
221+
t.Errorf("unexpected \"unexpected SPWRITE\" in traceback:\n%s", tb)
222+
}
217223
}
218224

219225
func init() {

src/runtime/traceback.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,12 @@ func (u *unwinder) resolveInternal(innermost, isSyscall bool) {
359359
//
360360
// uSE uPE inn | action
361361
// T _ _ | frame.lr = 0
362-
// F T F | frame.lr = 0; print
363-
// F T T | frame.lr = 0
362+
// F T _ | frame.lr = 0
364363
// F F F | print; panic
365364
// F F T | ignore SPWrite
366-
if u.flags&unwindSilentErrors == 0 && !innermost {
365+
if u.flags&(unwindPrintErrors|unwindSilentErrors) == 0 && !innermost {
367366
println("traceback: unexpected SPWRITE function", funcname(f))
368-
if u.flags&unwindPrintErrors == 0 {
369-
throw("traceback")
370-
}
367+
throw("traceback")
371368
}
372369
frame.lr = 0
373370
} else {

0 commit comments

Comments
 (0)