From 53ba38e98d3b64f19e7c1bb7f01f712131b6feac Mon Sep 17 00:00:00 2001 From: Eladash Date: Mon, 4 Sep 2023 19:30:23 +0300 Subject: [PATCH] Thread.cpp: Flush log and make thread context dump on exception --- Utilities/Thread.cpp | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Utilities/Thread.cpp b/Utilities/Thread.cpp index f8b13425c6..c0c3598d29 100644 --- a/Utilities/Thread.cpp +++ b/Utilities/Thread.cpp @@ -1745,6 +1745,28 @@ static LONG exception_handler(PEXCEPTION_POINTERS pExp) noexcept } } + switch (pExp->ExceptionRecord->ExceptionCode) + { + case EXCEPTION_ACCESS_VIOLATION: + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + case EXCEPTION_DATATYPE_MISALIGNMENT: + case EXCEPTION_ILLEGAL_INSTRUCTION: + case EXCEPTION_IN_PAGE_ERROR: + case EXCEPTION_INT_DIVIDE_BY_ZERO: + case EXCEPTION_NONCONTINUABLE_EXCEPTION: + case EXCEPTION_PRIV_INSTRUCTION: + //case EXCEPTION_STACK_OVERFLOW: + { + sys_log.notice("\n%s", dump_useful_thread_info()); + logs::listener::sync_all(); + break; + } + default: + { + break; + } + } + return EXCEPTION_CONTINUE_SEARCH; } @@ -1827,6 +1849,9 @@ static LONG exception_filter(PEXCEPTION_POINTERS pExp) noexcept // TODO: print registers and the callstack + sys_log.fatal("\n%s", msg); + logs::listener::sync_all(); + thread_ctrl::emergency_exit(msg); } @@ -1912,12 +1937,12 @@ static void signal_handler(int /*sig*/, siginfo_t* info, void* uct) noexcept append_thread_name(msg); + sys_log.fatal("\n%s", msg); + sys_log.notice("\n%s", dump_useful_thread_info()); + logs::listener::sync_all(); + if (IsDebuggerPresent()) { - sys_log.fatal("\n%s", msg); - - sys_log.notice("\n%s", dump_useful_thread_info()); - // Convert to SIGTRAP raise(SIGTRAP); return; @@ -1932,12 +1957,12 @@ static void sigill_handler(int /*sig*/, siginfo_t* info, void* /*uct*/) noexcept append_thread_name(msg); + sys_log.fatal("\n%s", msg); + sys_log.notice("\n%s", dump_useful_thread_info()); + logs::listener::sync_all(); + if (IsDebuggerPresent()) { - sys_log.fatal("\n%s", msg); - - sys_log.notice("\n%s", dump_useful_thread_info()); - // Convert to SIGTRAP raise(SIGTRAP); return;