This CL fixes two problems:
- NewContextStub initialize a context with the wrong FP. That
function should dereference the FP returned by getcallerfp, as it
returns the callers's FP instead of the caller's caller FP.
CL 494857 will rename getcallerfp to getfp to make this fact clearer.
- sehCallers skips the bottom frame when it should.
Fixes #60053
Change-Id: I7d59b0175fc95281fcc7dd565ced9293064df3a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/496140
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
return c.ip()
}
-func NewContextStub() ContextStub {
+func NewContextStub() *ContextStub {
var ctx context
ctx.set_ip(getcallerpc())
ctx.set_sp(getcallersp())
- ctx.set_fp(getfp())
- return ContextStub{ctx}
+ fp := getfp()
+ // getfp is not implemented on windows/386 and windows/arm,
+ // in which case it returns 0.
+ if fp != 0 {
+ ctx.set_fp(*(*uintptr)(unsafe.Pointer(fp)))
+ }
+ return &ContextStub{ctx}
}
if fn == 0 {
break
}
- windows.RtlVirtualUnwind(0, base, ctx.GetPC(), fn, uintptr(unsafe.Pointer(&ctx)), nil, &frame, nil)
- n++
pcs[i] = ctx.GetPC()
+ n++
+ windows.RtlVirtualUnwind(0, base, ctx.GetPC(), fn, uintptr(unsafe.Pointer(ctx)), nil, &frame, nil)
}
return pcs[:n]
}