I'm using Eclipse (Neon.3 Release 4.6.3) with gdb 7.11.1 and gfortran 5.4.0, to debug an executable, but it only seems possible to watch local subroutine variables and simple external variables properly. Consider this simplified example:
module ext_class
type extstruct_type
integer(kind=4), ::svar1
integer(kind=4), ::svar2
end type extstruct_type
integer(kind=4), save :: extvar
integer(kind=4), dimension(4), save :: extarray
type (extstruct_type), save :: extstruct
end
module mod
subroutine foo(invar)
use ext_class, only : extvar, extarray, extstruct
type (real::8), intent(in) :: invar
integer(kind=4) :: i
...
!Debugger breakpoint inserted here to check variable visibility
end
end
Eclipse's variable list will properly show the local variables (i
) and the inputs (invar
) even if they're modules/arrays, but any external/global variables (extvar, extarray, extstruct
) don't show up in the list. If I try typing them manually into the "expressions" view, it gives errors about being unable to evaluate missing symbols:
Multiple errors reported.
1) Failed to execute MI command: -var-create - * extvar Error message from debugger back end: -var-create: unable to create variable object
2) Unable to create variable object
3) Failed to execute MI command: -data-evaluate-expression extvar Error message from debugger back end: No symbol "extvar" in current context.
4) Failed to execute MI command: -var-create - * extvar Error message from debugger back end: -var-create: unable to create variable object
I discovered the special notation used by the compiler to store these global variables in the binary executable using the command:
nm <binaryname> | grep <modulename>
I can then generally see the global module members in gdb by typing:
print __<modulename>_MOD_<membername>
However, it only works for simple member types in the module! For example I can see the integer member properly:
print __ext_class_MOD_extvar
$1 = 0
For a static array of integers, it improperly only prints the first element, thus preventing me from viewing any of the member array's other elements:
print __ext_class_MOD_extarray
$2 = 0
print __ext_class_MOD_extarray(1:4)
Cannot perform substring on this type
For a structure type, it improperly only prints the first member (svar1
), thus preventing me from viewing any of the structure's other members:
print __ext_class_MOD_extstruct
$3 = 0
print __ext_class_MOD_extstruct%svar2
Attempt to extract a component of a value that is not a structure.
I read here that this might actually be a problem with gfortran, not gdb, because it works fine when using Intel compilers. Is there possibly an extra flag I need to set when compiling? I already use -g -O0