Merge pull request #47829 from Calinou/improve-crash-handler-display

Improve crash handler message display
This commit is contained in:
Hugo Locurcio 2021-08-25 08:03:10 +02:00 committed by GitHub
commit 3db8359324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 0 deletions

View File

@ -32,6 +32,8 @@
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "main/main.h" #include "main/main.h"
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
@ -61,12 +63,19 @@ static void handle_crash(int sig) {
} }
// Dump the backtrace to stderr with a message to the user // Dump the backtrace to stderr with a message to the user
fprintf(stderr, "\n================================================================\n");
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
if (OS::get_singleton()->get_main_loop()) { if (OS::get_singleton()->get_main_loop()) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
} }
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).length() != 0) {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
} else {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
}
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data()); fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
char **strings = backtrace_symbols(bt_buffer, size); char **strings = backtrace_symbols(bt_buffer, size);
if (strings) { if (strings) {
@ -115,6 +124,7 @@ static void handle_crash(int sig) {
free(strings); free(strings);
} }
fprintf(stderr, "-- END OF BACKTRACE --\n"); fprintf(stderr, "-- END OF BACKTRACE --\n");
fprintf(stderr, "================================================================\n");
// Abort to pass the error to the OS // Abort to pass the error to the OS
abort(); abort();

View File

@ -32,6 +32,8 @@
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "main/main.h" #include "main/main.h"
#include <string.h> #include <string.h>
@ -85,11 +87,18 @@ static void handle_crash(int sig) {
} }
// Dump the backtrace to stderr with a message to the user // Dump the backtrace to stderr with a message to the user
fprintf(stderr, "\n================================================================\n");
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig); fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
if (OS::get_singleton()->get_main_loop()) if (OS::get_singleton()->get_main_loop())
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH); OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).length() != 0) {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
} else {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
}
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data()); fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
char **strings = backtrace_symbols(bt_buffer, size); char **strings = backtrace_symbols(bt_buffer, size);
if (strings) { if (strings) {
@ -148,6 +157,7 @@ static void handle_crash(int sig) {
free(strings); free(strings);
} }
fprintf(stderr, "-- END OF BACKTRACE --\n"); fprintf(stderr, "-- END OF BACKTRACE --\n");
fprintf(stderr, "================================================================\n");
// Abort to pass the error to the OS // Abort to pass the error to the OS
abort(); abort();

View File

@ -32,6 +32,8 @@
#include "core/config/project_settings.h" #include "core/config/project_settings.h"
#include "core/os/os.h" #include "core/os/os.h"
#include "core/version.h"
#include "core/version_hash.gen.h"
#include "main/main.h" #include "main/main.h"
#ifdef CRASH_HANDLER_EXCEPTION #ifdef CRASH_HANDLER_EXCEPTION
@ -127,6 +129,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
} }
fprintf(stderr, "\n================================================================\n");
fprintf(stderr, "%s: Program crashed\n", __FUNCTION__); fprintf(stderr, "%s: Program crashed\n", __FUNCTION__);
if (OS::get_singleton()->get_main_loop()) if (OS::get_singleton()->get_main_loop())
@ -175,6 +178,12 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
msg = proj_settings->get("debug/settings/crash_handler/message"); msg = proj_settings->get("debug/settings/crash_handler/message");
} }
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(VERSION_HASH).length() != 0) {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
} else {
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
}
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data()); fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
int n = 0; int n = 0;
@ -200,6 +209,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
} while (frame.AddrReturn.Offset != 0 && n < 256); } while (frame.AddrReturn.Offset != 0 && n < 256);
fprintf(stderr, "-- END OF BACKTRACE --\n"); fprintf(stderr, "-- END OF BACKTRACE --\n");
fprintf(stderr, "================================================================\n");
SymCleanup(process); SymCleanup(process);