Debugging & Compiler Options

28.1 DISPLAY tracing

The simplest, universal technique:

Use a debug switch so traces can stay in the code:

Debugging lines (D in column 7) compile only when WITH DEBUGGING MODE is specified in SOURCE-COMPUTER (or GnuCOBOL -fdebugging-line):

DISPLAY "DBG 2200-CALC: AMT=" WS-AMOUNT " RATE=" WS-RATE
01  WS-DEBUG-SW          PIC X VALUE "N".
           88  DEBUG-ON         VALUE "Y".
      * ...
           IF DEBUG-ON
               DISPLAY "DBG READ CUST " CUST-ID " FS=" WS-CUST-FS
           END-IF
SOURCE-COMPUTER. X86-64 WITH DEBUGGING MODE.
      * ...
      D    DISPLAY "THIS LINE ONLY IN DEBUG BUILDS"

28.2 GnuCOBOL options

-Wall, -Wextra Runtime checks: subscripts, reference modification, numeric data, file status without handlers

Enable specific exception checks (COBOL 2002 exception names) -ftrace, -ftraceall

Trace paragraph/section (and statement) execution; output controlled by COB_SET_TRACE and COB_TRACE_FILE

Keep generated C and debug info for gdb (GnuCOBOL's cobcd gdb extension helps debug at COBOL level)

-t file.lst, -Xref, -O2, -std=ibm Listing and cross-reference, optimization, dialect

Runtime errors in GnuCOBOL report the program, line, and reason (e.g., "subscript of 'WS-SALES' out of bounds: 13").

28.3 IBM Enterprise COBOL options (selection)

Debug information for IBM z/OS Debugger Runtime check of subscripts, indexes, reference modification

Runtime check that numeric data is valid (6.2+) Compile-time detection of items used before being initialized LIST, MAP, XREF, OFFSET

Listing: generated assembler, data map, cross-reference, offsets Target hardware generation

NUMPROC(PFD/NOPFD), TRUNC(STD/OPT/BIN) Numeric sign and binary truncation behavior RENT, DYNAM

Reentrant code; dynamic CALL for literals Integrated DB2 and CICS coprocessors

28.4 Common z/OS abends

Non-numeric data in a packed/zoned field used in arithmetic (uninitialized field, wrong record layout)

Subscript out of range, bad LINKAGE address, parameter mismatch Decimal divide exception

Division by zero without ON SIZE ERROR Module not found Dynamic CALL target not in STEPLIB/JOBLIB CPU time exceeded

Infinite loop or job TIME limit too low SB37 / SD37 / SE37

Dataset needs more primary/secondary space or extents DCB conflict (record length, RECFM) between program and dataset LE severe error

Language Environment detected a severe condition (see CEEDUMP/message)

Tools: IBM z/OS Debugger (formerly Debug Tool; step through source, set breakpoints, watch variables, from VS Code/IDz), IBM Fault Analyzer, BMC Compuware Xpediter and Abend-AID, LE CEEDUMP, and the compile listing — use OFFSET to map the abend offset to a statement.

28.5 File error handling with DECLARATIVES

The declarative runs automatically after any I/O error on the file not handled by AT END/INVALID KEY.

PROCEDURE DIVISION.
       DECLARATIVES.
       CUST-FILE-ERROR SECTION.
           USE AFTER STANDARD ERROR PROCEDURE ON CUST-FILE.
       CUST-ERR-PARA.
           DISPLAY "I/O ERROR ON CUST-FILE, STATUS " WS-CUST-FS.
       END DECLARATIVES.

       MAIN-LOGIC SECTION.
       0000-MAIN.
      *    ... normal processing ...