From a854d40441b90a63e54e3bd0c005fedfc05efbf9 Mon Sep 17 00:00:00 2001 From: Peter Edge Date: Fri, 10 Mar 2017 13:51:26 -0500 Subject: [PATCH] Use runtime.CallersFrames (#365) To support Go 1.9's improved inlining, use runtime.CallersFrames to generate stack traces. Fixes #354. --- stacktrace.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/stacktrace.go b/stacktrace.go index 2726d84c7..a214c162d 100644 --- a/stacktrace.go +++ b/stacktrace.go @@ -60,31 +60,29 @@ func takeStacktrace() string { } i := 0 - for _, programCounter := range programCounters.pcs { - f := runtime.FuncForPC(programCounter) - name := f.Name() - if shouldIgnoreStacktraceName(name) { + frames := runtime.CallersFrames(programCounters.pcs) + for frame, more := frames.Next(); more; frame, more = frames.Next() { + if shouldIgnoreStacktraceFunction(frame.Function) { continue } if i != 0 { buffer.AppendByte('\n') } i++ - file, line := f.FileLine(programCounter - 1) - buffer.AppendString(name) + buffer.AppendString(frame.Function) buffer.AppendByte('\n') buffer.AppendByte('\t') - buffer.AppendString(file) + buffer.AppendString(frame.File) buffer.AppendByte(':') - buffer.AppendInt(int64(line)) + buffer.AppendInt(int64(frame.Line)) } return buffer.String() } -func shouldIgnoreStacktraceName(name string) bool { +func shouldIgnoreStacktraceFunction(function string) bool { for _, prefix := range _stacktraceIgnorePrefixes { - if strings.HasPrefix(name, prefix) { + if strings.HasPrefix(function, prefix) { return true } }