Entries returns all the entries for the stack trace.
()
| 64 | |
| 65 | // Entries returns all the entries for the stack trace. |
| 66 | func (c Callstack) Entries() []Entry { |
| 67 | frames := runtime.CallersFrames([]uintptr(c)) |
| 68 | out := []Entry{} |
| 69 | for { |
| 70 | frame, more := frames.Next() |
| 71 | dir, file := path.Split(frame.File) |
| 72 | fullname := frame.Function |
| 73 | var pkg, name string |
| 74 | if i := strings.LastIndex(fullname, "/"); i > 0 { |
| 75 | i += strings.IndexRune(fullname[i+1:], '.') |
| 76 | // name is of the form github.com/google/gapid/framework/log.StacktraceOnError |
| 77 | // we find the last /, then find the next . to split the function name from the package name |
| 78 | pkg, name = fullname[:i+1], fullname[i+2:] |
| 79 | } |
| 80 | out = append(out, Entry{ |
| 81 | Location: Location{ |
| 82 | Directory: dir, |
| 83 | File: file, |
| 84 | Line: frame.Line, |
| 85 | }, |
| 86 | Function: Function{ |
| 87 | Package: pkg, |
| 88 | Name: name, |
| 89 | }, |
| 90 | PC: frame.PC, |
| 91 | }) |
| 92 | if !more { |
| 93 | break |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return out |
| 98 | } |
| 99 | |
| 100 | func (c Callstack) String() string { |
| 101 | entries := c.Entries() |