Global arrays / structures not available in gdb when debugging gfortran executable in Eclipse

I use Eclipse (Neon.3 Release 4.6.3) with gdb 7.11.1 and gfortran 5.4.0 to debug the executable, but it seems that you can only observe local subroutine variables and simple strong> external variables. 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 

List of Variables Eclipse will correctly display local variables ( i ) and inputs ( invar ), even if they are modules / arrays, but any external / global variables ( extvar, extarray, extstruct ) are not displayed in the list. If I try to enter them manually in the expression view, this will give errors in that you cannot evaluate the missing characters:

Several bugs reported.

1) Failed to execute MI command: -var-create - * extvar Error message from the end of the debugger: -var-create: cannot create a variable object

2) Unable to create a variable object

3) The MI command failed to execute: -data-evaluation-expression extvar Error message from the back of the debugger: in the current context, the symbol "extvar" is missing.

4) Failed to execute the MI command: -var-create - * extvar Error message from the end of the debugger: -var-create: cannot create a variable object

I found a special notation used by the compiler to store these global variables in a binary executable using the command:

 nm <binaryname> | grep <modulename> 

In general, I can see the global members of a module in gdb by typing:

 print __<modulename>_MOD_<membername> 

However, it only works for simple member types in a module ! For example, I can correctly see the integer element:

 print __ext_class_MOD_extvar $1 = 0 

For a static array of integers, it only prints the first element incorrectly, which prevents me from viewing any of the elements in the array of other elements:

 print __ext_class_MOD_extarray $2 = 0 print __ext_class_MOD_extarray(1:4) Cannot perform substring on this type 

For the structure type, it only incorrectly prints the first element ( svar1 ), which prevents me from viewing any structure of 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 could be a problem with gfortran, not gdb, because it works fine when using Intel compilers. Is it possible to set an additional flag during compilation? I already use -g -O0

+1
source share
1 answer

EDIT: This problem has been resolved in some versions (gfortran 6.2.0 with gdb 7.12 on MacOS, but not on the same versions in Ubuntu). Upgrade to the latest version before trying the following steps.

I found a workaround that is also compatible in Eclipse. It seems that the binary does not track information about the types of variables, but only their addresses in memory. Thus, variables can be viewed by converting them to the appropriate type. Type __ext_class_MOD_extstruct into the Eclipse Expressions tab, then right-click the entry and select Cast to type ... by typing extstruct_type ! Alternatively, just type

 (extstruct_type)__ext_class_MOD_extstruct 

on the expression tab. Note that no asterisks are specified (different from C syntax). The same thing can be achieved on the gdb command line, and individual members can be obtained by name using the % separator:

 print ((extstruct_type)(__ext_class_MOD_extstruct) $5 = (0, 0) print ((extstruct_type)(__ext_class_MOD_extstruct)%svar2 $6 = 0 

The Eclipse instance "expression" "Display as an array ..." fails because it seems to use syntax syntax ( * ) arithmetic, which is incompatible with gdb for fortran, but works when manually omitting the stars

 print __ext_class_MOD_extarray@4 $7 = (0, 0, 0, 0) print __ext_class_MOD_extarray(2) Cannot perform substring on this type 

Please note that access to individual elements of the array is still not performed in some versions. Let's hope that they fix this problem once and for all in new versions.

0
source

All Articles