Poor man’s “Data” breakpoints in managed debugging

time to read 1 min | 160 words

One of the things that is really annoying with unmanaged code is that it is easy to overwrite memory that doesn’t strictly belongs to you. That can lead to interesting corruption bugs, especially if the problem occurs only a while after the actual change happened. This is why it is so good to have a memory breakpoint. That will force a breakpoint in the debugger when a particular memory location is written. However, in VS, those are only available for unmanaged code, not for managed code that directly manipulate memory.

Therefor, I resorted to using the following method, instead:

image

I run in the debugger, and issue this statement after every line, waiting for that value to change, which will tell me what line is the culprit.

Not as easy, but it works.