1

I have three machine, two run Linux and one run OS X Yosemite with different version of gfortran and gdb. gdb on my old box work well with allocated arrays, however, newer version of gdb (after 7.2) and gfortran (after 4.7) do not seem to be able to examine the allocatable variables.

My question is: is this an expected behavior or is there a patch to keep gfortran, gdb work like the older version?

This is a small version of code I tested:

integer :: x(2,3)
integer, allocatable :: y(:,:)

allocate(y(2,3))

x = reshape([1,2,3,4,5,6], [2,3], order=[2,1])
y = reshape([1,2,3,4,5,6], [2,3], order=[2,1])

print *, 'x', transpose(x)
print *, 'y', transpose(y)

end

And results from three machine

It works well on 4.7 on Fedora 17 (no longer maintained)

[qlle@(none) ~]$ gdb --version | head -n1
GNU gdb (GDB) Fedora (7.4.50.20120120-54.fc17)
[qlle@(none) ~]$ gfortran --version | head -n1
GNU Fortran (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)

(gdb) i lo
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = (( 1, 4) ( 2, 5) ( 3, 6) )
(gdb) p y(:,2)
$1 = (2, 5)
(gdb) p y(2,:)
$2 = (4, 5, 6)
(gdb) show language 
The current source language is "auto; currently fortran".

However, with latest version through homebrew on Mac machine, I got incomplete type instead.

~/Downloads❯ gdb --version | head -n 1
GNU gdb (GDB) 7.8.1

~/Downloads❯ gfortran --version | head -n1
GNU Fortran (Homebrew gcc 4.9.2_1) 4.9.2

~/Downloads❯ gdb a.out
...
(gdb) break 9
Breakpoint 1 at 0x100000b41: file alloc.f90, line 9.
run
...
(gdb) info locals
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = <incomplete type>

And even worse, on other Linux box with 4.8 (Ubuntu 14.04), it seems to point to incorrect section (stack instead of heap):

link@hyrule:~$ gdb --version | head -n1
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
link@hyrule:~$ gfortran --version | head -n1
GNU Fortran (Ubuntu 4.8.2-19ubuntu1) 4.8.2
(gdb) i lo
x = (( 1, 4) ( 2, 5) ( 3, 6) )
y = (( 0) )
(gdb) p &y
$1 = (PTR TO -> ( integer(kind=4) (*,*))) 0x7fffffffe4f0
(gdb) p &x
$2 = (PTR TO -> ( integer(kind=4) (2,3))) 0x7fffffffe540
(gdb) p *((integer *) y)@6
$6 = (1, 4, 2, 5, 3, 6)
Quang Linh Le
  • 751
  • 1
  • 7
  • 16
  • This appears to be a bug that should be reported -- perhaps add it to this open bug: https://sourceware.org/bugzilla/show_bug.cgi?id=9395 – casey Jan 16 '15 at 17:27
  • Thank you for your reply @casey, actually `gdb` in Fedora (and RHEL) came with a patchset, include VLA http://pkgs.fedoraproject.org/cgit/gdb.git/, that's why it's the only version can print/examine allocated arrays. I'm trying to patch gdb in OS X the same way but it seems very long... – Quang Linh Le Jan 18 '15 at 15:16

1 Answers1

1

I think it's better to answer the question. Actually gdb on Fedora come with a patchset http://pkgs.fedoraproject.org/cgit/gdb.git/ that enable debugging allocatable arrays for Fortran code.

In order to get allocatable arrays working on other platform, we need to rebuild gdb from a specific branch like archer-jankratochvil-vla from Archer gdb https://sourceware.org/gdb/wiki/ProjectArcher.

No need to patch gfortran though.

Quang Linh Le
  • 751
  • 1
  • 7
  • 16
  • 1
    Sorry to be unclear, VLA http://intel-gdb.github.io/ or Variable Length Array help us to examine the heap arrays like the way we do a stack one, instead of `print *((integer *) x)@10`, just `print x` is enough, it much easier to work with multi-dimension arrays... – Quang Linh Le Jan 23 '15 at 13:03