MCPcopy
hub / github.com/gin-gonic/gin / stack

Function stack

recovery.go:114–140  ·  view source on GitHub ↗

stack returns a nicely formatted stack frame, skipping skip frames.

(skip int)

Source from the content-addressed store, hash-verified

112
113// stack returns a nicely formatted stack frame, skipping skip frames.
114func stack(skip int) []byte {
115 buf := new(bytes.Buffer) // the returned data
116 // As we loop, we open files and read them. These variables record the currently
117 // loaded file.
118 var (
119 nLine string
120 lastFile string
121 err error
122 )
123 for i := skip; ; i++ { // Skip the expected number of frames
124 pc, file, line, ok := runtime.Caller(i)
125 if !ok {
126 break
127 }
128 // Print this much at least. If we can't find the source, it won't show.
129 fmt.Fprintf(buf, "%s:%d (0x%x)\n", file, line, pc)
130 if file != lastFile {
131 nLine, err = readNthLine(file, line-1)
132 if err != nil {
133 continue
134 }
135 lastFile = file
136 }
137 fmt.Fprintf(buf, "\t%s: %s\n", function(pc), cmp.Or(nLine, dunno))
138 }
139 return buf.Bytes()
140}
141
142// readNthLine reads the nth line from the file.
143// It returns the trimmed content of the line if found,

Callers 2

BenchmarkStackFunction · 0.85
CustomRecoveryWithWriterFunction · 0.85

Calls 2

readNthLineFunction · 0.85
functionFunction · 0.85

Tested by 1

BenchmarkStackFunction · 0.68