This section of the archives stores flipcode's complete Developer Toolbox collection,
featuring a variety of mini-articles and source code contributions from our readers.

More About MSVC Conditional Breakpoints
Submitted by

I wanted to supplement Jayson Smiths TOTD by focusing on a particular type of
conditional breakpoint and demonstrating it with a clear example.

Sometimes you find yourself trying to track down where a variable gets
unexpectedly modified or corrupted. It can be pretty hard to find. You could
temporarily load up your code with debug prints and asserts, but there is a much
better way.

Let me demonstrate with an example. Say we have a integer variable called
Counter that is getting corrupted (set to an unintended value) somewhere deep in
the code.

Set a breakpoint where Counter is initialized. Then obtain the address of this
variable. In this case we could get this by adding &Counter to the watch window.
Say it tells us that the address is 0x00d24ea0.

We then go to the breakpoint dialog, click on the data tab, and enter the
following into the expression window:

*((int *) 0x00d24ea0)

When we continue execution, the program will break whenever this expression
changes.

The (int *) cast is necessary for us to instruct the debugger about the size of
this thing we are interested in. So here we are saying 0x00d24ea0 points to an
int. Breakpoint when that int changes.

Step past this breakpoint repeatedly until you find the spot at which something
unexpected happens to your variable.

Obviously this technique is not so useful when the variable is modified very
many times before being corrupted, but on occasion it allows you to arrow in on
a bug very quickly.

Theres nothing secret about this technique, but if I have persuaded a few more
coders to use it, then I will be content!

Mean Fox

The zip file viewer built into the Developer Toolbox made use
of the zlib library, as well as the zlibdll source additions.