Skip to content

Commit 5535fff

Browse files
committed
Made DumpType a a Char-based enum, used in generating file names. Include data segments for kernel32.
1 parent 6923fcd commit 5535fff

File tree

3 files changed

+43
-37
lines changed

3 files changed

+43
-37
lines changed

Core/GameEngine/Include/Common/MiniDumper.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
#ifdef RTS_ENABLE_CRASHDUMP
2222
#include "DbgHelpLoader.h"
2323

24-
enum DumpType CPP_11(: Int)
24+
enum DumpType CPP_11(: Char)
2525
{
2626
// Smallest dump type with call stacks and some supporting variables
27-
DUMP_TYPE_MINIMAL,
27+
DUMP_TYPE_MINIMAL = 'M',
2828
// Large dump including all memory regions allocated by the GameMemory implementaion
29-
DUMP_TYPE_GAMEMEMORY,
29+
DUMP_TYPE_GAMEMEMORY = 'X',
3030
// Largest dump size including complete memory contents of the process
31-
DUMP_TYPE_FULL,
31+
DUMP_TYPE_FULL = 'F',
3232
};
3333

3434
enum MiniDumperExitCode CPP_11(: Int)
@@ -69,7 +69,7 @@ class MiniDumper
6969

7070
// Dump file directory bookkeeping
7171
Bool InitializeDumpDirectory(const AsciiString& userDirPath);
72-
static void KeepNewestFiles(const std::string& directory, const std::string& fileWildcard, const Int keepCount);
72+
static void KeepNewestFiles(const std::string& directory, const DumpType dumpType, const Int keepCount);
7373

7474
// Struct to hold file information
7575
struct FileInfo

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,21 @@ double SimpleProfiler::getAverageTime()
718718
}
719719
}
720720

721+
#ifdef RTS_ENABLE_CRASHDUMP
722+
static void TriggerMiniDump()
723+
{
724+
if (TheMiniDumper && TheMiniDumper->IsInitialized())
725+
{
726+
// Do dumps both with and without extended info
727+
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_MINIMAL);
728+
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_GAMEMEMORY);
729+
}
730+
731+
MiniDumper::shutdownMiniDumper();
732+
733+
}
734+
#endif
735+
721736
void ReleaseCrash(const char *reason)
722737
{
723738
/// do additional reporting on the crash, if possible
@@ -729,14 +744,7 @@ void ReleaseCrash(const char *reason)
729744
}
730745

731746
#ifdef RTS_ENABLE_CRASHDUMP
732-
if (TheMiniDumper && TheMiniDumper->IsInitialized())
733-
{
734-
// Do dumps both with and without extended info
735-
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_MINIMAL);
736-
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_GAMEMEMORY);
737-
}
738-
739-
MiniDumper::shutdownMiniDumper();
747+
TriggerMiniDump();
740748
#endif
741749

742750
char prevbuf[ _MAX_PATH ];
@@ -805,14 +813,7 @@ void ReleaseCrashLocalized(const AsciiString& p, const AsciiString& m)
805813
}
806814

807815
#ifdef RTS_ENABLE_CRASHDUMP
808-
if (TheMiniDumper && TheMiniDumper->IsInitialized())
809-
{
810-
// Do dumps both with and without extended info
811-
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_MINIMAL);
812-
TheMiniDumper->TriggerMiniDump(DUMP_TYPE_GAMEMEMORY);
813-
}
814-
815-
MiniDumper::shutdownMiniDumper();
816+
TriggerMiniDump();
816817
#endif
817818

818819
UnicodeString prompt = TheGameText->fetch(p);

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ _EXCEPTION_POINTERS g_exceptionPointers = { 0 };
3535
EXCEPTION_RECORD g_exceptionRecord = { 0 };
3636
CONTEXT g_exceptionContext = { 0 };
3737

38+
constexpr const char* DumpFileNamePrefix = "Crash";
39+
3840
void MiniDumper::initMiniDumper(const AsciiString& userDirPath)
3941
{
4042
DEBUG_ASSERTCRASH(TheMiniDumper == NULL, ("MiniDumper::initMiniDumper called on already created instance"));
@@ -71,9 +73,9 @@ MiniDumper::MiniDumper()
7173
m_dumpObjectsSubState = 0;
7274
m_dmaRawBlockIndex = 0;
7375
#endif
74-
memset(m_dumpDir, 0, ARRAY_SIZE(m_dumpDir));
75-
memset(m_dumpFile, 0, ARRAY_SIZE(m_dumpFile));
76-
memset(m_executablePath, 0, ARRAY_SIZE(m_executablePath));
76+
m_dumpDir[0] = 0;
77+
m_dumpFile[0] = 0;
78+
m_executablePath[0] = 0;
7779
};
7880

7981
LONG WINAPI MiniDumper::DumpingExceptionFilter(struct _EXCEPTION_POINTERS* e_info)
@@ -214,8 +216,9 @@ Bool MiniDumper::IsDumpThreadStillRunning() const
214216

215217
Bool MiniDumper::InitializeDumpDirectory(const AsciiString& userDirPath)
216218
{
217-
constexpr Int MaxExtendedFileCount = 2;
218-
constexpr Int MaxMiniFileCount = 10;
219+
constexpr const Int MaxExtendedFileCount = 2;
220+
constexpr const Int MaxFullFileCount = 2;
221+
constexpr const Int MaxMiniFileCount = 10;
219222

220223
strlcpy(m_dumpDir, userDirPath.str(), ARRAY_SIZE(m_dumpDir));
221224
strlcat(m_dumpDir, "CrashDumps\\", ARRAY_SIZE(m_dumpDir));
@@ -228,9 +231,10 @@ Bool MiniDumper::InitializeDumpDirectory(const AsciiString& userDirPath)
228231
}
229232
}
230233

231-
// Clean up old files (we keep a maximum of 10 small and 2 extended)
232-
KeepNewestFiles(m_dumpDir, "CrashX*", MaxExtendedFileCount);
233-
KeepNewestFiles(m_dumpDir, "CrashM*", MaxMiniFileCount);
234+
// Clean up old files (we keep a maximum of 10 small, 2 extended and 2 full)
235+
KeepNewestFiles(m_dumpDir, DUMP_TYPE_GAMEMEMORY, MaxExtendedFileCount);
236+
KeepNewestFiles(m_dumpDir, DUMP_TYPE_FULL, MaxFullFileCount);
237+
KeepNewestFiles(m_dumpDir, DUMP_TYPE_MINIMAL, MaxMiniFileCount);
234238

235239
return true;
236240
}
@@ -354,16 +358,16 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
354358
SYSTEMTIME sysTime;
355359
::GetLocalTime(&sysTime);
356360
#if RTS_GENERALS
357-
Char product = 'G';
361+
const Char product = 'G';
358362
#elif RTS_ZEROHOUR
359-
Char product = 'Z';
363+
const Char product = 'Z';
360364
#endif
361-
Char dumpTypeSpecifier = dumpType == DUMP_TYPE_MINIMAL ? 'M' : 'X';
365+
Char dumpTypeSpecifier = static_cast<Char>(dumpType);
362366
DWORD currentProcessId = ::GetCurrentProcessId();
363367

364368
// m_dumpDir is stored with trailing backslash in Initialize
365-
snprintf(m_dumpFile, ARRAY_SIZE(m_dumpFile), "%sCrash%c%c-%04d%02d%02d-%02d%02d%02d-%s-pid%ld.dmp",
366-
m_dumpDir, dumpTypeSpecifier, product, sysTime.wYear, sysTime.wMonth,
369+
snprintf(m_dumpFile, ARRAY_SIZE(m_dumpFile), "%s%s%c%c-%04d%02d%02d-%02d%02d%02d-%s-pid%ld.dmp",
370+
m_dumpDir, DumpFileNamePrefix, dumpTypeSpecifier, product, sysTime.wYear, sysTime.wMonth,
367371
sysTime.wDay, sysTime.wHour, sysTime.wMinute, sysTime.wSecond,
368372
GitShortSHA1, currentProcessId);
369373

@@ -456,7 +460,8 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
456460
// Only include data segments for the game and ntdll modules to keep dump size low
457461
if (output.ModuleWriteFlags & ModuleWriteDataSeg)
458462
{
459-
if (::StrCmpIW(input.Module.FullPath, m_executablePath) && !::StrStrIW(input.Module.FullPath, L"ntdll.dll"))
463+
if (::StrCmpIW(input.Module.FullPath, m_executablePath) && !::StrStrIW(input.Module.FullPath, L"ntdll.dll") &&
464+
!::StrStrIW(input.Module.FullPath, L"kernel32.dll"))
460465
{
461466
// Exclude data segments for the module
462467
output.ModuleWriteFlags &= (~ModuleWriteDataSeg);
@@ -645,10 +650,10 @@ bool MiniDumper::CompareByLastWriteTime(const FileInfo& a, const FileInfo& b)
645650
return ::CompareFileTime(&a.lastWriteTime, &b.lastWriteTime) > 0;
646651
}
647652

648-
void MiniDumper::KeepNewestFiles(const std::string& directory, const std::string& fileWildcard, const Int keepCount)
653+
void MiniDumper::KeepNewestFiles(const std::string& directory, const DumpType dumpType, const Int keepCount)
649654
{
650655
// directory already contains trailing backslash
651-
std::string searchPath = directory + fileWildcard;
656+
std::string searchPath = directory + DumpFileNamePrefix + static_cast<Char>(dumpType) + "*";
652657
WIN32_FIND_DATA findData;
653658
HANDLE hFind = ::FindFirstFile(searchPath.c_str(), &findData);
654659

0 commit comments

Comments
 (0)