HP OpenVMS Systems Documentation

Content starts here

User Manual

Previous Contents Index

C.3 OpenVMS Debugger (OpenVMS)

This section provides an introduction to using the OpenVMS debugger with HP COBOL programs. It includes the following:

  • A description of OpenVMS debugger support for HP COBOL
  • A note about using both the /DEBUG qualifier and the /NOOPTIMIZE (Alpha and I64 only) qualifier when you compile images for debugging
  • A sample debugging session that demonstrates using the debugger

For complete reference information on the OpenVMS debugger, refer to the OpenVMS Debugger Manual in the OpenVMS documentation set. Online help is immediately available to you during a debugging session when you type the HELP command at the debugger prompt (DBG>).

C.3.1 Notes on HP COBOL Support

In general, the OpenVMS debugger supports the data types and operators of HP COBOL and other debugger-supported languages. However, there are important language-specific limitations. (To get information about the supported data types and operators for a language, type the HELP LANGUAGE command at the DBG> prompt.)

The debugger shows source text included in a program with the COBOL COPY file statement or the COPY module of library statement. However, the debugger does not show text which was created with the COPY REPLACING or REPLACE statement, or included by the COPY text FROM DICTIONARY statement.

The debugger cannot show the original source lines associated with the code for a REPORT section. You can see the DATA SECTION source lines associated with a report, but no source lines are associated with the compiled code that generates the report.

C.3.2 Notes on Debugging Optimized Programs (Alpha, I64)

The HP COBOL compiler is a highly optimizing compiler. Several of the optimizations it performs, such as instruction scheduling and label deletion, can cause unexpected behavior in the OpenVMS Debugger.

Instruction scheduling can make the debugger appear to execute statements out of order. A single COBOL source statement can often result in several machine instructions. A RISC architecture machine, like the Alpha processor, can start working on a new instruction every machine cycle, but not all instructions can complete within one machine cycle. If the output from one machine instruction is used as the input to a subsequent machine instruction, the machine cannot begin processing the second instruction until it has finished processing the first. In many cases an entirely separate instruction can execute in parallel with the first instruction to perform a related computation.

During instruction scheduling, instructions are reordered to minimize waiting time. As a result an instruction resulting from a subsequent COBOL statement can be scheduled in the middle of (or even before) a sequence of instructions from a preceding statement. This reordering NEVER changes the meaning of your program, but it can make your program's execution in the debugger seem incorrect. The most common symptom of instruction scheduling is that the pointer in the debugger source window jumps back and forth between lines when you use the debugger STEP command.

When the compiler performs label deletion, it deletes paragraph and section labels that you do not explicitly reference in your source program. This prevents you from setting breakpoints on the affected labels which can make the analysis and optimization of your program more difficult.

Because of these and other HP COBOL compiler optimizations, Hewlett-Packard recommends that you use the /NOOPTIMIZE qualifier in conjunction with the /DEBUG qualifier when you are debugging your COBOL programs. Using /NOOPTIMIZE qualifier disables most of the HP COBOL optimizations. In particular it suppresses most instruction scheduling and all label deletion optimizations.

C.3.3 Sample Debugging Session (Alpha, I64)

The following OpenVMS Alpha and I64 debugging session does not show the location of program errors; it is designed to show only the use of debugger features.

  1. The following example shows how to compile and link an HP COBOL program consisting of a single compilation unit named TESTA.


    The /DEBUG qualifier on the COBOL command causes the compiler to write the debug symbol records associated with TESTA into the object module, TESTA.OBJ. These records allow you to use the names of variables and other symbols declared in TESTA in debugger commands. (If your program has several compilation units, you must compile each unit that you want to debug with the /DEBUG qualifier.)
    For Alpha and I64, the /NOOPTIMIZE qualifier on the COBOL command disables default optimization for debugging. Because HP COBOL is, by default, a highly optimizing compiler, you will notice unusual and confusing program execution when you step through an optimized program with the debugger.
    The /DEBUG qualifier on the LINK command causes the linker to include all symbol information that is contained in TESTA.OBJ in the executable image. The qualifier also causes the image activator to start the debugger at run time. (If your program has several object modules, you might need to specify other modules in the LINK command.)
  2. The RUN command starts the session. If you compile and link the program with /DEBUG, you do not need to use the /DEBUG qualifier in the RUN command.
    When you give the RUN command, the debugger displays its standard header, showing that the default language is COBOL and the default scope and module are your main program. The debugger returns control with the prompt, DBG>.

                  OpenVMS Alpha DEBUG Version V7.1-000
    %DEBUG-I-INITIAL, Language: COBOL, Module: TESTA
    %DEBUG-I-NOTATMAIN, type GO to get reach MAIN program
  3. Use the GO command to get to the start of the main program.

    DBG> GO
    break at routine TESTA
        11:     DISPLAY "ENTER WORD"
  4. Set a breakpoint.

  5. Begin execution with the GO command. The debugger displays the execution starting point, and the image continues until TESTA displays its prompt and waits for a response.

    DBG> GO
  6. Enter the word to be reversed. Execution continues until the image reaches the breakpoint at line 43 of the contained program.

    break at TESTA\TESTB\%LINE 43
        43:        PERFORM LOOK-BACK  VARYING SUB-1 FROM 20 BY -1
  7. Set two breakpoints. When the debugger reaches line 50 of TESTB, it executes the commands in parentheses, displays the two data items, and resumes execution.

  8. Display the active breakpoints.

    breakpoint at TESTA\TESTB\%LINE 43
    breakpoint at TESTA\TESTB\%LINE 47
    breakpoint at TESTA\TESTB\%LINE 50
  9. Use the TYPE command to display the source lines where you set breakpoints.

    DBG> TYPE 43:50
    module TESTA
        43:     PERFORM LOOK-BACK  VARYING SUB-1 FROM 20 BY -1
        44:         UNTIL TEMP_CHAR (SUB-1) NOT = SPACE.
        45:     MOVE SUB-1 TO CHARCT.
        46:     PERFORM MOVE-IT   VARYING SUB-2 FROM 1 BY 1   UNTIL SUB-1 = 0.
        47:     MOVE HOLD-WORD TO TEMP-WORD.
        48: MOVE-IT.
        49:     MOVE TEMP-CHAR (SUB-1)  TO HOLD-CHAR (SUB-2).
        50:     SUBTRACT 1 FROM SUB-1.
  10. Set a tracepoint at line 15 of TESTA.

  11. Set a watchpoint on the data item DISP-COUNT. When an instruction tries to change the contents of DISP-COUNT, the debugger returns control to you.

    DEBUG-I-WPTTRACE, non-static watchpoint, tracing every instruction
  12. Execution resumes with the GO command. Before line 50 in TESTB executes, the debugger executes the contents of the DO command entered at step 7. It displays the contents of HOLD-CHARS and SUB-1, then resumes execution.

    DBG> GO
    break at TESTA\TESTB\%LINE 50
        50:        SUBTRACT 1 FROM SUB-1.
        CHARS:            "c                   "
    TESTA\TESTB\SUB-1:         3
    break at TESTA\TESTB\%LINE 50
        50:        SUBTRACT 1 FROM SUB-1.
        CHARS:            "cb                  "
    TESTA\TESTB\SUB-1:         2
    break at TESTA\TESTB\%LINE 50
        50:        SUBTRACT 1 FROM SUB-1.
        CHARS:            "cba                 "
    TESTA\TESTB\SUB-1:         1
    break at TESTA\TESTB\%LINE 47
        47:        MOVE HOLD-WORD TO TEMP-WORD.
  13. Examine the contents of SUB-1.

    TESTA\TESTB\SUB-1:     0
  14. Deposit the value --42 into data item SUB-2.

    DBG> DEPOSIT SUB-2 = -42
  15. Examine the contents of SUB-2.

    TESTA\TESTB\SUB-2:    -42
  16. Examine the contents of CHARCT, whose picture is 99V99.

    Previous Next Contents Index