Skip to content

Commit

Permalink
Display human-readable descriptions for signal types in crash handlers
Browse files Browse the repository at this point in the history
Previously, only the signal number was displayed:

    handle_crash: Program crashed with signal 4

Now, the signal code and description are shown:

    handle_crash: Program crashed with signal 4 (SIGILL) - Illegal instruction

This only affects Linux and macOS, not Windows.
  • Loading branch information
Calinou committed May 20, 2023
1 parent 809a982 commit 9b3f13d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
23 changes: 22 additions & 1 deletion platform/linuxbsd/crash_handler_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,28 @@ static void handle_crash(int sig) {

// Dump the backtrace to stderr with a message to the user
print_error("\n================================================================");
print_error(vformat("%s: Program crashed with signal %d", __FUNCTION__, sig));
String signal_description;
switch (sig) {
case SIGTERM:
signal_description = "(SIGTERM) - Terminated";
break;
case SIGSEGV:
signal_description = "(SIGSEGV) - Segmentation fault";
break;
case SIGINT:
signal_description = "(SIGINT) - Interrupt";
break;
case SIGILL:
signal_description = "(SIGILL) - Illegal instruction";
break;
case SIGABRT:
signal_description = "(SIGABRT) - Abnormal termination condition";
break;
case SIGFPE:
signal_description = "(SIGFPE) - Floating-point exception";
break;
}
print_error(vformat("%s: Program crashed with signal %d %s", __FUNCTION__, sig, signal_description));

// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).is_empty()) {
Expand Down
23 changes: 22 additions & 1 deletion platform/macos/crash_handler_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,28 @@ static void handle_crash(int sig) {

// Dump the backtrace to stderr with a message to the user
print_error("\n================================================================");
print_error(vformat("%s: Program crashed with signal %d", __FUNCTION__, sig));
String signal_description;
switch (sig) {
case SIGTERM:
signal_description = "(SIGTERM) - Terminated";
break;
case SIGSEGV:
signal_description = "(SIGSEGV) - Segmentation fault";
break;
case SIGINT:
signal_description = "(SIGINT) - Interrupt";
break;
case SIGILL:
signal_description = "(SIGILL) - Illegal instruction";
break;
case SIGABRT:
signal_description = "(SIGABRT) - Abnormal termination condition";
break;
case SIGFPE:
signal_description = "(SIGFPE) - Floating-point exception";
break;
}
print_error(vformat("%s: Program crashed with signal %d %s", __FUNCTION__, sig, signal_description));

// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).is_empty()) {
Expand Down

0 comments on commit 9b3f13d

Please sign in to comment.