gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:45:32 25 4
gpt4 key购买 nike

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





Fortran print allocatable array in gdb

(3 个回答)


5年前关闭。




我在 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 打印正确的值?

背景

我知道:
  • 这个错误: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 社区还没有更好的免费调试器解决方案吗?

    最佳答案

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

  • 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)

  • 下面是测试程序:
    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/这对我没有帮助,因为我没有看到问题。

    关于gdb - GDB 可以用于打印 Fortran 90 中派生类型的可分配数组的值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16447741/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com