Sterk
Sterk

Reputation: 41

Fortran debugging with gdb on Mac OS?

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.

Upvotes: 4

Views: 2000

Answers (1)

user1139069
user1139069

Reputation: 1623

You can use lldb with Fortran. Take an example program.

      PROGRAM test

      IMPLICIT NONE

      INTEGER                :: i
      INTEGER, DIMENSION(10) :: array

      DO i = 1, 10
         array(i) = i
      END DO

      END PROGRAM

You can run this in 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) 

There is one caveat. lldb doesn't understand Fortran natively but you can still use the C equivalents. For instance if you want to inspect the fortran array index array(3) you need to use the C equivalent of

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

Everything that has a C or C++ equivalent will work. Derived types will act like structs, etc... All the regular lldb commands will work. You can change stack frames. You can set break points, you can step instructions, etc... it will all just work.

Upvotes: 2

Related Questions