[Patch, libfortran] PR 46686 Implement backtrace using libgcc functionality

Janne Blomqvist blomqvist.janne@gmail.com
Tue Nov 1 18:24:00 GMT 2011


Hi,

the attached patch changes the backtracing functionality, which is
used to print a stack trace before aborting when something goes
belly-up, to use the stack unwinding functionality provided by libgcc
instead of using the glibc backtrace_symbols and backtrace_symbols_fd
functions, or the "pstack" utility which is available on some systems
(Solaris?). There are some nice benefits of this:

- It should work on all targets, not only those which use glibc or pstack.

- It gets the correct line numbers, whereas the backtrace_symbols_fd
output was usually (but not always) offset by one. This is probably
related to the use of _Unwind_GetIPInfo and in some cases decrementing
the IP.

- Based on some googling, it's a bit unclear whether backtrace()
and/or backtrace_symbols_fd() actually are async-signal-safe due to
usage of dlsym/dladdr and such.

It still uses addr2line if available to print out function and file
names and line numbers. If addr2line is not found on the path during
program startup, it resorts to printing out the addresses only.

Regtested on x86_64-unknown-linux-gnu, Ok for trunk?

2011-11-01  Janne Blomqvist  <jb@gcc.gnu.org>

	PR fortran/46686
	* configure.ac: Don't check execinfo.h, backtrace,
	backtrace_symbols_fd. Check execve instead of execvp. Call
	GCC_CHECK_UNWIND_GETIPINFO.
	* runtime/backtrace.c: Don't include unused headers, include
	limits.h and unwind.h.
	(CAN_FORK): Check execve instead of execvp.
	(GLIBC_BACKTRACE): Remove.
	(bt_header): Conform to gdb backtrace format.
	(struct bt_state): New struct.
	(trace_function): New function.
	(show_backtrace): Use _Unwind_Backtrace from libgcc instead of
	glibc backtrace functions.



-- 
Janne Blomqvist
-------------- next part --------------
A non-text attachment was scrubbed...
Name: backtrace.diff
Type: text/x-patch
Size: 9844 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20111101/c7eb8505/attachment.bin>


More information about the Fortran mailing list