Use libbacktrace (instead of our own unwind-based code) to display backtraces 
from libgfortran upon error or user request.

  1. In toplevel Makefile.def, make libgfortran depend on libbacktrace (needs 
global reviewer approval)
  2. In gcc/fortran/config-lang.in, add libbacktrace to target_libs
  3. In libgfortran, we remove our own code and substitute calls to libbacktrace

Bootstrapped and regtested on x86_64-pc-linux-gnu (which has full libbacktrace 
support) and x86_64-apple-darwin14 (which has minimal libbacktrace support). OK 
to commit to trunk?

FX

------

The fine print:

This is a great simplification of the library code, because we get rid of the 
unwind code, and don’t need all the code to find out our executable’s absolute 
path, find addr2line, pipe-fork-exec addr2line, etc. Just 
libgfortran/runtime/backtrace.c’s size is reduced by half. And we will benefit 
from future possible improvements in libbacktrace.

One choice I have made is to not display in backtraces the libgfortran 
functions, i.e. anything starting with _gfortran_ or _gfortrani_ is simply not 
printed. I think this is more convenient for some users, because it will avoid 
them being confused by symbols they don’t recognize. It means, however, that 
runtime backtraces are a little less useful for us in debugging… but then, we 
know how to use gdb :)  I am open to being convinced otherwise and remove these 
few lines of code.

Other than that deliberate choice, no functionality is lost. On dwarf/elf 
targets (the majority), we get beautiful backtraces as before if code is 
compiled with “-g”:

#0  0x4006f5 __foo_MOD_gee
        /home/fx/gcc/irun/a.f90:4
#1  0x400706 bar
        /home/fx/gcc/irun/a.f90:16
#2  0x40072e foo
        /home/fx/gcc/irun/a.f90:12
#3  0x400715 test
        /home/fx/gcc/irun/a.f90:9
#4  0x400765 main
        /home/fx/gcc/irun/a.f90:9

and if not compiled with “-g”, we get the nonsymbolic backtrace, as before:

#0  0x4010bd ???
#1  0x4010ce ???
#2  0x4010f6 ???
#3  0x4010dd ???
#4  0x40112d ???
#5  0x42a6b3 ???
#6  0x400fbc ???


We will get backtraces on PE/COFF targets (i.e. Windows), where I don’t think 
we had them before (but cannot test).
And on non-elf targets such as Mac OS X, we stay with the same as before, i.e. 
non-symbolic backtraces.



PS: This is probably one of the last of my “summer” gfortran projects for this 
year. The end of holidays is near, and I’ll have to get back to work. It was 
fun, as always!


Attachment: backtrace.ChangeLog
Description: application/applefile

Attachment: backtrace.diff
Description: Binary data

Attachment: backtrace_withregeneratedfiles.diff
Description: Binary data

Reply via email to