in appinsights/exception.go [86:138]
func GetCallstack(skip int) []*contracts.StackFrame {
var stackFrames []*contracts.StackFrame
if skip < 0 {
skip = 0
}
stack := make([]uintptr, 64+skip)
depth := runtime.Callers(skip+1, stack)
if depth == 0 {
return stackFrames
}
frames := runtime.CallersFrames(stack[:depth])
level := 0
for {
frame, more := frames.Next()
stackFrame := &contracts.StackFrame{
Level: level,
FileName: frame.File,
Line: frame.Line,
}
if frame.Function != "" {
/* Default */
stackFrame.Method = frame.Function
/* Break up function into assembly/function */
lastSlash := strings.LastIndexByte(frame.Function, '/')
if lastSlash < 0 {
// e.g. "runtime.gopanic"
// The below works with lastSlash=0
lastSlash = 0
}
firstDot := strings.IndexByte(frame.Function[lastSlash:], '.')
if firstDot >= 0 {
stackFrame.Assembly = frame.Function[:lastSlash+firstDot]
stackFrame.Method = frame.Function[lastSlash+firstDot+1:]
}
}
stackFrames = append(stackFrames, stackFrame)
level++
if !more {
break
}
}
return stackFrames
}