Skip to content

Instantly share code, notes, and snippets.

@MaikBeckmann
Created September 18, 2012 18:08
Show Gist options
  • Save MaikBeckmann/3744733 to your computer and use it in GitHub Desktop.
Save MaikBeckmann/3744733 to your computer and use it in GitHub Desktop.

gdb and gfortran

gdb seems not to be able to reason about dynamically allocated fortran arrays. Here an example

program test
  implicit none
  double precision, dimension(3) :: sa
  double precision, dimension(:), pointer :: da
  integer :: i

  allocate(da(size(sa)))
  do i= 1, size(sa)
    sa(i) = i
    da(i) = i
  end do
  print *, da
end program test

Compiled via

/tmp $ gfortran --version
GNU Fortran (GCC) 4.7.1 20120721 (prerelease)
...
/tmp $ gfortran -g -O0 test.f90 -o test
/tmp $ gdb test
Reading symbols from /tmp/test...done.
(gdb) b 13
Breakpoint 1 at 0x4009c7: test.f90:13. (2 locations)
(gdb) run
Starting program: /tmp/test 
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Breakpoint 1, main (argc=1, argv=0x7fffffffcd5f) at test.f90:13
13      end program test
(gdb) c
Continuing.
   1.0000000000000000        2.0000000000000000        3.0000000000000000     

Breakpoint 1, test () at test.f90:13
13      end program test
(gdb) p sa
$1 = (1, 2, 3)
(gdb) p da
$2 = (0)
(gdb) ptype sa
type = real(kind=8) (3)
(gdb) ptype da
type = real(kind=8) (*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment