File: capture.go

package info (click to toggle)
runc 0.1.1%2Bdfsg1-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,684 kB
  • sloc: ansic: 698; sh: 156; makefile: 71
file content (27 lines) | stat: -rw-r--r-- 617 bytes parent folder | download | duplicates (2)
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
package stacktrace

import "runtime"

// Caputure 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 + 1 // add one for our own function
		frames []Frame
		prevPc uintptr = 0
	)
	for i := skip; ; i++ {
		pc, file, line, ok := runtime.Caller(i)
		//detect if caller is repeated to avoid loop, gccgo
		//currently runs  into a loop without this check
		if !ok || pc == prevPc {
			break
		}
		frames = append(frames, NewFrame(pc, file, line))
		prevPc = pc
	}
	return Stacktrace{
		Frames: frames,
	}
}