Debugging an Application

To debug a Visual Basic application, you basically need to perform two steps:

• Enable the Debug configuration in the compile options.

• Press F5 to start debugging.

By pressing F5, Visual Studio runs your application and attaches an instance of the debugger to the application. Because the Visual Studio debugger needs the debug symbols to proceed, if you do not choose the Debug configuration, you cannot debug your applications. The instance of the debugger detaches when you shut down your application.

Tip

As an alternative to pressing F5, you can click the Start Debugging button on the Visual Studio standard toolbar.

The debugger monitors your application’s execution and notifies for runtime errors; it allows you to take control over the execution flow as well. Figure 2.28 shows our sample application running with the Visual Studio debugger attached. In the bottom area of the IDE; you can notice the availability of some new windows, such as Locals, Watch 1, Watch 2, Call Stack, Breakpoints, Command Window, Immediate Window, and Output.

Figure 2.28 Our sample application running with an attached instance of the Visual Studio debugger.

image

The Visual Studio debugger is a powerful tool; next you learn the most important tasks in debugging applications. Chapter 5 instead dives deeper into the debugger instrumentation for complex debugging tasks. Before explaining the tooling, it is a good idea to modify the source code of our test application so that we can cause some errors and see the debugger in action. We could rewrite the Sub Main method’s code, as shown in Listing 2.3.

Listing 2.3 Modifying the Sub Main for Debugging Purposes

image

New to Visual Basic .Net?

If you are not an existing Visual Basic .NET developer, you may not know some of the objects and keywords shown in the code listings of this chapter. The code is the simplest possible, should be quite easy to understand, and is provided with comments. The next chapters guide you to the details of the programming language, so everything used here will be explained. At the moment, it is important for you to focus on the instrumentation more than on the code.

The code simply declares a message object of type String, containing a text message. This message is then shown in the Console window. This is useful for understanding breakpoints and other features in the code editor. The second part of the code will try to open a text file, which effectively does not exist, and store its content into a variable called getSomeText of type String. We need this to understand how the debugger catches errors at runtime, together with the edit and continue feature.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.169.40