Tier2: check for user consent before submitting crash report

If the crash occurs during the initialization of systems, and Tier1 wasn't initialized yet, the system will display a prompt asking the user whether or not to send the reports. If the crash occurs after Tier1 was initialized, the system will check if the user has crash reporting enabled, and if the user has accepted the EULA before submitting it automatically.
This commit is contained in:
Kawe Mazidjatari 2024-10-06 12:30:56 +02:00
parent 130161128c
commit e551bb9e6f
3 changed files with 42 additions and 21 deletions

View File

@ -77,7 +77,7 @@ public:
void CaptureCallStack();
void WriteFile();
void CreateMessageProcess();
void CreateMessageProcess() const;
void CrashCallback() const;
private:
@ -125,9 +125,6 @@ private:
// Buffer containing the module name we crashed in.
CFmtStrQuietTruncationN<256> m_CrashingModule;
// Buffer containing cmd line arguments for the external crash message
// process.
CFmtStrQuietTruncationN<256> m_MessageCmdLine;
uint8_t m_nCrashMsgFlags;
// Set when called to prevent recursive calls.

View File

@ -502,15 +502,9 @@ void CCrashHandler::WriteFile()
// Purpose: creates the crashmsg process displaying the error to the user
// the process has to be separate as the current process is getting killed
//-----------------------------------------------------------------------------
void CCrashHandler::CreateMessageProcess()
void CCrashHandler::CreateMessageProcess() const
{
if (m_bMessageCreated)
{
// Crash message already displayed.
return;
}
m_bMessageCreated = true;
CFmtStrQuietTruncationN<256> messageCmdLine;
const PEXCEPTION_RECORD pExceptionRecord = m_pExceptionPointers->ExceptionRecord;
const PCONTEXT pContextRecord = m_pExceptionPointers->ContextRecord;
@ -519,12 +513,11 @@ void CCrashHandler::CreateMessageProcess()
pExceptionRecord->ExceptionInformation[0] == 8 &&
pExceptionRecord->ExceptionInformation[1] != pContextRecord->Rip)
{
m_MessageCmdLine.Clear();
m_MessageCmdLine.Append(CRASHMESSAGE_MSG_EXECUTABLE" overclock");
messageCmdLine.Append(CRASHMESSAGE_MSG_EXECUTABLE" overclock");
}
else
{
m_MessageCmdLine.Format(CRASHMESSAGE_MSG_EXECUTABLE" crash %hhu \"%s\"",
messageCmdLine.Format(CRASHMESSAGE_MSG_EXECUTABLE" crash %hhu \"%s\"",
m_nCrashMsgFlags, m_CrashingModule.String());
}
@ -533,7 +526,7 @@ void CCrashHandler::CreateMessageProcess()
startupInfo.cb = sizeof(STARTUPINFOA);
if (CreateProcessA(NULL, (LPSTR)m_MessageCmdLine.String(),
if (CreateProcessA(NULL, (LPSTR)messageCmdLine.String(),
NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &startupInfo, &processInfo))
{
CloseHandle(processInfo.hProcess);
@ -598,9 +591,6 @@ long __stdcall BottomLevelExceptionFilter(EXCEPTION_POINTERS* const pExceptionIn
g_CrashHandler.WriteFile();
// Display the message to the user.
g_CrashHandler.CreateMessageProcess();
// Run the crash callback
g_CrashHandler.CrashCallback();
@ -638,7 +628,6 @@ void CCrashHandler::Reset()
{
m_Buffer.Clear();
m_CrashingModule.Clear();
m_MessageCmdLine.Clear();
m_nCrashMsgFlags = 0;
}

View File

@ -13,6 +13,39 @@ static ConVar backtrace_hostname("backtrace_hostname", "submit.backtrace.io", FC
static ConVar backtrace_universe("backtrace_universe", "r5reloaded", FCVAR_RELEASE, "Holds the error collection server hosted instance");
static ConVar backtrace_token("backtrace_token", "f178fd48d89c8fec7f8b6404ae6dae591c330fd3e2599cab888788033944ec98", FCVAR_RELEASE, "Holds the error collection server submission token");
static inline bool CrashReporter_ShowMessageBox()
{
if (MessageBoxA(NULL,
"The program encountered a critical error and was terminated.\n"
"Would you like to send this report to help solve the problem?",
"Critical Error Detected", MB_ICONERROR | MB_YESNO) == IDYES)
{
return true;
}
return false;
}
static inline bool CrashReporter_ShouldSubmitReport()
{
if (!ConVar_IsRegistered())
{
// Can't check if the user accepted the EULA or not, show a prompt instead.
if (!CrashReporter_ShowMessageBox())
return false;
}
else
{
if (!backtrace_enabled.GetBool())
return false;
if (!IsEULAUpToDate())
return false;
}
return true;
}
static inline string CrashReporter_FormatAttributes(const CCrashHandler* const handler)
{
const CPUInformation& pi = GetCPUInformation();
@ -36,7 +69,9 @@ static inline string CrashReporter_FormatAttributes(const CCrashHandler* const h
void CrashReporter_SubmitToCollector(const CCrashHandler* const handler)
{
if (!backtrace_enabled.GetBool())
handler->CreateMessageProcess();
if (!CrashReporter_ShouldSubmitReport())
return;
curl_slist* slist = nullptr;