Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions platform/linuxbsd/crash_handler_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <dlfcn.h>
#include <execinfo.h>
#include <link.h>
#include <unistd.h>
#include <csignal>
#include <cstdlib>

Expand Down Expand Up @@ -77,9 +78,13 @@ static void handle_crash(int sig) {
OS::get_singleton()->get_main_loop()->notification(MainLoop::NOTIFICATION_CRASH);
}

// Dump the backtrace to stderr with a message to the user
// 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));
if (OS::get_singleton()->get_stderr_type() == OS::STD_HANDLE_CONSOLE) {
print_error(vformat("\x1b[1;91m%s: Program crashed with signal %d.\x1b[0m", __FUNCTION__, sig));
} else {
print_error(vformat("%s: Program crashed with signal %d.", __FUNCTION__, sig));
}

// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(GODOT_VERSION_HASH).is_empty()) {
Expand Down Expand Up @@ -138,8 +143,14 @@ static void handle_crash(int sig) {
}
}

// Simplify printed file paths to remove redundant `/./` sections (e.g. `/opt/godot/./core` -> `/opt/godot/core`).
print_error(vformat("[%d] %s (%s)", (int64_t)i, fname, err == OK ? addr2line_results[i].replace("/./", "/") : ""));
if (OS::get_singleton()->get_stderr_type() == OS::STD_HANDLE_CONSOLE) {
// Print colors using ANSI escape codes for easier visual grepping.
// Simplify printed file paths to remove redundant `/./` sections (e.g. `/opt/godot/./core` -> `/opt/godot/core`).
print_error(vformat("\x1b[94m[%d] \x1b[96m%s \x1b[90m(%s)\x1b[0m", (int64_t)i, fname, err == OK ? addr2line_results[i].replace("/./", "/") : ""));
} else {
// Not a TTY (could be writing to a file). Don't use ANSI escape codes.
print_error(vformat("[%d] %s (%s)", (int64_t)i, fname, err == OK ? addr2line_results[i].replace("/./", "/") : ""));
}
}

free(strings);
Expand Down
15 changes: 13 additions & 2 deletions platform/macos/crash_handler_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <execinfo.h>
#include <csignal>
#include <cstdlib>
#include <unistd>

Check failure on line 53 in platform/macos/crash_handler_macos.mm

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor)

'unistd' file not found

#import <mach-o/dyld.h>
#import <mach-o/getsect.h>
Expand Down Expand Up @@ -100,7 +101,11 @@

// 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));
if (OS::get_singleton()->get_stderr_type() == OS::STD_HANDLE_CONSOLE) {
print_error(vformat("\x1b[1;91m%s: Program crashed with signal %d.\x1b[0m", __FUNCTION__, sig));
} else {
print_error(vformat("%s: Program crashed with signal %d.", __FUNCTION__, sig));
}

// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(GODOT_VERSION_HASH).is_empty()) {
Expand Down Expand Up @@ -174,7 +179,13 @@
output = fname;
}

print_error(vformat("[%d] %s", (int64_t)i, output));
if (OS::get_singleton()->get_stderr_type() == OS::STD_HANDLE_CONSOLE) {
// Print colors using ANSI escape codes for easier visual grepping.
print_error(vformat("\x1b[94m[%d] \x1b[96m%s\x1b[0m", uint64_t(i), output.utf8().ptr()));
} else {
// Not a TTY (could be writing to a file). Don't use ANSI escape codes.
print_error(vformat("[%d] %s", uint64_t(i), output.utf8().ptr()));
}
}

if (strings) {
Expand Down
8 changes: 4 additions & 4 deletions platform/windows/crash_handler_windows_seh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
}

print_error("\n================================================================");
print_error(vformat("%s: Program crashed", __FUNCTION__));
print_error(vformat("\x1b[1;91m%s: Program crashed.\x1b[0m", __FUNCTION__));

// Print the engine version just before, so that people are reminded to include the version in backtrace reports.
if (String(GODOT_VERSION_HASH).is_empty()) {
Expand Down Expand Up @@ -210,12 +210,12 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
std::string fnName = symbol(process, frame.AddrPC.Offset).undecorated_name();

if (SymGetLineFromAddr64(process, frame.AddrPC.Offset, &offset_from_symbol, &line)) {
print_error(vformat("[%d] %s (%s:%d)", n, fnName.c_str(), (char *)line.FileName, (int)line.LineNumber));
print_error(vformat("\x1b[94m[%d] \x1b[96m%s \x1b[90m(%s:%d)\x1b[0m", n, fnName.c_str(), line.FileName, uint32_t(line.LineNumber)));
} else {
print_error(vformat("[%d] %s", n, fnName.c_str()));
print_error(vformat("\x1b[94m[%d] \x1b[96m%s\x1b[0m", n, fnName.c_str()));
}
} else {
print_error(vformat("[%d] ???", n));
print_error(vformat("\x1b[94m[%d] \x1b[96m???\x1b[0m", n));
}

n++;
Expand Down
Loading