From b3ed716e948e511112d83aeb7e36bbad64ada82f Mon Sep 17 00:00:00 2001 From: Reece Date: Fri, 31 Mar 2023 04:24:19 +0100 Subject: [PATCH] [*] fix minidump writing --- Source/Debug/ExceptionWatcher.NT.cpp | 10 ++++++++-- Source/Debug/ExceptionWatcher.Win32.cpp | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/Debug/ExceptionWatcher.NT.cpp b/Source/Debug/ExceptionWatcher.NT.cpp index 1626760c..bae12978 100644 --- a/Source/Debug/ExceptionWatcher.NT.cpp +++ b/Source/Debug/ExceptionWatcher.NT.cpp @@ -181,8 +181,11 @@ namespace Aurora::Debug static bool forceFail {false}; _EXCEPTION_POINTERS ptrs; StackTrace ret; - CONTEXT ctx; + CONTEXT ctx {}; + EXCEPTION_RECORD ex {}; + ctx.ContextFlags = CONTEXT_ALL; + if (!GetThreadContext(GetCurrentThread(), &ctx)) { Debug::Panic(); @@ -193,8 +196,11 @@ namespace Aurora::Debug Exit::PostLevel(AuThreads::GetThread(), Aurora::Exit::ETriggerLevel::eFatalException); } - ptrs.ExceptionRecord = {}; + ex.ExceptionCode = 0x1337; + + ptrs.ExceptionRecord = &ex; ptrs.ContextRecord = &ctx; + HandleFatal(fatal, &ptrs); } diff --git a/Source/Debug/ExceptionWatcher.Win32.cpp b/Source/Debug/ExceptionWatcher.Win32.cpp index fec253cb..ee36fdd4 100644 --- a/Source/Debug/ExceptionWatcher.Win32.cpp +++ b/Source/Debug/ExceptionWatcher.Win32.cpp @@ -277,10 +277,10 @@ namespace Aurora::Debug void SaveMinidump(_EXCEPTION_POINTERS *ExceptionInfo, bool isFatal) { bool ok {}; - MINIDUMP_EXCEPTION_INFORMATION info; + MINIDUMP_EXCEPTION_INFORMATION info {}; info.ThreadId = GetCurrentThreadId(); - info.ClientPointers = ExceptionInfo != nullptr; + info.ClientPointers = false; info.ExceptionPointers = ExceptionInfo; static const DWORD flags = MiniDumpWithFullMemory | @@ -316,7 +316,7 @@ namespace Aurora::Debug ok = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, (MINIDUMP_TYPE)flags, &info, nullptr, nullptr); if (!ok) { - AuLogWarn("Couldn't write minidump"); + AuLogWarn("Couldn't write minidump: {:x}", GetLastError()); goto miniDumpOut; } @@ -334,6 +334,16 @@ namespace Aurora::Debug if (isFatal) { + try + { + Grug::GrugFlushFlushs(); + Grug::GrugFlushWrites(); + } + catch (...) + { + + } + __fastfail('fokd'); } } @@ -346,13 +356,18 @@ namespace Aurora::Debug AuString utf8Path; MINIDUMP_EXCEPTION_INFORMATION info; + if (fatal) + { + AuDebug::AddMemoryCrunch(); + } + auto ok = AuIOFS::GetProfileDomain(path); // < could throw inside if (!ok) { path = ".\\"; } - info.ClientPointers = true; + info.ClientPointers = false; info.ThreadId = GetCurrentThreadId(); info.ExceptionPointers = ExceptionInfo; @@ -388,7 +403,7 @@ namespace Aurora::Debug ok = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, (MINIDUMP_TYPE)flags, &info, nullptr, nullptr); if (!ok) { - AuLogWarn("Couldn't write minidump"); + AuLogWarn("Couldn't write minidump: {:x}", GetLastError()); goto miniMiniDumpOut; }