-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.go
More file actions
42 lines (38 loc) · 739 Bytes
/
stack.go
File metadata and controls
42 lines (38 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package errors
import (
"fmt"
"io"
"runtime"
"strconv"
)
type stack []uintptr
func (s *stack) Format(st fmt.State, verb rune) {
switch verb {
case 'v':
switch {
case st.Flag('+'):
for _, pc := range *s {
pc = pc - 1
fn := runtime.FuncForPC(pc)
name, line, file := "unknown", 0, "unknown"
if fn != nil {
name = fn.Name()
file, line = fn.FileLine(pc)
}
io.WriteString(st, "\n")
io.WriteString(st, name)
io.WriteString(st, "\n\t")
io.WriteString(st, file)
io.WriteString(st, ":")
io.WriteString(st, strconv.Itoa(line))
}
}
}
}
func callers() *stack {
const depth = 32
var pcs [depth]uintptr
n := runtime.Callers(3, pcs[:])
var st stack = pcs[0:n]
return &st
}