sys: Improved exception debug output

This commit is contained in:
WerWolv 2023-01-16 18:17:13 +01:00
parent e078d810de
commit 7e17059154
2 changed files with 16 additions and 5 deletions

View File

@ -41,7 +41,7 @@ macro(addVersionDefines)
set(IMHEX_VERSION_STRING ${IMHEX_VERSION_STRING})
elseif (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION_STRING}-Debug)
add_compile_definitions(DEBUG _GLIBCXX_DEBUG)
add_compile_definitions(DEBUG _GLIBCXX_DEBUG _GLIBCXX_VERBOSE)
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(IMHEX_VERSION_STRING ${IMHEX_VERSION_STRING}-RelWithDebInfo)
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")

View File

@ -9,11 +9,11 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <fmt/printf.h>
#include <llvm/Demangle/Demangle.h>
#include <chrono>
#include <csignal>
#include <iostream>
#include <set>
#include <thread>
#include <cassert>
@ -82,7 +82,7 @@ namespace hex {
std::signal(signalNumber, nullptr);
#if defined(DEBUG)
assert(false);
assert(!"Debug build, triggering breakpoint");
#else
std::raise(signalNumber);
#endif
@ -170,7 +170,18 @@ namespace hex {
HANDLE_SIGNAL(SIGABRT)
HANDLE_SIGNAL(SIGFPE)
#undef HANDLE_SIGNAL
std::set_terminate([]{ signalHandler(SIGABRT, "Unhandled C++ exception"); });
std::set_terminate([]{
try {
std::rethrow_exception(std::current_exception());
} catch (std::exception &ex) {
log::fatal(
"Program terminated with uncaught exception: {}()::what() -> {}",
llvm::itaniumDemangle(typeid(ex).name(), nullptr, nullptr, nullptr),
ex.what()
);
}
EventManager::post<EventAbnormalTermination>(0);
});
auto logoData = romfs::get("logo.png");
this->m_logoTexture = ImGui::Texture(reinterpret_cast<const ImU8 *>(logoData.data()), logoData.size());