Debugging heap corruption
Vladimir Panteleev
thecybershadow at gmail.com
Sun Jul 29 00:03:01 PDT 2007
Hello,
I have a memory corruption problem. Namely, my application randomly crashes with access violations or the heap data is corrupted.
The application in question is sizeable (over 8000 lines). The crash is hard to reproduce (requires an amount of user interaction), however I've noticed that it always happens after a certain user action. I have thoroughly examined the code handling that action, tried modifying the code (adding asserts and .dups), but to no avail. I might as well expect that it's a bug in the compiler or Phobos.
I noticed that Phobos's GC has some debug code for "underrun/overrrun protection" [sic] in phobos\internal\gc\gcx.d, however I found that the code is unfinished. For some reason the corresponding code is put in "version (SENTINEL)" blocks, instead of "debug (SENTINEL)" ones - which would explain why it never worked (there is also a typo in code on line 567). Even with those obvious mistakes fixed, I have no idea how much work would be required to get the SENTINEL debug option working, since it's interfering with other language features such as array concatenation, and firing off false alarms.
Someone has also suggested GDB/Vargrind, however I haven't attempted this combination out of reasoning that since D's GC handles all the allocation and manages the memory, Valgrind wouldn't be able to hook the memory allocation routines and take over memory management from D's GC. If I reasoned wrongly, please let me know.
Has anyone met and fought heap corruption issues with D before? I could really use some advice, since I've been trying to solve it for weeks and it's causing me to lose motivation in my project :(
Any help is appreciated!
--
Thanks,
Vladimir mailto:thecybershadow at gmail.com
More information about the Digitalmars-d
mailing list