How to print size of array (related) with gdb for Fortran program

I am starting to work in gdb under Linux. When I try to debug my program compiled with the ifort and -c, -g options, I would like to check the boundary of multiple arrays. Unfortunately, I cannot google any information on how to print the array associated with the gdb debugger.


I have a module with an allocatable, public array that is properly allocated in a routine from that module. In the main program (after calling the subroutine) I am trying to use whatis

and see (*,*)

shapes instead.


source to share

1 answer

You can use the whatis command to view the bounds of an array: for example,

program arr
  real, dimension(2:41) :: arr1
  real, allocatable, dimension(:), target :: arr2
  integer :: i


  forall(i = 2:41) arr1(i) = i
  arr2 = arr1 + 2

  print *, arr1(2)

end program are


Running gives

$ gfortran -g foo.f90
$ gdb a.out
(gdb) break 11
Breakpoint 1 at 0x400b01: file foo.f90, line 11.
(gdb) run

Breakpoint 1, arr () at foo.f90:11
11    print *, arr1(2)
(gdb) whatis arr1
type = real(kind=4) (2:41)
(gdb) whatis arr2
type = real(kind=4) (40)




All Articles