...
Source file src/runtime/debugcall.go
1
2
3
4
5
6
7 package runtime
8
9 import "unsafe"
10
11 const (
12 debugCallSystemStack = "executing on Go runtime stack"
13 debugCallUnknownFunc = "call from unknown function"
14 debugCallRuntime = "call from within the Go runtime"
15 debugCallUnsafePoint = "call not at safe point"
16 )
17
18 func debugCallV1()
19 func debugCallPanicked(val interface{})
20
21
22
23
24
25
26 func debugCallCheck(pc uintptr) string {
27
28 if getg() != getg().m.curg {
29 return debugCallSystemStack
30 }
31 if sp := getcallersp(); !(getg().stack.lo < sp && sp <= getg().stack.hi) {
32
33
34
35
36 return debugCallSystemStack
37 }
38
39
40
41 var ret string
42 systemstack(func() {
43 f := findfunc(pc)
44 if !f.valid() {
45 ret = debugCallUnknownFunc
46 return
47 }
48
49 name := funcname(f)
50
51 switch name {
52 case "debugCall32",
53 "debugCall64",
54 "debugCall128",
55 "debugCall256",
56 "debugCall512",
57 "debugCall1024",
58 "debugCall2048",
59 "debugCall4096",
60 "debugCall8192",
61 "debugCall16384",
62 "debugCall32768",
63 "debugCall65536":
64
65
66 return
67 }
68
69
70
71
72
73
74 if pfx := "runtime."; len(name) > len(pfx) && name[:len(pfx)] == pfx {
75 ret = debugCallRuntime
76 return
77 }
78
79
80 pcdata := int32(-1)
81 if pc != f.entry {
82 pc--
83 pcdata = pcdatavalue(f, _PCDATA_RegMapIndex, pc, nil)
84 }
85 if pcdata == -1 {
86 pcdata = 0
87 }
88 stkmap := (*stackmap)(funcdata(f, _FUNCDATA_RegPointerMaps))
89 if pcdata == -2 || stkmap == nil {
90
91 ret = debugCallUnsafePoint
92 return
93 }
94 })
95 return ret
96 }
97
98
99
100 func debugCallWrap(dispatch uintptr) {
101 var dispatchF func()
102 dispatchFV := funcval{dispatch}
103 *(*unsafe.Pointer)(unsafe.Pointer(&dispatchF)) = noescape(unsafe.Pointer(&dispatchFV))
104
105 var ok bool
106 defer func() {
107 if !ok {
108 err := recover()
109 debugCallPanicked(err)
110 }
111 }()
112 dispatchF()
113 ok = true
114 }
115
View as plain text