[DRWTSN32] Add code to write a minidump

This commit is contained in:
William Kent 2018-03-08 20:51:15 +01:00 committed by Mark Jansen
parent 1d10606fad
commit 6f6ce101f7
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B

View file

@ -178,6 +178,62 @@ std::wstring Settings_GetOutputPath(void)
return std::wstring(Buffer);
}
BOOL Settings_GetShouldWriteDump(void)
{
CRegKey key;
if (key.Open(HKEY_CURRENT_USER, L"SOFTWARE\\ReactOS\\Crash Reporter", KEY_READ) != ERROR_SUCCESS)
{
return FALSE;
}
DWORD Value;
if (key.QueryDWORDValue(L"Minidump", Value) != ERROR_SUCCESS)
{
return FALSE;
}
return (Value != 0);
}
HRESULT WriteMinidump(LPCWSTR LogFilePath, DumpData& data)
{
HRESULT hr = S_OK;
WCHAR DumpFilePath[MAX_PATH] = L"";
StringCchCopyW(DumpFilePath, _countof(DumpFilePath), LogFilePath);
PathRemoveExtensionW(DumpFilePath);
PathAddExtensionW(DumpFilePath, L".dmp");
HANDLE hDumpFile = CreateFileW(DumpFilePath, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDumpFile == INVALID_HANDLE_VALUE)
{
return HRESULT_FROM_WIN32(GetLastError());
}
ThreadData& Thread = data.Threads[data.ThreadID];
Thread.Update();
PCONTEXT ContextPointer = &Thread.Context;
MINIDUMP_EXCEPTION_INFORMATION DumpExceptionInfo = {0};
EXCEPTION_POINTERS ExceptionPointers = {0};
ExceptionPointers.ExceptionRecord = &data.ExceptionInfo.ExceptionRecord;
ExceptionPointers.ContextRecord = ContextPointer;
DumpExceptionInfo.ThreadId = data.ThreadID;
DumpExceptionInfo.ExceptionPointers = &ExceptionPointers;
DumpExceptionInfo.ClientPointers = FALSE;
BOOL DumpSucceeded = MiniDumpWriteDump(data.ProcessHandle, data.ProcessID, hDumpFile, MiniDumpNormal, &DumpExceptionInfo, NULL, NULL);
if (!DumpSucceeded)
{
// According to MSDN, this value is already an HRESULT, so don't convert it again.
hr = GetLastError();
}
CloseHandle(hDumpFile);
return hr;
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR cmdLine, INT)
{
int argc;
@ -284,6 +340,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR cmdLine, INT)
}
PrintBugreport(output, data);
if (Settings_GetShouldWriteDump() && HasPath)
{
WriteMinidump(OutputPath.c_str(), data);
}
TerminateProcess(data.ProcessHandle, data.ExceptionInfo.ExceptionRecord.ExceptionCode);