views:

148

answers:

3

Hi,

I have a bunch of generic code that is used a lot, which i'd like to poke into in order to deal with a bug in a certain specific case.

So I'd like to break on a set of breakpoints only if some other breakpoint has been hit. Is there a way to do this in Visual 2005? I'm using C++ code.

Thanks!

+2  A: 

Have your first breakpoint change the value of some variable to a magic value (you can use a conditional breakpoint, with an expression which changed the variable and then returned true). Then, have the second breakpoint break when the variable is at that magic value. e.g.,

int debug_flag = 0;

First breakpoint condition:

debug_flag = 0xdeadbeef, true

Second breakpoint condition:

debug_flag == 0xdeadbeef
Chris Jester-Young
the breakpoints are in much different areas of code. i guess i might be able to use a global variable though. i was hoping there was some way to do it without modifying the code.
evilfred
Yeah, you'd probably use a global variable. If you just create a new .cpp file with just that global variable, and arrange to link it into your program, you don't have to modify any other code.
Chris Jester-Young
+3  A: 

If the trigger logic is complex enough, sometimes I find it easier to just add a DebugBreak(); call into the source.

Jeff Youel
+1  A: 

Please remember you can disable a breakpoint - it might be easier/more efficient/cleaner (then adding debug flags to your code and recompiling for example) to just disable the second breakpoint, wait till the first one breaks and then enable the second one in your breakpoints window - it takes just two mouse clicks each time you debug... :)

RnR