BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Debugging
VS 2003+

Visual Studio Debug Mode

In addition to being a complex code editing tool, Visual Studio includes a debugger. This tool allows a program to be paused, then stepped through line-by-line whilst allowing you to monitor the values of variables, helping to identify bugs.

Controlling the Program Flow

Often you will create breakpoints to force the executing assembly to halt at a specific point in the code. However, occasionally you may want to run until a command is reached but will not want a breakpoint to be inserted. If you right-click the desired location, a context-sensitive menu will appear. Select "Run to Cursor" from this menu to run the program until the clicked position is reached. NB: If the position is never reached, the code may never halt.

You can also change the program flow to select the next command to execute. If you right-click a statement and select "Set Next Statement" from the menu that appears, the selected command will be highlighted as the next statement to process. In this case, any commands between the original position and the new location are ignored. You can even select a command that has already executed, moving backwards through the code.

Using the Locals Window

So far we have looked at how to navigate through the code of a program using the debugger. One of the primary purposes for this is to see the values of variables and object properties at different times to deduce where problems may be occurring. One of the ways in which you can see these values is by using Visual Studio's Locals window, pictured below:

Visual Studio Locals Window

The Locals window is displayed during debugging. If you cannot see it whilst the program is paused, open the Debug menu, select Windows and click the Locals option.

The Locals window shows a list of all of the local variables for the current method. The current value of each variable and its type are also shown. If the variable contains an object, the row in the window will be expandable to show all of the property values. You can also view this information by simply pointing at a variable using the mouse. In this case, a tool tip will appear containing the values.

In the figure above, you can see the values of the three variables declared in the Main method and the args array that is passed to the method as a parameter. The multiplied parameter is highlighted in red as it has just been modified.

23 October 2008