]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.21] runtime: don't print "unexpected SPWRITE" when printing traceback
authorCherry Mui <cherryyz@google.com>
Fri, 29 Sep 2023 18:00:04 +0000 (14:00 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 10 Jan 2024 19:17:07 +0000 (19:17 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
(cherry picked from commit 15a274b621b3654e9b4962a27c9d14ea51645b6c)
Reviewed-on: https://go-review.googlesource.com/c/go/+/553476
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@golang.org>

src/runtime/crash_unix_test.go
src/runtime/traceback.go

index 6bca2ac66e480a9e5df4f146090e25031e9905a1..8d205e1de5389d1ff7309cb907483c272f66ac11 100644 (file)
@@ -214,6 +214,12 @@ func TestPanicSystemstack(t *testing.T) {
        if nUser != 2 || nSys != 2 {
                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))
        }
+
+       // Traceback should not contain "unexpected SPWRITE" when
+       // unwinding the system stacks.
+       if bytes.Contains(tb, []byte("unexpected SPWRITE")) {
+               t.Errorf("unexpected \"unexpected SPWRITE\" in traceback:\n%s", tb)
+       }
 }
 
 func init() {
index 72200d436f3c6dd990a64813b7c85b6d931ee071..32a538526cd5f3b365c9ea2225b6c7d115aabf05 100644 (file)
@@ -359,15 +359,12 @@ func (u *unwinder) resolveInternal(innermost, isSyscall bool) {
                //
                // uSE uPE inn | action
                //  T   _   _  | frame.lr = 0
-               //  F   T   F  | frame.lr = 0; print
-               //  F   T   T  | frame.lr = 0
+               //  F   T   _  | frame.lr = 0
                //  F   F   F  | print; panic
                //  F   F   T  | ignore SPWrite
-               if u.flags&unwindSilentErrors == 0 && !innermost {
+               if u.flags&(unwindPrintErrors|unwindSilentErrors) == 0 && !innermost {
                        println("traceback: unexpected SPWRITE function", funcname(f))
-                       if u.flags&unwindPrintErrors == 0 {
-                               throw("traceback")
-                       }
+                       throw("traceback")
                }
                frame.lr = 0
        } else {