Switch to new vendor directory layout
Fixes #113 Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
parent
bc6adb7e4d
commit
d5742209d3
806 changed files with 2 additions and 7 deletions
27
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/capture.go
generated
vendored
Normal file
27
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/capture.go
generated
vendored
Normal file
|
@ -0,0 +1,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,
|
||||
}
|
||||
}
|
31
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/capture_test.go
generated
vendored
Normal file
31
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/capture_test.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
package stacktrace
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func captureFunc() Stacktrace {
|
||||
return Capture(0)
|
||||
}
|
||||
|
||||
func TestCaptureTestFunc(t *testing.T) {
|
||||
stack := captureFunc()
|
||||
|
||||
if len(stack.Frames) == 0 {
|
||||
t.Fatal("expected stack frames to be returned")
|
||||
}
|
||||
|
||||
// the first frame is the caller
|
||||
frame := stack.Frames[0]
|
||||
if expected := "captureFunc"; frame.Function != expected {
|
||||
t.Fatalf("expteced function %q but recevied %q", expected, frame.Function)
|
||||
}
|
||||
expected := "github.com/opencontainers/runc/libcontainer/stacktrace"
|
||||
if !strings.HasSuffix(frame.Package, expected) {
|
||||
t.Fatalf("expected package %q but received %q", expected, frame.Package)
|
||||
}
|
||||
if expected := "capture_test.go"; frame.File != expected {
|
||||
t.Fatalf("expected file %q but received %q", expected, frame.File)
|
||||
}
|
||||
}
|
38
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/frame.go
generated
vendored
Normal file
38
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/frame.go
generated
vendored
Normal file
|
@ -0,0 +1,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
|
||||
}
|
20
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/frame_test.go
generated
vendored
Normal file
20
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/frame_test.go
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
package stacktrace
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParsePackageName(t *testing.T) {
|
||||
var (
|
||||
name = "github.com/opencontainers/runc/libcontainer/stacktrace.captureFunc"
|
||||
expectedPackage = "github.com/opencontainers/runc/libcontainer/stacktrace"
|
||||
expectedFunction = "captureFunc"
|
||||
)
|
||||
|
||||
pack, funcName := parseFunctionName(name)
|
||||
if pack != expectedPackage {
|
||||
t.Fatalf("expected package %q but received %q", expectedPackage, pack)
|
||||
}
|
||||
|
||||
if funcName != expectedFunction {
|
||||
t.Fatalf("expected function %q but received %q", expectedFunction, funcName)
|
||||
}
|
||||
}
|
5
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/stacktrace.go
generated
vendored
Normal file
5
vendor/github.com/opencontainers/runc/libcontainer/stacktrace/stacktrace.go
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
package stacktrace
|
||||
|
||||
type Stacktrace struct {
|
||||
Frames []Frame
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue