To help you debug DEC COBOL programs on the Digital UNIX operating system, Ladebug supports:
print
command.
assign
command, including numeric
literals and other program items. However, there are some
limitations to assignment (see Section 13.5).
(ladebug) print itema + itemb
The following features are also supported for DEC COBOL debugging:
print
command
Some of the features are further described in this chapter. This chapter also:
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.
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:
-g
(or -g2
) flag, perhaps specifying
-O0
(which is the default with -g
or -g2
) to enable debugging and create unoptimized
code. This flag also might be chosen later to debug reported
problems from later stages.
-g3.
This flag might also be
used during later stages to debug reported problems. (Certain
problems may be reproducible only when the code is optimized,
but be aware that debugging inaccuracies can result from the
optimization.)
-g0
to minimize the object file
size and, as a result, the memory needed for program execution,
with fully optimized code for best performance.
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.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.
COBOL_EXAMPLE
is implicitly
external and is emitted as cobol_example.
external
causes B-2
to be emitted as B_2
and C_3
to be
emitted as C_3.
overloaded-
name.
Because it is a local symbol, it is emitted as
OVERLOADED-NAME.
C_3
and C-3
refer to the
same object, which is C_3
in 2.
D-4
and D_4
refer to the
local symbol emitted as D-4.
overloaded-
name.
Since it is a program ID, it is implicitly external
and is emitted as overloaded_name.
b_2.
Because
it is a local symbol, it is emitted as B-2.
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.
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
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.
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
B_2 PIC X external
instance of b-2
is the one visibile in the
current scope.
b-2
refers to
"example.cob"`cobol_example`B_2
, which has a value
of 2.
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.
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.
The following limitations apply to assignment in COBOL debugging:
01 itema pic 9(9)v99. 01 itemb pic 9999v99. 01 bigitem pic 9(13)v9(5).
The debugger allows assignment of the values 1.23 or 8765.22 to
itema,
but does not allow assignment of the value
1.2 to itema.
The following debugger commands are
supported because the quantities on both sides of the assignment
operator (=) have the same scale:
(ladebug) assign itema = 1.23 (ladebug) assign itema = 8765.22 (ladebug) assign itema = itemb
The following debugger commands are not supported because the quantities involved are of different scales:
(ladebug) assign itema = 1.2 (ladebug) assign bigitem = itema
itema
has greater precision than
itemb:
(ladebug) assign itemb = itema
Other limitations when you debug COBOL programs include:
01 A. 03 B. 05 C pic 9.
For this group, the debugger cannot find C unless you fully qualify it, as follows:
C of B of a
C of B of a
for the group is
supported, but not if B
is an OCCURS item.
For the transformation rules, see Section 13.3.
(ladebug) ./10i
This debugger command says "from the current program location" (signified by the dot), examine the next 10 program locations (10 being the count) in instruction mode (signified by the "i").
When debugging COBOL programs, you need to enter this command as follows:
(ladebug) ./10 i
Add a space between the count (10
) and the mode
indicator (i
) .