runtime: abort stack scan in cases that we cannot unwind the stack

In signal-triggered stack scan, if the signal is delivered at
certain bad time (e.g. in vdso, or in the middle of setcontext?),
the unwinder may not be able to unwind the whole stack, while it
still reports _URC_END_OF_STACK. So we cannot rely on _URC_END_OF_STACK
to tell if it successfully scanned the stack. Instead, we check
the last Go frame to see it actually reached the end of the stack.
For Go-created stack, this is runtime.kickoff. For C-created
stack, we need to record the outermost Go frame when it enters
the Go side.

Also we cannot unwind the stack if the signal is delivered in the
middle of runtime.gogo, halfway through a goroutine switch, where
the g and the stack don't match. Give up in this case as well.

Change-Id: I58ba32f13c40951c2a12b3f42d95687a3e1d2112
Reviewed-on: https://go-review.googlesource.com/c/159098
Reviewed-by: Ian Lance Taylor <iant@golang.org>
5 files changed