|
Page 2 of 3
.
.
.
Analyzing Program State to Resolve Errors
The Visual Studio debugger is a powerful tool that allows users observe the state of the program and locate logic errors. The debugger works with all Visual Studio programming languages and their associated libraries. With the debugger, execution of the program can be suspended to examine the code, evaluate and edit variables in the program, view registers, see the instructions created from the source code, and view the memory space used by the application. With Edit and Continue, changes can be made to the code while debugging and continue execution.
The Visual Studio debugger provides a Debug menu for access to debugger tools. Debugger windows and dialog boxes display information about the program and allows the user enter additional information. Help can be obtained on any window or dialog box by pressing F1.
Debugging on Exceptions
An exception is an abnormal situation that happens while a program is running. Exceptions are often indications of problems that have to be debugged. When an exception occurs, the debugger writes an exception message to the Output window (unless disabled in the Options dialog box).
The debugger may or may not break execution when exception occurs.
-
If an exception occurs and is not handled, the debugger always breaks execution.
-
The debugger can be told to break execution immediately when an exception is thrown (before any handler is invoked).
-
If the user is debugging with Just Mode Code, a third option is also available. The debugger can be told to break on any exception that is not handled by a handler in user code ("My Code").
Remember, if an exception occurs and is not handled at all, the debugger always break. The user-unhandled setting does not change that.
The Visual Studio debugger recognizes the following categories of exceptions:
Most exceptions have handlers, which are designed to respond to an exception when it occurs, giving the program a chance to recover from the abnormal situation. Native Run-time Checks do not have handlers.
In a Visual Basic application, the debugger represents all errors as exceptions, even if you use On Error–style error handlers.
For Visual Basic, C#, and J#, the debugger now features a new Exception Assistant that provides more information when an exception occurs.
Please note (Visual Basic and Visual C# only) If an uncaught exception occurs with the Exception Assistant turned off, a pseudovariable $exception is added to the Locals window. This pseudovariable can be expanded to see information on the exception.
Exception Assistant
The Exception Assistant is a new feature for debugging Visual Basic, C#, and J# applications. The Exception Assistant takes the place of the Exceptions dialog box that appears when an exception occurs in other languages, such as C/C++. The Exception Assistant provides more information on an exception than the Exceptions dialog box, making it easier for you to locate the cause of the exception and fix the problem.
The Exception Assistant, which appears whenever a run-time exception occurs in the debugger, shows the type of exception, troubleshooting tips, and corrective actions that may be applied through the Exception Assistant.
An exception is an object that inherits from the System.Exception class. An exception is thrown by code whenever a problem occurs; it is passed up the stack until the application handles it or the program fails.
Please note:-- The options available in dialog boxes, and the names and locations of menu commands, might differ from what is described in Help depending on the active settings or edition. This Help page was written with General Development Settings in mind. To change the settings, choose Import and Export Settings on the Tools menu.
The following table lists the actions that may appear in the Exception Assistant Actions pane:
|
Action
|
Description
|
|
Find out more about the exception
|
Displays the exception object's properties.
|
|
Add permission.
|
Adds necessary security permissions.
|
To apply an action from the Exception Assistant Actions pane
Debugging a Running Process
The Processes window shows all processes that have been attached to or launched from Visual Studio.
In the Processes window, the user can choose any attached process and make it the current process for debugging. The user can also:
-
Terminate a process
-
Detach a process
-
Break a process
-
Continue a process
The Processes window is found in Visual C++ Express Edition and Visual Studio Professional, Enterprise, and Enterprise Architect Editions only. The default integrated development environment (IDE) settings chosen when Visual Studio is set up, may hide the menu command that displays this window. In that case, the user must add the command back to the Debug menu before this feature can be used.
The Visual Studio debugger has the ability to attach to a process that is running outside of Visual Studio. The attach capability can do the following:
- Debug an application that was not created in Visual Studio.
- Debug multiple processes simultaneously. (You can also debug multiple processes by starting multiple projects within a single solution.)
- Debug a process running on a remote machine.
- Debug a DLL that runs in a separate process that cannot easily be started from Visual Studio (for example, a service or an ISAPI DLL running with Internet Information Services).
- Start the debugger automatically when a process crashes while running outside of Visual Studio (Just-In-Time debugging).
Once a program has been attached, the user can use debugger execution commands, inspect the program state, and so on. The ability to inspect the program may be limited, of course, depending on whether the program was built with debug information and whether the user has access to the program's source code, and whether the common language runtime JIT compiler is tracking debug information.
The Visual Studio debugger can be attached to any running process.
|