2

I have problems debugging Fortran programs on Mac OS Mountain Lion with gdb. When I invoke

gdb (fortran executable name)

from a terminal, I get the following message:

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

Basically, gdb is searching for a bunch of object files in paths (/Users/fx/...) that do not exist.

Other than that, the debugger seems to be working fine. Does anyone know how can I fix this?

A a side note, gdb works fine on C programs. Both C and Fortran compilers run smoothly; gcc was included in Xcode command line tools, while gfortran was installed from a separate source (path: /usr/local/bin/gfortran).

I tried to read several other answers but no one seemed to match this issue.

4

1 回答 1

1

您可以将 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 命令都可以工作。您可以更改堆栈帧。你可以设置断点,你可以步进指令,等等......这一切都会奏效。

于 2015-09-24T01:41:03.100 回答