getStack is a formatting wrapper around runtime.Callers. It returns a stack trace in the form of a StackFrame slice.
(skip int, size int)
| 31 | // getStack is a formatting wrapper around runtime.Callers. It returns a stack |
| 32 | // trace in the form of a StackFrame slice. |
| 33 | func getStack(skip int, size int) []StackFrame { |
| 34 | var ( |
| 35 | pc = make([]uintptr, size) |
| 36 | calls = runtime.Callers(skip+1, pc) |
| 37 | trace []StackFrame |
| 38 | ) |
| 39 | |
| 40 | for i := 0; i < calls; i++ { |
| 41 | f := runtime.FuncForPC(pc[i]) |
| 42 | file, line := f.FileLine(pc[i] - 1) |
| 43 | trace = append(trace, StackFrame{ |
| 44 | Func: f.Name(), |
| 45 | File: file, |
| 46 | Line: line, |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | return trace |
| 51 | } |