Skip to content

Commit 90a0b49

Browse files
committed
Moved dbghelp interaction to DbgHelpLoader
1 parent a5a2419 commit 90a0b49

File tree

7 files changed

+58
-59
lines changed

7 files changed

+58
-59
lines changed

Core/GameEngine/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ set(GAMEENGINE_SRC
7272
# Include/Common/MapReaderWriterInfo.h
7373
# Include/Common/MessageStream.h
7474
Include/Common/MiniDumper.h
75-
Include/Common/MiniDumper_compat.h
7675
# Include/Common/MiniLog.h
7776
Include/Common/MiscAudio.h
7877
# Include/Common/MissionStats.h

Core/GameEngine/Include/Common/MiniDumper.h

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
#pragma once
2020

2121
#ifdef RTS_ENABLE_CRASHDUMP
22-
#include <imagehlp.h>
23-
#include "Common/MiniDumper_compat.h"
22+
#include "DbgHelpLoader.h"
2423

2524
enum DumpType CPP_11(: Int)
2625
{
@@ -87,12 +86,8 @@ class MiniDumper
8786
// Path buffers
8887
Char m_dumpDir[MAX_PATH];
8988
Char m_dumpFile[MAX_PATH];
90-
Char m_sysDbgHelpPath[MAX_PATH];
9189
WideChar m_executablePath[MAX_PATH];
9290

93-
// Module handles
94-
HMODULE m_dbgHlp;
95-
9691
// Event handles
9792
HANDLE m_dumpRequested;
9893
HANDLE m_dumpComplete;
@@ -110,19 +105,6 @@ class MiniDumper
110105

111106
AllocationRangeIterator m_rangeIter;
112107
#endif
113-
114-
// Function pointer to MiniDumpWriteDump in dbghelp.dll
115-
typedef BOOL(WINAPI* MiniDumpWriteDump_t)(
116-
HANDLE hProcess,
117-
DWORD ProcessId,
118-
HANDLE hFile,
119-
MINIDUMP_TYPE DumpType,
120-
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
121-
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
122-
PMINIDUMP_CALLBACK_INFORMATION CallbackParam
123-
);
124-
125-
MiniDumpWriteDump_t m_pMiniDumpWriteDump;
126108
};
127109

128110
extern MiniDumper* TheMiniDumper;

Core/GameEngine/Source/Common/System/MiniDumper.cpp

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ MiniDumper::MiniDumper()
6060
{
6161
m_miniDumpInitialized = false;
6262
m_requestedDumpType = DUMP_TYPE_MINIMAL;
63-
m_dbgHlp = NULL;
64-
m_pMiniDumpWriteDump = NULL;
6563
m_dumpRequested = NULL;
6664
m_dumpComplete = NULL;
6765
m_quitting = NULL;
@@ -74,7 +72,6 @@ MiniDumper::MiniDumper()
7472
#endif
7573
memset(m_dumpDir, 0, ARRAY_SIZE(m_dumpDir));
7674
memset(m_dumpFile, 0, ARRAY_SIZE(m_dumpFile));
77-
memset(m_sysDbgHelpPath, 0, ARRAY_SIZE(m_sysDbgHelpPath));
7875
memset(m_executablePath, 0, ARRAY_SIZE(m_executablePath));
7976
};
8077

@@ -148,36 +145,12 @@ void MiniDumper::TriggerMiniDumpForException(struct _EXCEPTION_POINTERS* e_info,
148145

149146
void MiniDumper::Initialize(const AsciiString& userDirPath)
150147
{
151-
// Find the full path to the dbghelp.dll file in the system32 dir
152-
::GetSystemDirectory(m_sysDbgHelpPath, MAX_PATH);
153-
strlcat(m_sysDbgHelpPath, "\\dbghelp.dll", MAX_PATH);
148+
bool success = DbgHelpLoader::load();
154149

155150
// We want to only use the dbghelp.dll from the OS installation, as the one bundled with the game does not support MiniDump functionality
156-
Bool loadedDbgHelp = false;
157-
HMODULE m_dbgHlp = ::GetModuleHandle(m_sysDbgHelpPath);
158-
if (m_dbgHlp == NULL)
151+
if (!(success && DbgHelpLoader::isLoadedFromSystem()))
159152
{
160-
// Load the dbghelp library from the system folder
161-
m_dbgHlp = ::LoadLibrary(m_sysDbgHelpPath);
162-
if (m_dbgHlp == NULL)
163-
{
164-
DEBUG_LOG(("MiniDumper::Initialize: Unable to load system-provided dbghelp.dll from '%s': error=%u", m_sysDbgHelpPath, ::GetLastError()));
165-
return;
166-
}
167-
168-
loadedDbgHelp = true;
169-
}
170-
171-
m_pMiniDumpWriteDump = reinterpret_cast<MiniDumpWriteDump_t>(::GetProcAddress(m_dbgHlp, "MiniDumpWriteDump"));
172-
if (m_pMiniDumpWriteDump == NULL)
173-
{
174-
if (loadedDbgHelp)
175-
{
176-
::FreeLibrary(m_dbgHlp);
177-
m_dbgHlp = NULL;
178-
}
179-
180-
DEBUG_LOG(("MiniDumper::Initialize: Could not get address of proc MiniDumpWriteDump from '%s'!", m_sysDbgHelpPath));
153+
DEBUG_LOG(("MiniDumper::Initialize: Unable to load system-provided dbghelp.dll, minidump functionality disabled."));
181154
return;
182155
}
183156

@@ -291,11 +264,7 @@ void MiniDumper::CleanupResources()
291264
m_quitting = NULL;
292265
}
293266

294-
if (m_dbgHlp != NULL)
295-
{
296-
::FreeModule(m_dbgHlp);
297-
m_dbgHlp = NULL;
298-
}
267+
DbgHelpLoader::unload();
299268
}
300269

301270
void MiniDumper::ShutDown()
@@ -438,7 +407,7 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
438407
}
439408

440409
MINIDUMP_TYPE miniDumpType = static_cast<MINIDUMP_TYPE>(dumpTypeFlags);
441-
BOOL success = m_pMiniDumpWriteDump(
410+
BOOL success = DbgHelpLoader::miniDumpWriteDump(
442411
::GetCurrentProcess(),
443412
currentProcessId,
444413
dumpFile,

Core/Libraries/Source/WWVegas/WWLib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ set(WWLIB_SRC
3636
DbgHelpGuard.h
3737
DbgHelpLoader.cpp
3838
DbgHelpLoader.h
39+
DbgHelpLoader_minidump.h
3940
Except.cpp
4041
Except.h
4142
FastAllocator.cpp

Core/Libraries/Source/WWVegas/WWLib/DbgHelpLoader.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
DbgHelpLoader* DbgHelpLoader::Inst = NULL;
2323

2424
DbgHelpLoader::DbgHelpLoader()
25-
: m_symInitialize(NULL)
25+
: m_miniDumpWriteDump(NULL)
26+
, m_symInitialize(NULL)
2627
, m_symCleanup(NULL)
2728
, m_symLoadModule(NULL)
2829
, m_symUnloadModule(NULL)
@@ -86,6 +87,7 @@ bool DbgHelpLoader::load()
8687
Inst->m_loadedFromSystem = true;
8788
}
8889

90+
Inst->m_miniDumpWriteDump = reinterpret_cast<MiniDumpWriteDump_t>(::GetProcAddress(Inst->m_dllModule, "MiniDumpWriteDump"));
8991
Inst->m_symInitialize = reinterpret_cast<SymInitialize_t>(::GetProcAddress(Inst->m_dllModule, "SymInitialize"));
9092
Inst->m_symCleanup = reinterpret_cast<SymCleanup_t>(::GetProcAddress(Inst->m_dllModule, "SymCleanup"));
9193
Inst->m_symLoadModule = reinterpret_cast<SymLoadModule_t>(::GetProcAddress(Inst->m_dllModule, "SymLoadModule"));
@@ -134,6 +136,23 @@ void DbgHelpLoader::unload()
134136
Inst = NULL;
135137
}
136138

139+
#ifdef RTS_ENABLE_CRASHDUMP
140+
BOOL DbgHelpLoader::miniDumpWriteDump(
141+
HANDLE hProcess,
142+
DWORD ProcessId,
143+
HANDLE hFile,
144+
MINIDUMP_TYPE DumpType,
145+
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
146+
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
147+
PMINIDUMP_CALLBACK_INFORMATION CallbackParam)
148+
{
149+
if (Inst != NULL && Inst->m_miniDumpWriteDump)
150+
return Inst->m_miniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
151+
152+
return FALSE;
153+
}
154+
#endif
155+
137156
BOOL DbgHelpLoader::symInitialize(
138157
HANDLE hProcess,
139158
LPSTR UserSearchPath,

Core/Libraries/Source/WWVegas/WWLib/DbgHelpLoader.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include <win.h>
2424
#include <imagehlp.h> // Must be included after Windows.h
2525
#include <set>
26+
#ifdef RTS_ENABLE_CRASHDUMP
27+
#include <DbgHelpLoader_minidump.h>
28+
#endif
2629

2730
#include "SystemAllocator.h"
2831

@@ -50,6 +53,17 @@ class DbgHelpLoader
5053
static bool reload();
5154
static void unload();
5255

56+
#ifdef RTS_ENABLE_CRASHDUMP
57+
static BOOL WINAPI miniDumpWriteDump(
58+
HANDLE hProcess,
59+
DWORD ProcessId,
60+
HANDLE hFile,
61+
MINIDUMP_TYPE DumpType,
62+
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
63+
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
64+
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
65+
#endif
66+
5367
static BOOL WINAPI symInitialize(
5468
HANDLE hProcess,
5569
LPSTR UserSearchPath,
@@ -106,6 +120,17 @@ class DbgHelpLoader
106120

107121
private:
108122

123+
#ifdef RTS_ENABLE_CRASHDUMP
124+
typedef BOOL(WINAPI* MiniDumpWriteDump_t)(
125+
HANDLE hProcess,
126+
DWORD ProcessId,
127+
HANDLE hFile,
128+
MINIDUMP_TYPE DumpType,
129+
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
130+
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
131+
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
132+
#endif
133+
109134
typedef BOOL (WINAPI *SymInitialize_t) (
110135
HANDLE hProcess,
111136
LPSTR UserSearchPath,
@@ -160,6 +185,9 @@ class DbgHelpLoader
160185
PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
161186
PTRANSLATE_ADDRESS_ROUTINE TranslateAddress);
162187

188+
#ifdef RTS_ENABLE_CRASHDUMP
189+
MiniDumpWriteDump_t m_miniDumpWriteDump;
190+
#endif
163191
SymInitialize_t m_symInitialize;
164192
SymCleanup_t m_symCleanup;
165193
SymLoadModule_t m_symLoadModule;

Core/GameEngine/Include/Common/MiniDumper_compat.h renamed to Core/Libraries/Source/WWVegas/WWLib/DbgHelpLoader_minidump.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
// Backported defines from minidumpapiset.h for VC6.
66
// minidumpapiset.h is Copyright (C) Microsoft Corporation. All rights reserved.
7+
78
#if defined(_MSC_VER) && _MSC_VER < 1300
8-
#pragma pack(push, 4)
9+
#include <pshpack4.h>
910

1011
typedef enum _MINIDUMP_CALLBACK_TYPE {
1112
ModuleCallback,
@@ -249,6 +250,6 @@ typedef enum _MODULE_WRITE_FLAGS {
249250
ModuleWriteCodeSegs = 0x0040,
250251
} MODULE_WRITE_FLAGS;
251252

252-
#pragma pack(pop)
253+
#include <poppack.h>
253254
#endif
254255
#endif

0 commit comments

Comments
 (0)