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.
gdb introduction by example is written for the science/engineering programmer who more typically uses a high-level language.
Note: In these descriptions, “function” is synonymous for program, function, and subroutine.
Start GDB Fortran debugger
- assuming executable
gdb --args ./myprog hello 3
- Run program in
gdb(perhaps after setting breakpoints) with
Breakpoints are where the debugger stops running until you type
Set breakpoints by
Example: Set a breakpoint in function
myfun on line 32
For breakpoints in Fortran modules in this example line 32 of a module named
mymod in function
List all variables
List all scope variables as two separate steps.
- local variables
- arguments to the function.
variable type, size (bytes/element), and shape (elements/dim) are available for each variable “var” by
Example: a Fortran
real64 3-D array of size 220 x 23 x 83:
var = REAL(8) (220,23,83)
If “var” is a “derived type” (similar to “struct” in other languages), get the same information about each record (akin to “property”) of the derived type by
function local variables
Local variables are variables used only within the scope of the function–excluding arguments to the function.
List the names and values of all arguments to the current function:
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, array values are printed as well.