• Welcome to Valhalla Legends Archive.
 

Heap debugging

Started by Arta, January 28, 2004, 01:36 PM

Previous topic - Next topic

Arta

Given that the file name and line number (presumeably where an allocation takes place) is stored on the debug heap in _CrtMemBlockHeader, shouldn't it be possible, when given a message such as...


DAMAGE: after Normal block (#2681) at 0x008AAB58.
Normal located at 0x008AAB58 is 8 bytes long.


...to find the nomansland buffer in which the damage occurs and thus find the block header for the memory you allocated after which the damage occured? Surely this would be immensely useful? I don't see a function under 'Debug Functions' in the documentation that does this.

Adron

Isn't that message printed as a debug string?

Arta

Yes. I've looked into this further, however, and found that CRT debug stack code doesn't make use of those fields, it just sets them to NULL. I've tried using _CRTDBG_MAP_ALLOC as well, but that just seems to map everything to the line inside ::new. I used allocation breakpoints to figure it out instead.

Adron

An alternative way would be to use windbg's heap debugging / page heap, and setting your application to use Windows' native heap. That way you can capture stack traces as well as breaking exactly when the corruption happens.