@@ -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
521519void 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