aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2016-02-03 21:58:02 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2016-02-03 21:58:02 +0000
commitf98dd1a338867a408f7c72d73fbad7fe7fc93e3a (patch)
tree2f8da9862a9c1fe0df138917f997b03439c02773 /libgo/runtime
parentb081ed4efc144da0c45a6484aebfd10e0eb9fda3 (diff)
downloadgcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.zip
gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.gz
gcc-f98dd1a338867a408f7c72d73fbad7fe7fc93e3a.tar.bz2
libgo: Update to go1.6rc1.
Reviewed-on: https://go-review.googlesource.com/19200 From-SVN: r233110
Diffstat (limited to 'libgo/runtime')
-rw-r--r--libgo/runtime/go-signal.c75
-rw-r--r--libgo/runtime/runtime.c98
-rw-r--r--libgo/runtime/runtime.h15
-rw-r--r--libgo/runtime/signal_unix.c27
4 files changed, 125 insertions, 90 deletions
diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
index 4a1bf56..a948c31 100644
--- a/libgo/runtime/go-signal.c
+++ b/libgo/runtime/go-signal.c
@@ -33,105 +33,107 @@ extern void __splitstack_setcontext(void *context[10]);
#define D SigDefault
/* Signal actions. This collects the sigtab tables for several
- different targets from the master library. SIGKILL, SIGCONT, and
- SIGSTOP are not listed, as we don't want to set signal handlers for
- them. */
+ different targets from the master library. SIGKILL and SIGSTOP are
+ not listed, as we don't want to set signal handlers for them. */
SigTab runtime_sigtab[] = {
#ifdef SIGHUP
- { SIGHUP, N + K },
+ { SIGHUP, N + K, NULL },
#endif
#ifdef SIGINT
- { SIGINT, N + K },
+ { SIGINT, N + K, NULL },
#endif
#ifdef SIGQUIT
- { SIGQUIT, N + T },
+ { SIGQUIT, N + T, NULL },
#endif
#ifdef SIGILL
- { SIGILL, T },
+ { SIGILL, T, NULL },
#endif
#ifdef SIGTRAP
- { SIGTRAP, T },
+ { SIGTRAP, T, NULL },
#endif
#ifdef SIGABRT
- { SIGABRT, N + T },
+ { SIGABRT, N + T, NULL },
#endif
#ifdef SIGBUS
- { SIGBUS, P },
+ { SIGBUS, P, NULL },
#endif
#ifdef SIGFPE
- { SIGFPE, P },
+ { SIGFPE, P, NULL },
#endif
#ifdef SIGUSR1
- { SIGUSR1, N },
+ { SIGUSR1, N, NULL },
#endif
#ifdef SIGSEGV
- { SIGSEGV, P },
+ { SIGSEGV, P, NULL },
#endif
#ifdef SIGUSR2
- { SIGUSR2, N },
+ { SIGUSR2, N, NULL },
#endif
#ifdef SIGPIPE
- { SIGPIPE, N },
+ { SIGPIPE, N, NULL },
#endif
#ifdef SIGALRM
- { SIGALRM, N },
+ { SIGALRM, N, NULL },
#endif
#ifdef SIGTERM
- { SIGTERM, N + K },
+ { SIGTERM, N + K, NULL },
#endif
#ifdef SIGSTKFLT
- { SIGSTKFLT, T },
+ { SIGSTKFLT, T, NULL },
#endif
#ifdef SIGCHLD
- { SIGCHLD, N },
+ { SIGCHLD, N, NULL },
+#endif
+#ifdef SIGCONT
+ { SIGCONT, N + D, NULL },
#endif
#ifdef SIGTSTP
- { SIGTSTP, N + D },
+ { SIGTSTP, N + D, NULL },
#endif
#ifdef SIGTTIN
- { SIGTTIN, N + D },
+ { SIGTTIN, N + D, NULL },
#endif
#ifdef SIGTTOU
- { SIGTTOU, N + D },
+ { SIGTTOU, N + D, NULL },
#endif
#ifdef SIGURG
- { SIGURG, N },
+ { SIGURG, N, NULL },
#endif
#ifdef SIGXCPU
- { SIGXCPU, N },
+ { SIGXCPU, N, NULL },
#endif
#ifdef SIGXFSZ
- { SIGXFSZ, N },
+ { SIGXFSZ, N, NULL },
#endif
#ifdef SIGVTALRM
- { SIGVTALRM, N },
+ { SIGVTALRM, N, NULL },
#endif
#ifdef SIGPROF
- { SIGPROF, N },
+ { SIGPROF, N, NULL },
#endif
#ifdef SIGWINCH
- { SIGWINCH, N },
+ { SIGWINCH, N, NULL },
#endif
#ifdef SIGIO
- { SIGIO, N },
+ { SIGIO, N, NULL },
#endif
#ifdef SIGPWR
- { SIGPWR, N },
+ { SIGPWR, N, NULL },
#endif
#ifdef SIGSYS
- { SIGSYS, N },
+ { SIGSYS, N, NULL },
#endif
#ifdef SIGEMT
- { SIGEMT, T },
+ { SIGEMT, T, NULL },
#endif
#ifdef SIGINFO
- { SIGINFO, N },
+ { SIGINFO, N, NULL },
#endif
#ifdef SIGTHR
- { SIGTHR, N },
+ { SIGTHR, N, NULL },
#endif
- { -1, 0 }
+ { -1, 0, NULL }
};
#undef N
#undef K
@@ -526,6 +528,9 @@ os_sigpipe (void)
struct sigaction sa;
int i;
+ if (__go_sigsend (SIGPIPE))
+ return;
+
memset (&sa, 0, sizeof sa);
sa.sa_handler = SIG_DFL;
diff --git a/libgo/runtime/runtime.c b/libgo/runtime/runtime.c
index be7ccbd..4140d33 100644
--- a/libgo/runtime/runtime.c
+++ b/libgo/runtime/runtime.c
@@ -20,23 +20,28 @@ enum {
// The cached value is a uint32 in which the low bit
// is the "crash" setting and the top 31 bits are the
// gotraceback value.
-static uint32 traceback_cache = ~(uint32)0;
+enum {
+ tracebackCrash = 1 << 0,
+ tracebackAll = 1 << 1,
+ tracebackShift = 2,
+};
+static uint32 traceback_cache = 2 << tracebackShift;
+static uint32 traceback_env;
extern volatile intgo runtime_MemProfileRate
__asm__ (GOSYM_PREFIX "runtime.MemProfileRate");
-// The GOTRACEBACK environment variable controls the
-// behavior of a Go program that is crashing and exiting.
-// GOTRACEBACK=0 suppress all tracebacks
-// GOTRACEBACK=1 default behavior - show tracebacks but exclude runtime frames
-// GOTRACEBACK=2 show tracebacks including runtime frames
-// GOTRACEBACK=crash show tracebacks including runtime frames, then crash (core dump etc)
+// gotraceback returns the current traceback settings.
+//
+// If level is 0, suppress all tracebacks.
+// If level is 1, show tracebacks, but exclude runtime frames.
+// If level is 2, show tracebacks including runtime frames.
+// If all is set, print all goroutine stacks. Otherwise, print just the current goroutine.
+// If crash is set, crash (core dump, etc) after tracebacking.
int32
runtime_gotraceback(bool *crash)
{
- String s;
- const byte *p;
uint32 x;
if(crash != nil)
@@ -44,20 +49,9 @@ runtime_gotraceback(bool *crash)
if(runtime_m()->traceback != 0)
return runtime_m()->traceback;
x = runtime_atomicload(&traceback_cache);
- if(x == ~(uint32)0) {
- s = runtime_getenv("GOTRACEBACK");
- p = s.str;
- if(s.len == 0)
- x = 1<<1;
- else if(s.len == 5 && runtime_strcmp((const char *)p, "crash") == 0)
- x = (2<<1) | 1;
- else
- x = runtime_atoi(p, s.len)<<1;
- runtime_atomicstore(&traceback_cache, x);
- }
if(crash != nil)
- *crash = x&1;
- return x>>1;
+ *crash = x&tracebackCrash;
+ return x>>tracebackShift;
}
static int32 argc;
@@ -319,6 +313,31 @@ runtime_signalstack(byte *p, int32 n)
*(int *)0xf1 = 0xf1;
}
+void setTraceback(String level)
+ __asm__ (GOSYM_PREFIX "runtime_debug.SetTraceback");
+
+void setTraceback(String level) {
+ uint32 t;
+
+ if (level.len == 4 && __builtin_memcmp(level.str, "none", 4) == 0) {
+ t = 0;
+ } else if (level.len == 0 || (level.len == 6 && __builtin_memcmp(level.str, "single", 6) == 0)) {
+ t = 1 << tracebackShift;
+ } else if (level.len == 3 && __builtin_memcmp(level.str, "all", 3) == 0) {
+ t = (1<<tracebackShift) | tracebackAll;
+ } else if (level.len == 6 && __builtin_memcmp(level.str, "system", 6) == 0) {
+ t = (2<<tracebackShift) | tracebackAll;
+ } else if (level.len == 5 && __builtin_memcmp(level.str, "crash", 5) == 0) {
+ t = (2<<tracebackShift) | tracebackAll | tracebackCrash;
+ } else {
+ t = (runtime_atoi(level.str, level.len)<<tracebackShift) | tracebackAll;
+ }
+
+ t |= traceback_env;
+
+ runtime_atomicstore(&traceback_cache, t);
+}
+
DebugVars runtime_debug;
// Holds variables parsed from GODEBUG env var,
@@ -331,11 +350,22 @@ static struct {
int32* value;
} dbgvar[] = {
{"allocfreetrace", &runtime_debug.allocfreetrace},
+ {"cgocheck", &runtime_debug.cgocheck},
{"efence", &runtime_debug.efence},
+ {"gccheckmark", &runtime_debug.gccheckmark},
+ {"gcpacertrace", &runtime_debug.gcpacertrace},
+ {"gcshrinkstackoff", &runtime_debug.gcshrinkstackoff},
+ {"gcstackbarrieroff", &runtime_debug.gcstackbarrieroff},
+ {"gcstackbarrierall", &runtime_debug.gcstackbarrierall},
+ {"gcstoptheworld", &runtime_debug.gcstoptheworld},
{"gctrace", &runtime_debug.gctrace},
{"gcdead", &runtime_debug.gcdead},
+ {"invalidptr", &runtime_debug.invalidptr},
+ {"sbrk", &runtime_debug.sbrk},
+ {"scavenge", &runtime_debug.scavenge},
{"scheddetail", &runtime_debug.scheddetail},
{"schedtrace", &runtime_debug.schedtrace},
+ {"wbshadow", &runtime_debug.wbshadow},
};
void
@@ -345,17 +375,7 @@ runtime_parsedebugvars(void)
const byte *p, *pn;
intgo len;
intgo i, n;
- bool tmp;
- // gotraceback caches the GOTRACEBACK setting in traceback_cache.
- // gotraceback can be called before the environment is available.
- // traceback_cache must be reset after the environment is made
- // available, in order for the environment variable to take effect.
- // The code is fixed differently in Go 1.4.
- // This is a limited fix for Go 1.3.3.
- traceback_cache = ~(uint32)0;
- runtime_gotraceback(&tmp);
-
s = runtime_getenv("GODEBUG");
if(s.len == 0)
return;
@@ -378,6 +398,20 @@ runtime_parsedebugvars(void)
len -= (pn - p) - 1;
p = pn + 1;
}
+
+ setTraceback(runtime_getenv("GOTRACEBACK"));
+ traceback_env = traceback_cache;
+}
+
+// SetTracebackEnv is like runtime/debug.SetTraceback, but it raises
+// the "environment" traceback level, so later calls to
+// debug.SetTraceback (e.g., from testing timeouts) can't lower it.
+void SetTracebackEnv(String level)
+ __asm__ (GOSYM_PREFIX "runtime.SetTracebackEnv");
+
+void SetTracebackEnv(String level) {
+ setTraceback(level);
+ traceback_env = traceback_cache;
}
// Poor mans 64-bit division.
diff --git a/libgo/runtime/runtime.h b/libgo/runtime/runtime.h
index cbf1fe1..f4b170d 100644
--- a/libgo/runtime/runtime.h
+++ b/libgo/runtime/runtime.h
@@ -329,6 +329,7 @@ struct SigTab
{
int32 sig;
int32 flags;
+ void* fwdsig;
};
enum
{
@@ -338,8 +339,7 @@ enum
SigPanic = 1<<3, // if the signal is from the kernel, panic
SigDefault = 1<<4, // if the signal isn't explicitly requested, don't monitor it
SigHandling = 1<<5, // our signal handler is registered
- SigIgnored = 1<<6, // the signal was ignored before we registered for it
- SigGoExit = 1<<7, // cause all runtime procs to exit (only used on Plan 9).
+ SigGoExit = 1<<6, // cause all runtime procs to exit (only used on Plan 9).
};
// Layout of in-memory per-function information prepared by linker
@@ -450,11 +450,22 @@ struct CgoMal
struct DebugVars
{
int32 allocfreetrace;
+ int32 cgocheck;
int32 efence;
+ int32 gccheckmark;
+ int32 gcpacertrace;
+ int32 gcshrinkstackoff;
+ int32 gcstackbarrieroff;
+ int32 gcstackbarrierall;
+ int32 gcstoptheworld;
int32 gctrace;
int32 gcdead;
+ int32 invalidptr;
+ int32 sbrk;
+ int32 scavenge;
int32 scheddetail;
int32 schedtrace;
+ int32 wbshadow;
};
extern bool runtime_precisestack;
diff --git a/libgo/runtime/signal_unix.c b/libgo/runtime/signal_unix.c
index 43be0d8..2028933 100644
--- a/libgo/runtime/signal_unix.c
+++ b/libgo/runtime/signal_unix.c
@@ -24,14 +24,15 @@ runtime_initsig(void)
if((t->flags == 0) || (t->flags & SigDefault))
continue;
+ t->fwdsig = runtime_getsig(i);
+
// For some signals, we respect an inherited SIG_IGN handler
// rather than insist on installing our own default handler.
// Even these signals can be fetched using the os/signal package.
switch(t->sig) {
case SIGHUP:
case SIGINT:
- if(runtime_getsig(i) == GO_SIG_IGN) {
- t->flags = SigNotify | SigIgnored;
+ if(t->fwdsig == GO_SIG_IGN) {
continue;
}
}
@@ -60,8 +61,7 @@ runtime_sigenable(uint32 sig)
if((t->flags & SigNotify) && !(t->flags & SigHandling)) {
t->flags |= SigHandling;
- if(runtime_getsig(i) == GO_SIG_IGN)
- t->flags |= SigIgnored;
+ t->fwdsig = runtime_getsig(i);
runtime_setsig(i, runtime_sighandler, true);
}
}
@@ -83,12 +83,9 @@ runtime_sigdisable(uint32 sig)
if(t == nil)
return;
- if((t->flags & SigNotify) && (t->flags & SigHandling)) {
+ if((sig == SIGHUP || sig == SIGINT) && t->fwdsig == GO_SIG_IGN) {
t->flags &= ~SigHandling;
- if(t->flags & SigIgnored)
- runtime_setsig(i, GO_SIG_IGN, true);
- else
- runtime_setsig(i, GO_SIG_DFL, true);
+ runtime_setsig(i, t->fwdsig, true);
}
}
@@ -133,18 +130,6 @@ runtime_resetcpuprofiler(int32 hz)
}
void
-os_sigpipe(void)
-{
- int32 i;
-
- for(i = 0; runtime_sigtab[i].sig != -1; i++)
- if(runtime_sigtab[i].sig == SIGPIPE)
- break;
- runtime_setsig(i, GO_SIG_DFL, false);
- runtime_raise(SIGPIPE);
-}
-
-void
runtime_unblocksignals(void)
{
sigset_t sigset_none;