BreakPoints - makes your development easier
What are breakpoints and how can we efficiently work with them and use them to make your development easier and faster? This article will include points like debugging tips, execution control transfer, stepIn and stipOut through methods and other usage of debugger.
Really it's very difficult task to find out the exact code line which gives you error. Many times there are ocean of code on a single page. To solve such a problems, DEBUGGER sort out the issues. Debug is the process of tracing code line by line with dynamic object values. Here in this article i have used Visual Studio 2010 debugger. VS2010 editor provides us strong debugging techniques that helps to make development easier.
in this article we will see what is breakpoints how to use it and some nice tricks that will reduce our development time.What is Breakpoint
Break point is a point where your code take pause and wait for the next command. From this point onwards you can step by step debug the code.
Get dynamic values of objects. Visual studio provides us many features such as Labeling breakpoint, Pinned DataTip, Multithreaded Debugging, Parallel debugging and IntelliTrace. How can i use Breakpoints
Using debugger is very easy. Just open your code select the line where you want to put break point, put cursor on that line and press F9 . that's it.
Or right the line select Breakpoint and click on insert breakpoint
check following snap to put debugger point.
Breakpoint is used to notify debugger where and when to pause the execution of program.
now just hit F5 to run the code the code will automatically take pause at break point from now onwards you can use F10 or F11 buttons to trace the code.
where F10, will step over debugging and F11 is step into debugging.
by using F10 we can skip the inner calling code and continue main source of line code but with the help of F11 we can step into code and debug the inner codes line methods, classes, properties, enum, structures.
check following snap in which we can take the use of F10 and F11
if you place a 'break point' in your code but you don't want to debug your code then you press F5 to continue execution.Tricks that help you
Following are some useful debugging tools and Tricks that helps you more.
Set Next Statement
"Set Next Statement" allows you to change the execution path means you can change the execution flow, just right click on line to which you want to execute directly and click on "Set Next Statement". you will see execution comes to that line without executing the previous lines of code. This is quite useful when you found some line of code may causing breaking your application.
Labeled breakpoints
This is the new features in visual studio 2010. if you are dealing with a huge code and put lots of debugger in it then it may be confusing for you to identify the debugger from debugger window. To solve this conflicts we have labeling facility in debugger and directly we can jump on particular source code line using debugger. Just right click on debugger and give label, check following snap.
Conditional breakpoints
This is the most wonderful features of debugger which will save our development time, most of the developer may not about it.
when we debug very large code with iteration in it and we have to stop debug only at specific time or only at specific conditions then ew can use this facility. So if and only if that condition is satisfied, the debugger will pause the execution. To start with this right click on debugger and click on "Hit Count" and a window will open which contains a conditions when the break will hit, give the counter number and click on ok.
now run the program and see the magic. in following snippet the debugger will stop when hit count is 70
we have seen the condition of counter, here we can also give condition of string comparison also. Just right click on debugger and click on "condition" a window will appear with Break point condition choose "Is True" or "Has changed" condition and your debugger is ready to use and follow the condition you have given. in following example the debugger will stop only if "iCount" value is 70
Debugger hitcount gives us different inbuilt conditions to stop debugger
1. Break always
2. Break when the hit count is equal to
3. Break when the hit count is multiple of (used when we want to check odd/even conditions)
4. Break when the hit count is greater than or equal to.
we can take the advantage of hitcount and can save our coding time and improve code debugging.
Sometimes, you may need to specify too big or complex conditions also. visual studio provide a intellisense In Condition Text Box.
press some character in condition textbox and press Ctrl+space it will open the suggestion window for you.
Summing up
Debugger is the very powerful features of visual studio, we can use it to check stepwise flow of our program and can reduce or development time.
we have seen the use of step over and step into flow, Hitcount, conditional break point, labeling to breakpoint, SetNextStatement But still there are lot of features of breakpoint are remaining like Pinup variables, adding comments while debugging, last run debugging value, other debugging windows like local, autos, watch, Immediate Window, call stack, shortcut keys for debugging etc.
we will cover all remaining points in next version of this article.
Suggestion and Queries always welcome.