Edit & Continue trick for Conditional Bps

Using Edit and Continue to fix a bug is handy, but don't wait until you've found the bug to start editing.   One powerful technique is to use E&C when you are still trying to find the problem.  Edit and Continue allows you to make any conditional bp into a normal bp.  This is useful for two reasons. 

 

First, if you only have an Express Edition this is the only way you are going to get a conditional bp for managed code.  The C++ express edition does have conditional bps for native.  If you have a full edition it is still useful because conditional bps are sometimes just too slow. The debugger implements conditional bps by setting a breakpoint that is always hit, then evaluating the condition on each hit. If the location you want to stop at is a cpu hot spot, it may be too slow.

 

Here's an example using native C++ E&C to place a fast conditional bp:

 

First, a normal conditional bp:

 

int i = 0; // Instruction Pointer starts here

while(true)

{

i++;  // Conditional bp "i==10000" here, takes ~ 134ms on my machine

}

 

Now, using E&C (note 2 orders of magnitude are added to the condition so the time registers):

 

int i = 0; // Instruction Pointer starts here

while(true)

{

// Two lines below are added via E&C

if (i==1000000)

i=i; // bp here, takes 3 ms (including E&C apply)

i++;

}

 

Remember to delete your inline conditional bps once you are done debugging!