Debugging is enabled using the -g and -p options when calling the compiler. (see Compiler options.)
The compiler will generate code that is not optimised, and that allows to easily step thru the code.
The intermediate C++ code must be compiled with the -g option, and the debug library must be added using the '-lkoboldebug' option.
To debug a COBOL program with gdb, start gdb with as parameter the program name. (Refer to the gdb documentation for more details).
gdb myprog
The following gdb commands are supported (check the gdb manual for more detailed information):
b file:line
The b command is used to set a breakpoint in a cobol program. The file name given must be the Cobol source file, the line number given must be the number of a line in the PROCEDURE DIVISION. The line number used must be the sequential line number in the file, starting with 1.
n
The n command steps to the next Cobol instructions. It steps over PERFORMED procedures when a PERFORM statement is encountered.
s
The scommand steps to the next Cobol instructions. It steps in PERFORMED procedures when a PERFORM statement is encountered.
When stepping into a procedure, the next line shown by the debugger will be the one containing 'PROCEDURE DIVISION'. Use the 'n' command to proceed to the real start of the procedure.
At the end of execution of a procedure, the last line of the procedure division will be displyed. This is unfortunate, but is due to the way the generated code and gdb interact. Use the 'finish' command to finish execution of the procedure.
finish
The finish command is used to continue execution until the currently active procedure (started with a PERFORM) is finished.
The gdb debugger has no equivalents for most of the data used in a Cobol program. Therefore, Kobol will generate extra code to display data items.
Use the following command to show data items:
call displayWs ("regular-expresssion")
All data items whose name matches the regular expression will be displayed.
Some versions of gdb have a defect that may result in the following error message:
Cannot resolve method displayWs to any overloaded instance
This can be worked around by entering the command:
set overload-resolution off