在 Mac OS 上使用 gdb 进行 Fortran 调试



我在使用 gdb 在 Mac OS Mountain Lion 上调试 Fortran 程序时遇到问题。当我调用

gdb (fortran executable name)

从终端,我收到以下消息:

This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared libraries.
warning: Could not find object file "/Users/fx/devel/gcc/ibin-462-x86_64/x86_64-apple-darwin11/libgfortran/.libs/backtrace.o"
- no debug information available for "../../../gcc-4.6.2-RC-20111019/libgfortran/runtime/backtrace.c". ... (an extremely long list of analogous warnings pop up for libgcc and libquadmath libraries) ...

基本上,gdb 正在搜索一堆不存在的路径 (/Users/fx/...) 中的对象文件。

除此之外,调试器似乎工作正常。有谁知道我该如何解决这个问题?

附带说明一下,gdb 在 C 程序上运行良好。C 和 Fortran 编译器运行流畅;gcc 包含在 Xcode 命令行工具中,而 gfortran 是从单独的源代码(路径:/usr/local/bin/gfortran)安装的。

我试图阅读其他几个答案,但似乎没有人符合这个问题。

您可以将 lldb 与 Fortran 一起使用。举一个示例程序。

      PROGRAM test
      IMPLICIT NONE
      INTEGER                :: i
      INTEGER, DIMENSION(10) :: array
      DO i = 1, 10
         array(i) = i
      END DO
      END PROGRAM

你可以在 lldb 中运行它

$ lldb -- test
(lldb) target create "test"
Current executable set to 'test' (x86_64).
(lldb) b test.f:9
Breakpoint 1: where = test`test + 17 at test.f:9, address = 0x0000000100000eac
(lldb) run
Process 869 launched: '/Users/mark/Desktop/test' (x86_64)
Process 869 stopped
* thread #1: tid = 0xb5f5, 0x0000000100000eac test`test + 17 at test.f:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000eac test`test + 17 at test.f:9
   6          INTEGER, DIMENSION(10) :: array
   7    
   8          DO i = 1, 10
-> 9             array(i) = i
   10         END DO
   11   
   12         END PROGRAM
(lldb) c
Process 869 resuming
Process 869 stopped
* thread #1: tid = 0xb5f5, 0x0000000100000eac test`test + 17 at test.f:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000eac test`test + 17 at test.f:9
   6          INTEGER, DIMENSION(10) :: array
   7    
   8          DO i = 1, 10
-> 9             array(i) = i
   10         END DO
   11   
   12         END PROGRAM
(lldb) c
Process 869 resuming
Process 869 stopped
* thread #1: tid = 0xb5f5, 0x0000000100000eac test`test + 17 at test.f:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000eac test`test + 17 at test.f:9
   6          INTEGER, DIMENSION(10) :: array
   7    
   8          DO i = 1, 10
-> 9             array(i) = i
   10         END DO
   11   
   12         END PROGRAM
(lldb) c
Process 869 resuming
Process 869 stopped
* thread #1: tid = 0xb5f5, 0x0000000100000eac test`test + 17 at test.f:9, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000eac test`test + 17 at test.f:9
   6          INTEGER, DIMENSION(10) :: array
   7    
   8          DO i = 1, 10
-> 9             array(i) = i
   10         END DO
   11   
   12         END PROGRAM
(lldb) p array
(int [11]) $0 = ([0] = 1, [1] = 2, [2] = 3, [3] = 0, [4] = 0, [5] = 0, [6] = 0, [7] = 0, [8] = 0, [9] = 0, [10] = 0)
(lldb) 

LLDB本身不理解Fortran,但你仍然可以使用C等效项。例如,如果要检查 fortran 数组索引array(3)则需要使用 C 等效的

(lldb) p array[2]
(int) $1 = 3
(lldb)

所有具有 C 或 C++ 等价物的东西都可以工作。派生类型将充当结构等...所有常规的 lldb 命令都可以工作。您可以更改堆栈帧。您可以设置断点,可以分步说明等...这一切都会奏效。

最新更新