Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[DRWTSN32] Add code to write a minidump
  • Loading branch information
wjk authored and learn-more committed Mar 9, 2018
1 parent 1d10606 commit 6f6ce10
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions base/applications/drwtsn32/main.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6f6ce10

Please sign in to comment.