aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2020-03-20 12:25:57 -0700
committerIan Lance Taylor <iant@golang.org>2020-03-30 23:01:07 +0000
commit8980ff45cf766f8ab4a3d28ad758f2930de05b6e (patch)
tree0cd0dab879dab193801f2b55fbd9d9d48ef6934b
parentcdd55a324b2baf8db4891dcd741a26a31f986d8f (diff)
downloadgo-8980ff45cf766f8ab4a3d28ad758f2930de05b6e.tar.gz
go-8980ff45cf766f8ab4a3d28ad758f2930de05b6e.zip
[release-branch.go1.14] runtime: handle empty stack in expandFinalInlineFrame
Fixes #37970 Change-Id: I6fc22bdd65f0263d5672731b73d09249201ab0aa Reviewed-on: https://go-review.googlesource.com/c/go/+/224458 Reviewed-by: Michael Pratt <mpratt@google.com> (cherry picked from commit 5bc75a3097a3671055f0f9c503850edbe830601d) Reviewed-on: https://go-review.googlesource.com/c/go/+/224597 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r--src/runtime/pprof/proto_test.go13
-rw-r--r--src/runtime/symtab.go3
2 files changed, 16 insertions, 0 deletions
diff --git a/src/runtime/pprof/proto_test.go b/src/runtime/pprof/proto_test.go
index f3456ffede..37e68b9c53 100644
--- a/src/runtime/pprof/proto_test.go
+++ b/src/runtime/pprof/proto_test.go
@@ -422,3 +422,16 @@ func TestFakeMapping(t *testing.T) {
}
}
}
+
+// Make sure the profiler can handle an empty stack trace.
+// See issue 37967.
+func TestEmptyStack(t *testing.T) {
+ b := []uint64{
+ 3, 0, 500, // hz = 500
+ 3, 0, 10, // 10 samples with an empty stack trace
+ }
+ _, err := translateCPUProfile(b)
+ if err != nil {
+ t.Fatalf("translating profile: %v", err)
+ }
+}
diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go
index 997cfa3f7a..b2147c4cb4 100644
--- a/src/runtime/symtab.go
+++ b/src/runtime/symtab.go
@@ -153,6 +153,9 @@ func (ci *Frames) Next() (frame Frame, more bool) {
//
//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame
func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr {
+ if len(stk) == 0 {
+ return stk
+ }
pc := stk[len(stk)-1]
tracepc := pc - 1