Printing allocatable array in Fortran with gdb: Un

2019-08-14 05:42发布

问题:

This question already has an answer here:

  • Fortran print allocatable array in gdb 3 answers

I've debugged the following piece of code in Cygwin and Eclipse using gdb as the debugger:

program codetest
    implicit none

    integer, parameter :: dp = kind(1.0d0)
    integer, parameter :: N = 10
    real(dp), dimension(:), allocatable :: vector
    integer :: i

    allocate(vector(1:N))

    forall(i = 1:10)
        vector(i) = sqrt(real(i, dp))
    end forall

    write(*, '(F7.3, 1X)', advance = 'no') (vector(i), i = 1, N)

    deallocate(vector)
end program codetest

When running gdb, I attempt to print the allocatable array "vector" following its allocation, but I end up with the following:

(gdb) p vector
Unhandled dwarf expression opcode 0x97

I've scoured Stack Overflow and Google, but I haven't found anything that gets to the heart of the matter. I've checked out the following,

  • http://numericalnoob.blogspot.be/2012/08/fortran-allocatable-arrays-and-pointers.html
  • Unhandled dwarf expression
  • Fortran print allocatable array in gdb

but I'm still not understanding what the problem is or how to fix it. I've gotten the same complaint from gdb in Eclipse (Mars.1 Release, 4.5.1) when trying to print/display the contents of a derived type. Current specs about my machine/compiler/debugger include the following:

  • Windows 8.1
  • gfortran version: GNU Fortran (GCC) 4.9.3
  • gdb version: GNU gdb (GDB) 7.8

Any help is appreciated.

回答1:

As was pointed out in the comments, I just needed to update my version of gdb, which I did via Cygwin. I'm now running gdb version 7.9.1-1 with the same version of gfortran as before.