10.1 Compiling your program with debugger support

First of all, you must be sure that the compiler is compiled with debugging support. Unfortunately, there is no way to check this at run time, except by trying to compile a program with debugging support.

To compile a program with debugging support, just specify the -g option on the command line, as follows:

fpc -g hello.pp

This will incorporate debugging information in the executable generated from your program source. You will notice that the size of the executable increases substantially because of this1.

Note that the above will only incorporate debug information for the code that has been generated when compiling hello.pp. This means that if you used some units (the system unit, for instance) which were not compiled with debugging support, no debugging support will be available for the code in these units.

There are 2 solutions for this problem.

1.
Recompile all units manually with the -g option.
2.
Specify the ’build’ option (-B) when compiling with debugging support. This will recompile all units, and insert debugging information in each of the units.

The second option may have undesirable side effects. It may be that some units aren’t found, or compile incorrectly due to missing conditionals, etc.

If all went well, the executable now contains the necessary information with which you can debug it using gnu gdb.

1A good reason not to include debug information in an executable you plan to distribute.