@@ -70,9 +70,9 @@ MiniDumper::MiniDumper()
7070 m_dumpThread = NULL ;
7171 m_dumpThreadId = 0 ;
7272#ifndef DISABLE_GAMEMEMORY
73- m_dumpObjectsState = 0 ;
73+ m_dumpObjectsState = MEMORY_POOLS ;
7474 m_dumpObjectsSubState = 0 ;
75- m_dmaRawBlockIndex = 0 ;
75+ m_currentAllocator = NULL ;
7676#endif
7777 m_dumpDir[0 ] = 0 ;
7878 m_dumpFile[0 ] = 0 ;
@@ -372,6 +372,8 @@ void MiniDumper::CreateMiniDump(DumpType dumpType)
372372 return ;
373373 }
374374
375+ m_dumpObjectsState = MEMORY_POOLS;
376+
375377 PMINIDUMP_EXCEPTION_INFORMATION exceptionInfoPtr = NULL ;
376378 MINIDUMP_EXCEPTION_INFORMATION exceptionInfo = { 0 };
377379 if (g_dumpException != NULL )
@@ -463,11 +465,12 @@ Bool MiniDumper::ShouldWriteDataSegsForModule(const PWCHAR module) const
463465// This is where the memory regions and things are being filtered
464466BOOL MiniDumper::CallbackInternal (const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP_CALLBACK_OUTPUT& output)
465467{
466- BOOL retVal = TRUE ;
468+ BOOL success = TRUE ;
467469 switch (input.CallbackType )
468470 {
469471 case IncludeModuleCallback:
470- retVal = TRUE ;
472+ case ThreadCallback:
473+ case ThreadExCallback:
471474 break ;
472475 case ModuleCallback:
473476 if (output.ModuleWriteFlags & ModuleWriteDataSeg)
@@ -478,63 +481,53 @@ BOOL MiniDumper::CallbackInternal(const MINIDUMP_CALLBACK_INPUT& input, MINIDUMP
478481 output.ModuleWriteFlags &= (~ModuleWriteDataSeg);
479482 }
480483 }
481-
482- retVal = TRUE ;
483484 break ;
484485 case IncludeThreadCallback:
485486 // We want all threads except the dumping thread
486487 if (input.IncludeThread .ThreadId == m_dumpThreadId)
487488 {
488- retVal = FALSE ;
489+ output. ThreadWriteFlags &= (~ThreadWriteThread) ;
489490 }
490491 break ;
491- case ThreadCallback:
492- retVal = TRUE ;
493- break ;
494- case ThreadExCallback:
495- retVal = TRUE ;
496- break ;
497492 case MemoryCallback:
498493#ifndef DISABLE_GAMEMEMORY
499494 do
500495 {
501- // DumpMemoryObjects will return false once it's completed, signalling the end of memory callbacks
502- retVal = DumpMemoryObjects (output.MemoryBase , output.MemorySize );
503- } while ((output.MemoryBase == NULL || output.MemorySize == NULL ) && retVal == TRUE );
496+ // DumpMemoryObjects will set outputMemorySize to 0 once it's completed, signalling the end of memory callbacks
497+ DumpMemoryObjects (output.MemoryBase , output.MemorySize );
498+ } while ((output.MemoryBase == 0 || output.MemorySize == 0 ) && m_dumpObjectsState != COMPLETED );
504499#else
505- retVal = FALSE ;
500+ output.MemoryBase = 0 ;
501+ output.MemorySize = 0 ;
506502#endif
507503 break ;
508504 case ReadMemoryFailureCallback:
509505 DEBUG_LOG ((" MiniDumper::CallbackInternal: ReadMemoryFailure with MemoryBase=%llu, MemorySize=%lu: error=%u" ,
510506 input.ReadMemoryFailure .Offset , input.ReadMemoryFailure .Bytes , input.ReadMemoryFailure .FailureStatus ));
511- retVal = TRUE ;
512507 break ;
513508 case CancelCallback:
514509 output.Cancel = FALSE ;
515510 output.CheckCancel = FALSE ;
516- retVal = TRUE ;
517511 break ;
518512 }
519513
520- return retVal ;
514+ return success ;
521515}
522516
523517#ifndef DISABLE_GAMEMEMORY
524- BOOL MiniDumper::DumpMemoryObjects (ULONG64& memoryBase, ULONG& memorySize)
518+ void MiniDumper::DumpMemoryObjects (ULONG64& memoryBase, ULONG& memorySize)
525519{
526- BOOL moreToDo = TRUE ;
527520 // m_dumpObjectsState is used to keep track of the current "phase" of the memory dumping process
528521 // m_dumpObjectsSubState is used to keep track of the progress within each phase, and is reset when advancing on to the next phase
529522 switch (m_dumpObjectsState)
530523 {
531- case 0 :
524+ case MEMORY_POOLS :
532525 {
533526 // Dump all the MemoryPool instances in TheMemoryPoolFactory
534527 // This only dumps the metadata, not the actual MemoryPool contents (done in the next phase).
535528 if (TheMemoryPoolFactory == NULL )
536529 {
537- ++ m_dumpObjectsState;
530+ m_dumpObjectsState = MEMORY_POOL_ALLOCATIONS ;
538531 break ;
539532 }
540533
@@ -558,17 +551,17 @@ BOOL MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
558551 if (m_dumpObjectsSubState == poolCount)
559552 {
560553 m_dumpObjectsSubState = 0 ;
561- ++ m_dumpObjectsState;
554+ m_dumpObjectsState = MEMORY_POOL_ALLOCATIONS ;
562555 }
563556 break ;
564557 }
565- case 1 :
558+ case MEMORY_POOL_ALLOCATIONS :
566559 {
567560 // Iterate through all the allocations of memory pools and containing blobs that has been done via the memory pool factory
568561 // and include all of the storage space allocated for objects
569562 if (TheMemoryPoolFactory == NULL )
570563 {
571- ++ m_dumpObjectsState;
564+ m_dumpObjectsState = DMA_ALLOCATIONS ;
572565 break ;
573566 }
574567
@@ -587,66 +580,61 @@ BOOL MiniDumper::DumpMemoryObjects(ULONG64& memoryBase, ULONG& memorySize)
587580
588581 if (m_rangeIter == TheMemoryPoolFactory->cend ())
589582 {
590- ++ m_dumpObjectsState;
583+ m_dumpObjectsState = DMA_ALLOCATIONS ;
591584 m_dumpObjectsSubState = 0 ;
592585 }
593586 break ;
594587 }
595- case 2 :
588+ case DMA_ALLOCATIONS :
596589 {
597590 // Iterate through all the direct allocations ("raw blocks") done by DMAs, as these are done outside of the
598591 // memory pool factory allocations dumped in the previous phase.
599592 if (TheDynamicMemoryAllocator == NULL )
600593 {
601- ++ m_dumpObjectsState;
594+ m_dumpObjectsState = COMPLETED ;
602595 break ;
603596 }
604597
605- DynamicMemoryAllocator* allocator = TheDynamicMemoryAllocator;
606-
607- // m_dumpObjectsSubState is used to track the index of the allocator we are currently traversing
608- for (int i = 0 ; i < m_dumpObjectsSubState; ++i)
598+ if (m_currentAllocator == NULL )
609599 {
610- allocator = allocator->getNextDmaInList ();
600+ m_currentAllocator = TheDynamicMemoryAllocator;
601+ // m_dumpObjectsSubState is used to track the index of the raw block in the allocator we are currently traversing
602+ m_dumpObjectsSubState = 0 ;
611603 }
612604
613605 MemoryPoolAllocatedRange rawBlockRange = {0 };
614- int rawBlocksInDma = allocator ->getRawBlockCount ();
615- if (m_dmaRawBlockIndex < rawBlocksInDma)
606+ int rawBlocksInDma = m_currentAllocator ->getRawBlockCount ();
607+ if (m_dumpObjectsSubState < rawBlocksInDma)
616608 {
617609 // Dump this block
618- allocator ->fillAllocationRangeForRawBlockN (m_dmaRawBlockIndex , rawBlockRange);
610+ m_currentAllocator ->fillAllocationRangeForRawBlockN (m_dumpObjectsSubState , rawBlockRange);
619611 memoryBase = reinterpret_cast <ULONG64>(rawBlockRange.allocationAddr );
620612 memorySize = rawBlockRange.allocationSize ;
621- ++m_dmaRawBlockIndex ;
613+ ++m_dumpObjectsSubState ;
622614 }
623615
624- if (rawBlocksInDma == m_dmaRawBlockIndex )
616+ if (rawBlocksInDma == m_dumpObjectsSubState )
625617 {
626618 // Advance to the next DMA
627- ++m_dumpObjectsSubState;
628- m_dmaRawBlockIndex = 0 ;
629- if (allocator->getNextDmaInList () == NULL )
619+ m_currentAllocator = m_currentAllocator->getNextDmaInList ();
620+ m_dumpObjectsSubState = 0 ;
621+
622+ if (m_currentAllocator == NULL )
630623 {
631624 // Done iterating through all the DMAs
632- m_dumpObjectsSubState = 0 ;
633- ++m_dumpObjectsState;
625+ m_dumpObjectsState = COMPLETED;
634626 }
635627 }
636628 break ;
637629 }
638630 default :
639- // Done, set "no more stuff " values
640- m_dumpObjectsState = 0 ;
631+ // Done, set "no more regions to dump " values
632+ m_dumpObjectsState = COMPLETED ;
641633 m_dumpObjectsSubState = 0 ;
642- m_dmaRawBlockIndex = 0 ;
643634 memoryBase = 0 ;
644635 memorySize = 0 ;
645- moreToDo = FALSE ;
646636 break ;
647637 }
648-
649- return moreToDo;
650638}
651639#endif
652640
0 commit comments