aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/stack_test.go
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2020-11-20 17:32:46 -0500
committerAustin Clements <austin@google.com>2020-11-24 21:47:44 +0000
commite8de596f04d0ea7fb6fb68b036760bf088a9c6c2 (patch)
treeac9399d5206140e2a46ef66b41715e42b3ab198a /src/runtime/stack_test.go
parentba2adc21e8c416c47dec5fbce76286758f15b177 (diff)
downloadgo-e8de596f04d0ea7fb6fb68b036760bf088a9c6c2.tar.xz
runtime: use inlined function name for traceback elision
Currently, gentraceback decides which frames to print or elide when unwinding inlined frames using only the name of the outermost function. If the outermost function should be elided, then inlined functions will also be elided, even if they shouldn't be. This happens in practice in at least one situation. As of CL 258938, exported Go functions (and functions they call) can now be inlined into the generated _cgoexp_HASH_FN function. The runtime elides _cgoexp_HASH_FN from tracebacks because it doesn't contain a ".". Because of this bug, it also elides anything that was inlined into it. This CL fixes this by synthesizing a funcInfo for the inlined functions to pass to showframe. Fixes #42754. Change-Id: Ie6c663a4a1ac7f0d4beb1aa60bc26fc8cddd0f9d Reviewed-on: https://go-review.googlesource.com/c/go/+/272131 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
Diffstat (limited to 'src/runtime/stack_test.go')
-rw-r--r--src/runtime/stack_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/runtime/stack_test.go b/src/runtime/stack_test.go
index adfc65384a..43fc5cac55 100644
--- a/src/runtime/stack_test.go
+++ b/src/runtime/stack_test.go
@@ -17,6 +17,7 @@ import (
"sync/atomic"
"testing"
"time"
+ _ "unsafe" // for go:linkname
)
// TestStackMem measures per-thread stack segment cache behavior.
@@ -851,3 +852,43 @@ func deferHeapAndStack(n int) (r int) {
// Pass a value to escapeMe to force it to escape.
var escapeMe = func(x interface{}) {}
+
+// Test that when F -> G is inlined and F is excluded from stack
+// traces, G still appears.
+func TestTracebackInlineExcluded(t *testing.T) {
+ defer func() {
+ recover()
+ buf := make([]byte, 4<<10)
+ stk := string(buf[:Stack(buf, false)])
+
+ t.Log(stk)
+
+ if not := "tracebackExcluded"; strings.Contains(stk, not) {
+ t.Errorf("found but did not expect %q", not)
+ }
+ if want := "tracebackNotExcluded"; !strings.Contains(stk, want) {
+ t.Errorf("expected %q in stack", want)
+ }
+ }()
+ tracebackExcluded()
+}
+
+// tracebackExcluded should be excluded from tracebacks. There are
+// various ways this could come up. Linking it to a "runtime." name is
+// rather synthetic, but it's easy and reliable. See issue #42754 for
+// one way this happened in real code.
+//
+//go:linkname tracebackExcluded runtime.tracebackExcluded
+//go:noinline
+func tracebackExcluded() {
+ // Call an inlined function that should not itself be excluded
+ // from tracebacks.
+ tracebackNotExcluded()
+}
+
+// tracebackNotExcluded should be inlined into tracebackExcluded, but
+// should not itself be excluded from the traceback.
+func tracebackNotExcluded() {
+ var x *int
+ *x = 0
+}