impr: Unionize exception and assertion handling

(cherry picked from commit cfac7ff0ba)
This commit is contained in:
WerWolv
2025-12-15 09:52:13 +01:00
parent f6b2251205
commit 81826df897
10 changed files with 84 additions and 37 deletions

View File

@@ -1,4 +1,6 @@
#include <hex/helpers/debugging.hpp>
#include <hex/helpers/logger.hpp>
#include <hex/trace/stacktrace.hpp>
namespace hex::dbg {
@@ -21,4 +23,23 @@ namespace hex::dbg {
s_debugMode = enabled;
}
[[noreturn]] void assertionHandler(const char* file, int line, const char *function, const char* exprString) {
log::error("Assertion failed: {} at {}:{} => {}", exprString, file, line, function);
const auto stackTrace = trace::getStackTrace();
dbg::printStackTrace(stackTrace);
std::abort();
}
void printStackTrace(const trace::StackTraceResult &stackTrace) {
log::fatal("Printing stacktrace using implementation '{}'", stackTrace.implementationName);
for (const auto &stackFrame : stackTrace.stackFrames) {
if (stackFrame.line == 0)
log::fatal(" ({}) | {}", stackFrame.file, stackFrame.function);
else
log::fatal(" ({}:{}) | {}", stackFrame.file, stackFrame.line, stackFrame.function);
}
}
}