【问题标题】:How to print array size (bound) with gdb for Fortran program如何使用 gdb 为 Fortran 程序打印数组大小(绑定)
【发布时间】:2014-10-07 12:12:25
【问题描述】:

我是Linux下gdb的初学者。 当我尝试调试使用 ifort 和 -c, -g 选项编译的程序时,我想检查几个数组的边界。 不幸的是,我在 Google 中找不到任何关于如何打印与 gdb 调试器绑定的数组的信息。

[更新]

我有一个带有可分配的公共数组的模块,它在该模块的子例程中正确分配。 在主程序中(调用子程序后)我尝试使用whatis 并看到(*,*) 而不是形状。

【问题讨论】:

    标签: gdb fortran intel-fortran


    【解决方案1】:

    您可以使用whatis 命令查看数组边界:例如,

    program arr
      real, dimension(2:41) :: arr1
      real, allocatable, dimension(:), target :: arr2
      integer :: i
    
      allocate(arr2(40))
    
      forall(i = 2:41) arr1(i) = i
      arr2 = arr1 + 2
    
      print *, arr1(2)
    
      deallocate(arr2)
    end program are
    

    跑步给予

    $ gfortran -g foo.f90
    $ gdb a.out
    [...]
    (gdb) break 11
    Breakpoint 1 at 0x400b01: file foo.f90, line 11.
    (gdb) run
    [...]
    
    Breakpoint 1, arr () at foo.f90:11
    11    print *, arr1(2)
    (gdb) whatis arr1
    type = real(kind=4) (2:41)
    (gdb) whatis arr2
    type = real(kind=4) (40)
    

    【讨论】:

    • 我应该注意到,上面的内容也适用于 ifort,唯一的区别是输出格式略有不同:type = REAL(4) (2:41)
    • 非常感谢您的帮助!但是可分配的公共数组呢?我已经在一个主程序中尝试了 whatis 命令,其中数组在模块的调用例程中定义为可分配的公共。我刚刚看到 (,) 维度...
    • @KonstantinEbauer ,你能给出一个代码示例吗?数组分配了吗?
    • 如何使用 ifort 做到这一点?请提供一些指导谢谢...
    猜你喜欢
    • 1970-01-01
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    相关资源
    最近更新 更多