Skip to content

Commit

Permalink
add Frame
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jan 13, 2025
1 parent 35826fe commit b51a1d9
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,14 @@ func (ctx *Context) SetPanic(fn func(*PanicInfo)) {
ctx.panicFunc = fn
}

type PanicInfo struct {
funcInstr
fset *token.FileSet
fr *frame
Error error // PanicError
}
type Frame = frame

func (i *PanicInfo) Position() token.Position {
return i.fset.Position(i.Pos())
}

func (i *PanicInfo) CallerFrames() (frames []runtime.Frame) {
func (fr *Frame) CallerFrames() (frames []runtime.Frame) {
rpc := make([]uintptr, 64)
n := runtimeCallers(i.fr, 1, rpc)
n := runtimeCallers(fr, 1, rpc)
fs := runtime.CallersFrames(rpc[:n])
for {
f, more := runtimeFramesNext(i.fr, fs)
f, more := runtimeFramesNext(fr, fs)
frames = append(frames, f)
if !more {
break
Expand All @@ -242,14 +233,25 @@ func (i *PanicInfo) CallerFrames() (frames []runtime.Frame) {
return
}

type PanicInfo struct {
funcInstr
*Frame
fset *token.FileSet
Error error // PanicError
}

func (i *PanicInfo) Position() token.Position {
return i.fset.Position(i.Pos())
}

type funcInstr interface {
Parent() *ssa.Function
Pos() token.Pos
String() string
}

func (ctx *Context) handlePanic(fr *frame, fn funcInstr, err error) error {
info := &PanicInfo{funcInstr: fn, fset: ctx.FileSet, fr: fr, Error: err}
info := &PanicInfo{funcInstr: fn, Frame: fr, fset: ctx.FileSet, Error: err}
ctx.panicFunc(info)
if info.Error != nil {
return info.Error
Expand Down

0 comments on commit b51a1d9

Please sign in to comment.