From 777229f28f8f5de19376459e85b434576af8e010 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Fri, 31 Jul 2020 09:56:19 -0400 Subject: added startSafeThread() to get core dumps for threads other than the main thread added terminate handler --- src/main.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 46f2f0aa..f008896b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -127,9 +127,9 @@ bool bootstrap() return true; } -LPTOP_LEVEL_EXCEPTION_FILTER prevUnhandledExceptionFilter = nullptr; +thread_local LPTOP_LEVEL_EXCEPTION_FILTER prevUnhandledExceptionFilter = nullptr; -static LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *exceptionPtrs) +LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *exceptionPtrs) { const std::wstring& dumpPath = OrganizerCore::crashDumpsPath(); int dumpRes = @@ -139,12 +139,33 @@ static LONG WINAPI MyUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *except else log::error("ModOrganizer has crashed, CreateMiniDump failed ({}, error {}).", dumpRes, GetLastError()); - if (prevUnhandledExceptionFilter) + if (prevUnhandledExceptionFilter && exceptionPtrs) return prevUnhandledExceptionFilter(exceptionPtrs); else return EXCEPTION_CONTINUE_SEARCH; } +void terminateHandler() noexcept +{ + __try + { + // force an exception to get a valid stack trace for this thread + *(int*)0 = 42; + } + __except + ( + MyUnhandledExceptionFilter(GetExceptionInformation()), EXCEPTION_EXECUTE_HANDLER + ) + { + } +} + +void setUnhandledExceptionHandler() +{ + prevUnhandledExceptionFilter = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter); + std::set_terminate(terminateHandler); +} + // Parses the first parseArgCount arguments of the current process command line and returns // them in parsedArgs, the rest of the command line is returned untouched. LPCWSTR UntouchedCommandLineArguments(int parseArgCount, std::vector& parsedArgs) @@ -171,6 +192,7 @@ LPCWSTR UntouchedCommandLineArguments(int parseArgCount, std::vectorproperty("dataPath").toString() + "/logs/mo_interface.log"; -- cgit v1.3.1