Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran module variables not accessible in debuggers

I've compiled a Fortran code, which contains several modules, using both gfortran 4.4 and intel 11.1 and subsequently tried to debug it using both gdb and DDT. In all cases, I cannot see the values of any variables that are declared in modules. These global variables have values, as the code still runs correctly, but I can't see what the values are in my debuggers. Local variables are fine. I've had trouble finding a solution to this problem elsewhere online, so perhaps there is no straightforward solution, but it's going to be really difficult to debug my code if I can't see the values of any of my global variables.

like image 277
rks171 Avatar asked Apr 22 '12 00:04

rks171


1 Answers

With newer GDBs (7.2 if I recall correctly), debugging modules is simple. Take the following program:

module modname
  integer :: var1 = 1 , var2 = 2
end module modname

use modname, only: newvar => var2
newvar = 7
end

You can now run:

$ gfortran -g -o mytest test.f90; gdb --quiet ./mytest
Reading symbols from /dev/shm/mytest...done.
(gdb) b 6
Breakpoint 1 at 0x4006a0: file test.f90, line 6.
(gdb) run
Starting program: /dev/shm/mytest
Breakpoint 1, MAIN__ () at test.f90:6
6       newvar = 7
(gdb) p newvar
$1 = 2
(gdb) p var1
No symbol "var1" in current context.
(gdb) p modname::var1
$2 = 1
(gdb) p modname::var2
$3 = 2
(gdb) n
7       end
(gdb) p modname::var2
$4 = 7
(gdb)
like image 138
Tobias Avatar answered Oct 13 '22 12:10

Tobias