[gfortran,patch] Allow backtracing non-library errors

FX Coudert fxcoudert@gmail.com
Sat Aug 4 21:56:00 GMT 2007


Attached patch allows the library, when asked to backtrace by use of  
the -fbacktrace option, to setup signal handlers on the common deadly  
signals SIG{SEGV,ILL,BUG,FPE}, and to emit backtrace information from  
these signal handlers. This allows the following type of debugging:

$ cat u.f90
   integer, pointer :: i
   i = 5
   end

$ gfortran -g u.f90 -fbacktrace && ./a.out

Program received signal 11 (SIGSEGV): Segmentation fault.

Backtrace for this error:
   + function __restore_rt (0x417830)
     from file libgcc2.c
   + in the main program
     at line 2 of file u.f90
   + function __libc_start_main (0x412DB8)

$ cat u2.f90
   integer :: i
   i = 0
   i = 2 / i
   print *, i
   end

$ gfortran -g u2.f90 -fbacktrace && ./a.out

Program received signal 8 (SIGFPE): Floating-point exception.

Backtrace for this error:
   + function __restore_rt (0x4178A0)
     from file libgcc2.c
   + in the main program
     at line 3 of file u2.f90
   + function __libc_start_main (0x412E28)

$ cat u3.f90
   real :: x
   x = -1
   x = sqrt(x)
   print *, x
   end

$ gfortran -g u3.f90 -fbacktrace && ./a.out
             NaN

$ gfortran -g u3.f90 -fbacktrace -ffpe-trap=invalid && ./a.out

Program received signal 8 (SIGFPE): Floating-point exception.

Backtrace for this error:
   + function __restore_rt (0x4178B0)
     from file libgcc2.c
   + in the main program
     at line 3 of file u3.f90
   + function __libc_start_main (0x412E38)




Bootstrapped and regtested on x86_64-linux, no testcase because of  
the nature of the patch, documentation adjusted to describe the new  
behaviour. OK to commit?
FX


:ADDPATCH fortran:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.ChangeLog
Type: application/octet-stream
Size: 524 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070804/fe5286d2/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.diff
Type: application/octet-stream
Size: 3820 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070804/fe5286d2/attachment-0001.obj>


More information about the Fortran mailing list