Top
NetCOBOL V11.0 Debugging Guide
FUJITSU Software

2.5.2 Function of the Debugger

2.5.2.1 Using the Debugger

This section explains how to use the debugger for the following tasks:

2.5.2.1.1 Setting Breakpoints

You can set breakpoints at specific locations, at the entry or exit of programs, and on specific conditions being satisfied.

You set simple breakpoints at the current cursor location by using the toolbar Set/Delete Breakpoint button

or the breakpoint function on the shortcut menu. More complex breakpoints are set using the Debug menu Breakpoint function.

In the Line Command window, use the BREAK command.

The Specific Execution Condition on the Continue menu offers another way of executing to a particular point in the program. This function allows you to execute the program up to a particular verb, location or access point of a particular file. Use the Continue, Specific Execution function to execute up to the selected point(s).

2.5.2.1.2 Checking and Changing Data Contents

Use the Data function on the Debug or shortcut menus to check and change the contents of data items.

Data,

, is also available on the toolbar.

In the Line Command window, LIST and SET correspond to the Data function.

2.5.2.1.3 Breaking Execution when Data Changes

Sometimes you know that a data item does not have the correct value but it is not obvious where the incorrect value is coming from. In these situations you need to use the Data Monitor function. Data Monitor monitors the data item and interrupts execution when the contents change.

You switch on the monitoring of a data item from the Watch window or by using the MONITOR line command.

For example, to find out where the application updates data item A, consider the following figure.

Figure 2.10 Finding Data Modification Locations

2.5.2.1.4 Changing the Statement Execution Sequence

The debugger can bypass statements that contain errors and pass control to statements that are not in the original execution sequence.

Use the Change Start-Point to Cursor function, on the Continue or shortcut menus, to change the program execution sequence.

For example, to bypass line 220 in the program below:

Figure 2.11 Changing the Statement Execution Sequence

2.5.2.1.5 Tracing the Execution Path

You can often encounter situations where you can stop a program at the point an error occurs, but there are many possible routes to that point. The Backward Trace function highlights (colors) the statement currently being traced. As a colored statement shifts, you can visually review the flow of program controls.

The Trace function enables the recording of the flow of control. When execution is interrupted, you can use the Backward Trace functions to retrace the path of execution.

There are four trace functions:

Previous Statement: Steps backward from the current trace sentence to the sentence that was executed before it.

Next Statement: Steps forwards from the current trace sentence to the sentence that was executed after it.

Previous Procedure: Jumps backwards from the current trace statement to the first statement in the procedure containing the statement, and then to the first statement in the procedure that was executed before the current trace procedure.

Next Procedure: Jumps forwards to the first statement in the procedure that was executed after the current trace procedure.

The Trace function is not available as a line command.

For example, to confirm which location calls procedure PRM, consider the following figure.

Figure 2.12 Tracing an Execution Path

2.5.2.1.6 Tracing the Program Calling Path

When data in the linkage section is incorrect or the timing of a program call is incorrect, you often need to confirm which program made the call. The debugger lets you check the calling path using the Call Stack function available from the Window menu and the toolbar.

Call Stack displays a list of the active programs in the call stack. For example, suppose the application executes the following sequence:

			MAINPROG     CALLS    PROGRAMA
    PROGRAMA    CALLS    PROGRAMC
      PROGRAMC    EXITS
    PROGRAMA    EXITS
MAINPROG    CALLS    PROGRAMB
    PROGRAMB    CALLS    PROGRAMC
    Breakpoint encountered in PROGRAMC.

Then the Call Stack list looks like this:

Figure 2.13 Call Stack Window

Note that PROGRAMA does not appear in the list, as it is no longer active in the CALL hierarchy.

2.5.2.1.7 Breaking into an Executing Program

You can break into looping programs, or regain control of programs being run, by pressing the esc key. You can also select the Break function from the Continue menu or the toolbar.

If you are working with a Windows application, for example using PowerCOBOL generated code, you may need to take an action in the user window before control returns to the debugger.

2.5.2.1.8 Allocating Linkage Section Items

Finding linkage section allocation errors in the midst of debugging large program suites is potentially time consuming. You need to correct and recompile program source, rebuild the application, and restart debugging. The debugger provides the Linkage function to ease such situations.

For example, if a calling program omits a parameter from the CALL statement, debugging of the subprogram can continue without interrupting the debugging session. Use the Linkage function to allocate an area in memory for the missing linkage section item.

The debugger deal locates the allocated area when it returns control to the calling program from the subprogram.

Figure 2.14 Allocating Linkage Section Items

2.5.2.1.9 Checking Test Coverage

When testing programs, you often want to be sure that certain sections or lines of code have at least been executed. The Passage Count function lets you do this.

First, determine the points in your programs that you want to check. Then, set passage counts by either selecting the Passage Count function on the Debug menu or the Set Passage Count function on the shortcut menu. Execute the program. Selecting Debug, Update Passage Count Display, causes the highlight color to change for executed statements. Alternatively, you can select Debug, Passage Count that displays the Passage Count window. This window gives a list of all passage count statements and the number of executions for each statement.

2.5.2.1.10 Restarting the Debug Session

You can restart debugging the same program, without terminating the debugger, by using the Continue, Re-debug function. All data is re-initialized and you can choose whether to retain or reset the following:

2.5.2.1.11 Automating Debug Operations

If you need to demonstrate your debugging steps, or to perform the same debugging procedures frequently, you can automate your debug operations. The debugger supports two types of automated debugging: batch and automatic.

Both types use a command file that contains debugger commands.

Batch Debugging

In this mode, you specify a command file at the start of debugging. The command file drives the whole debugging session; you do not have to interact with the debugger.

Automatic Debugging

With automatic debugging, you select a command file during a debugging session, and the debugger executes the commands in the file. Control returns to you when all the commands have been executed. Automatic debugging is useful when you want to repeat the execution of a string of commands.

Creating Command Files

You create command files by:

You can use the history files, created by the debugger, as command files with no changes. Alternatively, you can use a text editor to make appropriate changes to the history files, or to select particular sections for use in batch or automated debugging.

The following example shows a command file to set a breakpoint, and display a data value before and after the breakpoint.

	  break 47      ; Set a breakpoint
  list data-out ; Display data
  cont          ; Run
  list data-out ; Display data
  cont          ; Run
  quit          ; Quit

The debugger treats characters following semicolons as comments.

2.5.2.1.12 Configuring the Debugger

You can use the Option, Environments function to configure the following aspects of the debugging environment:

The environments other than the statement identification number mode and replacement character will be enabled the next time the debugger is started.

2.5.2.1.13 Splitting the Source File Window

You can split the Source File window into two separately scrollable windows. To do this, click and drag the Split box that is in the top right hand corner of the window, immediately above the scroll bar.

Figure 2.15 The Split Box

2.5.2.1.14 Configuring Source Code Font and Colors

The Font and Color commands under View bring up dialog boxes that let you configure the font for the source code and the color of fifteen different attributes of the COBOL source display.

2.5.2.1.15 Checking the Status of the Debugger

The debugger maintains information about a number of items: breakpoints, passage counts, watch data, and the watch conditional expression. It displays these in the dialog box for each function.

The Breakpoint dialog box displays a list of the breakpoints set and whether they are enabled or disabled.

The Passage Count dialog box displays a list of statements with passage counts, and the counts for these statements.

The Watch window displays a list of data items being watched or monitored and a list of the conditional expressions being monitored.

2.5.2.1.16 Data File Input/Output

The Data File I/O capability is available to read/write data values to/from a file. Brief descriptions of these functions follow.

Reading from a File

This sets a data item to the value read from a file. This is useful when you set a large number of values, because you can store them in a file in advance, instead of using the SET command to change data.

The typical usage is to identify process routes. To do this, you need to prepare values that let your program take every route. Reading such values from a file saves you the time it would take to enter values during a test, thus making the task much easier.

Writing into a File

This writes values of data items into a file. Because you can reference values previously stored in a file, instead of using the LIST command for displaying data, this is useful when you need to reference many values at a time.

The typical usage is to review processing results that might vary depending on process routes or entered data. Writing into a file allows you to focus on checking process routes during a test, because you can take the time to review processing results after the test is completed.

Using the Fujitsu Data Editor is recommended when you create or check a data file that is to be used for the Data File I/O capability.

Example

In this example, we identify the process route the subprogram takes, and review all the return values from the parameters after the debugging activities are completed.

  1. Create a file for reading

    Create a file (INFL) in which the values required to take every route are set to the data item (A), assuming the data area (LINK) in the linkage section to be one record.

  2. Debug

    At the entry point of the subprogram, read values stored in a file (INFL) into the data area (LINK) in the linkage section to identify the route.

    At the exit of the subprogram, write values stored in the data area (LINK) in the linkage section into a file (OUTFL).

  3. Review the written file

    Check the file (OUTFL) to review the values in the data area (LINK) in the linkage section that were changed by the subprogram.