From 3a81338622eb5c8b94f11001855e2a68a9e36bed Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Sat, 18 Feb 2017 03:03:32 -0700 Subject: runtime: make stack traces of endless recursion print only top and bottom 50 This CL makes it so that instead of printing massive stack traces during endless recursion, which spams users and aren't useful, it now prints out the top and bottom 50 frames. If the number of frames <= 100 (_TracebackMaxFrames), we'll just print all the frames out. Modified gentraceback to return counts of: * ntotalframes * nregularframes which allows us to get accurate counts of the various kinds of frames. While here, also fixed a bug that resulted from CL 37222, in which we no longer accounted for decrementing requested frame skips, and assumed that when printing, that skip would always be 0. The fix is instead to add precondition that we'll only print if skip <= 0, but also decrement skip as we iterate. Fixes #7181. Fixes #24628. Change-Id: Ie31ec6413fdfbe43827b254fef7d99ea26a5277f Reviewed-on: https://go-review.googlesource.com/c/go/+/37222 Run-TryBot: Emmanuel Odeke TryBot-Result: Go Bot Reviewed-by: Keith Randall Trust: Emmanuel Odeke --- src/runtime/testdata/testprog/deadlock.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/runtime/testdata') diff --git a/src/runtime/testdata/testprog/deadlock.go b/src/runtime/testdata/testprog/deadlock.go index 105d6a5faa..0ee1557b13 100644 --- a/src/runtime/testdata/testprog/deadlock.go +++ b/src/runtime/testdata/testprog/deadlock.go @@ -20,6 +20,7 @@ func init() { register("LockedDeadlock2", LockedDeadlock2) register("GoexitDeadlock", GoexitDeadlock) register("StackOverflow", StackOverflow) + register("StackOverflowTopAndBottomTraces", StackOverflowTopAndBottomTraces) register("ThreadExhaustion", ThreadExhaustion) register("RecursivePanic", RecursivePanic) register("RecursivePanic2", RecursivePanic2) @@ -85,6 +86,18 @@ func StackOverflow() { f() } +func StackOverflowTopAndBottomTraces() { + var fi, gi func() + fi = func() { + gi() + } + gi = func() { + fi() + } + debug.SetMaxStack(10000) + fi() +} + func ThreadExhaustion() { debug.SetMaxThreads(10) c := make(chan int) -- cgit v1.3-5-g9baa