Package stack implements utilities to capture, manipulate, and format call stacks.
Call records a single function invocation from a goroutine stack. It is a wrapper for the program counter values returned by runtime.Caller and runtime.Callers and consumed by runtime.FuncForPC.
Format implements fmt.Formatter with support for the following verbs.
%s source file %d line number %n function name %v equivalent to %s:%d
It accepts the '+' and '#' flags for most of the verbs as follows.
%+s path of source file relative to the compile time GOPATH %#s full path of source file %+n import path qualified function name %+v equivalent to %+s:%d %#v equivalent to %#s:%d
Trace records a sequence of function invocations from a goroutine stack.
Callers returns a Trace for the current goroutine with element 0 identifying the calling function.
Format implements fmt.Formatter by printing the Trace as square brackes ([, ]) surrounding a space separated list of Calls each formatted with the supplied verb and options.
TrimAbove returns a slice of the Trace with all entries above pc removed.
TrimAboveName returns a slice of the Trace with all entries above the highest with function name name removed.
TrimBelow returns a slice of the Trace with all entries below pc removed.
TrimBelowName returns a slice of the Trace with all entries below the lowest with function name name removed.
TrimRuntime returns a slice of the Trace with the topmost entries from the go runtime removed. It considers any calls originating from files under GOROOT as part of the runtime.
☞ Subtracting one from pc is a work around for https://code.google.com/p/go/issues/detail?id=7690. The idea for this work around comes from rsc's initial patch at https://codereview.appspot.com/84100043/#ps20001, but as noted in the issue discussion, it is not a complete fix since it doesn't handle some cases involving signals. Just the same, it handles all of the other cases I have tested.