mirror of https://github.com/WerWolv/ImHex
impr: Only add stacktrace to exceptions thrown in main thread
This commit is contained in:
parent
5c890e710e
commit
ed32439645
|
|
@ -7,5 +7,6 @@
|
|||
namespace hex::trace {
|
||||
|
||||
std::optional<StackTraceResult> getLastExceptionStackTrace();
|
||||
void enableExceptionCaptureForCurrentThread();
|
||||
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
namespace hex::trace {
|
||||
|
||||
static std::optional<StackTraceResult> s_lastExceptionStackTrace;
|
||||
static thread_local bool s_threadExceptionCaptureEnabled = false;
|
||||
|
||||
std::optional<StackTraceResult> getLastExceptionStackTrace() {
|
||||
if (!s_lastExceptionStackTrace.has_value())
|
||||
return std::nullopt;
|
||||
|
|
@ -13,6 +15,10 @@ namespace hex::trace {
|
|||
return result;
|
||||
}
|
||||
|
||||
void enableExceptionCaptureForCurrentThread() {
|
||||
s_threadExceptionCaptureEnabled = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#if defined(HEX_WRAP_CXA_THROW)
|
||||
|
|
@ -21,7 +27,9 @@ namespace hex::trace {
|
|||
|
||||
[[noreturn]] void __real___cxa_throw(void* thrownException, void* type, void (*destructor)(void*));
|
||||
[[noreturn]] void __wrap___cxa_throw(void* thrownException, void* type, void (*destructor)(void*)) {
|
||||
hex::trace::s_lastExceptionStackTrace = hex::trace::getStackTrace();
|
||||
if (hex::trace::s_threadExceptionCaptureEnabled)
|
||||
hex::trace::s_lastExceptionStackTrace = hex::trace::getStackTrace();
|
||||
|
||||
__real___cxa_throw(thrownException, type, destructor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <hex/api/task_manager.hpp>
|
||||
#include <hex/api/plugin_manager.hpp>
|
||||
#include <hex/helpers/utils.hpp>
|
||||
#include <hex/trace/exceptions.hpp>
|
||||
|
||||
namespace hex::init {
|
||||
|
||||
|
|
@ -41,17 +42,21 @@ int main(int argc, char **argv) {
|
|||
// Setup crash handlers right away to catch crashes as early as possible
|
||||
crash::setupCrashHandlers();
|
||||
|
||||
// Enable exception tracing on the main thread
|
||||
trace::enableExceptionCaptureForCurrentThread();
|
||||
|
||||
// Run platform-specific initialization code
|
||||
Window::initNative();
|
||||
|
||||
// Setup messaging system to allow sending commands to the main ImHex instance
|
||||
hex::messaging::setupMessaging();
|
||||
messaging::setupMessaging();
|
||||
|
||||
// Handle command line arguments if any have been passed
|
||||
if (argc > 1) {
|
||||
init::runCommandLine(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
// Log some system information to aid debugging when users share their logs
|
||||
log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion().get());
|
||||
log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash());
|
||||
|
|
|
|||
Loading…
Reference in New Issue