Skip to content

Commit c4398cf

Browse files
committed
Merge with updated DbgHelpLoader behavior
1 parent f58d620 commit c4398cf

File tree

4 files changed

+56
-42
lines changed

4 files changed

+56
-42
lines changed

Core/GameEngine/Include/Common/MiniDumper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class MiniDumper
8181

8282
private:
8383
Bool m_miniDumpInitialized;
84+
Bool m_loadedDbgHelp;
8485
DumpType m_requestedDumpType;
8586

8687
// Path buffers

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ void MiniDumper::shutdownMiniDumper()
5959
MiniDumper::MiniDumper()
6060
{
6161
m_miniDumpInitialized = false;
62+
m_loadedDbgHelp = false;
6263
m_requestedDumpType = DUMP_TYPE_MINIMAL;
6364
m_dumpRequested = NULL;
6465
m_dumpComplete = NULL;
@@ -145,10 +146,10 @@ void MiniDumper::TriggerMiniDumpForException(struct _EXCEPTION_POINTERS* e_info,
145146

146147
void MiniDumper::Initialize(const AsciiString& userDirPath)
147148
{
148-
bool success = DbgHelpLoader::load();
149+
m_loadedDbgHelp = DbgHelpLoader::load();
149150

150151
// We want to only use the dbghelp.dll from the OS installation, as the one bundled with the game does not support MiniDump functionality
151-
if (!(success && DbgHelpLoader::isLoadedFromSystem()))
152+
if (!(m_loadedDbgHelp && DbgHelpLoader::isLoadedFromSystem()))
152153
{
153154
DEBUG_LOG(("MiniDumper::Initialize: Unable to load system-provided dbghelp.dll, minidump functionality disabled."));
154155
return;
@@ -265,12 +266,20 @@ void MiniDumper::CleanupResources()
265266
}
266267

267268
DbgHelpLoader::unload();
269+
m_loadedDbgHelp = false;
268270
}
269271

270272
void MiniDumper::ShutDown()
271273
{
272274
if (!m_miniDumpInitialized)
273275
{
276+
// Even if we failed to initialize, DbgHelpLoader could still have loaded its library
277+
if (m_loadedDbgHelp)
278+
{
279+
DbgHelpLoader::unload();
280+
m_loadedDbgHelp = false;
281+
}
282+
274283
return;
275284
}
276285

@@ -399,7 +408,7 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
399408
dumpTypeFlags |= MiniDumpWithFullMemory;
400409
FALLTHROUGH;
401410
case DUMP_TYPE_GAMEMEMORY:
402-
dumpTypeFlags |= MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithFullMemoryInfo;
411+
dumpTypeFlags |= MiniDumpWithDataSegs | MiniDumpWithHandleData | MiniDumpWithThreadInfo | MiniDumpWithFullMemoryInfo | MiniDumpWithPrivateReadWriteMemory;
403412
FALLTHROUGH;
404413
case DUMP_TYPE_MINIMAL:
405414
dumpTypeFlags |= MiniDumpWithIndirectlyReferencedMemory | MiniDumpScanMemory;
@@ -455,7 +464,7 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
455464
// Only include data segments for the game and ntdll modules to keep dump size low
456465
if (output.ModuleWriteFlags & ModuleWriteDataSeg)
457466
{
458-
if (!::StrCmpIW(input.Module.FullPath, m_executablePath) && !::StrStrIW(input.Module.FullPath, L"ntdll.dll"))
467+
if (::StrCmpIW(input.Module.FullPath, m_executablePath) && !::StrStrIW(input.Module.FullPath, L"ntdll.dll"))
459468
{
460469
// Exclude data segments for the module
461470
output.ModuleWriteFlags &= (~ModuleWriteDataSeg);

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

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ CriticalSectionClass DbgHelpLoader::CriticalSection;
2424

2525
DbgHelpLoader::DbgHelpLoader()
2626
: m_symInitialize(NULL)
27-
#ifdef RTS_ENABLE_CRASHDUMP
28-
, m_miniDumpWriteDump(NULL)
29-
#endif
3027
, m_symCleanup(NULL)
3128
, m_symLoadModule(NULL)
3229
, m_symUnloadModule(NULL)
@@ -36,6 +33,9 @@ DbgHelpLoader::DbgHelpLoader()
3633
, m_symSetOptions(NULL)
3734
, m_symFunctionTableAccess(NULL)
3835
, m_stackWalk(NULL)
36+
#ifdef RTS_ENABLE_CRASHDUMP
37+
, m_miniDumpWriteDump(NULL)
38+
#endif
3939
, m_dllModule(HMODULE(0))
4040
, m_referenceCount(0)
4141
, m_failed(false)
@@ -111,9 +111,6 @@ bool DbgHelpLoader::load()
111111
Inst->m_loadedFromSystem = true;
112112
}
113113

114-
#ifdef RTS_ENABLE_CRASHDUMP
115-
Inst->m_miniDumpWriteDump = reinterpret_cast<MiniDumpWriteDump_t>(::GetProcAddress(Inst->m_dllModule, "MiniDumpWriteDump"));
116-
#endif
117114
Inst->m_symInitialize = reinterpret_cast<SymInitialize_t>(::GetProcAddress(Inst->m_dllModule, "SymInitialize"));
118115
Inst->m_symCleanup = reinterpret_cast<SymCleanup_t>(::GetProcAddress(Inst->m_dllModule, "SymCleanup"));
119116
Inst->m_symLoadModule = reinterpret_cast<SymLoadModule_t>(::GetProcAddress(Inst->m_dllModule, "SymLoadModule"));
@@ -124,6 +121,9 @@ bool DbgHelpLoader::load()
124121
Inst->m_symSetOptions = reinterpret_cast<SymSetOptions_t>(::GetProcAddress(Inst->m_dllModule, "SymSetOptions"));
125122
Inst->m_symFunctionTableAccess = reinterpret_cast<SymFunctionTableAccess_t>(::GetProcAddress(Inst->m_dllModule, "SymFunctionTableAccess"));
126123
Inst->m_stackWalk = reinterpret_cast<StackWalk_t>(::GetProcAddress(Inst->m_dllModule, "StackWalk"));
124+
#ifdef RTS_ENABLE_CRASHDUMP
125+
Inst->m_miniDumpWriteDump = reinterpret_cast<MiniDumpWriteDump_t>(::GetProcAddress(Inst->m_dllModule, "MiniDumpWriteDump"));
126+
#endif
127127

128128
if (Inst->m_symInitialize == NULL || Inst->m_symCleanup == NULL)
129129
{
@@ -177,26 +177,12 @@ void DbgHelpLoader::freeResources()
177177
Inst->m_symSetOptions = NULL;
178178
Inst->m_symFunctionTableAccess = NULL;
179179
Inst->m_stackWalk = NULL;
180-
181-
Inst->m_loadedFromSystem = false;
182-
}
183-
184180
#ifdef RTS_ENABLE_CRASHDUMP
185-
BOOL DbgHelpLoader::miniDumpWriteDump(
186-
HANDLE hProcess,
187-
DWORD ProcessId,
188-
HANDLE hFile,
189-
MINIDUMP_TYPE DumpType,
190-
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
191-
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
192-
PMINIDUMP_CALLBACK_INFORMATION CallbackParam)
193-
{
194-
if (Inst != NULL && Inst->m_miniDumpWriteDump)
195-
return Inst->m_miniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
181+
Inst->m_miniDumpWriteDump = NULL;
182+
#endif
196183

197-
return FALSE;
184+
Inst->m_loadedFromSystem = false;
198185
}
199-
#endif
200186

201187
BOOL DbgHelpLoader::symInitialize(
202188
HANDLE hProcess,
@@ -355,3 +341,22 @@ BOOL DbgHelpLoader::stackWalk(
355341

356342
return FALSE;
357343
}
344+
345+
#ifdef RTS_ENABLE_CRASHDUMP
346+
BOOL DbgHelpLoader::miniDumpWriteDump(
347+
HANDLE hProcess,
348+
DWORD ProcessId,
349+
HANDLE hFile,
350+
MINIDUMP_TYPE DumpType,
351+
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
352+
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
353+
PMINIDUMP_CALLBACK_INFORMATION CallbackParam)
354+
{
355+
CriticalSectionClass::LockClass lock(CriticalSection);
356+
357+
if (Inst != NULL && Inst->m_miniDumpWriteDump)
358+
return Inst->m_miniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam);
359+
360+
return FALSE;
361+
}
362+
#endif

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,6 @@ class DbgHelpLoader
5858
static bool load();
5959
static void unload();
6060

61-
#ifdef RTS_ENABLE_CRASHDUMP
62-
static BOOL WINAPI miniDumpWriteDump(
63-
HANDLE hProcess,
64-
DWORD ProcessId,
65-
HANDLE hFile,
66-
MINIDUMP_TYPE DumpType,
67-
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
68-
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
69-
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
70-
#endif
71-
7261
static BOOL WINAPI symInitialize(
7362
HANDLE hProcess,
7463
LPSTR UserSearchPath,
@@ -123,6 +112,17 @@ class DbgHelpLoader
123112
PGET_MODULE_BASE_ROUTINE GetModuleBaseRoutine,
124113
PTRANSLATE_ADDRESS_ROUTINE TranslateAddress);
125114

115+
#ifdef RTS_ENABLE_CRASHDUMP
116+
static BOOL WINAPI miniDumpWriteDump(
117+
HANDLE hProcess,
118+
DWORD ProcessId,
119+
HANDLE hFile,
120+
MINIDUMP_TYPE DumpType,
121+
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
122+
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
123+
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
124+
#endif
125+
126126
private:
127127

128128
static void freeResources();
@@ -192,9 +192,6 @@ class DbgHelpLoader
192192
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
193193
#endif
194194

195-
#ifdef RTS_ENABLE_CRASHDUMP
196-
MiniDumpWriteDump_t m_miniDumpWriteDump;
197-
#endif
198195
SymInitialize_t m_symInitialize;
199196
SymCleanup_t m_symCleanup;
200197
SymLoadModule_t m_symLoadModule;
@@ -205,13 +202,15 @@ class DbgHelpLoader
205202
SymSetOptions_t m_symSetOptions;
206203
SymFunctionTableAccess_t m_symFunctionTableAccess;
207204
StackWalk_t m_stackWalk;
205+
#ifdef RTS_ENABLE_CRASHDUMP
206+
MiniDumpWriteDump_t m_miniDumpWriteDump;
207+
#endif
208208

209209
typedef std::set<HANDLE, std::less<HANDLE>, stl::system_allocator<HANDLE> > Processes;
210210

211211
Processes m_initializedProcesses;
212212
HMODULE m_dllModule;
213213
int m_referenceCount;
214-
CriticalSectionClass m_criticalSection;
215214
bool m_failed;
216215
bool m_loadedFromSystem;
217216
};

0 commit comments

Comments
 (0)