Debugging Basics

The process of locating and fixing errors in your application is known as debugging. The development environment's debugging support includes breakpoints, break expressions, watch expressions, and the ability to step through code one statement or one procedure at a time and display the values of variables and properties. Many of the languages supported in the development environment also include special debugging features, such as edit-and-continue capability, setting the next statement to execute, and procedure testing while the application is in break mode.

Debugging tools are designed to help you with:

  • Compile errors that result from incorrectly constructed code. If you incorrectly type a keyword, omit some necessary punctuation, or use an opening identifier without a corresponding closing identifier at design time, these errors are detected when you compile the application.

  • Run-time errors that occur while the application is running and the environment detects an operation that is impossible to carry out. An example of this is division by zero.

  • Logic errors that occur when an application doesn't perform the way it was intended to. An application can have syntactically valid code, run without performing any invalid operations, and yet produce incorrect results. Only by testing the application and analyzing results can you verify that the application is performing correctly.

Debugging tools give you a snapshot of the current state of your application, including:

  • Appearance of the user interface.

  • Values of variables and expressions.

  • Active procedure calls.

There are four main windows that you'll use while debugging your application:

  • The Immediate window allows you to change the values of variables so that you can immediately see the effect of your changes. When the application is in break mode, you can evaluate expressions by typing in the Immediate window.

  • The Watch window shows the current watch expressions, which are expressions whose values you decide to monitor as the code runs. The Watch window can display a value for a watch expression only if the current statement is in the specified context. Otherwise, the Value column shows a message indicating the statement is not in context.

  • The Locals window shows the value of any variables within the scope of the current procedure. As the execution switches from procedure to procedure, the contents of the Locals window changes to reflect only the variables applicable to the current procedure.

  • The Output window displays status messages at run time. With some language engines, this window is also used to display debugging strings generated in code.

There are also several other debugging windows that you will use in certain situations, depending upon the type of application you are debugging and upon the language engine.

  • For multithreaded applications, the Threads window allows you to change the current thread of execution or view the threads in any attached process. The contents of the other debugging windows change to reflect the selected thread.

  • The Call Stack window displays a list of all active procedures or stack frames for the current thread of execution. Active procedures are the uncompleted procedures in a process. For Internet applications, the Running Documents window displays a list of documents that are currently loaded into the process you are debugging. For example, if you load an HTML frameset into the browser, the Running Documents window shows you which pages are currently loaded.