Commit 28c515f4 authored by Alan Donovan's avatar Alan Donovan

runtime: fix bug in GOTRACEBACK=crash causing suppression of core dumps.

Because gotraceback is called early and often, its cache commits to the value of getenv("GOTRACEBACK") before getenv is even ready.  So now we reset its cache once getenv becomes ready.  Panicking programs now dump core again.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/97800045
parent 8afa086c
...@@ -11,6 +11,13 @@ enum { ...@@ -11,6 +11,13 @@ enum {
maxround = sizeof(uintptr), maxround = sizeof(uintptr),
}; };
// Keep a cached value to make gotraceback fast,
// since we call it on every call to gentraceback.
// 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;
// The GOTRACEBACK environment variable controls the // The GOTRACEBACK environment variable controls the
// behavior of a Go program that is crashing and exiting. // behavior of a Go program that is crashing and exiting.
// GOTRACEBACK=0 suppress all tracebacks // GOTRACEBACK=0 suppress all tracebacks
...@@ -20,12 +27,6 @@ enum { ...@@ -20,12 +27,6 @@ enum {
int32 int32
runtime·gotraceback(bool *crash) runtime·gotraceback(bool *crash)
{ {
// Keep a cached value to make gotraceback fast,
// since we call it on every call to gentraceback.
// 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 cache = ~(uint32)0;
byte *p; byte *p;
uint32 x; uint32 x;
...@@ -33,7 +34,7 @@ runtime·gotraceback(bool *crash) ...@@ -33,7 +34,7 @@ runtime·gotraceback(bool *crash)
*crash = false; *crash = false;
if(m->traceback != 0) if(m->traceback != 0)
return m->traceback; return m->traceback;
x = runtime·atomicload(&cache); x = runtime·atomicload(&traceback_cache);
if(x == ~(uint32)0) { if(x == ~(uint32)0) {
p = runtime·getenv("GOTRACEBACK"); p = runtime·getenv("GOTRACEBACK");
if(p == nil) if(p == nil)
...@@ -44,7 +45,7 @@ runtime·gotraceback(bool *crash) ...@@ -44,7 +45,7 @@ runtime·gotraceback(bool *crash)
x = (2<<1) | 1; x = (2<<1) | 1;
else else
x = runtime·atoi(p)<<1; x = runtime·atoi(p)<<1;
runtime·atomicstore(&cache, x); runtime·atomicstore(&traceback_cache, x);
} }
if(crash != nil) if(crash != nil)
*crash = x&1; *crash = x&1;
...@@ -137,6 +138,8 @@ runtime·goenvs_unix(void) ...@@ -137,6 +138,8 @@ runtime·goenvs_unix(void)
syscall·envs.array = (byte*)s; syscall·envs.array = (byte*)s;
syscall·envs.len = n; syscall·envs.len = n;
syscall·envs.cap = n; syscall·envs.cap = n;
traceback_cache = ~(uint32)0;
} }
int32 int32
......
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