From 3fae3df69422be8a7f60bace6e40c2106a93e98a Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Sun, 11 May 2025 15:25:07 +0200 Subject: [PATCH] linux: improve crash handling (#1103) linux: improve crash log and crash handling * add device info to crash log * add contents of backlog to the crash log * use abort() instead of exit() calling exit could cause problems because of exithandlers, abort is safer. --- Editor/main_SDL2.cpp | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/Editor/main_SDL2.cpp b/Editor/main_SDL2.cpp index 3eb7e2286..05e59951b 100644 --- a/Editor/main_SDL2.cpp +++ b/Editor/main_SDL2.cpp @@ -15,7 +15,19 @@ using namespace std; -Editor editor; +class EditorWithDevInfo : public Editor +{ +public: + const char* GetAdapterName() const + { + return graphicsDevice == nullptr ? "(no device)" : graphicsDevice->GetAdapterName().c_str(); + } + + const char* GetDriverDescription() const + { + return graphicsDevice == nullptr ? "(no device)" : graphicsDevice->GetDriverDescription().c_str(); + } +} editor; int sdl_loop() { @@ -107,18 +119,29 @@ void set_window_icon(SDL_Window *window) { void crash_handler(int sig) { + static bool already_handled = false; + void* btbuf[100]; - char outbuf[256]; + char outbuf[512]; + + if (already_handled) return; + + already_handled = true; size_t size = backtrace(btbuf, 100); + snprintf( outbuf, sizeof(outbuf), "Signal: %i (%s)\n" - "Version: %s\nStacktrace:\n", - sig, - sigdescr_np(sig), - wi::version::GetVersionString() + "Version: %s\n" + "Adapter: %s\n" + "Driver: %s\n" + "Stacktrace:\n", + sig, sigdescr_np(sig), + wi::version::GetVersionString(), + editor.GetAdapterName(), + editor.GetDriverDescription() ); fprintf( @@ -144,11 +167,14 @@ void crash_handler(int sig) fputs(outbuf, logfile); fflush(logfile); backtrace_symbols_fd(btbuf, size, fileno(logfile)); + fputs("\nBacklog:\n", logfile); + fflush(logfile); + fputs(wi::backlog::getText().c_str(), logfile); fclose(logfile); char cwdbuf[200]; fprintf(stderr, "\e[1mcrash log written to %s/%s\e[m\n", getcwd(cwdbuf, sizeof(cwdbuf)), filename); } - exit(1); + abort(); } #endif