可以使用GDB在Fortran 90中打印派生类型的可分配数组的值吗?

Nea*_*uis 6 fortran gdb gfortran fortran90 derived-types

我在Fortran90程序中有以下数据结构:

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

TYPE (derivedType), ALLOCATABLE, DIMENSION(:) :: arrayOfDerivedTypes
Run Code Online (Sandbox Code Playgroud)

当我尝试在GDB中调试和打印值时:

(gdb) p arrayOfDerivedTypes(1)%name
Run Code Online (Sandbox Code Playgroud)

我得到非敏感值(通常为零,正斜杠和字母串)或完全错误的值(如arrayOfDerivedTypes(1)%name = 9,当我知道它是= 2时).如何让GDB打印正确的值?

背景

我知道:

我不想经历编译GDB的单独分支以测试它是否解决了这个问题的麻烦,如果有人已经知道它不会或者是否有更好的解决方案可用.

我很难想象还没有解决方案.fortran社区没有更好的免费调试器解决方案吗?

Tim*_*own 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
Run Code Online (Sandbox Code Playgroud)

我将其编译为

gfortran -o test -g -O0 -Wall test.f90
Run Code Online (Sandbox Code Playgroud)

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

$ 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>
Run Code Online (Sandbox Code Playgroud)

我能看到一切。

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