Skip to content

Commit 7cc9b3c

Browse files
committed
Make state enums private, init all meory objs in DumpObjectsState_Begin
1 parent 7399cce commit 7cc9b3c

File tree

2 files changed

+87
-90
lines changed

2 files changed

+87
-90
lines changed

Core/GameEngine/Include/Common/MiniDumper.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ enum DumpType CPP_11(: Char)
3131
DUMP_TYPE_FULL = 'F',
3232
};
3333

34-
enum MiniDumperExitCode CPP_11(: Int)
34+
class MiniDumper
3535
{
36-
DUMPER_EXIT_SUCCESS = 0x0,
37-
DUMPER_EXIT_FAILURE_WAIT = 0x37DA1040,
38-
DUMPER_EXIT_FAILURE_PARAM = 0x4EA527BB,
39-
DUMPER_EXIT_FORCED_TERMINATE = 0x158B1154,
40-
};
36+
enum MiniDumperExitCode CPP_11(: Int)
37+
{
38+
DUMPER_EXIT_SUCCESS = 0x0,
39+
DUMPER_EXIT_FAILURE_WAIT = 0x37DA1040,
40+
DUMPER_EXIT_FAILURE_PARAM = 0x4EA527BB,
41+
DUMPER_EXIT_FORCED_TERMINATE = 0x158B1154,
42+
};
4143

42-
enum DumpObjectsState CPP_11(: Int)
43-
{
44-
BEGIN,
45-
MEMORY_POOLS,
46-
MEMORY_POOL_ALLOCATIONS,
47-
DMA_ALLOCATIONS,
48-
COMPLETED
49-
};
44+
enum DumpObjectsState CPP_11(: Int)
45+
{
46+
DumpObjectsState_Begin,
47+
DumpObjectsState_Memory_Pools,
48+
DumpObjectsState_Memory_Pool_Allocations,
49+
DumpObjectsState_DMA_Allocations,
50+
DumpObjectsState_Completed
51+
};
5052

51-
class MiniDumper
52-
{
5353
public:
5454
MiniDumper();
5555
Bool IsInitialized() const;

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

Lines changed: 71 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ MiniDumper::MiniDumper()
7070
m_dumpThread = NULL;
7171
m_dumpThreadId = 0;
7272
#ifndef DISABLE_GAMEMEMORY
73-
m_dumpObjectsState = MEMORY_POOLS;
73+
m_dumpObjectsState = DumpObjectsState_Begin;
7474
m_currentAllocator = NULL;
7575
m_currentSingleBlock = NULL;
7676
m_currentPool = NULL;
@@ -373,7 +373,7 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
373373
return;
374374
}
375375

376-
m_dumpObjectsState = BEGIN;
376+
m_dumpObjectsState = DumpObjectsState_Begin;
377377

378378
PMINIDUMP_EXCEPTION_INFORMATION exceptionInfoPtr = NULL;
379379
MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = { 0 };
@@ -492,11 +492,9 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
492492
break;
493493
case MemoryCallback:
494494
#ifndef DISABLE_GAMEMEMORY
495-
do
496-
{
497-
// DumpMemoryObjects will set outputMemorySize to 0 once it's completed, signalling the end of memory callbacks
498-
DumpMemoryObjects(output.MemoryBase, output.MemorySize);
499-
} while (output.MemorySize == 0 && m_dumpObjectsState != COMPLETED);
495+
// DumpMemoryObjects will set output.MemorySize to 0 once it's completed,
496+
// signalling to end the memory callbacks.
497+
DumpMemoryObjects(output.MemoryBase, output.MemorySize);
500498
#else
501499
output.MemoryBase = 0;
502500
output.MemorySize = 0;
@@ -520,90 +518,89 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
520518
#ifndef DISABLE_GAMEMEMORY
521519
void MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
522520
{
523-
// m_dumpObjectsState is used to keep track of the current "phase" of the memory dumping process
524-
// m_dumpObjectsSubState is used to keep track of the progress within each phase, and is reset when advancing on to the next phase
525-
switch (m_dumpObjectsState)
526-
{
527-
case BEGIN:
528-
m_dumpObjectsState = MEMORY_POOLS;
529-
if (TheMemoryPoolFactory)
530-
{
531-
m_currentPool = TheMemoryPoolFactory->getFirstMemoryPool();
532-
}
533-
break;
534-
case MEMORY_POOLS:
521+
memorySize = 0;
522+
do
535523
{
536-
// Dump all the MemoryPool instances in TheMemoryPoolFactory
537-
// This only dumps the metadata, not the actual MemoryPool contents (done in the next phase).
538-
if (m_currentPool == NULL)
524+
// m_dumpObjectsState is used to keep track of the current "phase" of the memory dumping process
525+
switch (m_dumpObjectsState)
539526
{
540-
m_dumpObjectsState = MEMORY_POOL_ALLOCATIONS;
527+
case DumpObjectsState_Begin:
528+
m_dumpObjectsState = DumpObjectsState_Memory_Pools;
541529
if (TheMemoryPoolFactory)
542530
{
531+
m_currentPool = TheMemoryPoolFactory->getFirstMemoryPool();
543532
m_rangeIter = TheMemoryPoolFactory->cbegin();
533+
m_currentAllocator = TheDynamicMemoryAllocator;
534+
if (m_currentAllocator)
535+
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
544536
}
545537
break;
546-
}
547-
548-
memoryBase = reinterpret_cast<ULONG64>(m_currentPool);
549-
memorySize = sizeof(MemoryPool);
550-
m_currentPool = m_currentPool->getNextPoolInList();
551-
break;
552-
}
553-
case MEMORY_POOL_ALLOCATIONS:
554-
{
555-
// Iterate through all the allocations of memory pools and containing blobs that has been done via the memory pool factory
556-
// and include all of the storage space allocated for objects
557-
if (m_rangeIter == TheMemoryPoolFactory->cend())
538+
case DumpObjectsState_Memory_Pools:
558539
{
559-
m_dumpObjectsState = DMA_ALLOCATIONS;
560-
m_currentAllocator = TheDynamicMemoryAllocator;
561-
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
540+
// Dump all the MemoryPool instances in TheMemoryPoolFactory
541+
// This only dumps the metadata, not the actual MemoryPool contents (done in the next phase).
542+
if (m_currentPool == NULL)
543+
{
544+
m_dumpObjectsState = DumpObjectsState_Memory_Pool_Allocations;
545+
break;
546+
}
547+
548+
memoryBase = reinterpret_cast<ULONG64>(m_currentPool);
549+
memorySize = sizeof(MemoryPool);
550+
m_currentPool = m_currentPool->getNextPoolInList();
562551
break;
563552
}
564-
565-
memoryBase = reinterpret_cast<ULONG64>(m_rangeIter->allocationAddr);
566-
memorySize = m_rangeIter->allocationSize;
567-
++m_rangeIter;
568-
break;
569-
}
570-
case DMA_ALLOCATIONS:
571-
{
572-
// Iterate through all the direct allocations ("raw blocks") done by DMAs, as these are done outside of the
573-
// memory pool factory allocations dumped in the previous phase.
574-
if (m_currentAllocator == NULL)
553+
case DumpObjectsState_Memory_Pool_Allocations:
575554
{
576-
m_dumpObjectsState = COMPLETED;
555+
// Iterate through all the allocations of memory pools and containing blobs that has been done via the memory pool factory
556+
// and include all of the storage space allocated for objects
557+
if (!TheMemoryPoolFactory || m_rangeIter == TheMemoryPoolFactory->cend())
558+
{
559+
m_dumpObjectsState = DumpObjectsState_DMA_Allocations;
560+
break;
561+
}
562+
563+
memoryBase = reinterpret_cast<ULONG64>(m_rangeIter->allocationAddr);
564+
memorySize = m_rangeIter->allocationSize;
565+
++m_rangeIter;
577566
break;
578567
}
579-
580-
if (m_currentSingleBlock == NULL)
568+
case DumpObjectsState_DMA_Allocations:
581569
{
582-
// Iterated to a new allocator, start iterating over its blocks
583-
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
584-
}
570+
// Iterate through all the direct allocations ("raw blocks") done by DMAs, as these are done outside of the
571+
// memory pool factory allocations dumped in the previous phase.
572+
if (m_currentAllocator == NULL || m_currentSingleBlock == NULL)
573+
{
574+
m_dumpObjectsState = DumpObjectsState_Completed;
575+
break;
576+
}
585577

586-
MemoryPoolAllocatedRange rawBlockRange = { 0 };
587-
m_currentAllocator->fillAllocationRangeForRawBlock(m_currentSingleBlock, rawBlockRange);
588-
memoryBase = reinterpret_cast<ULONG64>(rawBlockRange.allocationAddr);
589-
memorySize = rawBlockRange.allocationSize;
590-
m_currentSingleBlock = m_currentAllocator->getNextRawBlock(m_currentSingleBlock);
578+
MemoryPoolAllocatedRange rawBlockRange = { 0 };
579+
m_currentAllocator->fillAllocationRangeForRawBlock(m_currentSingleBlock, rawBlockRange);
580+
memoryBase = reinterpret_cast<ULONG64>(rawBlockRange.allocationAddr);
581+
memorySize = rawBlockRange.allocationSize;
582+
m_currentSingleBlock = m_currentAllocator->getNextRawBlock(m_currentSingleBlock);
591583

592-
if (m_currentSingleBlock == NULL)
593-
{
594-
m_currentAllocator = m_currentAllocator->getNextDmaInList();
584+
if (m_currentSingleBlock == NULL)
585+
{
586+
m_currentAllocator = m_currentAllocator->getNextDmaInList();
587+
if (m_currentAllocator)
588+
m_currentSingleBlock = m_currentAllocator->getFirstRawBlock();
589+
}
590+
break;
595591
}
596-
break;
597-
}
598-
case COMPLETED:
599-
// Done, set "no more regions to dump" values
600-
memoryBase = 0;
601-
memorySize = 0;
602-
break;
603-
default:
604-
DEBUG_CRASH(("Invalid object state"));
605-
break;
606-
}
592+
case DumpObjectsState_Completed:
593+
// Done, set "no more regions to dump" values
594+
memoryBase = 0;
595+
memorySize = 0;
596+
return;
597+
default:
598+
DEBUG_CRASH(("Invalid object state"));
599+
break;
600+
}
601+
// If memorySize is 0 we transitioned from one phase to the next.
602+
// Go again so the memory block info gets populated in the new phase.
603+
} while (memorySize == 0);
607604
}
608605
#endif
609606

0 commit comments

Comments
 (0)