mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
[DRWTSN32] Add code to write a minidump
This commit is contained in:
parent
1d10606fad
commit
6f6ce101f7
1 changed files with 60 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue