This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Printing allocatable v.s. normal arrays from fortran code in GDB


On Sun, Feb 8, 2015 at 4:53 PM, Morten Olsen Lysgaard
<morten@lysgaard.no> wrote:
> I am writing some scientific fortran code where I have some allocatable arrays.
> When I want to print them in GDB, the data I get is gibberish, even
> though the program itself easily can compute with the allocated array.
> To demonstrate the problem I have created a small archive containing a
> test program, a makefile and the output generated when run on my
> system.
> The program is alloc.f90
> The output is is output.txt
> The program can be compiled and run by running make on a system with
> gfortran installed.
> Because the mailing list doesn't support attatchments the tarfile is
> available at (1 Kb)
> https://www.dropbox.com/s/zj4pgcbp44p5q4z/alloc.tar.gz?dl=1
>
> The interesting part is line 22-23 in output.txt. I would expect the
> output on the two lines to be the same, but for some reason the
> allocatable array is printed wrong.
>
> Is this a known problem? Am I misunderstanding how allocatable arrays
> work? Any help would be greatly appreciated.
>
> GDB version: GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
> gfortran version: GNU Fortran (Ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2
>
> Have a nice day - Morten

Please use the latest version, gdb 7.9. I am seeing the problem in
7.7.1+dfsg-5 but 7.9 seems to work fine.


% ~/software/myroot/gdb-7.9/bin/gdb ./a.out
GNU gdb (GDB) 7.9
...
(gdb) b alloc.f90:18
Breakpoint 1 at 0x400bd0: file alloc.f90, line 18.
(gdb) r
Starting program: /home/rajulocal/debug/gdb_fortran/alloc/a.out
   55.0000000     ,    55.0000000

Breakpoint 1, average () at alloc.f90:18
18        write(*,*) 'done'
(gdb) p p1(1)
$1 = 1
(gdb) p p2(1)
$2 = 1
(gdb) p p2(5)
$3 = 5

However, when I used the old version, I get

 % /usr/bin/gdb ./a.out
GNU gdb (Debian 7.7.1+dfsg-5) 7.7.1
...
(gdb) b alloc.f90:18
Breakpoint 1 at 0x400bd0: file alloc.f90, line 18.
(gdb) r
Starting program: /home/rajulocal/debug/gdb_fortran/alloc/a.out
   55.0000000     ,    55.0000000

Breakpoint 1, average () at alloc.f90:18
18        write(*,*) 'done'
(gdb) p p1(1)
$1 = 1
(gdb) p p2(1)
$2 = 8.84510801e-39
(gdb) p p2(5)
$3 = 3.93764868e-43

raju
-- 
Kamaraju S Kusumanchi
http://raju.shoutwiki.com/wiki/Blog


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]