]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle empty stack in expandFinalInlineFrame
authorKeith Randall <khr@golang.org>
Fri, 20 Mar 2020 19:25:57 +0000 (12:25 -0700)
committerKeith Randall <khr@golang.org>
Fri, 20 Mar 2020 20:01:06 +0000 (20:01 +0000)
Fixes #37967

Change-Id: I6fc22bdd65f0263d5672731b73d09249201ab0aa
Reviewed-on: https://go-review.googlesource.com/c/go/+/224458
Reviewed-by: Michael Pratt <mpratt@google.com>
src/runtime/pprof/proto_test.go
src/runtime/symtab.go

index f3456ffede49906974e8c224cf9dafb8613954f0..37e68b9c535d48af7dd85c519c548168f538203d 100644 (file)
@@ -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)
+       }
+}
index 997cfa3f7ae893d7619e7534164267c6b6668509..b2147c4cb40f4105fdf1d166ca4860ceb7953974 100644 (file)
@@ -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