Presentation is loading. Please wait.

Presentation is loading. Please wait.

Visual Studio: Custom debugger visualizers. Creating Debugger Visualizers with Visual Studio : Introduction Code debugging is one of the most important.

Similar presentations


Presentation on theme: "Visual Studio: Custom debugger visualizers. Creating Debugger Visualizers with Visual Studio : Introduction Code debugging is one of the most important."— Presentation transcript:

1 Visual Studio: Custom debugger visualizers

2 Creating Debugger Visualizers with Visual Studio : Introduction Code debugging is one of the most important parts of any development life cycle because it gives you the technique to find the problem and how to resolve it. When we talk about the visual debugging Visual Studio has tremendous potential in the term visual debugging features in the form of DataTips. DataTips tool provide a handy way to view information about your variables in visual studio during debugging only. In old versions of Visual Studio DataTips were limited in the amount of the information they could display. Now in Visual Studio particularly after VS2005 DataTips have been enhanced to give more detail information about the simple and complex variables. By the help of DataTips tool programmer easily visualize different variable data types in their Visualizers. One of the very many cool new features in Visual Studio 2005 is the debugger visualizer. With debugger visualizers, developers are able to define what information they would like to see about a particular.NET class or even one of their own classes during debug mode. And as the name suggests, you can also choose how you would like to visualize these details.

3 Visual Studio has some pre-existing visualizers that you will discover during debug mode. You can access the visualizers by using a dropdown list on the left side of the new DataTips between the selection and its value. For example, if you point to a string object in Debug mode as in below snapshot, you will have access to three pre-existing debugger visualizers: Text, XML and HTML. You can also access visualizers through the Watch windows. Figure 3 shows the DataTip's Watch window where you can see the _stringvalue property of a StringBuilder object. When you select the XML visualizer, you will get a better view of the XML-formatted string, demonstrated in below figure:

4 4 An XML visualizer displays XML in a format that is perfectly readable. Another handy visualizer that Microsoft has already written and included with the Beta1 version of Visual Studio is for DataTables and DataSets. Something that surely many developers have considered this visualizer presents a quick way to see the contents of a DataTable. Though they are named "DataSet visualizer" and "DataTable visualizer," they present the same UI. These two visualizers are read-only. The screenshots in a DataSet visualizer in Figure 5 and Figure 6 show how you can select the various DataTables within a DataSet to view. Microsoft has also provided pre-written visualizers for DataSets and DataTables.

5 5 The Dataset and Datatable visualizer shows a grid view of the actual data. You can access all Datatable(s) in a Dataset through the Dataset visualizer's interface:

6 6 The real beauty of debugger visualizers is that you can write your own. You can create debugger visualizers to display information about.NET Framework classes or your own custom classes. Debugger visualizers inherit from the DialogDebuggerVisualizer class which is part of the Microsoft.VisualStudio.DebuggerVisualizers assembly. Note that Microsoft did not include this assembly with the current Express versions of Visual Studio. Since you will need to compile and deploy your visualizers, they are not written in the same project or the same solution as the projects that will actually use them. After you write the required code to identify the visualizer and what class it will work with, you can write whatever code you wish to create the display information. As an example, the next-coming snapshots (i.e. Figure-A and Figure-B) demonstrate two custom visualizers that show some helpful metadata about a Datatable object: “Out-of-the-box" Visualizers : Roll Your Own Visualizers using C#

7 7 Figure – A (This custom visualizer displays useful metadata of a DataTable inside a MessageBox): Figure – B (This custom visualizer displays useful metadata of a DataTable inside a Win-Form):

8 8 With the pre-existing visualizers given by the Visual Studio Framework, if someone wants to debug/see the content of an Image’s object, one can not see any visualizer for this image object: Please note that In the above image Visual Studio debugger not able to load image visualizer because as there is no visualizer available. But you can also customize the visualizer to debug the image data to view the exact image and its other details like height and breadth features. When you debug the image and click “Image Visualizer” option as below:

9 9 You will get the image in debug-mode, on windows form as:

10 10 Building a Debugger Visualizer A few ground rules: Each debugger visualizer is a separate class. You can combine multiple debugger visualizers for the same class into one project/assembly. Debugger visualizers for different classes must reside in a separate project. You may have multiple assemblies targeted to the same class. To write a custom Image visualizer, please follow the following steps: 1.Create a Class Library project in Visual C#. 2.Name it “ ImageVisualizer ”. 3.Add following Assemblies References. a)Microsoft.VisualStudio.DebuggerVisualizers.dll b)System.Drawing.dll c)System.Windows.Forms.dll 4.Rename the class1 to ImageDebugger.cs 5.Your class must inherit from the DialogDebuggerVisualizer class and also must override the Show method from that class.

11 11 Your code will look like : Please add one assembly as shown below so that it helps your DLL to be recognised as one of debugger visualizers and after doing your custom coding, build this to have updated DLL

12 12 Deployment of Visualizer Copy the DLL to either of the following locations: Install path\Microsoft Visual Studio 9\Common7\Packages\Debugger\Visualizers\ — or — My Documents\Visual Studio 2008\Visualizers\

13 13 Test Visualizer (Custom) Please follow the following steps: 1.Create a new VS solution and project (Windows Forms Application) 2.Give it name as “ImageVisualizerDemo”. 3.And write the following code and set the breakpoint on as below snapshot: Run the program and you will find debugger on the breakpoint as below:

14 14 You can clearly see the new Image Visualizer in the preceding image and click on the magnifying glass icon and get output, as below:

15 15 Conclusion This feature was first introduced in Visual Studio 2005 onwards. With all that is new and exciting feature about Visual Studio.NET. Hope the team members developers will realize the beauty of this class. Sample code will be available for your further reference, if anybody is interested. Some useful links for your reference:  http://keyvan.io/how-to-write-a-visual-studio-visualizer http://keyvan.io/how-to-write-a-visual-studio-visualizer  http://blogs.msdn.com/b/scottno/archive/2004/04/17/115328.aspx http://blogs.msdn.com/b/scottno/archive/2004/04/17/115328.aspx  http://blogs.msdn.com/b/deeptanshuv/archive/2005/03/21/400194.aspx http://blogs.msdn.com/b/deeptanshuv/archive/2005/03/21/400194.aspx

16 16 “ Thank You ”


Download ppt "Visual Studio: Custom debugger visualizers. Creating Debugger Visualizers with Visual Studio : Introduction Code debugging is one of the most important."

Similar presentations


Ads by Google