Skip to content

Commit

Permalink
Merge branch 'release/v1.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHines committed Jul 10, 2017
2 parents 7a2f196 + 3bd81bd commit 54be5f3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 38 deletions.
31 changes: 2 additions & 29 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func Caller(skip int) Call {
}

c.pc = pcs[1]
if runtime.FuncForPC(pcs[0]) != sigpanic {
if runtime.FuncForPC(pcs[0]).Name() != "runtime.sigpanic" {
c.pc--
}
c.fn = runtime.FuncForPC(c.pc)
Expand Down Expand Up @@ -205,33 +205,6 @@ func (cs CallStack) Format(s fmt.State, verb rune) {
s.Write(closeBracketBytes)
}

// findSigpanic intentionally executes faulting code to generate a stack trace
// containing an entry for runtime.sigpanic.
func findSigpanic() *runtime.Func {
var fn *runtime.Func
var p *int
func() int {
defer func() {
if p := recover(); p != nil {
var pcs [512]uintptr
n := runtime.Callers(2, pcs[:])
for _, pc := range pcs[:n] {
f := runtime.FuncForPC(pc)
if f.Name() == "runtime.sigpanic" {
fn = f
break
}
}
}
}()
// intentional nil pointer dereference to trigger sigpanic
return *p
}()
return fn
}

var sigpanic = findSigpanic()

// Trace returns a CallStack for the current goroutine with element 0
// identifying the calling function.
func Trace() CallStack {
Expand All @@ -241,7 +214,7 @@ func Trace() CallStack {

for i, pc := range pcs[:n] {
pcFix := pc
if i > 0 && cs[i-1].fn != sigpanic {
if i > 0 && cs[i-1].fn.Name() != "runtime.sigpanic" {
pcFix--
}
cs[i] = Call{
Expand Down
10 changes: 1 addition & 9 deletions stackinternal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@ import (
"testing"
)

func TestFindSigpanic(t *testing.T) {
t.Parallel()
sp := findSigpanic()
if got, want := sp.Name(), "runtime.sigpanic"; got != want {
t.Errorf("got == %v, want == %v", got, want)
}
}

func TestCaller(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -55,7 +47,7 @@ func TestTrace(t *testing.T) {

cs := fh.labyrinth()

lines := []int{51, 41, 56}
lines := []int{43, 33, 48}

for i, line := range lines {
if got, want := cs[i].line(), line; got != want {
Expand Down

0 comments on commit 54be5f3

Please sign in to comment.