MCPcopy
hub / github.com/uber-go/fx / CallerStack

Function CallerStack

internal/fxreflect/stack.go:137–158  ·  view source on GitHub ↗

CallerStack returns the call stack for the calling function, up to depth frames deep, skipping the provided number of frames, not including Callers itself. If zero, depth defaults to 8.

(skip, depth int)

Source from the content-addressed store, hash-verified

135//
136// If zero, depth defaults to 8.
137func CallerStack(skip, depth int) Stack {
138 if depth <= 0 {
139 depth = _defaultCallersDepth
140 }
141
142 pcs := make([]uintptr, depth)
143
144 // +2 to skip this frame and runtime.Callers.
145 n := runtime.Callers(skip+2, pcs)
146 pcs = pcs[:n] // truncate to number of frames actually read
147
148 result := make([]Frame, 0, n)
149 frames := runtime.CallersFrames(pcs)
150 for f, more := frames.Next(); more; f, more = frames.Next() {
151 result = append(result, Frame{
152 Function: sanitize(f.Function),
153 File: f.File,
154 Line: f.Line,
155 })
156 }
157 return result
158}

Callers 12

ReplaceFunction · 0.92
InvokeFunction · 0.92
ModuleFunction · 0.92
WithLoggerFunction · 0.92
NewFunction · 0.92
DecorateFunction · 0.92
ProvideFunction · 0.92
SupplyFunction · 0.92
AppendMethod · 0.92
TestStackFunction · 0.85
TestDeepStackFunction · 0.85
CallerFunction · 0.85

Calls 1

sanitizeFunction · 0.85

Tested by 2

TestStackFunction · 0.68
TestDeepStackFunction · 0.68