File: capture.go

package info (click to toggle)
runc 1.0.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,836 kB
  • sloc: sh: 1,571; ansic: 1,236; makefile: 136
file content (30 lines) | stat: -rw-r--r-- 575 bytes parent folder | download | duplicates (4)
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
package stacktrace

import "runtime"

// Capture captures a stacktrace for the current calling go program
//
// skip is the number of frames to skip
func Capture(userSkip int) Stacktrace {
	var (
		skip   = userSkip + 2 // add one for our own function, one for runtime.Callers
		frames []Frame
	)

	pc := make([]uintptr, 10)
	n := runtime.Callers(skip, pc)
	if n == 0 {
		return Stacktrace{}
	}
	f := runtime.CallersFrames(pc)
	for {
		frame, more := f.Next()
		frames = append(frames, newFrame(frame))
		if !more {
			break
		}
	}
	return Stacktrace{
		Frames: frames,
	}
}