Debugging Fortran code with GNU Debugger
gdb is roughly akin to debugging from the command line with Python
Intel forked GDB into
formerly “gdb-ia”, that replaced “idb”.
gdb is capable of far more than what’s listed here, down to stack registers and assembly instructions.
works with Visual Studio Code.
Start GDB Fortran debugger: assuming executable
myprog with arguments
gdb --args ./myprog hello 3
Run program in
gdb (perhaps after setting breakpoints) with
A typical debugging task uses breakpoints. 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 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 Fortran derived type, get the same information about each record (akin to “property”) of the derived type by:
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.