1
0
mirror of https://github.com/golang/go synced 2024-11-19 12:54:45 -07:00
go/src/runtime/defs_plan9_386.go
Ian Lance Taylor d03e8b226c runtime: record current PC for SIGPROF on non-Go thread
If we get a SIGPROF on a non-Go thread, and the program has not called
runtime.SetCgoTraceback so we have no way to collect a stack trace, then
record a profile that is just the PC where the signal occurred. That
will at least point the user to the right area.

Retrieving the PC from the sigctxt in a signal handler on a non-G thread
required marking a number of trivial sigctxt methods as nosplit, and,
for extra safety, nowritebarrierrec.

The test shows that the existing test CgoPprofThread test does not test
the stack trace, just the profile signal. Leaving that for later.

Change-Id: I8f8f3ff09ac099fc9d9df94b5a9d210ffc20c4ab
Reviewed-on: https://go-review.googlesource.com/30252
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
2016-10-11 12:56:15 +00:00

61 lines
1.5 KiB
Go

package runtime
const _PAGESIZE = 0x1000
type ureg struct {
di uint32 /* general registers */
si uint32 /* ... */
bp uint32 /* ... */
nsp uint32
bx uint32 /* ... */
dx uint32 /* ... */
cx uint32 /* ... */
ax uint32 /* ... */
gs uint32 /* data segments */
fs uint32 /* ... */
es uint32 /* ... */
ds uint32 /* ... */
trap uint32 /* trap _type */
ecode uint32 /* error code (or zero) */
pc uint32 /* pc */
cs uint32 /* old context */
flags uint32 /* old flags */
sp uint32
ss uint32 /* old stack segment */
}
type sigctxt struct {
u *ureg
}
//go:nosplit
//go:nowritebarrierrec
func (c *sigctxt) pc() uintptr { return uintptr(c.u.pc) }
func (c *sigctxt) sp() uintptr { return uintptr(c.u.sp) }
func (c *sigctxt) lr() uintptr { return uintptr(0) }
func (c *sigctxt) setpc(x uintptr) { c.u.pc = uint32(x) }
func (c *sigctxt) setsp(x uintptr) { c.u.sp = uint32(x) }
func (c *sigctxt) setlr(x uintptr) {}
func (c *sigctxt) savelr(x uintptr) {}
func dumpregs(u *ureg) {
print("ax ", hex(u.ax), "\n")
print("bx ", hex(u.bx), "\n")
print("cx ", hex(u.cx), "\n")
print("dx ", hex(u.dx), "\n")
print("di ", hex(u.di), "\n")
print("si ", hex(u.si), "\n")
print("bp ", hex(u.bp), "\n")
print("sp ", hex(u.sp), "\n")
print("pc ", hex(u.pc), "\n")
print("flags ", hex(u.flags), "\n")
print("cs ", hex(u.cs), "\n")
print("fs ", hex(u.fs), "\n")
print("gs ", hex(u.gs), "\n")
}
func sigpanictramp() {}