Debugging Go with stack traces

about | archive


[ 2020-April-12 11:31 ]

One of the most primitive but extremely useful tools for debugging is a stack trace: a list of all active functions and their callers (also called a traceback or backtrace). Since Go programs can easily have tens of thousands of goroutines, the output can be large, so you may need tools to work with them. This post lists all the ways I know to get stack traces, and brief notes on using go tool pprof with the binary format, or combining the text format using a hacky tool I wrote. After posting this, someone told me about panicparse, which is a much better tool for this purpose.

Getting stack traces in Go

If you want to play with these, see stackdemo.go, a program I wrote with command line flags to try all these approaches.

Combining stack traces

If you have a lot of stack traces, you are going to need some tools. If you have the binary format, there are two reports I like:

If you have the text format, you can use panicparse, which formats the output in a friendly format on your console. I made a hacky version of panicparse on the web. See the Github repository for the source.