
godep restore pushd $GOPATH/src/github.com/appc/spec git co master popd go get go4.org/errorutil rm -rf Godeps godep save ./... git add vendor git add -f $(git ls-files --other vendor/) git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
28 lines
617 B
Go
28 lines
617 B
Go
package stacktrace
|
|
|
|
import "runtime"
|
|
|
|
// Caputure captures a stacktrace for the current calling go program
|
|
//
|
|
// skip is the number of frames to skip
|
|
func Capture(userSkip int) Stacktrace {
|
|
var (
|
|
skip = userSkip + 1 // add one for our own function
|
|
frames []Frame
|
|
prevPc uintptr = 0
|
|
)
|
|
for i := skip; ; i++ {
|
|
pc, file, line, ok := runtime.Caller(i)
|
|
//detect if caller is repeated to avoid loop, gccgo
|
|
//currently runs into a loop without this check
|
|
if !ok || pc == prevPc {
|
|
break
|
|
}
|
|
frames = append(frames, NewFrame(pc, file, line))
|
|
prevPc = pc
|
|
}
|
|
return Stacktrace{
|
|
Frames: frames,
|
|
}
|
|
}
|