views:

127

answers:

3

I have a bug which happens very rarely but crashes my C++ program. It's seems I have a buffer overflow problem or something similar. I find that these types of bug are the most difficult to diagnose.

My program always crashes because of the same corrupted memory location. Is there some debugging tool which could detect when a particular memory location get written to and logs the function which does it?

I'm using Visual Leak Detector (VLD) for my memory leak hunting and it works great. It substitutes the original mallocs which its own and logs every allocation. I was wondering if there is something similar for memory?

I know that something like that would cripple a program, but it could be really helpful.

I'm using Visual Studio 2008.

+3  A: 

Many debuggers can watch a particular memory location, and break whenever the contents of that location are changed. Not sure about your particular toolchain, but gdb certainly supports this.

Thomi
gdb's scripting could particularly come in handy here.
Roger Pate
I'm using VS 2008 for this project.
rusbi
+3  A: 

If you are using Visual C++ then look up data breakpoints.

Goz
I just found it a minute ago, but thanks anyway! Should have googled a bit more before posting...
rusbi
+1  A: 

Valgrind is a tool that can detect problems like this. It's free, open source and easy to use.

Beta
... and Linux/Darwin only.
unwind
I think I heard about this one, but I'm using windows...
rusbi
Rats. Sorry about that.
Beta