Skip to content

Improve script backtrace print in crash handlers #106139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
16 changes: 6 additions & 10 deletions platform/linuxbsd/crash_handler_linuxbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,8 @@ static void handle_crash(int sig) {
String _execpath = OS::get_singleton()->get_executable_path();

String msg;
const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
if (proj_settings) {
msg = proj_settings->get("debug/settings/crash_handler/message");
if (ProjectSettings::get_singleton()) {
msg = GLOBAL_GET("debug/settings/crash_handler/message");
}

// Tell MainLoop about the crash. This can be handled by users too in Node.
Expand Down Expand Up @@ -144,21 +143,18 @@ static void handle_crash(int sig) {

free(strings);
}
print_error("-- END OF BACKTRACE --");
print_error("-- END OF C++ BACKTRACE --");
print_error("================================================================");

Vector<Ref<ScriptBacktrace>> script_backtraces;
if (ScriptServer::are_languages_initialized()) {
script_backtraces = ScriptServer::capture_script_backtraces(false);
}
if (!script_backtraces.is_empty()) {
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
if (!backtrace->is_empty()) {
print_error(backtrace->format());
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
print_error("================================================================");
}
}
print_error("-- END OF SCRIPT BACKTRACE --");
print_error("================================================================");
}

// Abort to pass the error to the OS
Expand Down
16 changes: 6 additions & 10 deletions platform/macos/crash_handler_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ static void handle_crash(int sig) {
String _execpath = OS::get_singleton()->get_executable_path();

String msg;
const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
if (proj_settings) {
msg = proj_settings->get("debug/settings/crash_handler/message");
if (ProjectSettings::get_singleton()) {
msg = GLOBAL_GET("debug/settings/crash_handler/message");
}

// Tell MainLoop about the crash. This can be handled by users too in Node.
Expand Down Expand Up @@ -174,21 +173,18 @@ static void handle_crash(int sig) {

free(strings);
}
print_error("-- END OF BACKTRACE --");
print_error("-- END OF C++ BACKTRACE --");
print_error("================================================================");

Vector<Ref<ScriptBacktrace>> script_backtraces;
if (ScriptServer::are_languages_initialized()) {
script_backtraces = ScriptServer::capture_script_backtraces(false);
}
if (!script_backtraces.is_empty()) {
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
if (!backtrace->is_empty()) {
print_error(backtrace->format());
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
print_error("================================================================");
}
}
print_error("-- END OF SCRIPT BACKTRACE --");
print_error("================================================================");
}

// Abort to pass the error to the OS
Expand Down
16 changes: 6 additions & 10 deletions platform/windows/crash_handler_windows_seh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,8 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
}

String msg;
const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
if (proj_settings) {
msg = proj_settings->get("debug/settings/crash_handler/message");
if (ProjectSettings::get_singleton()) {
msg = GLOBAL_GET("debug/settings/crash_handler/message");
}

// Tell MainLoop about the crash. This can be handled by users too in Node.
Expand Down Expand Up @@ -226,23 +225,20 @@ DWORD CrashHandlerException(EXCEPTION_POINTERS *ep) {
}
} while (frame.AddrReturn.Offset != 0 && n < 256);

print_error("-- END OF BACKTRACE --");
print_error("-- END OF C++ BACKTRACE --");
print_error("================================================================");

SymCleanup(process);

Vector<Ref<ScriptBacktrace>> script_backtraces;
if (ScriptServer::are_languages_initialized()) {
script_backtraces = ScriptServer::capture_script_backtraces(false);
}
if (!script_backtraces.is_empty()) {
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
if (!backtrace->is_empty()) {
print_error(backtrace->format());
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
print_error("================================================================");
}
}
print_error("-- END OF SCRIPT BACKTRACE --");
print_error("================================================================");
}

// Pass the exception to the OS
Expand Down
16 changes: 6 additions & 10 deletions platform/windows/crash_handler_windows_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,8 @@ extern void CrashHandlerException(int signal) {
}

String msg;
const ProjectSettings *proj_settings = ProjectSettings::get_singleton();
if (proj_settings) {
msg = proj_settings->get("debug/settings/crash_handler/message");
if (ProjectSettings::get_singleton()) {
msg = GLOBAL_GET("debug/settings/crash_handler/message");
}

// Tell MainLoop about the crash. This can be handled by users too in Node.
Expand Down Expand Up @@ -182,21 +181,18 @@ extern void CrashHandlerException(int signal) {
backtrace_simple(data.state, 1, &trace_callback, &error_callback, reinterpret_cast<void *>(&data));
}

print_error("-- END OF BACKTRACE --");
print_error("-- END OF C++ BACKTRACE --");
print_error("================================================================");

Vector<Ref<ScriptBacktrace>> script_backtraces;
if (ScriptServer::are_languages_initialized()) {
script_backtraces = ScriptServer::capture_script_backtraces(false);
}
if (!script_backtraces.is_empty()) {
Vector<Ref<ScriptBacktrace>> script_backtraces = ScriptServer::capture_script_backtraces(false);
for (const Ref<ScriptBacktrace> &backtrace : script_backtraces) {
if (!backtrace->is_empty()) {
print_error(backtrace->format());
print_error(vformat("-- END OF %s BACKTRACE --", backtrace->get_language_name().to_upper()));
print_error("================================================================");
}
}
print_error("-- END OF SCRIPT BACKTRACE --");
print_error("================================================================");
}
}
#endif
Expand Down