Skip to content

Commit 15a274b

Browse files
committed
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. 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]>
1 parent b56645a commit 15a274b

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
@@ -216,6 +216,12 @@ func TestPanicSystemstack(t *testing.T) {
216216
if nUser != 2 || nSys != 2 {
217217
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))
218218
}
219+
220+
// Traceback should not contain "unexpected SPWRITE" when
221+
// unwinding the system stacks.
222+
if bytes.Contains(tb, []byte("unexpected SPWRITE")) {
223+
t.Errorf("unexpected \"unexpected SPWRITE\" in traceback:\n%s", tb)
224+
}
219225
}
220226

221227
func init() {

src/runtime/traceback.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,15 +356,12 @@ func (u *unwinder) resolveInternal(innermost, isSyscall bool) {
356356
//
357357
// uSE uPE inn | action
358358
// T _ _ | frame.lr = 0
359-
// F T F | frame.lr = 0; print
360-
// F T T | frame.lr = 0
359+
// F T _ | frame.lr = 0
361360
// F F F | print; panic
362361
// F F T | ignore SPWrite
363-
if u.flags&unwindSilentErrors == 0 && !innermost {
362+
if u.flags&(unwindPrintErrors|unwindSilentErrors) == 0 && !innermost {
364363
println("traceback: unexpected SPWRITE function", funcname(f))
365-
if u.flags&unwindPrintErrors == 0 {
366-
throw("traceback")
367-
}
364+
throw("traceback")
368365
}
369366
frame.lr = 0
370367
} else {

0 commit comments

Comments
 (0)