Working with Breakpoints

 <  Day Day Up  >  

You use breakpoints to halt the execution of your program at a certain location in your code in order to inspect the values of any variables in your code as well as to view the order of statement execution, a process known as stepping . To add a breakpoint to a certain line, click in the left-side margin of the source window. A red dot appears at that location, and the corresponding statement is highlighted. If you later want to jump to the source code file where a certain breakpoint appears, you can use the Breakpoints tool window, which is accessible using the Debug, Windows menu item. You can also use this window to change the properties of the breakpoint if it is conditional.

Conditional Breakpoints

You can add conditional breakpoints that break only when a certain condition is met. To add a conditional breakpoint, right-click in the source window at the location to place the breakpoint and select New Breakpoint. Within the New Breakpoint dialog, click on the Condition button. The Breakpoint Condition dialog lets you enter a expression that is evaluated each time the program reaches that breakpoint. If the condition evaluates to true , then the program is halted at the breakpoint location. An example of where this is useful is a for loop. If you had a for loop that looped many times, but you were only interested in viewing the statement executions when the counter variable reaches a certain point, specify a breakpoint condition. The following code shows a for loop with a large range specified for the counter. To create a conditional breakpoint when the counter is above 100, use the expression i >= 100 :

 
 for( int i = 0; i < 1024; ++i ) {     someArray[i] += someArray[i+1]; } 

You can also add a breakpoint that only breaks after its location is passed a certain number of times. You use the same method described earlier, but instead of clicking the Condition button, click the Hit Count button. Within the Hit Count dialog, you can specify whether the breakpoint should stop execution all the time, only after a certain amount of hits occur, only when the hit count is a multiple of a certain number (useful, for instance, to only break every other hit), and if the hit count is greater than or equal to a certain value.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net