background preloader

Debugging

Facebook Twitter

Mastering in Visual Studio 2010 Debugging « Abhijit's World of .NET. Visual Studio IDE gives us a lot of tools to debug our application. Sometimes debugging activity takes a very long time to identify the root cause. But VS IDE provides a lot of handy tools which help to debug code in a better way. Debugger features include error listing, adding breakpoints, visualize the program flow, control the flow of execution, data tips, watch variables and many more. Many of them are very common for many developers and many are not. In this article, I have discussed all the important features of VS IDE for debugging like Breakpoint, labeling and saving breakpoints, putting conditions and filter on breakpoints, DataTips, Watch windows, Multithreaded debugging, Thread window, overview of parallel debugging and overview of IntelliTrace DebuggingNote : This article is also Published @ CodeProject Table of Contents Introduction In the software development life cycle, testing and defect fixing take more time than actually code writing.

Now how to debug the code? Step Over. How to track an object which is Out of Scope while Debugging ? « Abhijit's World of .NET. In Mastering in Visual Studio 2010 Debugging article I have discussed about the basic of Object ID creation while debugging. I received some request from some readers to explain the use of “Make Object ID” in details. In this blog post I am going explain how we can track an Object which is already out of scope using by creating a Object ID while debugging.

By using “Make Object ID” option we are informing Visual Studio Debugger to keep track of that object no matter it’s within scope or out of scope for the current context. We can create “Object ID” either from Locals, Autos or from Watch Windows. Object ID is a integer number followed by a pound (#) sign. When we create Object ID for an particular object, Visual Studio Debugger ( CLR Debugging Services ) use an integer value to uniquely identify the object.

This “Object ID” allows you to get the object details even if it is out of scope. Let’s explore this with the help of below code block Creating Object ID Using Object ID Thanks ! 10 Tips you should know about “Watch Window” While debugging in Visual Studio « Abhijit's World of .NET. Watch windows is one of most commonly used debugging tool with Visual Studio. We generally used to explore the objects, values, properties and other nested objects as a tree structure. Most of the time we used watch window to only view the values or change the current object properties values to see the effects of changed object during debugging. But we can use watch windows for many different purposes. In this blog post I am going to show 10 Tips, that may help you while dealing with Watch Window. Tips 1 : Calling Methods From Watch Window As I said earlier, most of time we used watch window to explore the objects and it’s properties but we can call a methods from watch window as well.

As you can see from the above image, when you have typed stud object, you are able to access all the properties and methods that is accessible by the original object. As for example, you can pass the proper marks inside AddMarks() methods to get the result details as shown in below image. Thanks ! Like this: Customize the Debugging Windows : Change Debugging Window View as per your requirements « Abhijit's World of .NET. Namespace DebugWindowCustomizationDemo class Program static void Main(string[] args) List<Student> student = new List<Student>(); student.Add(new Student { Roll = 1, Name = "Abhijit", Marks= new Marks {Subject1=56,Subject2=66,Subject3=67} , Addresses = new Address { City = "add1", Pin = 312312 } }); student.Add(new Student { Roll = 2, Name = "Abhishek", Marks = new Marks {Subject1=78,Subject2=66,Subject3=67}, Addresses = new Address { City = "add3", Pin = 123123 } }); student.Add(new Student { Roll = 3, Name = "Rahul", Marks = new Marks {Subject1=78,Subject2=43,Subject3=77}, Addresses = new Address { City = "add5", Pin = 123123 } }); student.Add(new Student { Roll = 4, Name = "Sunil", Marks = new Marks {Subject1=74,Subject2=96,Subject3=57}, Addresses = new Address { City = "add11", Pin = 57567 } }); student.Add(new Student { Roll = 5, Name = "Atul", Marks = new Marks {Subject1=78,Subject2=76,Subject3=47}, Addresses = new Address { City = "add12", Pin = 57567 } }); /// <summary> /// </summary> get.

Few Tips on Customizing Debugging Window View in Visual Studio « Abhijit's World of .NET. In this post I am going to discuss about few tips on customizing debugging debugging windows. This may be very helpful during debugging of application. While debugging, you may want to simplify debug window or you may want to clean up all the unnecessary fields that are not important during debugging from debugging windows. Here is few tips for customization of debug window. Use DebuggerBrowsable attribute to customize the debugging windows Use DebuggerDisplay attribute to customize the debugging display. To use above attributes you have to use System.Diagnostics namesapce 1.

If you want to customize the view on debugger window for any properties during debugging you can easily do it using DebuggerBrowsable attributes. We can provide three state for DebuggerBrowsable attributes. 1. If we set DebuggerBrowsableState as collapsed, then debugger window will show the element as collapsed. it’s the default behavior. 2. 3. You can read the complete definition of these DebuggerBrowsableState at MSDN. Tips on Debugging : Using DebuggerHidden attribute « Abhijit's World of .NET. DubuggerHidden attribute tells the Visual Studio debugger that the method is hidden from the debugging process and while debugging.

This is quite helpful when you don’t want to go to stepping inside of a method while debugging. When you mark a method with DebuggerHidden() attributes, It’s explicitly tells the debugger not to step inside of that methods and no break point will be hit over that method. Now I am going to explain the same using a Example with Intellitrace debugging. Let’s consider you have below code snippet We have set two break points in each of the method ( Line 22, and Line 31 as shown ) . As per the above image, you can see the flow of the application from Main() > Method1() > Method2() . Now, If you don’t need to go inside Method1() while debugging and debugger should not stop inside method1() for any of the breakpoint, you have to add “DebuggerHidden()” attributes with the method1(). Hope this will help you. My Other’s Articles on Debugging : Like this: Like Loading... Tips on Debugging : Using DebuggerStepThrough attribute « Abhijit's World of .NET.

In my few previous blog post I have explained how we can customize the Debugging windows view during debugging of application using “DebuggerBrowseable “ attributes and “DebuggerDisplay” , then I have also explained use of “DubuggerHidden” attribute which tells the Visual Studio debugger that the method is hidden from the debugging process and while debugging. In this blog post I am going to explain one similar features of “DebuggerHidden” attributes, named “DebuggerStepThrough” Marking a piece of code using DebuggerStepThrough attribute tells the Visual Studio debugger that, the code block will be stepped over from debugging process. you can mark methods, properties with DebuggerStepThrough attributes where you don’t want to stop your code to break.

If there is any break point inside a code section which is marked as “DebuggerStepThrough” attributes, that code block will be marked as “[External code]” in stack Trace. Where as “Debugger hidden” attributes didn’t marked is External code.