How to turn GCStress on in Windows 7?

2019-02-09 06:59发布

问题:

I am debugging a GC heap corruption and came to the step where I want to try running the program under WinDbg + PageHeap + AppVerifier + GCStress.

I found in the article Software crash: faulting module mscorwks.dll, version 1.1.4322.2379 that I can enable GCStress like this:

reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f  /v HeapVerify  /t REG_DWORD  /d 1  
reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f  /v StressLog  /t REG_DWORD  /d 1  
reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f  /v GCStress  /t REG_DWORD  /d 3  
reg.exe add "HKLM\SOFTWARE\Microsoft\.NETFramework" /f  /v FastGcStress  /t REG_DWORD  /d 2

(I am trying this method. It takes the program forever to launch. I deleted the last two entries from the registry to have it work, probably something is wrong with the approach itself.)

Or the article Access Violation in .NET 4 Runtime in gc_heap::garbage_collect with no unmanaged modules described the other method:

(DWORD) StressLog = 1  
(DWORD) LogFacility = 0xffffffff  
(DWORD) StressLogSize = 65536

Which way is correct or is there another correct way?

回答1:

I searched GCStress on Koders. It turned out the best way to understand it is by looking at .NET's source code:

enum  GCStressFlags {
    GCSTRESS_NONE               = 0,
    GCSTRESS_ALLOC              = 1,    // GC on all allocations and 'easy' places
    GCSTRESS_TRANSITION         = 2,    // GC on transitions to preemtive GC
    GCSTRESS_INSTR_JIT          = 4,    // GC on every allowable JITed instruction
    GCSTRESS_INSTR_NGEN         = 8,    // GC on every allowable NGEN instruction
    GCSTRESS_UNIQUE             = 16,   // GC only on a unique stack trace
};