The Science of Debugging
Chapter 7


7.5.2 Advanced Breakpoints

On to advanced breakpoint usage. Perhaps it's the fact that most of the advanced breakpoint options are hidden in menus or that most windows programmers I know aren't really interested in actually debugging their work. (Guess how many people I know who work for Microsoft ... things start to make sense). Either way, the more advanced features of MSVC's breakpoints are just not used that often; people usually write their code and perform their debugging in such a way to avoid their use altogether.

I'm going to take a wild guess and assume that it's because they're not out in the open.

That having been said, here's how you get to the flashy breakpoint option window; go to Edit Breakpoints. For something that's only one level deep, I have yet to see anyone actually use it. With our example from before, it'll look a litle something like this:

Not much there, huh?

What we can see here is all the breakpoints on all your code (we only have one, on line 13), as well as turn them on or off. All of which you can also do by simply looking at the code, clicking on the line of code and selecting a menu button, or using our shortcut key (F9). So, why are we here? Simple - that 'conditions' button. Press it. You know you want to. You'll have to have a breakpoint selected first though. You'll get another exciting, flashy, er..rather dull and boring dialog box like this;

It looks simple, but it's really quite confusing. Let's start with the easy one, the 'skip' bit. Enter a number in here. The breakpoint won't be thrown until the code passes through this point that many times. That way, you can break at the 99'th iteration of a loop, instead of having to hit F5 98 times before getting to the state you really wanted to look at!

The next tag we'll deal with is the 'Expression' line. It's difficult to explain the full range of operations you can perform here , but in brief, type in any expression. This can be a variable, or a mathematic expression (using variables). If you just type in "i", for example, this breakpoint will be triggered any time "i" changes it's value. Pretty cool.

The remaining tag, relating to the number of elements in an array, allows you to do whatever checking you'd like over a range of values contained in an array. Setting it to "1" insures that you'll only select that one item listed in the Expression line. Usually, you'd use it to check activity in an array. An example for an array of size 50; expression = "array[0]", number of elements in the array = 50. This way, the breakpoint is triggered any time there's any change in any of the values in the entire array.

Colloquially, breakpoints that are triggered when data values change are called "Watch points," so it's good to recognize that phrase if you're going to talk to anyone else about them.

One last thing; if you click on the little right-pointing arrow to the right of the Expression window, you'll pop up a small menu, from which you have one selection choice; "Advanced". Clicking on advanced brings up a dialog box letting you specify placing a breakpoint on a function, file, line, and others. It's not used too much, so I'll skip it. For those truly interested though, you can even set breakpoints on memory addresses and the sort - you may want to check out the Data tab in the main dialog box if this interests you.



Index
7.5.1 Breakpoints Examining the Stack 7.5.3 Stepping Through Code