[*] Improve non-fatal exception handling

This commit is contained in:
Reece Wilson 2023-06-28 04:48:11 +01:00
parent 894df69fe0
commit 3563ece47b
3 changed files with 41 additions and 27 deletions

View File

@ -318,6 +318,10 @@ namespace Aurora
*/
bool bIsExceptionThrowFatal { false };
bool bSaveAllExceptionsAsMinidumpInBg { false };
bool bRaiseDebuggerToAllExceptionsInStageAndDbg { true };
bool bPrintExceptionStackTracesOut { true };
bool bIsApplicationClientSoftwareOnJitteryMemorySystem { false }; // enable me to enable padding from system out of memory conditions.

View File

@ -170,15 +170,28 @@ namespace Aurora::Debug
#if defined(AU_ENABLE_NATIVE_MINIDUMP)
if (!fatal)
{
if (IsDebuggerPresent()) __debugbreak();
else BlackboxReport(pExceptionInfo, false);
if (gRuntimeConfig.debug.bRaiseDebuggerToAllExceptionsInStageAndDbg &&
IsDebuggerPresent())
{
__debugbreak();
}
else
{
if (gRuntimeConfig.debug.bSaveAllExceptionsAsMinidumpInBg)
{
BlackboxReport(pExceptionInfo, false);
}
}
}
else
{
SaveMinidump(pExceptionInfo, true);
}
#else
BlackboxReport(pExceptionInfo, true);
if (fatal)
{
BlackboxReport(pExceptionInfo, true);
}
#endif
}

View File

@ -432,9 +432,10 @@ namespace Aurora::Debug
void BlackboxReport(_EXCEPTION_POINTERS *ExceptionInfo, bool fatal)
{
AuString path;
HANDLE hFile;
std::wstring path;
AuString utf8Path;
bool ok { true };
MINIDUMP_EXCEPTION_INFORMATION info;
if (fatal)
@ -442,11 +443,7 @@ namespace Aurora::Debug
AuDebug::AddMemoryCrunch();
}
auto ok = AuIOFS::GetProfileDomain(path); // < could throw inside
if (!ok)
{
path = ".\\";
}
auto dumpName = GetDumpName();
info.ClientPointers = false;
info.ThreadId = GetCurrentThreadId();
@ -458,23 +455,22 @@ namespace Aurora::Debug
MiniDumpWithUnloadedModules |
MiniDumpWithThreadInfo;
while (path.empty())
{
try
{
utf8Path = AuIOFS::NormalizePathRet("./Logs/Crashes/" + dumpName);
path = Locale::ConvertFromUTF8(utf8Path);
}
catch (...)
{
static std::wstring pathStorage(8192, L' ');
int index {};
index += MultiByteToWideChar(CP_UTF8, 0, path.c_str(), path.length(), pathStorage.data() + index, pathStorage.size() - index);
static const std::string crashesSlash = "Crashes\\";
index += MultiByteToWideChar(CP_UTF8, 0, crashesSlash.c_str(), crashesSlash.length(), pathStorage.data() + index, pathStorage.size() - index);
auto dumpName = GetDumpName();;
index += MultiByteToWideChar(CP_UTF8, 0, dumpName.c_str(), dumpName.length(), pathStorage.data() + index, pathStorage.size() - index);
pathStorage.resize(index);
}
}
AuIOFS::CreateDirectories(utf8Path, true); // potentially unsafe / could throw inside
hFile = CreateFileW(pathStorage.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
hFile = CreateFileW(path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile != INVALID_HANDLE_VALUE)
{
AuLogWarn("[1] Couldn't open minidump file. Has a debugger locked the .dmp file?");
@ -491,14 +487,15 @@ namespace Aurora::Debug
CloseHandle(hFile);
miniMiniDumpOut:
Telemetry::NewBlackBoxEntryMinidump report {};
report.includesRx = false;
report.resource.path = dumpName; // <COPY
report.resource.type = Telemetry::ENewBlackBoxResourceType::eLocal;
Telemetry::ReportDyingBreath(report);
if (fatal)
{
Telemetry::NewBlackBoxEntryMinidump report {};
report.includesRx = false;
report.resource.path = dumpName;
report.resource.type = Telemetry::ENewBlackBoxResourceType::eLocal;
Telemetry::ReportDyingBreath(report);
__fastfail('fokd');
}
}