diff options
Diffstat (limited to 'libgo/runtime/panic.c')
-rw-r--r-- | libgo/runtime/panic.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/libgo/runtime/panic.c b/libgo/runtime/panic.c index 7d79256cf41..7a8d95b1ade 100644 --- a/libgo/runtime/panic.c +++ b/libgo/runtime/panic.c @@ -38,7 +38,7 @@ runtime_startpanic(void) M *m; m = runtime_m(); - if(runtime_mheap == 0 || runtime_mheap->cachealloc.size == 0) { // very early + if(runtime_mheap.cachealloc.size == 0) { // very early runtime_printf("runtime: panic before malloc heap initialized\n"); m->mallocing = 1; // tell rest of panic not to try to malloc } else if(m->mcache == nil) // can happen if called from signal handler or throw @@ -48,8 +48,13 @@ runtime_startpanic(void) runtime_exit(3); } m->dying = 1; + if(runtime_g() != nil) + runtime_g()->writebuf = nil; runtime_xadd(&runtime_panicking, 1); runtime_lock(&paniclk); + if(runtime_debug.schedtrace > 0 || runtime_debug.scheddetail > 0) + runtime_schedtrace(true); + runtime_freezetheworld(); } void @@ -58,18 +63,22 @@ runtime_dopanic(int32 unused __attribute__ ((unused))) G *g; static bool didothers; bool crash; + int32 t; g = runtime_g(); if(g->sig != 0) runtime_printf("[signal %x code=%p addr=%p]\n", g->sig, (void*)g->sigcode0, (void*)g->sigcode1); - if(runtime_gotraceback(&crash)){ + if((t = runtime_gotraceback(&crash)) > 0){ if(g != runtime_m()->g0) { runtime_printf("\n"); runtime_goroutineheader(g); runtime_traceback(); - runtime_goroutinetrailer(g); + runtime_printcreatedby(g); + } else if(t >= 2 || runtime_m()->throwing > 0) { + runtime_printf("\nruntime stack:\n"); + runtime_traceback(); } if(!didothers) { didothers = true; @@ -113,11 +122,15 @@ runtime_panicstring(const char *s) { Eface err; + if(runtime_m()->mallocing) { + runtime_printf("panic: %s\n", s); + runtime_throw("panic during malloc"); + } if(runtime_m()->gcing) { runtime_printf("panic: %s\n", s); runtime_throw("panic during gc"); } - runtime_newErrorString(runtime_gostringnocopy((const byte*)s), &err); + runtime_newErrorCString(s, &err); runtime_panic(err); } |