Debugging: cobcdebug and -g

Compile with -g

Add -g when compiling to keep source lines in the object. Without it the debugger shows machine-level views only:

cobc -x -free -g -o payroll payroll.cob

Run the debugger

GnuCOBOL ships cobcdebug, a source-level debugger. Set breakpoints by paragraph name, step sentence by sentence, and print any working-storage field by name. This build does not install cobcdebug, so the session below is not run on this page:

cobcdebug ./payroll break PROCESS-ROW run display WS-TOTAL-PAY

DISPLAY as a poor man debugger

In production shops, a temporary DISPLAY of the suspect field is still the fastest way to see a value. Remove it before release: stray DISPLAY lines are a classic mainframe audit finding.

The compile command on this page was run with GnuCOBOL 3.2.0 on Alpine Linux 3.24.3 (x86_64) in a Docker container. The cobcdebug session was not run: cobcdebug is not installed in this environment.

Article author: Arthur Isaev