How do I debug my Pascal programs?

Please note: The FAQ pages at the HPCVL website are continuously being revised. Some pages might pertain to an older configuration of the system. Please let us know if you encounter problems or inaccuracies, and we will correct the entries.

In any cases where your program is longer than a few hundred lines, you will need to be able to run it through a debugger. Pascal programs compiled with GPC can be debugged via the GNU debugger dbg which we have installed on our Sun Fire system. However, the debugger is designed for C-code, and is rather kloncky if used with Pascal. But it is the only debugger available that works with GPC.
To be able to use the debuuger with your Pascal code, you have to include the -g option in your compilation. Since this option and optimization of the code (i.e. the -O options) are mutually exclusive, you will have to remove any -O directives from your compile command lines. Then you can start the debugger by typing "gdbname_of_executable". The debugger is operated by typing in commands such as
run Start the program from the beginning
stop Stop the program from executing
break Insert a break at a given line of the code, or in a specific subroutine or function
cont Continue from the present position in the code until the next break is encountered
list List the code around the present break point
print Show the value of a variable

Since the debugger has trouble handling Pascal code instead of C-code, the following command lines should be typed in as sson as the debugger was entered (you can copy-and-paste them onto the dgb command line):
break init_pascal_main_program
break pascal_main_program
break '_p_runfinalizers'
This will enable the debugger to display the current lines in Pascal code.
The documentation for this debugger is available online or in PDF format for printing .