[*] Win32: improve reporting of critical exceptions

This commit is contained in:
Reece Wilson 2023-06-24 21:21:00 +01:00
parent 752d67c0ff
commit a7730ed8ee
2 changed files with 57 additions and 53 deletions

View File

@ -45,66 +45,72 @@ namespace Aurora::Debug
{
AuString message;
if (handle != INVALID_HANDLE_VALUE)
if (throwInfo)
{
try
if (handle != INVALID_HANDLE_VALUE)
{
const ThrowInfo *pthrowInfo = reinterpret_cast<const ThrowInfo *>(throwInfo);
auto attribs = pthrowInfo->attributes;
const auto catchableTypeArray = reinterpret_cast<const CatchableTypeArray *>(reinterpret_cast<AuUInt>(handle) + (AuUInt)(pthrowInfo->pCatchableTypeArray));
AuString suffix;
for (int i = 0; i < catchableTypeArray->nCatchableTypes; i++)
try
{
const auto type = reinterpret_cast<CatchableType *> (reinterpret_cast<AuUInt>(handle) + (AuUInt)(catchableTypeArray->arrayOfCatchableTypes[i]));
const auto descriptor = reinterpret_cast<std::type_info *> (reinterpret_cast<AuUInt>(handle) + (AuUInt)(type->pType));
const ThrowInfo *pthrowInfo = reinterpret_cast<const ThrowInfo *>(throwInfo);
auto attribs = pthrowInfo->attributes;
message += (i == 0 ? "" : AuString(", ")) + descriptor->name(); // __std_type_info_name
const auto catchableTypeArray = reinterpret_cast<const CatchableTypeArray *>(reinterpret_cast<AuUInt>(handle) + (AuUInt)(pthrowInfo->pCatchableTypeArray));
if (_strnicmp(descriptor->raw_name(), ".?AVException@", 15 - 1) == 0)
AuString suffix;
for (int i = 0; i < catchableTypeArray->nCatchableTypes; i++)
{
auto exception2 = reinterpret_cast<std::exception *>(exception);
auto wptr = exception2->what();
if (wptr)
const auto type = reinterpret_cast<CatchableType *> (reinterpret_cast<AuUInt>(handle) + (AuUInt)(catchableTypeArray->arrayOfCatchableTypes[i]));
const auto descriptor = reinterpret_cast<std::type_info *> (reinterpret_cast<AuUInt>(handle) + (AuUInt)(type->pType));
message += (i == 0 ? "" : AuString(", ")) + descriptor->name(); // __std_type_info_name
if (_strnicmp(descriptor->raw_name(), ".?AVException@", 15 - 1) == 0)
{
suffix = wptr;
}
}
else if (_strnicmp(descriptor->raw_name(), ".PEAD", 5) == 0)
{
auto possibleStringPointer = reinterpret_cast<const char **>(exception);
if (IsReadable(possibleStringPointer))
{
auto string = *possibleStringPointer;
if (IsReadable(string) && (strnlen(string, 4096) < 1024))
auto exception2 = reinterpret_cast<std::exception *>(exception);
auto wptr = exception2->what();
if (wptr)
{
suffix = string;
suffix = wptr;
}
}
else if (_strnicmp(descriptor->raw_name(), ".PEAD", 5) == 0)
{
auto possibleStringPointer = reinterpret_cast<const char **>(exception);
if (IsReadable(possibleStringPointer))
{
auto string = *possibleStringPointer;
if (IsReadable(string) && (strnlen(string, 4096) < 1024))
{
suffix = string;
}
}
}
else if (_strnicmp(descriptor->raw_name(), kStringRawName.data(), kStringRawName.size()) == 0)
{
auto possibleStdStringPointer = reinterpret_cast<std::string *>(exception);
if (IsReadable(possibleStdStringPointer))
{
suffix = *possibleStdStringPointer;
}
}
}
else if (_strnicmp(descriptor->raw_name(), kStringRawName.data(), kStringRawName.size()) == 0)
if (suffix.size())
{
auto possibleStdStringPointer = reinterpret_cast<std::string *>(exception);
if (IsReadable(possibleStdStringPointer))
{
suffix = *possibleStdStringPointer;
}
message += AuString("\r\n ") + suffix;
}
}
if (suffix.size())
catch (...)
{
message += AuString("\r\n ") + suffix;
}
}
catch (...)
{
}
}
}
if (message.find("invalid sto") != AuString::npos) return message;
if (message.find("invalid sto") != AuString::npos)
{
return message;
}
try
{

View File

@ -261,23 +261,21 @@ namespace Aurora::Debug
doReportLocal = [&]()
{
if (pThrowInfo)
ReportSEH(handle, exception, pThrowInfo, handleNoCppObject, backtrace, [&](const AuString &str)
{
ReportSEH(handle, exception, pThrowInfo, handleNoCppObject, backtrace, [&](const AuString &str)
// Pre-submit callback -> its showtime
if ((isCritical || kShouldPrintErrors) && (minimal == 0))
{
// Pre-submit callback -> its showtime
if ((isCritical || kShouldPrintErrors) && (minimal == 0))
if (gRuntimeConfig.debug.bPrintExceptionStackTracesOut)
{
if (gRuntimeConfig.debug.bPrintExceptionStackTracesOut)
{
AuLogWarn("NT Exception: 0x{:x}, {}", ExceptionInfo->ExceptionRecord->ExceptionCode, str);
AuLogWarn("{}", StringifyStackTrace(backtrace));
}
AuLogWarn("NT Exception: 0x{:x}, {}", ExceptionInfo->ExceptionRecord->ExceptionCode, str);
AuLogWarn("{}", StringifyStackTrace(backtrace));
}
});
}
}
});
};
doReportLocal();
ReportStackTrace(backtrace, "");
}
auto pThread = AuThreads::GetThread();