README.md improved

This commit is contained in:
Timon Ringwald
2020-09-09 14:06:31 +02:00
parent b33b40c9ff
commit 37acf646f4
5 changed files with 99 additions and 9 deletions

View File

@ -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()
}