README.md improved
This commit is contained in:
13
calltrace.go
13
calltrace.go
@ -1,6 +1,7 @@
|
||||
package adverr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -9,19 +10,21 @@ import (
|
||||
// CallTrace represents a call stack trace similar to Java's stack trace
|
||||
type CallTrace struct {
|
||||
frames *runtime.Frames
|
||||
more bool
|
||||
}
|
||||
|
||||
// Trace returns a new CallTrace starting from this call
|
||||
// Use skip to skip the first entries in the trace
|
||||
func Trace(skip int) *CallTrace {
|
||||
if !TraceCallStack {
|
||||
if DisableTrace {
|
||||
return nil
|
||||
}
|
||||
|
||||
pc := make([]uintptr, CallStackLength)
|
||||
pc := make([]uintptr, CallStackLength+1)
|
||||
n := runtime.Callers(skip+1, pc)
|
||||
pc = pc[:n]
|
||||
return &CallTrace{runtime.CallersFrames(pc)}
|
||||
fmt.Println(n, CallStackLength)
|
||||
return &CallTrace{runtime.CallersFrames(pc), n == CallStackLength+1}
|
||||
}
|
||||
|
||||
func (ct *CallTrace) String() string {
|
||||
@ -42,5 +45,9 @@ func (ct *CallTrace) String() string {
|
||||
b.WriteString("\n")
|
||||
}
|
||||
|
||||
if ct.more {
|
||||
b.WriteString("\t ...\n")
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
Reference in New Issue
Block a user