Skip to content

Commit

Permalink
Merge pull request #1390 from MoarVM/exception-in-spesh-should-oops
Browse files Browse the repository at this point in the history
Exceptions in spesh should oops
  • Loading branch information
jnthn committed Nov 27, 2020
2 parents bfce053 + fa9b665 commit f3e9e35
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions src/core/exceptions.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit f3e9e35

Please sign in to comment.