https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6f6ce101f7705b93ff4fc…
commit 6f6ce101f7705b93ff4fcf15b8ea1ae01d349449
Author: William Kent <wjk011(a)gmail.com>
AuthorDate: Thu Mar 8 20:51:15 2018 +0100
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sat Mar 10 00:04:57 2018 +0100
[DRWTSN32] Add code to write a minidump
---
base/applications/drwtsn32/main.cpp | 60 +++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/base/applications/drwtsn32/main.cpp b/base/applications/drwtsn32/main.cpp
index 1224b7554e..436a18bf30 100644
--- a/base/applications/drwtsn32/main.cpp
+++ b/base/applications/drwtsn32/main.cpp
@@ -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);