2012-12-10 60 views
2

我在使用gdb在Mac OS Mountain Lion上调试Fortran程序时遇到问题。当我从终端调用Fortran在Mac OS上使用gdb进行调试?

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正在搜索在路径一堆对象文件(/用户/ FX/...)那不存在。

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

一个便笺,gdb在C程序上正常工作。 C和Fortran编译器都运行平稳; gcc包含在Xcode命令行工具中,而gfortran是从一个单独的源(路径:/ usr/local/bin/gfortran)安装的。

我试着读了几个其他的答案,但没有人似乎匹配这个问题。

+0

难道你不需要为gcc-fortran安装一些调试软件包吗? –

回答

0

您可以在Fortran中使用lldb。举一个例子程序。

 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相当于具有C或C++相当于将工作

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

一切的。派生类型将像结构体一样行事...所有常规的lldb命令都可以工作。您可以更改堆栈帧。你可以设置中断点,你可以按步骤说明等等,它们都可以正常工作。