To use gdb to debug your program, you can start the debugger, and give it as an option the full name of your program:
gdb hello |
gdb hello.exe |
This starts the debugger, and the debugger immediately loads your program into memory, but it does not run the program yet. Instead, you are presented with the following (more or less) message, followed by the gdb prompt '(gdb)':
GDB is free software and you are welcome to distribute copies of it under certain conditions; type "show copying" to see the conditions. There is absolutely no warranty for GDB; type "show warranty" for details. GDB 4.15.1 (i486-slackware-linux), Copyright 1995 Free Software Foundation, Inc... (gdb) |
(gdb) run -option -anotheroption needed_argument |
If something went wrong (a segmentation fault or so), gdb will stop the execution of your program, and inform you of this with an appropriate message. You can then use the other gdb commands to see what happened. Alternatively, you can instruct gdb to stop at a certain point in your program, with the break command.
Here is a short list of gdb commands, which you are likely to need when debugging your program:
Remark: My copy of gdb needs ’.’ to be added explicitly to the search path, otherwise it doesn’t find the sources.
for more information, see the gdb users’ guide, or use the 'help' function in gdb.
The appendix F contains a sample init file for gdb, which produces good results when debugging Free Pascal programs.
It is also possible to use RHIDE, a text-based IDE that uses gdb. There is a version of RHIDE available that can work together with FPC.