title: Global arrays/structs not accessible in gdb while debugging gfortran executable in Eclipse
body: <p>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 <strong>simple</strong> external variables properly. Consider this simplified example:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Eclipse's variable list will properly show the local variables (<code>i</code>) and the inputs (<code>invar</code>) even if they're modules/arrays, but any external/global variables (<code>extvar, extarray, extstruct</code>) 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:</p>
  
  <blockquote>
    <p>Multiple errors reported.</p>
    
    <p>1) Failed to execute MI command:
    -var-create - * extvar Error message from debugger back end:
    -var-create: unable to create variable object</p>
    
    <p>2) Unable to create variable object</p>
    
    <p>3) Failed to execute MI command:
    -data-evaluate-expression extvar Error message from debugger back end: No symbol "extvar" in current context.</p>
    
    <p>4) Failed to execute MI command:
    -var-create - * extvar Error message from debugger back end:
    -var-create: unable to create variable object</p>
  </blockquote>
  
  <p>I discovered the special notation used by the compiler to store these global variables in the binary executable using the command:</p>
  
  <pre><code>nm &lt;binaryname&gt; | grep &lt;modulename&gt;
  </code></pre>
  
  <p>I can then generally see the global module members in gdb by typing:</p>
  
  <pre><code>print __&lt;modulename&gt;_MOD_&lt;membername&gt;
  </code></pre>
  
  <p>However, <strong>it only works for simple member types in the module</strong>! For  example I can see the integer member properly:</p>
  
  <pre><code>print __ext_class_MOD_extvar
  $1 = 0
  </code></pre>
  
  <p>For a static array of integers, it improperly <strong>only prints the first element</strong>, thus preventing me from viewing any of the member array's other elements:</p>
  
  <pre><code>print __ext_class_MOD_extarray
  $2 = 0
  print __ext_class_MOD_extarray(1:4)
  Cannot perform substring on this type
  </code></pre>
  
  <p>For a structure type, it improperly <strong>only prints the first member</strong> (<code>svar1</code>), thus preventing me from viewing any of the structure's other members:</p>
  
  <pre><code>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.
  </code></pre>
  
  <p>I read <a href="https://stackoverflow.com/questions/10264329/fortran-module-variables-not-accessible-in-debuggers">here</a> 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 <code>-g -O0</code></p>