What MDAs are useful to track a heap corruption?
Asked Answered
C

2

1

I have a heap corruption in a .NET/C# program and cannot track it with WinDbg + PageHeap + Application Verifier. In the next step, I plan to use Managed Debugging Assistants (MDAs).

Currently I try using these MDAs:

<gcManagedToUnmanaged />
<gcUnmanagedToManaged />
<invalidVariant />

(Having these MDAs enabled makes the program run very slowly.)

Are there any other I can try in this case?

Cairn answered 26/9, 2011 at 18:15 Comment(1)
Yes, this will make it very slow, it calls GC.Collect() on every unmanaged code transition. Advantage is that the program crashes a lot quicker when unmanaged code writes into the GC heap. gcUnmanagedToManaged is the only one that's really useful. Disadvantage is that the corruption now might no longer occur.Grodno
C
3

As Hans Passant pointed out, the primary MDA for such cases would be <gcUnmanagedToManaged>. However, this MDA makes the program run very slow. Actually, the program becomes unusable (it takes "forever" to draw the program interface), thus it won't work in production. Visually this MDA is as slow as GCStress.

Other useful MDAs (work must faster):

<callbackOnCollectedDelegate />
<invalidOverlappedToPinvoke />
<overlappedFreeError />

To learn more about available MDAs and their detailed description, refer to the MSDN article Diagnosing Errors with Managed Debugging Assistants.

A good article on how to set MDAs for a program is Managed Debugging Assistants in .NET 2.0.

And finally, how to activate MDAs in the system, see Stack Overflow question .NET/C#: How to set debugging environment variable COMPLUS_HeapVerify?.

Cairn answered 7/10, 2011 at 18:9 Comment(0)
G
0

Try one of the commercial tools such as Red Gate's ANT's Memory Profiler or Jetbrain's DotTrace. I use ANTs Memory Profiler and was able to detect the memory leaks and fix the code that was causing the memory leaks, which may eventually lead to heap corruption. Here is an article on finding memory leaks using ANTs Memory Profiler

Gonadotropin answered 26/9, 2011 at 18:56 Comment(1)
That doesn't help, memory leaks are easy to detect. Heap corruption is much, much harder to diagnose, a memory profiler is useless.Grodno

© 2022 - 2024 — McMap. All rights reserved.