diff --git a/src/core/exceptions.c b/src/core/exceptions.c index f5429fbc10..b4533904c2 100644 --- a/src/core/exceptions.c +++ b/src/core/exceptions.c @@ -648,10 +648,10 @@ static void panic_unhandled_cat(MVMThreadContext *tc, MVMuint32 cat) { } else { if (tc->nested_interpreter) - fprintf(stderr, "An unhandled exception occurred in a native callback.\n" - "This situation is not recoverable, and the program will terminate.\n" - "The stack trace below helps indicate which library needs fixing.\n" - "The exception was thrown at:\n"); + fputs("An unhandled exception occurred in a native callback.\n" + "This situation is not recoverable, and the program will terminate.\n" + "The stack trace below helps indicate which library needs fixing.\n" + "The exception was thrown at:\n", stderr); else fprintf(stderr, "No exception handler located for %s\n", cat_name(tc, cat)); MVM_dump_backtrace(tc); @@ -843,11 +843,11 @@ void MVM_exception_resume(MVMThreadContext *tc, MVMObject *ex_obj) { */ MVM_NO_RETURN void MVM_panic(MVMint32 exitCode, const char *messageFormat, ...) { va_list args; - fprintf(stderr, "MoarVM panic: "); + fputs("MoarVM panic: ", stderr); va_start(args, messageFormat); vfprintf(stderr, messageFormat, args); va_end(args); - fwrite("\n", 1, 1, stderr); + fputc('\n', stderr); if (crash_on_error) abort(); else @@ -862,13 +862,23 @@ MVM_NO_RETURN void MVM_panic_allocation_failed(size_t len) { * process to indicate that we've made an error */ MVM_NO_RETURN void MVM_oops(MVMThreadContext *tc, const char *messageFormat, ...) { va_list args; - fprintf(stderr, "MoarVM oops: "); + fprintf(stderr, "MoarVM oops%s: ", + !tc ? " with NULL tc" : + (MVMObject *) tc->thread_obj == tc->instance->spesh_thread + ? " in spesh thread" : + (MVMObject *) tc->thread_obj == tc->instance->event_loop_thread + ? " in event loop thread" : ""); va_start(args, messageFormat); vfprintf(stderr, messageFormat, args); va_end(args); - fprintf(stderr, "\n"); + fputc('\n', stderr); + + /* Our caller is seriously buggy if tc is NULL */ + if (!tc) + abort(); + MVM_dump_backtrace(tc); - fprintf(stderr, "\n"); + fputc('\n', stderr); exit(1); } @@ -899,6 +909,23 @@ MVM_NO_RETURN void MVM_exception_throw_adhoc_free(MVMThreadContext *tc, char **w MVM_NO_RETURN void MVM_exception_throw_adhoc_free_va(MVMThreadContext *tc, char **waste, const char *messageFormat, va_list args) { LocatedHandler lh; MVMException *ex; + const char *special = !tc ? " with NULL tc" + : (MVMObject *) tc->thread_obj == tc->instance->spesh_thread ? " in spesh thread" + : (MVMObject *) tc->thread_obj == tc->instance->event_loop_thread ? " in event loop thread" : NULL; + + if (special) { + fprintf(stderr, "MoarVM exception%s treated as oops: ", special); + vfprintf(stderr, messageFormat, args); + va_end(args); + fputc('\n', stderr); + if (!tc) + abort(); + + MVM_dump_backtrace(tc); + fputc('\n', stderr); + exit(1); + } + /* The current frame will be assigned as the thrower of the exception, so * force it onto the heap before we begin. */ if (tc->cur_frame) @@ -942,7 +969,7 @@ MVM_NO_RETURN void MVM_exception_throw_adhoc_free_va(MVMThreadContext *tc, char if (crash_on_error) { /* Yes, abort. */ vfprintf(stderr, messageFormat, args); - fwrite("\n", 1, 1, stderr); + fputc('\n', stderr); MVM_dump_backtrace(tc); abort(); }