4

I am a beginner in gdb under Linux. When I try to debug my program compiled with ifort and -c, -g options, I would like to check bound of several arrays. Unfortunately I cannot find in Google any information how to print array bound with gdb debugger.

[update]

I have a module with allocatable,public array, which is allocated correctly in a subroutine from this module. In main program (after calling the subroutine) I try to use whatis and see (*,*) instead of shapes.

1 Answer 1

6

You can use the whatis command to view array bounds: e.g.,

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

  allocate(arr2(40))

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

  print *, arr1(2)

  deallocate(arr2)
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)
Sign up to request clarification or add additional context in comments.

4 Comments

I should note that the above also works with ifort, with the only difference being slightly different formatting in the output: type = REAL(4) (2:41), etc.
Thank you a lot for your help! But what about allocatable,public arrays? I've tried whatis command in a main program with array defined as allocatable public in a called routine from a module. I've just see (,) dimension...
@KonstantinEbauer , can you give a code example? Is the array allocated yet?
how can you do this with ifort? Please provide some guidance thank you...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.