This is a “cheat sheet” for debugging Fortran code with
gdb (and Intel’s fork
gdb-ia that replaces
idb), targeted to those accustomed to Matlab or Python code debugging.
gdb is capable of far more than what’s listed here, down to stack registers and assembly instructions, but this is written for the science/engineering programmer who more typically uses a high-level language.
Note: In these descriptions, “function” is synonomous for program, function, and subroutine.
Start GDB debug of Fortran
assuming you have Fortran compiled program
myprog with arguments
gdb --args ./myprog hello 3
start the program (perhaps after setting breakpoints) with
Breakpoints are where the debugger stops running until you type
Set breakpoints by functionName:lineNumber.
So for function
myfun (gdb will find where it is) you might type
If you’re using modules, let’s suppose
List all variables
list all variables as two separate steps–one for local variables, and another for the arguments to the function.
Variable shape (elements/dim) and size (bytes/element)
variable type, per-element size in bytes, and shape are available for each variable “var” by
var = REAL(8) (220,23,83)
would be for a
real64 3-D array.
If “var” is a “derived type” (similar to “struct” in other languages) you can get the same information about each record “prop” of the derived type by
List values/names of function local variables
Local variables are variables used only within the scope of the function–excluding arguments to the function.
List values/names of function arguments
This lists the names and values of all arguments to the function you’re currently in.
For example, if you’re in
integer function myfun(a,b) or
subroutine mysub(a,b), upon
info args you’d see perhaps
a = 1.5 b = 0.2
b are arrays or structs, etc. you will see array values printed as well.