Skip to content

Commit 5bc75a3

Browse files
committed
runtime: handle empty stack in expandFinalInlineFrame
Fixes #37967 Change-Id: I6fc22bdd65f0263d5672731b73d09249201ab0aa Reviewed-on: https://go-review.googlesource.com/c/go/+/224458 Reviewed-by: Michael Pratt <[email protected]>
1 parent c505865 commit 5bc75a3

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/runtime/pprof/proto_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,3 +422,16 @@ func TestFakeMapping(t *testing.T) {
422422
}
423423
}
424424
}
425+
426+
// Make sure the profiler can handle an empty stack trace.
427+
// See issue 37967.
428+
func TestEmptyStack(t *testing.T) {
429+
b := []uint64{
430+
3, 0, 500, // hz = 500
431+
3, 0, 10, // 10 samples with an empty stack trace
432+
}
433+
_, err := translateCPUProfile(b)
434+
if err != nil {
435+
t.Fatalf("translating profile: %v", err)
436+
}
437+
}

src/runtime/symtab.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func (ci *Frames) Next() (frame Frame, more bool) {
153153
//
154154
//go:linkname runtime_expandFinalInlineFrame runtime/pprof.runtime_expandFinalInlineFrame
155155
func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr {
156+
if len(stk) == 0 {
157+
return stk
158+
}
156159
pc := stk[len(stk)-1]
157160
tracepc := pc - 1
158161

0 commit comments

Comments
 (0)