File: frame.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 (38 lines) | stat: -rw-r--r-- 732 bytes parent folder | download | duplicates (11)
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
31
32
33
34
35
36
37
38
package stacktrace

import (
	"path/filepath"
	"runtime"
	"strings"
)

// NewFrame returns a new stack frame for the provided information
func NewFrame(pc uintptr, file string, line int) Frame {
	fn := runtime.FuncForPC(pc)
	if fn == nil {
		return Frame{}
	}
	pack, name := parseFunctionName(fn.Name())
	return Frame{
		Line:     line,
		File:     filepath.Base(file),
		Package:  pack,
		Function: name,
	}
}

func parseFunctionName(name string) (string, string) {
	i := strings.LastIndex(name, ".")
	if i == -1 {
		return "", name
	}
	return name[:i], name[i+1:]
}

// Frame contains all the information for a stack frame within a go program
type Frame struct {
	File     string
	Function string
	Package  string
	Line     int
}