Friday, February 27, 2009

Debugging Tools for Windows

Some pretty good debugging tools for windows can be found here.

Most importantly the use of umdh.exe to find memory leaks in your application.

Steps are pretty simple :

1. Install debugging tools.
2. Set gflags -i yourapp.exe +ust
3. Run app and find a good place to halt it where your baseline memory should be.

4. Get a heapdump of it. umdh -pn:yourapp.exe -f:first.log
5. Run the stuff where you want to find leaks for. Then return to where the baseline should be.
6. Get another dump. umdh -pn:yourapp.exe -f:second.log
7. Test the first dump against the second ump. umdh first.log second.log > compare.txt
8. Look at compare to see what still has allocations in the heap.
9. Look in second.log and find the Baseline that is in compare if there is any. You should be able to see the function that called the alloc/new. That's it.

Also not to be left out since I found this after writing this.

How to use pageheap.exe. This should help you find other things like, double free, overruns and underruns.

If you're willing to actually use a memory manager in your code. You can try Paul Nettle's MMGR.

And if all else fails, you could always try a commercial app like Memory Validator.