13 Debugging DEC COBOL Programs

13.1 Significant Supported Features

To help you debug DEC COBOL programs on the Digital UNIX operating system, Ladebug supports:

The following features are also supported for DEC COBOL debugging:

Some of the features are further described in this chapter. This chapter also:

13.2 DEC COBOL Flags for Debugging

To use the Ladebug debugger on a COBOL program, invoke the COBOL compiler with the appropriate debugging flag: -g, -g2, or -g3. For example:

% cobol -g -o sample sample.cob

The -g flag on the compiler command instructs the compiler to write the program's debugger symbol table into the executable image. This flag also turns off optimization; optimization (which is the default for nondebugger compilations) could cause a confusing debugging session.

For Digital UNIX Vesion 3.2 systems, Table 13-1 summarizes the information provided by the - g n flags and their relationship to the - On flags, which control optimization. Refer to your language compiler documentation for information about compiler flag defaults for Digital UNIX Version 4.0.

Table 13-1 Summary of Symbol Table Flags

Flag  Traceback Information  Debugging Symbol Table Information  Effect on -On Flags 
-g0   No  No  Default is - O4 (full optimization). 
-g1 (default)  Yes  No  Default is -O4 (full optimization). 
-g2 or - g   Yes  Yes. For unoptimized code only.  Changes default to -O0 (no optimization). 
-g3   Yes  Yes. Use with optimized code. Inaccuracies may result.  Default is -O4 (full optimization). 

If you specify -g, -g2, or - g3, the compiler provides symbol table information for symbolic debugging. The symbol table allows the debugger to translate virtual addresses into source program routine names and compiler-generated line numbers.

Later, to remove this symbol table information, you can compile and link it again (without the -g flag) to create a new executable program or use the strip command (see strip(1) ) on the existing executable program.

The -g2 or -g flag provides symbol table information for symbolic debugging unoptimized code. If you use the -g2 or -g flag and do not specify an -On flag, the default optimization level changes to -O0 (in all other cases, the default optimization level is -O4 ) . If you use this flag and specify an -On flag other than - O0, a warning message is displayed. For example:

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

The -g3 flag is for symbolic debugging with optimized code.

Typical uses of the debugging flags at the various stages of program development are as follows:

13.3 Support for COBOL Identifiers

Ladebug supports the case insensitivity of COBOL identifiers and the hyphen-underscore exchanges made by the DEC COBOL compiler.

In case-insensitive languages (such as COBOL, Fortran, and Ada), you can enter identifiers in either uppercase or lowercase, or a combination of both. For example, the following are all legal and equivalent identifiers:

Identifier IDENTIFIER identifier IdEnTiFiEr

Ladebug and the DEC COBOL compiler treat all forms of identifers as references to the same object.

The DEC COBOL compiler performs transformations on identifiers with regard to both case and occurrences of hyphens and underscores. These transformed identifiers are visible in the listing file and in the symbol table of an image compiled with the -g flag. The rules for transformations are as follows:

Ladebug transforms all identifiers according to rule 2. When such a transformation causes a namespace conflict, an identifier is considered overloaded. When overloading occurs, it is necessary that you qualify an identifier to make it unique, as shown in Example 13-1, which demonstrates the application of the rules for transformation. Example 13-2 shows how Ladebug handles the COBOL identifiers.

Example 13-1 Sample COBOL Program

example.cob:
* Ladebug Version 4.0
*
* Demonstrates usage of COBOL expressions with Ladebug
*
* There are three procedures in this file, namely cobol_example,
* overloaded_name and b-2.
*
* (Rule #1)
* In cobol_example, note the symbols B-2 and C_3: these two are given as
* external and appear in the symbol table as B_2 and C_3 respectively.
* C-3 and C_3 are equivalent as are D-3 and D_3

*
* (Rule #2)
* In the procedure COBOL_EXAMPLE is the symbol overloaded-name, which appears
* in the symbol table as OVERLOADED-NAME
*
* (Rule #3)
* The procedure OverLoaded-NAME appears in the symbol table as
* overloaded_name.


* The procedure b-2 appears in the symbol table as b_2
*
* Note that there are three names referred to as B-2:
*
* "example.cob"`cobol_example`B_2    -- PIC X external
* "example.cob"`overloaded_name`B-2  -- PIX 99
* "example.cob"`b_2                  -- program id
*


IDENTIFICATION DIVISION.
PROGRAM-ID. COBOL_EXAMPLE.          1

DATA DIVISION.
WORKING-STORAGE SECTION.
01 A_1 PIC X VALUE IS "1".
01 B-2 PIC X             external.  2
01 C_3 PIC X             external.
01 D-4 PIC X VALUE IS "4".
01 overloaded-name pic 99.          3


PROCEDURE DIVISION.
P0-lab.
 DISPLAY "*** Ladebug COBOL Example ***".
 MOVE "2" TO B_2.
 MOVE "3" TO C-3.
 DISPLAY "A_1 = " A_1.
 DISPLAY "B-2 = " B-2.
 DISPLAY "C_3 = " C_3.       4
 DISPLAY "C-3 = " C-3.
P0_lab.
 DISPLAY "D-4 = " D-4.       5
 DISPLAY "D_4 = " D_4.
 CALL "Overloaded-Name".     6
 CALL "B-2".
 DISPLAY "***END Ladebug COBOL Example***".
 STOP RUN.
end program cobol-example.



identification division.
program-id. OverLoaded-NAME.        6

data division.
working-storage section.
01 b_2 pic 99 value is 12.          7

procedure division.
beg1.
        display "*** Overloaded-Name ***".
 display "b_2 = " b-2.       7
 display "*** end of Overloaded-Name ***".
end program overloaded-name.



identification division.
program-id. b-2.                    8

data division.
working-storage section.
procedure division.
beg1.

        display "*** b_2 ***".
 display "*** end of b_2 ***".
end program b-2.

  1. The program ID COBOL_EXAMPLE is implicitly external and is emitted as cobol_example.

  2. The use of external causes B-2 to be emitted as B_2 and C_3 to be emitted as C_3.

  3. This is the first occurrence of overloaded- name. Because it is a local symbol, it is emitted as OVERLOADED-NAME.

  4. Both C_3 and C-3 refer to the same object, which is C_3 in 2.

  5. Both D-4 and D_4 refer to the local symbol emitted as D-4.

  6. This is the second occurrence of overloaded- name. Since it is a program ID, it is implicitly external and is emitted as overloaded_name.

  7. This is the second occurrence of b_2. Because it is a local symbol, it is emitted as B-2.

  8. This is the third occurrence of b-2. Since it is a program ID, it is implicitly external and is emitted as b_2.

The sample debugging session in Example 13-2 demonstrates how Ladebug handles the symbols from the sample COBOL program in Example 13-1.

Example 13-2 Sample COBOL Debugging Session

Welcome to the Ladebug Debugger Version 4.0
------------------
object file name: example
Reading symbolic information ...done

(ladebug) stop at 51
[#1: stop at "example.cob":51 ]
(ladebug) run

*** Ladebug COBOL Example ***
A_1 = 1
B-2 = 2
C_3 = 3
C-3 = 3
D-4 = 4
D_4 = 4
[1] stopped at [cobol_example:51 0x12000cd14]
     51         CALL "Overloaded-Name".
(ladebug) whatis d-4   1
array [subrange 1 ... 1 of int] of char d-4
(ladebug) whatis D_4   1
array [subrange 1 ... 1 of int] of char D_4
(ladebug) print d_4    1
"4"
(ladebug) whereis d-4  1
"example.cob"`cobol_example`D-4


(ladebug) whereis b-2  2
"B_2"
B_2
"example.cob"`cobol_example`B_2
"example.cob"`overloaded_name`B-2
"example.cob"`b_2

(ladebug) which b-2    3
"example.cob"`cobol_example`B_2
(ladebug) print b-2    4
2

(ladebug) step
stopped at [overloaded_name:61 0x12000ce04]
     61 program-id. OverLoaded-NAME.
(ladebug) stop at 78 
[2] stopped at [cobol_example:78 0x12000cf20]


(ladebug) next

stopped at [overloaded_name:69 0x12000ce30]
     69         display "*** Overloaded-Name ***".
(ladebug) which b-2    5
"example.cob"`overloaded_name`B-2

(ladebug) whatis b-2
 pic 99 usage display b-2
(ladebug) print b-2
12


(ladebug) return
*** Overloaded-Name ***
b_2 = 12
*** end of Overloaded-Name ***
stopped at [cobol_example:51 0x12000cd58]
     51         CALL "Overloaded-Name".

(ladebug) n
stopped at [cobol_example:52 0x12000cd68]
     52         CALL "B-2".

(ladebug) s
stopped at [b_2:78 0x12000cef4]
     78 program-id. b-2.

(ladebug) which b-2
"c_example6-2.cob"`b_2
(ladebug) whatis c_example6-2.cob`b_2
void b_2(void)


(ladebug) cont
*** b_2 ***
*** end of b_2 ***
***END Ladebug COBOL Example***
Thread has finished executing
(ladebug) q

  1. Since there is only one object named D-4, all four spellings are resolved to the same address. The whereis command displays only one instance of d-4, namely "example.cob"`cobol_example`D- 4.

  2. There are three different instances of b-2 in this example. The whereis command lists all three.
     "example.cob"`cobol_example`B_2    -- PIC X external
     "example.cob"`overloaded_name`B-2  -- PIX 99
     "example.cob"`b_2                  -- program id
    

  3. Based on the current context, the B_2 PIC X external instance of b-2 is the one visibile in the current scope.

  4. Based on callout 3, b-2 refers to "example.cob"`cobol_example`B_2 , which has a value of 2.

  5. Since the current context is in the procedure Overloaded-name, the which command refers to the B-2 local to Overloaded- name ("example.cob"`overloaded_name`B-2` ) .

For another example of debugging a COBOL program with Ladebug, see the appendix on tools in the DEC COBOL User Manual.

13.4 Debugging Mixed-Language Programs

The Ladebug debugger lets you debug mixed-language programs. The flow of control across programs written in different languages in your executable image is transparent.

The debugger automatically identifies the language of the current program or code segment on the basis of information embedded in the executable file. For example, if program execution is suspended in a code segment in COBOL, the current language is COBOL. If the program executes a C function, the current language becomes C. The current language determines for the debugger the valid expression syntax and the semantics used to evaluate an expression.

The debugger sets the $lang variable to the language of the current program or code segment. By manually setting the $lang debugger variable, you can force the debugger to interpret expressions used in commands by the rules and semantics of a particular language. For example, you can check the current setting of $lang and change it as follows:

(ladebug) print $lang
"C++"
(ladebug) set $lang = "Cobol"

When the debugger reaches the end of your program, the $lang variable is not set to the language of the _ exit routine, which is written in machine code.

13.5 Limitations on Assignment

The following limitations apply to assignment in COBOL debugging:

13.6 Other Limitations

Other limitations when you debug COBOL programs include: