Commit 3d037cfa authored by Ian Lance Taylor's avatar Ian Lance Taylor

runtime: pass signal context to cgo traceback function

When doing a backtrace from a signal that occurs in C code compiled
without using -fasynchronous-unwind-tables, we have to rely on frame
pointers. In order to do that, the traceback function needs the signal
context to reliably pick up the frame pointer.

Change-Id: I7b45930fced01685c337d108e0f146057928f876
Reviewed-on: https://go-review.googlesource.com/23494
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: default avatarAustin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c52dff07
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
struct cgoTracebackArg { struct cgoTracebackArg {
uintptr_t Context; uintptr_t Context;
uintptr_t SigContext;
uintptr_t* Buf; uintptr_t* Buf;
uintptr_t Max; uintptr_t Max;
}; };
...@@ -22,6 +23,7 @@ x_cgo_callers(uintptr_t sig, void *info, void *context, void (*cgoTraceback)(str ...@@ -22,6 +23,7 @@ x_cgo_callers(uintptr_t sig, void *info, void *context, void (*cgoTraceback)(str
struct cgoTracebackArg arg; struct cgoTracebackArg arg;
arg.Context = 0; arg.Context = 0;
arg.SigContext = (uintptr_t)(context);
arg.Buf = cgoCallers; arg.Buf = cgoCallers;
arg.Max = 32; // must match len(runtime.cgoCallers) arg.Max = 32; // must match len(runtime.cgoCallers)
(*cgoTraceback)(&arg); (*cgoTraceback)(&arg);
......
...@@ -30,6 +30,7 @@ static int cpuHogCount; ...@@ -30,6 +30,7 @@ static int cpuHogCount;
struct cgoTracebackArg { struct cgoTracebackArg {
uintptr_t context; uintptr_t context;
uintptr_t sigContext;
uintptr_t* buf; uintptr_t* buf;
uintptr_t max; uintptr_t max;
}; };
......
...@@ -30,6 +30,7 @@ static int f1() { ...@@ -30,6 +30,7 @@ static int f1() {
struct cgoTracebackArg { struct cgoTracebackArg {
uintptr_t context; uintptr_t context;
uintptr_t sigContext;
uintptr_t* buf; uintptr_t* buf;
uintptr_t max; uintptr_t max;
}; };
......
...@@ -26,6 +26,7 @@ struct cgoContextArg { ...@@ -26,6 +26,7 @@ struct cgoContextArg {
struct cgoTracebackArg { struct cgoTracebackArg {
uintptr_t context; uintptr_t context;
uintptr_t sigContext;
uintptr_t* buf; uintptr_t* buf;
uintptr_t max; uintptr_t max;
}; };
......
...@@ -859,6 +859,7 @@ func isSystemGoroutine(gp *g) bool { ...@@ -859,6 +859,7 @@ func isSystemGoroutine(gp *g) bool {
// //
// struct { // struct {
// Context uintptr // Context uintptr
// SigContext uintptr
// Buf *uintptr // Buf *uintptr
// Max uintptr // Max uintptr
// } // }
...@@ -867,6 +868,7 @@ func isSystemGoroutine(gp *g) bool { ...@@ -867,6 +868,7 @@ func isSystemGoroutine(gp *g) bool {
// //
// struct { // struct {
// uintptr_t Context; // uintptr_t Context;
// uintptr_t SigContext;
// uintptr_t* Buf; // uintptr_t* Buf;
// uintptr_t Max; // uintptr_t Max;
// }; // };
...@@ -887,6 +889,13 @@ func isSystemGoroutine(gp *g) bool { ...@@ -887,6 +889,13 @@ func isSystemGoroutine(gp *g) bool {
// result, if possible, the first time this is called for a specific // result, if possible, the first time this is called for a specific
// context value. // context value.
// //
// If the traceback function is called from a signal handler on a Unix
// system, SigContext will be the signal context argument passed to
// the signal handler (a C ucontext_t* cast to uintptr_t). This may be
// used to start tracing at the point where the signal occurred. If
// the traceback function is not called from a signal handler,
// SigContext will be zero.
//
// Buf is where the traceback information should be stored. It should // Buf is where the traceback information should be stored. It should
// be PC values, such that Buf[0] is the PC of the caller, Buf[1] is // be PC values, such that Buf[0] is the PC of the caller, Buf[1] is
// the PC of that function's caller, and so on. Max is the maximum // the PC of that function's caller, and so on. Max is the maximum
...@@ -974,6 +983,7 @@ var cgoSymbolizer unsafe.Pointer ...@@ -974,6 +983,7 @@ var cgoSymbolizer unsafe.Pointer
// cgoTracebackArg is the type passed to cgoTraceback. // cgoTracebackArg is the type passed to cgoTraceback.
type cgoTracebackArg struct { type cgoTracebackArg struct {
context uintptr context uintptr
sigContext uintptr
buf *uintptr buf *uintptr
max uintptr max uintptr
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment