Fortran debugging with gdb on Mac OS?

核能气质少年 提交于 2019-12-02 01:10:00

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!