Skip to content

Commit 3db8359

Browse files
authored
Merge pull request #47829 from Calinou/improve-crash-handler-display
Improve crash handler message display
2 parents 24f562b + 8556dd1 commit 3db8359

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

platform/linuxbsd/crash_handler_linuxbsd.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "core/config/project_settings.h"
3434
#include "core/os/os.h"
35+
#include "core/version.h"
36+
#include "core/version_hash.gen.h"
3537
#include "main/main.h"
3638

3739
#ifdef DEBUG_ENABLED
@@ -61,12 +63,19 @@ static void handle_crash(int sig) {
6163
}
6264

6365
// Dump the backtrace to stderr with a message to the user
66+
fprintf(stderr, "\n================================================================\n");
6467
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
6568

6669
if (OS::get_singleton()->get_main_loop()) {
6770
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
6871
}
6972

73+
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
74+
if (String(VERSION_HASH).length() != 0) {
75+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
76+
} else {
77+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
78+
}
7079
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
7180
char **strings = backtrace_symbols(bt_buffer, size);
7281
if (strings) {
@@ -115,6 +124,7 @@ static void handle_crash(int sig) {
115124
free(strings);
116125
}
117126
fprintf(stderr, "-- END OF BACKTRACE --\n");
127+
fprintf(stderr, "================================================================\n");
118128

119129
// Abort to pass the error to the OS
120130
abort();

platform/osx/crash_handler_osx.mm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "core/config/project_settings.h"
3434
#include "core/os/os.h"
35+
#include "core/version.h"
36+
#include "core/version_hash.gen.h"
3537
#include "main/main.h"
3638

3739
#include <string.h>
@@ -85,11 +87,18 @@ static void handle_crash(int sig) {
8587
}
8688

8789
// Dump the backtrace to stderr with a message to the user
90+
fprintf(stderr, "\n================================================================\n");
8891
fprintf(stderr, "%s: Program crashed with signal %d\n", __FUNCTION__, sig);
8992

9093
if (OS::get_singleton()->get_main_loop())
9194
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
9295

96+
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
97+
if (String(VERSION_HASH).length() != 0) {
98+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
99+
} else {
100+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
101+
}
93102
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
94103
char **strings = backtrace_symbols(bt_buffer, size);
95104
if (strings) {
@@ -148,6 +157,7 @@ static void handle_crash(int sig) {
148157
free(strings);
149158
}
150159
fprintf(stderr, "-- END OF BACKTRACE --\n");
160+
fprintf(stderr, "================================================================\n");
151161

152162
// Abort to pass the error to the OS
153163
abort();

platform/windows/crash_handler_windows.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#include "core/config/project_settings.h"
3434
#include "core/os/os.h"
35+
#include "core/version.h"
36+
#include "core/version_hash.gen.h"
3537
#include "main/main.h"
3638

3739
#ifdef CRASH_HANDLER_EXCEPTION
@@ -127,6 +129,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
127129
return EXCEPTION_CONTINUE_SEARCH;
128130
}
129131

132+
fprintf(stderr, "\n================================================================\n");
130133
fprintf(stderr, "%s: Program crashed\n", __FUNCTION__);
131134

132135
if (OS::get_singleton()->get_main_loop())
@@ -175,6 +178,12 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
175178
msg = proj_settings->get("debug/settings/crash_handler/message");
176179
}
177180

181+
// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
182+
if (String(VERSION_HASH).length() != 0) {
183+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME " (" VERSION_HASH ")\n");
184+
} else {
185+
fprintf(stderr, "Engine version: " VERSION_FULL_NAME "\n");
186+
}
178187
fprintf(stderr, "Dumping the backtrace. %s\n", msg.utf8().get_data());
179188

180189
int n = 0;
@@ -200,6 +209,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
200209
} while (frame.AddrReturn.Offset != 0 && n < 256);
201210

202211
fprintf(stderr, "-- END OF BACKTRACE --\n");
212+
fprintf(stderr, "================================================================\n");
203213

204214
SymCleanup(process);
205215

0 commit comments

Comments
 (0)