From a3b76cd5c28da98c081e085a4e384bd1d3c340c1 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Thu, 2 Jan 2025 08:32:18 -0500 Subject: [PATCH] core: Let's try getting crash callstacks on win32 with a vectored exception handler. --- src/main.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.c b/src/main.c index bee69ff0..ad331d47 100644 --- a/src/main.c +++ b/src/main.c @@ -1008,6 +1008,23 @@ static void _error_handler(int sig) _exit(1); } +#if defined(_WIN32) +static LONG WINAPI _win32_exception_handler(EXCEPTION_POINTERS* info) +{ + if (info->ExceptionRecord->ExceptionCode == STATUS_ACCESS_VIOLATION || + info->ExceptionRecord->ExceptionCode == STATUS_ILLEGAL_INSTRUCTION || + info->ExceptionRecord->ExceptionCode == STATUS_STACK_OVERFLOW || + info->ExceptionRecord->ExceptionCode == STATUS_HEAP_CORRUPTION) + { + const char* stack = tf_util_backtrace_string(); + tf_printf("ERROR:\n%s\n", stack); + tf_free((void*)stack); + _exit(1); + } + return EXCEPTION_CONTINUE_SEARCH; +} +#endif + static void _startup(int argc, char* argv[]) { char buffer[8] = { 0 }; @@ -1055,6 +1072,10 @@ static void _startup(int argc, char* argv[]) perror("signal"); } } + +#if defined(_WIN32) + AddVectoredExceptionHandler(0, _win32_exception_handler); +#endif } #if defined(__ANDROID__)