Can GDB be used to print values of allocatable arrays of a derived type in Fortran 90? [duplicate]

老子叫甜甜 提交于 2019-11-30 14:46:55

Which version of gdb and fortran compiler (gfortran?) are you using? As I have no problems with

  • gdb - GNU gdb (GDB) Red Hat Enterprise Linux (7.2-56.el6)
  • gfortran - GNU Fortran (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)

Here's the test program:

program test
        implicit none

        TYPE derivedType
                CHARACTER(100)     :: name      = ' '
                INTEGER            :: type      = 0
                REAL(KIND(1.0D0))  :: property  = 0.0
        END TYPE derivedType

        TYPE (derivedType), ALLOCATABLE, DIMENSION(:) :: arrayOfDerivedTypes

        allocate(arrayOfDerivedTypes(10))

        write(6,*) arrayOfDerivedTypes(1)%type

end program test

And I compile it as

gfortran -o test -g -O0 -Wall test.f90

Then start up the debugger, set a breakpoint and run

$ gdb test
(gdb) break test.f90:14
Breakpoint 1 at 0x402c8a: file test.f90, line 14.
(gdb) r
[Thread debugging using libthread_db enabled]

Breakpoint 1, test () at test.f90:14
14              write(6,*) arrayOfDerivedTypes(1)%type
(gdb) p arrayOfDerivedTypes
$3 = (( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ))
(gdb) p arrayOfDerivedTypes(1)
$4 = ( ' ' <repeats 100 times>, 0, 0 )
(gdb) p arrayOfDerivedTypes(1)%property
$5 = 0
(gdb) p arrayOfDerivedTypes(1)%name
$6 = ' ' <repeats 100 times>

I can see everything.

There is also http://brulermavie.org/2012/02/how-to-debug-fortran-programs-using-gdb/ which didn't help me, as I don't see the problem.

I know may answer is a little off but Sun studio (sdb) and intel fortran also come with a debugger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!