Useful Versus .NET Debugging Tools[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

Useful Versus .NET Debugging Tools
Breakpoints are great, but they're not enough. You need to be able to view
and modify data, find out how the execution path got you to the current
location, and what's going on in the environment. To help you out, Visual
Studio .NET provides many useful tools you can use while debugging. The
following subsections show some of the tools you may want to investigate.

Watching Variables Using Your Mouse
If you want to investigate the value of a simple variable while debugging
in Break mode, you could use the Immediate window or one of several other
windows. The simplest technique, however, is to simply hover the mouse
pointer over the variable. Visual Studio .NET will display a tool tip
containing the name of the variable and the value contained within the
variable. Figure 9.11 shows the tool tip while in Break mode.

Figure 9.11. Hover your cursor over a variable in Break mode to see the
value of that variable.


Watch Window
You can use the Watch window to view the value of variables and expressions
as your code is executing. This can be useful if you want to be able to
single-step through code, and for each line of code, investigate the value
of one or more variables or expressions. Use the Debug, Windows, Watch menu
to display the window shown in Figure 9.12. You can add new variables or
expressions just by typing within the Name column. You can also modify the
values of your variables (but not expressions, of course) by typing within
the Value column.

Figure 9.12. The Watch window can display the value of variables or
expressions.


TIP

Right-click a specific watch within the Watch window and select Delete
Watch from the context menu to delete it.



Adding Watch Values Using QuickWatch
If you are in Break mode and wish to view the contents of a variable or
expression in the current procedure, position your cursor on that variable
(or select the expression) and select Debug, QuickWatch. You will then see
a dialog box like the one in Figure 9.13, showing your watch
variable/expression. Click Add Watch to add a watch to the Watch window.

Figure 9.13. QuickWatch is great for looking up the value of an expression,
and it allows you to easily add a watch to the Watch window.


Call Stack Window
While in Break mode, Visual Studio .NET allows you to display the list of
procedures you have executed to get your current location. This is very
handy when you are not sure how you got to where you are. You can display
the Call Stack window, shown in Figure 9.14, by selecting Debug, Windows,
Call Stack.

Figure 9.14. The Call Stack window lets you see where you came from as you
debug an application.


TIP

The grayed-out procedures in the Call Stack window are procedures you
didn't call directly梩hey were called by the .NET Framework in order to get
to your code. You can double-click any of your own procedures in the Call
Stack window to have Visual Studio .NET highlight the procedure call within
your code.



Using the Command Window
The Command window (also known as the Immediate window) allows you to
perform simple calculations. Use the Debug, Windows, Immediate menu item to
display this window. You can also display or modify the value of a
variable. The statements you enter into the Command window may be any valid
Visual Basic expression. For example, you can print the results of an
operation, print the contents of a variable or property, or even set the
value of a variable or property. Use the "?" operator (which stands for
"print the value of the expression that follows") to display a value or to


run a function. Simply enter an assignment or method call that doesn't
return a value into the window to execute the expression. Figure 9.15 shows
the Command window in use.



NOTE

Unlike in Visual Basic 6.0, in Visual Studio .NET, you must be in Break
mode in order to enter text into the Command window. You'll also find other
differences. For example, you cannot delete lines in the Command window.
Right-click and use the Clear All context menu item to delete text from the
window.



Other Useful Debugging Windows
Visual Studio .NET provides even more windows and tools. Some of these are
tools you'll use every day; others are a bit more specialized and won't be
used as part of your daily routine.

Locals Window
If you wish to keep an eye on all the local variables in a procedure, you
can select Debug, Windows, Locals from the menu bar. This window, shown in
Figure 9.16, will display each of

本文关键:Useful Versus .NET Debugging Tools
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top