More Debugger

From CometWiki

(Difference between revisions)
Jump to: navigation, search
(Stepping Into or Over a Subroutine)
(Editing Breakpoints)
 
(19 intermediate revisions not shown)
Line 2: Line 2:
-
== Overview ==
+
=== Overview ===
   
   
Line 22: Line 22:
-
== Getting Ready to Debug ==
+
=== Getting Ready to Debug ===
   
   
Line 96: Line 96:
* To stop whenever your program encounters an unhandled exception, check the "Unhandled Exceptions" box
* To stop whenever your program encounters an unhandled exception, check the "Unhandled Exceptions" box
-
== Source Code Display ==
+
=== Source Code Display ===
   
   
Line 107: Line 107:
[[Image:Debug6.jpg]]
[[Image:Debug6.jpg]]
-
== Watched Variables ==
+
=== Watched Variables ===
   
   
Line 122: Line 122:
[[Image:Debug9.jpg]]
[[Image:Debug9.jpg]]
-
== Quick Watch ==
+
=== Quick Watch ===
   
   
Line 155: Line 155:
[[Image:Debug11.jpg]]
[[Image:Debug11.jpg]]
-
== Stepping Into or Over a Subroutine ==
+
=== Stepping Into or Over a Subroutine ===
   
   
Line 187: Line 187:
As an alternative to stepping through your program one instruction at a time, you can set breakpoints where the debugger will stop program execution. You can set up to 20 breakpoints. To set a breakpoint, use one of the following methods:  
As an alternative to stepping through your program one instruction at a time, you can set breakpoints where the debugger will stop program execution. You can set up to 20 breakpoints. To set a breakpoint, use one of the following methods:  
-
Highlight the source line and press the F9 key  
+
* Highlight the source line and press the F9 key  
-
Double click the source line where you want to insert a breakpoint  
+
* Double click the source line where you want to insert a breakpoint  
 +
 
The breakpoint is shown as a red oval on the left of the source line.  
The breakpoint is shown as a red oval on the left of the source line.  
-
+
[[Image:Debug13.jpg]]
To start the program executing, use one of the following methods:  
To start the program executing, use one of the following methods:  
-
Select the "Go" option on the "Debug" menu  
+
* Select the "Go" option on the "Debug" menu  
-
Press the F5 key  
+
* Press the F5 key  
-
Click the "Run without tracing" icon on the tool bar  
+
* Click the "Run without tracing" icon on the tool bar  
-
+
[[Image:Debug14.jpg]]
The debugger will then stop the program at the first breakpoint it encounters. (The debugger also stops at any of the instructions you've chosen in the "Options" setting, including Run/Enter, Exit, I/O statements, RTDOS calls, handled exceptions, and unhandled exceptions. Also note that the program stops on its own accord at INPUT and WAIT statements.)  
The debugger will then stop the program at the first breakpoint it encounters. (The debugger also stops at any of the instructions you've chosen in the "Options" setting, including Run/Enter, Exit, I/O statements, RTDOS calls, handled exceptions, and unhandled exceptions. Also note that the program stops on its own accord at INPUT and WAIT statements.)  
Line 206: Line 207:
To force the program to stop at any other time, click on the "Stop program" icon on the tool bar.  
To force the program to stop at any other time, click on the "Stop program" icon on the tool bar.  
-
+
[[Image:Debug15.jpg]]
The window caption line indicates whether the program is running or stopped.  
The window caption line indicates whether the program is running or stopped.  
-
   
+
[[Image:Debug16.jpg]]  [[Image:Debug17.jpg]]
-
Program is running  Program is stopped 
+
 +
:'''Program is running'''
 +
::::::::::::'''Program is stopped'''
-
 
+
=== Editing Breakpoints ===
-
== Editing Breakpoints ==
+
   
   
Line 221: Line 222:
There are several ways to edit breakpoints. To remove a breakpoint, highlight the line containing a breakpoint and use one of the following methods:  
There are several ways to edit breakpoints. To remove a breakpoint, highlight the line containing a breakpoint and use one of the following methods:  
-
Select the "Remove Breakpoint" option on the "Debug" menu  
+
* Select the "Remove Breakpoint" option on the "Debug" menu  
-
Press the F9 key  
+
* Press the F9 key  
-
Press Alt+F9  
+
* Press Alt+F9  
-
Double click the source line  
+
* Double click the source line  
 +
 
To remove all breakpoints, use one of the following methods:  
To remove all breakpoints, use one of the following methods:  
 +
* Select the "Clear Breakpoints" option on the "Debug" menu
 +
* Press Ctrl+P
-
Select the "Clear Breakpoints" option on the "Debug" menu
 
-
Press Ctrl+P
 
You can also disable a breakpoint, which leaves a breakpoint marker in place but does not enable the breakpoint for that instruction. To disable a breakpoint, use one of the following methods:  
You can also disable a breakpoint, which leaves a breakpoint marker in place but does not enable the breakpoint for that instruction. To disable a breakpoint, use one of the following methods:  
 +
* Select the "Disable Breakpoint" option on the "Debug" menu
 +
* Press Ctrl+F9
-
Select the "Disable Breakpoint" option on the "Debug" menu
 
-
Press Ctrl+F9
 
The disabled breakpoint appears as follows:  
The disabled breakpoint appears as follows:  
-
+
[[Image:Debug18.jpg]]
To edit the entire list of breakpoints, use one of the following methods:  
To edit the entire list of breakpoints, use one of the following methods:  
 +
* Select the "Edit Breakpoints" option on the "Debug" menu
 +
* Press Ctrl+B
-
Select the "Edit Breakpoints" option on the "Debug" menu
 
-
Press Ctrl+B
 
The following dialog is displayed:  
The following dialog is displayed:  
-
+
[[Image:Debug19.jpg]]
This dialog shows all of the breakpoints and indicates, via a checkbox, whether the each breakpoint is enabled or disabled. To disable a breakpoint, uncheck the appropriate box. To enable a breakpoint, check the appropriate box.  
This dialog shows all of the breakpoints and indicates, via a checkbox, whether the each breakpoint is enabled or disabled. To disable a breakpoint, uncheck the appropriate box. To enable a breakpoint, check the appropriate box.  
-
This dialog also contains buttons that remove a breakpoint or remove all breakpoints.  
+
This dialog also contains buttons that remove a breakpoint or remove all breakpoints.
-
 
+
-
 
+
== Run to Selection ==
== Run to Selection ==
Line 260: Line 260:
If you want your program to run up to a certain instruction, but you don't want to set a breakpoint, you can use the "run to selection" option. In effect, this feature works as a "quick breakpoint." To use this feature, highlight the source line where you want to stop executing, and then use one of the following methods:  
If you want your program to run up to a certain instruction, but you don't want to set a breakpoint, you can use the "run to selection" option. In effect, this feature works as a "quick breakpoint." To use this feature, highlight the source line where you want to stop executing, and then use one of the following methods:  
-
Select the "Run to Selection" option on the "Debug" menu  
+
* Select the "Run to Selection" option on the "Debug" menu  
-
Press Ctrl+F10  
+
* Press Ctrl+F10
== Break ==
== Break ==
Line 268: Line 268:
The "Break" option causes the debugger to stop a currently executing program. This option is typically used when the program is stopped at an INPUT statement. Issuing a break at that point stops program execution after the INPUT is completed.  
The "Break" option causes the debugger to stop a currently executing program. This option is typically used when the program is stopped at an INPUT statement. Issuing a break at that point stops program execution after the INPUT is completed.  
 +
To issue a break, use one of the following methods:  
To issue a break, use one of the following methods:  
-
Select "Break" on the "Debug" menu  
+
* Select "Break" on the "Debug" menu  
-
Press Shift+F5  
+
* Press Shift+F5
== Go to IP ==
== Go to IP ==
Line 280: Line 281:
While looking at the source code in the "Source" window, you can instruct the debugger to display the source line where the instruction pointer (IP) is located. To use this feature, use one of the following methods:  
While looking at the source code in the "Source" window, you can instruct the debugger to display the source line where the instruction pointer (IP) is located. To use this feature, use one of the following methods:  
-
Select "Goto IP" on the "Debug" menu  
+
* Select "Goto IP" on the "Debug" menu  
-
Press Alt+F5  
+
* Press Alt+F5
== Call Stack ==
== Call Stack ==
Line 288: Line 289:
The Call Stack window displays the subroutine stack. This list is displayed in inverted order, with the most recent subroutine call shown at the top of the list.  
The Call Stack window displays the subroutine stack. This list is displayed in inverted order, with the most recent subroutine call shown at the top of the list.  
-
The following example shows the program name that is running ("TEST" on "BAM") and shows that the program is currently nested two subroutines deep ("ROUTINE1" followed by "ROUTINE2")
 
-
 
-
 
 +
The following example shows the program name that is running ("TEST" on "BAM") and shows that the program is currently nested two subroutines deep ("ROUTINE1" followed by "ROUTINE2")
 +
[[Image:Debug20.jpg]]
== Include Files ==
== Include Files ==
Line 299: Line 299:
If your program contains include files (i.e., usefiles), you can view any of them by choosing the file name on the "Window" menu. The contents of the include file are displayed in the source code window.  
If your program contains include files (i.e., usefiles), you can view any of them by choosing the file name on the "Window" menu. The contents of the include file are displayed in the source code window.  
-
+
[[Image:Debug21.jpg]]
If your program executes instructions in an executable include file, that file is automatically displayed in the source code window as you step through the code.  
If your program executes instructions in an executable include file, that file is automatically displayed in the source code window as you step through the code.  
-
Note that the debugger requires all source and include files to be text files.  
+
Note that the debugger requires all source and include files to be text files.
-
 
+
== Window Messages ==
== Window Messages ==
Line 311: Line 310:
The "Window Messages" window show messages generated by the Windows Development Library (WDL). This feature must be enabled in your code by setting the following symbolic constants:  
The "Window Messages" window show messages generated by the Windows Development Library (WDL). This feature must be enabled in your code by setting the following symbolic constants:  
-
SET NEW.TRACE = 1      ! Enable tracing
+
SET NEW.TRACE = 1      ! Enable tracing
-
SET TRACE.CALLS = 1    ! Show outgoing messages   
+
SET TRACE.CALLS = 1    ! Show outgoing messages   
-
SET TRACE.RECEIVE = 1  ! Show incoming messages
+
SET TRACE.RECEIVE = 1  ! Show incoming messages
Also, in order for the Windows message trace feature to work, you must first enable the cosTrace variable. This is a feature that allows the user to control when the messages are displayed.  
Also, in order for the Windows message trace feature to work, you must first enable the cosTrace variable. This is a feature that allows the user to control when the messages are displayed.  
-
cosTrace = TRUE        ! Enable trace messages
+
cosTrace = TRUE        ! Enable trace messages
The following sample display comes from the DIRECT.IBS,DLG program.
The following sample display comes from the DIRECT.IBS,DLG program.
 +
 +
[[Image:Debug22.jpg]]

Latest revision as of 21:25, 11 June 2009

Contents

Comet Debugger

Overview

The Comet Debugger is a powerful tool for debugging your Internet Basic programs. With the debugger, you can:

  • Watch your program execute one instruction at a time
  • Display the source code for the program that is running
  • Highlight the source code line for the instruction that is being executed
  • Examine the value of any of your program variables while the program is running
  • Examine the value of any system variable while the program is running
  • Dynamically set up to 20 breakpoints in your code where the debugger will temporarily stop program execution
  • Resume program execution, either one instruction at a time or until the next breakpoint
  • Look at the contents of the subroutine stack
  • Display window messages
  • Debug a program running in any partition on your system, including background partitions (including XAP programs)
  • Choose to step through or skip over subroutines

The Comet Debugger is available to those programmers using the Internet Basic Development Platform. The minimum Comet requirement is Comet2003 Build 321.


Getting Ready to Debug

In order to use the Comet Debugger, your source program and include files must be text files (i.e., UltraEdit files). To prepare for debugging your program, you must compile the program with the "D" option, as shown here:

    !//IB// Src(test.ibs,dsk) Obj(test,dsk) Opt(D)

Using the "D" option causes the compiler to create a debug file that has the same filename as the object program, but with a ".DBG" extension. In the above example, the debug file would be named TEST.DBG and would be located in the DSK directory. (Note: The debug file is not contained in the QDIR.)

The debug file is required for debugging. When you are done debugging, we recommend that you delete the .DBG file.


Starting the Debugger

Before starting the debugger, make sure that Comet is running. The Comet Debugger is included with the Comet release. The program name is:

  COSD.EXE

Create a desktop shortcut to this program. When you run the debugger, the following screen is displayed:

Debug1.jpg Notice the five windows contained in the display:


Debug Messages -- where status messages are displayed Source -- where the source code is displayed Watch Variables -- where selected variables are displayed Call Stack -- where subroutine labels are displayed Window Messages -- where Window messages are displayed The debugger works by latching onto a program as it is running. You have the option of attaching to a partition number, session number, or terminal number. These options are contained on the "Comet" menu.

Debug2.jpg

Alternatively, click the "Debug partition" icon on the tool bar.

Debug2a.jpg

Attach to the partition/session/terminal before running the program you want to debug.

When you are finished debugging your program, choose the "Stop Debugging" option. This detaches the debugger from your program.

Debug2b.jpg

Alternatively, click the "Stop debugging" icon on the tool bar.


Debug2c.jpg


Debugger Options

The debugger works by stopping your program when certain instructions are executed. You can choose the exact location where your program will stop by setting breakpoints (see below), or you can have the system stop when certain types of instructions occur.

To specify which type of instructions will automatically stop program execution, choose "Options..." from the "Edit" menu.

Debug3.jpg

The following options are available:

Debug4.jpg


  • To cause the debugger to stop whenever your program encounters a RUN or ENTER instruction, check the "Begin Program (Run/Enter)" box
  • To stop whenever your program encounters an EXIT instruction, check the "Return from Program (Exit)" box
  • To stop whenever your program encounters an I/O statement, check the "I/O Statements" box. Note that you program will always stop when it encounters an INPUT or WAIT statement.
  • To stop whenever your program encounters a Runtime DOS instruction, check the "RTDOS Calls" box
  • To stop whenever your program encounters a handled exception (via EXCP=), check the "Handled Exceptions" box
  • To stop whenever your program encounters an unhandled exception, check the "Unhandled Exceptions" box

Source Code Display

When you debug a program, the source code is displayed in the "Source" window. Notice the green arrow to the left of the current line. This arrow is the "instruction pointer" which indicates the location of the current instruction where the program is stopped.

Debug5.jpg The source code display includes the source line number, the name of the source program, the object code address (also known as the "offset"), and the source line itself. The line numbers, program name, and offsets are optional and may be turned on/off via the "View" menu.

Debug6.jpg

Watched Variables

The debugger provides a way for you to watch the values of your program variables, system variables, and symbolic constants. There are two ways to choose which variables will be watched. The first way is to select "Watch Variables" from the "Debug" menu (or use the Ctrl+W keyboard accelerator). Debug7.jpg

The following dialog is displayed. To choose a variable to watch, select the variable from the list of unwatched variables on the left and click the "Add" button. To remove a variable from the watch list, select the variable from the list of watched variables on the right and click the "Remove" button.

Debug8.jpg

The selected variables appear in the "Watch Variables" window. The current value of each variable is displayed, along with the length/precision of each variable. As you step through your code, these values are updated.

Debug9.jpg

Quick Watch

The second way to watch variables is to use the "Quick Watch" feature. The following methods activate the feature:

  • Selecting the "Quick Watch" option on the "Debug" menu
  • Using the Shift+F9 keyboard accelerator
  • Right clicking on a variable name in the "Source" window

The following dialog is displayed:

File:Debug10.jpg

The dialog shows the selected variable along with its current value, type, length, and precision.


  • To display the value in hex, check the "Display as Hex" box
  • To recalculate the value, click the "Recalculate" button
  • To add this variable to the watch list, click the "Add to Watch" button

Stepping Through Your Program

To step through your program one instruction at a time, use one of the following methods:

  • Select the "Step Into" option from the "Debug" menu
  • Press the F8 or F11 key
  • Click the "Step Program" icon on the tool bar

Debug11.jpg

Stepping Into or Over a Subroutine

When you encounter a GOSUB statement, you can choose to step into the subroutine (to step through the subroutine one line at a time) or step over the subroutine (to avoid stepping through the subroutine one line at a time). If you step over the subroutine, the subroutine code will be executed and the debugger will stop at the instruction following the GOSUB statement.

To step into a subroutine, use one of the following methods:


  • Select the "Step Into" option from the "Debug" menu
  • Press the F8 or F11 key
  • Click the "Step Program" icon on the tool bar

To step over a subroutine, use one of the following methods:

  • Select the "Step Over" option from the "Debug" menu
  • Press the F10 key

If the debugger is in a subroutine and you want to stop debugging the subroutine (but continue debugging the rest of the program), use one of the following methods to "step out" of the subroutine:

  • Select the "Step Out" option from the "Debug" menu
  • Press Shift+F11
  • Click the "Step out of function" icon on the tool bar

Debug12.jpg

Setting Breakpoints

As an alternative to stepping through your program one instruction at a time, you can set breakpoints where the debugger will stop program execution. You can set up to 20 breakpoints. To set a breakpoint, use one of the following methods:

  • Highlight the source line and press the F9 key
  • Double click the source line where you want to insert a breakpoint

The breakpoint is shown as a red oval on the left of the source line.

Debug13.jpg

To start the program executing, use one of the following methods:


  • Select the "Go" option on the "Debug" menu
  • Press the F5 key
  • Click the "Run without tracing" icon on the tool bar

Debug14.jpg

The debugger will then stop the program at the first breakpoint it encounters. (The debugger also stops at any of the instructions you've chosen in the "Options" setting, including Run/Enter, Exit, I/O statements, RTDOS calls, handled exceptions, and unhandled exceptions. Also note that the program stops on its own accord at INPUT and WAIT statements.)

To force the program to stop at any other time, click on the "Stop program" icon on the tool bar.

Debug15.jpg

The window caption line indicates whether the program is running or stopped.

Debug16.jpg Debug17.jpg

Program is running
Program is stopped

Editing Breakpoints

There are several ways to edit breakpoints. To remove a breakpoint, highlight the line containing a breakpoint and use one of the following methods:

  • Select the "Remove Breakpoint" option on the "Debug" menu
  • Press the F9 key
  • Press Alt+F9
  • Double click the source line

To remove all breakpoints, use one of the following methods:

  • Select the "Clear Breakpoints" option on the "Debug" menu
  • Press Ctrl+P

You can also disable a breakpoint, which leaves a breakpoint marker in place but does not enable the breakpoint for that instruction. To disable a breakpoint, use one of the following methods:

  • Select the "Disable Breakpoint" option on the "Debug" menu
  • Press Ctrl+F9

The disabled breakpoint appears as follows:

Debug18.jpg

To edit the entire list of breakpoints, use one of the following methods:

  • Select the "Edit Breakpoints" option on the "Debug" menu
  • Press Ctrl+B

The following dialog is displayed:

Debug19.jpg

This dialog shows all of the breakpoints and indicates, via a checkbox, whether the each breakpoint is enabled or disabled. To disable a breakpoint, uncheck the appropriate box. To enable a breakpoint, check the appropriate box.

This dialog also contains buttons that remove a breakpoint or remove all breakpoints.

Run to Selection

If you want your program to run up to a certain instruction, but you don't want to set a breakpoint, you can use the "run to selection" option. In effect, this feature works as a "quick breakpoint." To use this feature, highlight the source line where you want to stop executing, and then use one of the following methods:

  • Select the "Run to Selection" option on the "Debug" menu
  • Press Ctrl+F10

Break

The "Break" option causes the debugger to stop a currently executing program. This option is typically used when the program is stopped at an INPUT statement. Issuing a break at that point stops program execution after the INPUT is completed.

To issue a break, use one of the following methods:


  • Select "Break" on the "Debug" menu
  • Press Shift+F5

Go to IP

While looking at the source code in the "Source" window, you can instruct the debugger to display the source line where the instruction pointer (IP) is located. To use this feature, use one of the following methods:

  • Select "Goto IP" on the "Debug" menu
  • Press Alt+F5

Call Stack

The Call Stack window displays the subroutine stack. This list is displayed in inverted order, with the most recent subroutine call shown at the top of the list.

The following example shows the program name that is running ("TEST" on "BAM") and shows that the program is currently nested two subroutines deep ("ROUTINE1" followed by "ROUTINE2")

Debug20.jpg

Include Files

If your program contains include files (i.e., usefiles), you can view any of them by choosing the file name on the "Window" menu. The contents of the include file are displayed in the source code window. Debug21.jpg

If your program executes instructions in an executable include file, that file is automatically displayed in the source code window as you step through the code.

Note that the debugger requires all source and include files to be text files.

Window Messages

The "Window Messages" window show messages generated by the Windows Development Library (WDL). This feature must be enabled in your code by setting the following symbolic constants:

SET NEW.TRACE = 1       ! Enable tracing
SET TRACE.CALLS = 1     ! Show outgoing messages  
SET TRACE.RECEIVE = 1   ! Show incoming messages

Also, in order for the Windows message trace feature to work, you must first enable the cosTrace variable. This is a feature that allows the user to control when the messages are displayed.

cosTrace = TRUE         ! Enable trace messages

The following sample display comes from the DIRECT.IBS,DLG program.

Debug22.jpg

Personal tools