3

I am trying to breakpoint a fortran program with lldb on a Mac OS 10.12.5 system. I have

program badcall
      integer a,b
      a=2
      b=3

write(*,*) a, b
end

I (have to) compile with the intel compilers.

ifort -g badcall.f90 -o badcall

then I run with lldb and do

breakpoint set -f badcall.f90 -l 5

programs stops normally

Process 59474 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100000f35 prova`MAIN__ at badcall.f90:6
   3          a=2
   4          b=3
   5          

However if I then try to print the variable b I get nothing

(lldb) p b
(lldb) print b
(lldb) q

So am I missing something? Is lldb really usable to debug fortran code?

Manfredo
  • 1,760
  • 4
  • 25
  • 53

1 Answers1

3

It seems that lldb doesn't support Fortran, yet :( You will have to go with gdb:

curl "http://ftp.gnu.org/gnu/gdb/gdb-8.0.tar.gz" -o gdb-8.0.tar.gz
tar zxf gdb-8.0.tar.gz
cd gdb-8.0
./configure
make

Make sure to Code Sign the gdb! Follow instructions here:

https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html

and you should be good to go

gfortran -g -o fort_sample ./fort_sample.f90
gdb ./fort_sample
(gdb) list
1   program badcall
2         integer a,b
3         a=2
4         b=3
5
6   write(*,*) a, b
7   end
(gdb) break 6
Breakpoint 1 at 0x100000e0e: file ./fort_sample.f90, line 6.
(gdb) run
...
...
badcall () at ./fort_sample.f90:6
6   write(*,*) a, b
(gdb) print a
$1 = 2
(gdb) print b
$2 = 3
(gdb)
Oo.oO
  • 12,464
  • 3
  • 23
  • 45
  • 2
    I would actually much prefer working with gdb. However on 10.12.5 it's not as easy as it sounds. I have tried codesigning but that's not enough. I get an error `During startup program terminated with signal ?, Unknown signal`. I am trying to fix this but so far did not work. The topic is already been discussed in other SO threads, see https://stackoverflow.com/questions/40052171/gdb-terminated-with-signal-unknown-signal) – Manfredo Jul 09 '17 at 08:08
  • Solution given by lakeslove in the above mentioned comment fixed the issue. Finally gdb is working... – Manfredo Jul 09 '17 at 08:15
  • In my case: 10.12.4 - it is working just fine. Maybe, indeed, 10.12.5 has some issues. – Oo.oO Jul 09 '17 at 14:40
  • Anyway I guess the question is more related to lldb supporting fortran or not. I'll take your answer and accept it (as a no... unfortunately for apple). – Manfredo Jul 09 '17 at 14:59
  • I get your point. In fact, this solution is a sort of workaround. There was a discussion at intel forum (some time ago): https://software.intel.com/en-us/forums/debug-solutions/topic/622923 - so, I guess, all we can do, is to wait. – Oo.oO Jul 09 '17 at 16:07