2010年7月19日星期一

How to debug in Visual Studio

JavaScript Debugging in Visual Studio 2008
http://www.asp.net/aspnet-35/videos/javascript-debugging-in-visual-studio-2008

How Do I: Learn Tips and Tricks for Debugging in Visual Studio?
http://www.youtube.com/watch?v=4uyDBM-qTkk&feature=related

Visual Studio Debugging Tutorial
http://dotnetperls.com/debugging-1

It has many more options, including Call Stack, Command Window, Exceptions, and Autos. You can configure breakpoints to simply write messages to the console, or to keep counts of how many times they are hit. This is great for performance testing.

Here we note that the .NET Framework provides a variety of useful methods in the Debug class that can be used to hard-code debugging facilities in your programs. Some methods that you can use are Debug.Write and Debug.Assert. The benefit to these methods over the Console methods is that they are removed in Release builds of your application. You can find more details on these methods.

How to trace and debug in Visual C#
http://support.microsoft.com/kb/815788
You can also use the Trace class to produce messages that monitor the execution of an application. The Trace and Debug classes share most of the same methods to produce output, including the following:
WriteLine
WriteLineIf
Indent
Unindent
Assert
Flush

a Release Solution Configuration project only generates output from a Trace class. The Release Solution Configuration project ignores any Debug class method invocations.

To display the content of selected variables, use the Debug.WriteLine method.
Use the Assert method of the Debug class so that the Output window displays the message only if a specified condition evaluates to false.

Basic Debugging Features In Visual Studio 2005
http://odetocode.com/Articles/425.aspx

Another way to halt execution of a program is to ask the debugger to break when an exception occurs. By default, the debugger will only break if the exception goes unhandled, but this behavior is configurable. Select Exceptions from the Debug menu and you’ll see a tree display of all possible exceptions alongside checkboxes to indicate if the debugger should break when an exception “is thrown”, or only break if the exception is “user-unhandled”.

Breaking on exceptions can be useful when you are trying to track down an exception that occurs, but have not determined under what condition the exception occurs, or where the exception occurs.

DataTips are a transient display of information – once your mouse leaves the DataTip area the DataTip display will disappear.

A Watch Window will display an object’s state until you explicitly remove the object from the window.

The locals window will automatically display all local variables in the current block of code. If you are inside of a method, the locals window will display the method parameters and locally defined variables.

The Autos window (Debug -> Windows -> Autos) will display variables and expressions from the current line of code, and the preceding line of code.

A visualizer is a new way to view data in Visual Studio 2005. Some dataypes are too complex to display in a DataTip or watch window. For example, a DataSet is a tremendously complex and hierarchical object. Trying to drill into the 5th column of the 10th row of the 2nd table of a DataSet is cumbersome. Fortunately, a Visualizer exists for DataSet objects that will display the data in a more natural environment, namely an editable data grid.

Whenever a magnifying glass appears in a DataTip or watch window there is a visualizer available for the object. Double click on the magnifying glass to use the default visualizer. If multiple visualizers are available, you can click on the drop down chevron next to the magnifying glass and select which visualizer you’d like to use. For instance, a string will have three visualizers available: a text visualizer, an HTML visualizer, and an XML visualizer. There is also a visualizer for the DataSet and DataTable classes.

Improved Debugging with Visual Studio 2005's Debugger Visualizers
http://aspnet.4guysfromrolla.com/articles/011806-1.aspx

Visual Studio 2005 ships with four visualizers, a DataSet visualizer, which shows the contents of a DataSet in a grid, and three text-based visualizers: one for text, one for XML, and one for HTML. The screenshot below shows the XML Visualizer in action, which provides a much more readable view of the XML than simply squishing it all on one line.

Immediate and Command window in Visual Studio
http://dotnetdud.wordpress.com/2007/12/25/immediate-and-command-window-in-visual-studio/

The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window

The Immediate window is used to debug and evaluate expressions, execute statements, print variable values, and so forth. It allows you to enter expressions to be evaluated or executed by the development language during debugging. To display the Immediate window, open a project for editing, then choose Windows from the Debug menu and select Immediate.

It also includes a seemingly very complete list of commands and aliases that you can execute (for VS 2005 at least) - from either window, as far as I understand. Once of the nice features is that you can switch between the two windows simply by executing the cmd and immed commands.

In addition, see also the MSDN pages on the Command Window and the Immediate Window.

没有评论:

发表评论