Click here to Skip to main content
Click here to Skip to main content

Help Yourself in Debugging (Part-2) using Breakpoint/Tracepoint

, 18 Nov 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Help Yourself in Debugging (Part-2) using Breakpoint/Tracepoint
Read Part 1 : Help yourself in Debugging by using Call Stack and Immediate Window
In this post I am going to discuss about the “BreakPoint” which is one of the most used feature by developer to debugging application by breaking execution of program runtime at certain point. I am going to describe the feature provided in visual studio for breakpoint and how it’s useful for debugging code easily.

What is Breakpoint?
Breakpoint is feature provided in Microsoft Visual Studio which allows breaking execution of code at runtime when debugging application.

For Example:

When you click on side of the code in visual studio it setup break point in you code as displayed in above image. So when you start execution code it will break execution at this point.

BreakPoint Menu (Option for the Break)



Above image display the context-menu for breakpoint i.e breakpoint menu. Following describe the all the option one by one.
  1. Delete Breakpoint
  2. This option of the breakpoint menu allows removing breakpoint.
  3. Disable Breakpoint
  4. This option of the breakpoint menu allows disabling breakpoint, so the breakpoint just get disable and become gray. Useful when developer just want to execute code without stopping at breakpoint and later on enable when want to use it back.
  5. Location…
  6. This menu option allows setting break point at given location i.e. at given line in source code file.



    When click on the menu it display dialog that provide information about source code file, line number in code and character. This dialog allows changing line and character information.

    For Example:


    Change line number to 26 in the in dialog than it breakpoint change to line number 26.



  7. Condition…
  8. When this option clicked it below dialog get displayed which has two options.
    • (A).   IS true
    • This option allows setting condition for breakpoint, so according to this execution during debugging get stopped at breakpoint i.e. breakpoint get hit when condition satisfied.

      Fox Example:


      As in above image condition set is “i==1000” that means this breakpoint get hit when this condition is true i.e. satisfied.

      This is very helpful when you want to stop execution of the application when certain condition met specially as in example loop having many number of element and want to stop at given location.

      Once condition set breakpoint displayed as below.



      Breakpoint changed to read icon having + sign in it. When mouse get over on breakpoint visual studio display information related to breakpoint with condition in tooltip.
    • (B).   Has changed
    • This option allows breaking execution of code at breakpoint when there is change in the variable or object.

      For Example:


      Over here variable “i” is entered in the dialog i.e. if the value of variable “i” get changed than execution of program get stopped at breakpoint.

      Below image shows the tooltip on breack point once condition set.



      When this option utilize than in breakpoint context menu condition option get check as in below image.


  9. Hit Count…
  10. This option display count number of time breakpoint hit when executing program.



    This dialog box has three options which allow to set hit count and if the hit count matches than program execution get stop at breakpoint. Each option is self-explanatory you can see in following image.



  11. Filter…
  12. This option allow to set condition related to “Machinename and Process” according to which breakpoint get hit. Following image explain more detail about it.



  13. When Hit…
  14. This option allows setting the message than get print to output window when program executions pass the breakpoint.

    This option converts breakpoint to Tracepoint i.e. so the developer can do tracing of the import variable or things by printing message on the output window when code at trace point get executed.

    For Example:


    As in above image to read value of the variable developer created message that get printed on output window each time code in for loop get executed.

    You can read the text in dialog which also provides information about how to provide information in the textbox so that it gets print to output window.

    Once developer press ok by setting the tracing message breakpoint get display like square as in below window.



    So when this program gets executed in visual studio, messages get printed to output window as shown in below image.



  1. Edit Labels…
  2. This option allows setting label for your breakpoint. So it display dialog like this.



    This is helpful when developer exporting breakpoint from visual studio, help to remember how important breakpoint it via label, create of useful breakpoint by using same name etc.
  3. Export…
  4. This option allows exporting breakpoint set by developer.



    This exported breakpoint information get saved as “XML” as show in above image. Exported XML file for breakpoint look as below



    This option is helpful when developer want to export breakpoint and save it as XML than remove it. When there is need to same breakpoint he/she can load same breakpoint by loading XML file using Debug window of Visual studio.
BreakPoint window
Breakpoint/tracepoint set by developer in code is get displayed by this window. This window also displays breakpoint with other information.

Following is way which shows how one can start breakpoint window.



So one can either use debug menu and start breakpoint window or make use of short cut Ctrl+D,B.

Following is image of breakpoint window.



This window also has toolbar which allows following, which is also supported by breakpoint menu discussed above.
  1. Set new breakpoint
  2. Remove breakpoint
  3. Delete all breakpoint
  4. This option allows to delete all breakpoint which is selected in breakpoint grid.
  5. Enable/Disable breakpoint
  6. Export breakpoint
  7. Import breakpoint
  8. This option is not part of the breakpoint menu; it is used for importing breakpoint/tracepoint.



    When this button clicked by developer, visual studio open file browser window to browse xml file for breakpoint / tracepoint.



    So after loading this file breakpoint/tracepoint get set again in the code.


  9. Go to Source Code
  10. Go to Diassembly
  11. Columns
  12. This tool menu allows to set number of column in the below grid i.e. in breakpoint window grid which is below toolbar.



  13. Search
  14. Search allows searching breakpoint in the breakpoint grid of breakpoint window. Following is image of the same. As per the criteria specified breakpoint grid window display searched breakpoints.




Breakpoint Grid

This grid window displays all the breakpoint set by developer in source code. This grid provides information about each breakpoint according to columns set by developer in grid.



Conclusion

Breakpoints/tracepoints are very useful feature provided in visual studio, which is very usefl when you are debugging large amount of code. Visual studio provides flexibility to break execution of the code during debugging at breakpoint which is very helpful to the developer.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pranay Rana
Software Developer (Senior) GMind Solusion
India India

Microsoft C# MVP (12-13)

 
Hey, I am Pranay Rana, working as a ITA in MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.
 
For me def. of programming is : Programming is something that you do once and that get used by multiple for many years
 

You can visit my blog

StackOverFlow - http://stackoverflow.com/users/314488/pranay
My CV :- http://careers.stackoverflow.com/pranayamr
 
Awards:


Follow on   Twitter   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141216.1 | Last Updated 18 Nov 2013
Article Copyright 2013 by Pranay Rana
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid