From 5146a93e72e870b06150c5419e1b83056ecc697b Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 15 Mar 2013 01:11:03 -0400 Subject: runtime: accept GOTRACEBACK=crash to mean 'crash after panic' This provides a way to generate core dumps when people need them. The settings are: GOTRACEBACK=0 no traceback on panic, just exit GOTRACEBACK=1 default - traceback on panic, then exit GOTRACEBACK=2 traceback including runtime frames on panic, then exit GOTRACEBACK=crash traceback including runtime frames on panic, then crash Fixes #3257. R=golang-dev, devon.odell, r, daniel.morsing, ality CC=golang-dev https://golang.org/cl/7666044 --- src/pkg/runtime/runtime.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/pkg/runtime/runtime.c') diff --git a/src/pkg/runtime/runtime.c b/src/pkg/runtime/runtime.c index 3ff4d7fa7e..ef39a2d55f 100644 --- a/src/pkg/runtime/runtime.c +++ b/src/pkg/runtime/runtime.c @@ -17,14 +17,27 @@ enum { */ void runtime·sigpanic(void); +// 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) int32 -runtime·gotraceback(void) +runtime·gotraceback(bool *crash) { byte *p; + if(crash != nil) + *crash = false; p = runtime·getenv("GOTRACEBACK"); if(p == nil || p[0] == '\0') return 1; // default is on + if(runtime·strcmp(p, (byte*)"crash") == 0) { + if(crash != nil) + *crash = true; + return 2; // extra information + } return runtime·atoi(p); } -- cgit v1.3-5-g9baa