Debugging
Documentation
The debugger is in the
(Note: all commands should be typed without quotes and then
bin\win32 or bin\dos directories (the GDB.EXE file), for the Windows and DOS versions respectively. It usually comes already installed in most Linux distros.(Note: all commands should be typed without quotes and then
[return] must be pressed.)- Compile the source code for your program in debug mode
- use the
-gcommand-line option to add debugging support, e.g.fbc -g myapp.bas.
- use the
- Load your compiled program in GDB
- For example, in Windows/DOS:
gdb myapp.exe
- Note: under windows if the GDB command prompt seems not to work well (like backspace not working), try
set TERM=#win32conbefore launching GDB.
- For example, in Windows/DOS:
- For example:
set args arg1 arg2 argn.
- You can also run GDB and pass the arguments directly to the application been debugged:
gdb --args myapp.exe arg1 arg2 arg3.
- If the executable isn't in the same directory of the source files where it was compiled, type:
dir path/to/my/application/sources.
- Place a breakpoint in the first line using:
b main.
- To place a breakpoint in a function called
funcuse:b FUNC.
- Note: fbc exports variable/function names to UPPERCASE. GDB is case sensitive by default, but you can use the
set language pascalcommand to change GDB to case-insensitive mode.
- Type
rto start running the application.
- Type
nto step to the next line, stepping over function calls.
- Keep pressing
[return]to step forward to the next line.
- Type
sto step into function calls.
- As above, keep pressing
[return]to step through.
- Type
cto continue execution until the next breakpoint.
- Use
print VAR_NAMEto show the contents of the variable calledvar_name.
- GDB supports pointer/pointer field dereferencing, indexing and arithmetics too, so
print *MYPOINTERwill also work.
- (note: undeclared variables or the ones with suffixes like
%&!#$can't be printed).
- GDB supports pointer/pointer field dereferencing, indexing and arithmetics too, so
disp VAR_NAME to display the contents of a variable called var_name.watch VAR_NAME to stop each time a variable called var_name is changed.- Use
ragain to restart the application when it finishes.
- Type
qto quit.
- Type
helpto see a list of commands, there are many others.