HP OpenVMS Systems Documentation

Content starts here

User Manual

Previous Contents Index

C.2 Ladebug Debugger (Tru64 UNIX)

The Ladebug Debugger is used to debug HP COBOL programs on the Tru64 UNIX operating system.

This section provides a representative debugging session that is designed to demonstrate the use of debugger features. For complete reference information on the Ladebug Debugger, you should refer to the Ladebug Debugger Manual in the Tru64 UNIX operating system documentation set. Online help is immediately available to you during a debugging session when you type help command at the debugger prompt (ladebug) . Additional information about the flags shown in this section is available in the man page. For example, you can type man cobol , and page to the appropriate topic to read information about the flags ( -g , -o ) used at the beginning of the example in this section.

  1. To begin this example you compile an HP COBOL program consisting of the single compilation unit named TESTA.

    % cobol -g -o testa testa.cob
    cobol: Warning: file not optimized; use -g3 for debug with optimize

    The -g switch on the compiler command causes the compiler to write the debugger symbol table associated with the program into the executable program.
    Normally, the compiler turns off optimization when you specify -g and gives a warning to that effect. To debug your program with full optimization turned on, use the -g3 switch.
  2. The ladebug command starts the session. You provide your program name as a parameter (argument) to the command. After the debugger reads in your program's symbol table, it returns control with its prompt, (ladebug) .

    % ladebug testa
    Welcome to the Ladebug Debugger Version 2.0.8 eft
    object file name: testa
    Reading symbolic information ...done
  3. Set a breakpoint. In this case, you wish to break at line 43 of your program.

    (ladebug) stop at 43
    [#2: stop at "testa.cob":43 ]
  4. Begin execution with the run command. The debugger starts program TESTA, prompts for a keyboard entry, and waits for a response.

    (ladebug) run
  5. Enter the word to be reversed. Execution continues until the image reaches the breakpoint at line 43 of the contained program.

    [2] stopped at [TESTB:43 0x120001aa4]
         43     PERFORM LOOK-BACK  VARYING SUB-1 FROM 20 BY -1
  6. Set two breakpoints. You can give the debugger a list of commands to execute at breakpoints; the commands are entered in braces ({}).

    (ladebug) stop at 47
    [#2: stop at "testa.cob":47 ]
    (ladebug) when at 50 { print chars of hold-chars; print SUB-1; cont; }
    [#3: when at "testa.cob":50 { print CHARS of HOLD-CHARS; print SUB-1; ; cont ; } ]
  7. Display the active breakpoints.

    (ladebug) status
    #1 PC==0x120001e14 in testa "testa.cob":2 { break }
    #2 PC==0x120001ba4 in TESTB "testa.cob":47 { break }
    #3 PC==0x120001c1c in TESTB "testa.cob":50
       { ; print CHARS of HOLD-CHARS; print SUB-1; ; cont ; ; }
  8. Use the list command to display the source lines where you set breakpoints.

    (ladebug) list 43,50
         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.
  9. Set a tracepoint at line 15 of TESTA.

    (ladebug) trace at 15
    [#3: trace at "testa.cob":15 ]
  10. 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.

    (ladebug) stop disp-count of testa-data
    [#4: stop if DISP-COUNT of TESTA-DATA changes ]
  11. Execution resumes with the cont command. Each time line 50 in TESTB executes, the debugger executes the command list associated with this line; it displays the contents of HOLD-CHARS and SUB-1, then resumes execution. Finally, the debugger returns control to the user when the breakpoint at line 47 is reached.

    (ladebug) cont
    [3] when [TESTB:50 0x120001c1c]
    "c                   "
    [3] when [TESTB:50 0x120001c1c]
    "cb                  "
    [3] when [TESTB:50 0x120001c1c]
    "cba                 "
    [2] stopped at [TESTB:47 0x120001ba4]
         47     MOVE HOLD-WORD TO TEMP-WORD.
  12. Examine the contents of SUB-1.

    (ladebug) whatis sub-1
     unsigned short SUB-1
    (ladebug) print sub-1
  13. Deposit the value --42 into data item SUB-2.

    (ladebug) whatis sub-2
     pic s99 usage comp-3 SUB-2
    (ladebug) assign sub-2=-42
  14. Examine the contents of SUB-2.

    (ladebug) print sub-2
  15. Examine the contents of CHARCT, whose picture is 99V99.

    (ladebug) whatis charct
     pic 99v99 usage display charct
    (ladebug) print charct
  16. Deposit a new value into CHARCT.

    (ladebug) assign charct=15.95
  17. CHARCT now contains the new value.

    (ladebug) print charct
  18. You can examine any character of a subscripted data item by specifying the character position. The following EXAMINE command accesses the second character in TEMP-CHAR.

    (ladebug) print temp-char of temp-word(2)
  19. You can qualify data names in debug commands as you can in HP COBOL. For example, if you examine IN-WORD while you debug your program, you can use the following Ladebug Debugger command:

    (ladebug) print in-word of testa-data
     "abc                 "
  20. Restore CHARCT to its original value.

    (ladebug) assign charct=3.00
  21. Resume execution with the cont command. The program TESTA displays the reversed word. When the image reaches line 19 in TESTA, the debugger detects that an instruction changed the contents of DISP-COUNT. Because you set a watchpoint on DISP-COUNT, the debugger displays the old and new values, then returns control to you.

    (ladebug) cont
    [3] [calling testa from main cob_main.c:253 0x3ff8181f054]
    [4] The value of DISP-COUNT of TESTA-DATA was changed in testa,
        before entering cob_acc_display
            Old value =   0
            New value =   3
    [4] stopped at [cob_acc_display:349 0x3ff81808744]
    (Cannot find source file cob_accdis.c)

    Note that the Ladebug Debugger "watch" command shown here ( stop disp-count of testa-data ) does not stop immediately at the point when the value of the watched variable changes. In this example, the debugger takes control at the first procedure call or return after the value of the watched variable changes. For more information on the behavior of Ladebug Debugger watch , refer to the Ladebug Debugger Manual.
  22. To see the executable's current location, use the where command. Then, set the debugger file scope back to the main COBOL program, and stop at a specified line number in that file.

    (ladebug) where
    >0  0x3ff81808744 in cob_acc_display() cob_accdis.c:349
    #1  0x120001fbc in testa() testa.cob:20
    #2  0x3ff8181f054 in main() cob_main.c:253
    (ladebug) file testa.cob
    (ladebug) stop at 20
    [#6: stop at "testa.cob":20 ]
  23. Resume execution with the cont command. TESTA executes its final display. The debugger regains control when STOP RUN executes.

    (ladebug) cont
    Thread has finished executing
  24. At this point you end the session with the q command.

    (ladebug) q                                        <>

Previous Next Contents Index