Debugging lines missing from production COBOL build logs
0 reputation · 28 Jan 2022, 11:25 UTC
0 reputation · 28 Jan 2022, 11:25 UTC
When investigating a failed COBOL deployment, developers often rely on DEBUGGING lines and the USE FOR DEBUGGING declarative to trace program flow through log output. The goal is to retain this diagnostic capability in the production object module without incurring unnecessary size or performance penalties.
However, the inclusion of DEBUGGING lines depends on the WITH DEBUGGING MODE compiler option, and the exact syntax (column‑7 'D' versus *> DEBUG) and availability of the DEBUG‑ITEM register differ between IBM Enterprise COBOL, Micro Focus, and GnuCOBOL. This creates uncertainty about a portable strategy for keeping debugging code enabled across different compilers.
What compiler flags control the inclusion of DEBUGGING lines for each target platform? How does the USE FOR DEBUGGING declarative behave when the debugging mode is disabled? What are the measurable trade‑offs of leaving DEBUGGING lines in the final executable regarding object size and runtime overhead?
33775 reputation · 28 Jan 2022, 22:34 UTC
DEBUGGING lines and the USE FOR DEBUGGING declarative are conditionally compiled. If the production build is invoked without the debugging-mode option, the compiler treats every line marked with a D in the indicator area (column 7) as a comment and compiles the USE FOR DEBUGGING declarative as inert. The result is exactly the symptom described: no diagnostic output at runtime, even though the source still contains the debugging code. The fix is to compile with debugging mode enabled — but the flag name is vendor-specific.
The exact option names and defaults vary by release, so treat the following as the well-established conventions and confirm against your compiler's option reference before changing build scripts.
| Compiler | Typical control | Notes |
|---|---|---|
| IBM Enterprise COBOL | TEST / NOTEST governs debug information; the WITH DEBUGGING MODE clause in SOURCE-COMPUTER or the corresponding compile-time mechanism controls debugging lines | Historically, debugging mode was requested in the Environment Division; newer releases fold much of this into TEST. Verify for your version (e.g., 6.x). |
| Micro Focus COBOL | DEBUG / NODEBUG directive | Controls inclusion of debugging lines and declaratives; check whether your build uses directives files that override the command line. |
| GnuCOBOL | -fdebugging-line (compile flag); -debug for runtime tracing support | Without -fdebugging-line, D-lines are comments. DEBUG-ITEM support and *> DEBUG syntax availability differ by release. |
Because flag names, the DEBUG-ITEM register, and free-form *> DEBUG syntax are not portable, a cross-compiler strategy needs per-compiler source conventions or a preprocessing step — do not assume one flag works everywhere.
When debugging mode is disabled, the declarative section is compiled but never executed — the runtime has no hook to invoke it, and debugging lines it might reference are absent from the object. There is no error and no output; the code is simply dead. This is standard-defined behavior, so the missing logs are a compile-time decision, not a runtime failure.
D-line and a USE FOR DEBUGGING paragraph, once with production flags and once with debugging mode enabled.# GnuCOBOL example
cobc -x -fdebugging-line myprog.cob # debugging lines included
cobc -x myprog.cob # D-lines treated as commentsFlag names above are version-sensitive and flagged for human review against your specific compiler release.
Use comments to ask for clarification. Post a solution as an answer.
5,750 reputation · 28 Jan 2022, 22:14 UTC
One clarification worth adding to the flag table: on IBM Enterprise COBOL, TEST and WITH DEBUGGING MODE are independent mechanisms. TEST emits symbolic information for the debugger, but it does not cause column-7 D lines to compile — those still require debugging mode (the SOURCE-COMPUTER ... WITH DEBUGGING MODE clause). A build can have TEST on and still produce zero output from USE FOR DEBUGGING declaratives, which matches the reported symptom.
A quick way to confirm what's actually happening in your build: compile a minimal program with one D line and one declarative, then diff the compiler listing with and without the flag. If the D line shows as a comment in the listing, it's excluded regardless of runtime settings.
Also note the overhead isn't uniform: the declarative code itself is cheap, but DISPLAY-based tracing in batch jobs can dominate cost through I/O. Measuring object size alone understates that. Verify flag names against your installed compiler version.