[Patch,fortran] Backtrace support (PR30498)
Tobias Burnus
burnus@net-b.de
Thu Feb 8 20:26:00 GMT 2007
:ADDPATCH fortran:
The following patch by François-Xavier implements backtrace support.
The backtracing can be enabled at compile time with the -fbacktrace
option and overwritten at run time via the GFORTRAN_ERROR_BACKTRACE
environment variable.
Backtracing currently only works for glibc systems, for the translation
of the hex address into file/line, the program addr2line is called.
(This util is part of binutils but as binutils is pure GPL we cannot use
it as library in libgfortran. It was said that Daniel Berlin has an
internal-Google library which extracts the line and file information
from DWARF2; cf. PR30498 and PR5773.)
I augmented the support to not only give a backtrace for library
internal errors (sys_exit calls) but also for SIGSEGV, SIGILL, SIGFPE
and SIGBUS; additionally, I added lots of missing environment variables
to gfortran.texi.
If addr2line is available, an error message might look like:
gfortran -g -ffpe-trap=zero -fbacktrace y.f90 && ./a.out
- - - - - - - - -
Program received signal SIGSEGV: Segmentation fault.
Backtrace for this error:
+ /lib64/libc.so.6 [0x2b0771688410]
+ function foo (0x400898)
at line 5 of file y.f90
+ in the main program
at line 1 of file y.f90
+ /lib64/libc.so.6(__libc_start_main+0xf4) [0x2b0771675944]
- - - - - - - - -
where y.f90 contains in line 4 and 5:
4 integer, pointer :: x
5 x = 5
A less-useful backtrace is shown if addr2line is missing. For example, using
10 print '(x)', 10
gives then:
- - - - - - - - -
At line 10 of file y.f90
Fortran runtime error: Insufficient data descriptors in format after
reversion
Backtrace for this error:
+ /projects/tob/gcc-trunk/lib64/libgfortran.so.3 [0x2ac4a727c9f6]
+ /projects/tob/gcc-trunk/lib64/libgfortran.so.3 [0x2ac4a727e305]
+ /projects/tob/gcc-trunk/lib64/libgfortran.so.3 [0x2ac4a727e518]
+ /projects/tob/gcc-trunk/lib64/libgfortran.so.3 [0x2ac4a72e5990]
+ /projects/tob/gcc-trunk/lib64/libgfortran.so.3 [0x2ac4a72e62b3]
+ ./a.out [0x4008ec]
+ ./a.out [0x40087f]
+ ./a.out [0x40092c]
+ /lib64/libc.so.6(__libc_start_main+0xf4) [0x2ac4a79b3944]
+ ./a.out [0x4007b9]
- - - - - - - - -
The patch has been bootstrapped and regression tested on
x86_64-unknown-linux-gnu,
I did also a make pdf (the make info is part of the bootstapping).
Ok for the trunk? (As FX has written most of the patch, it would be nice
if someone else could have a look, too.)
Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.diff
Type: text/x-patch
Size: 26467 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070208/bfec05e3/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace-gen.diff
Type: text/x-patch
Size: 11817 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20070208/bfec05e3/attachment-0001.bin>
More information about the Fortran
mailing list