In my ever continuing quest of trying to abolish the need for use of Windbg for application debugging, I keep trying to find various debugging techniques using the VS2005 debugger.
Part one of this series contains instructions on how to have advanced conditional breakpoints. Conditional breakpoints are great when you need to break on something that is either global or in the immediate state, however, what do you do when you want to break in one function based on what happens on another function?
For this example, we will break on function f2(), but only if f1() was executed.
To do this, use the following steps:
1. Break at the beginning of your program (before any of the actual bps you want are hit) and go into the immediate window (Ctrl-Shift-I).
2. In the immediate window, type the following:
(Note that if you have a local variable or any symbol that is bpNeedToStop, you should choose a different name).
3. In f1(), place a breakpoint that will set the value of bpNeedToStop. To do this, we will use Conditional Breakpoints, but we will make sure they dont actually break (since it’s f2() we want to break into, not f1()). In the Condition of the breakpoint, type the following:
(bpNeedToStop = true) && false
4. Now go to f2() and place a conditional bp in the location you are interested in. In the condition type:
That’s it. Your program will now stop in f2() only if it first hit f1(). If you wish for the breakpoint to work again in that scenario, you will need to set bpNeedtoStop to false before continuing execution.
Also, if you are rerunning the program, you should remember to do step 1 again so that the debugger recognizes the variable.
Note: Forgot to add that this will work with C# in the debugger. If you are using VB.NET or C++, it should still be possible, but the syntax might be different.