-->

可以GDB用于打印在Fortran 90的派生类型的分配数组的值? [重复](Can GDB b

2019-09-02 07:36发布

这个问题已经在这里有一个答案:

  • FORTRAN打印分配数组在gdb 3个答案

我有一个FORTRAN90程序的数据结构如下:

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

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

当我尝试调试和打印值GDB,如:

(gdb) p arrayOfDerivedTypes(1)%name

我得到无意义的值(通常是零,正斜杠和字母的字符串),或完全错误的价值观(如arrayOfDerivedTypes(1)%NAME = 9,当我知道这是= 2)。 我怎样才能得到GDB打印正确的价值观?

背景

我所知道的:

  • 这个bug: http://sourceware.org/bugzilla/show_bug.cgi?id=9395
  • GDB的这个分支: http://sourceware.org/gdb/wiki/ProjectArcher
  • 而这个博客帖子上打印分配数组: http://numericalnoob.blogspot.be/2012/08/fortran-allocatable-arrays-and-pointers.html

我并不想通过编译GDB的一个独立分支,以测试的麻烦,如果它解决了这个问题,如果有人已经知道它不会或是否有更好的解决方案。

我也很难想象,有没有一个解决方案呢。 请问FORTRAN社区没有一个免费的调试器更好的解决办法了吗?

Answer 1:

哪个版本的GDB和Fortran编译器(gfortran?)您使用的是? 因为我没有问题

  • GDB - GNU GDB(GDB)的红帽企业Linux(7.2-56.el6)
  • gfortran - GNU的Fortran(GCC)4.4.6 20120305(红帽4.4.6-4)

这里的测试程序:

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

我编译为

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

然后启动调试器,设置断点和运行

$ 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>

我所看到的一切。

还有http://brulermavie.org/2012/02/how-to-debug-fortran-programs-using-gdb/这并不能帮助我,因为我没有看到这个问题。



Answer 2:

我知道可能的答案是有点偏离,但太阳工作室(SDB)和英特尔Fortran还配备了一个调试器



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