From f0f67c96c3906c09d9a9e00cbdbbb959c9c6e539 Mon Sep 17 00:00:00 2001 From: Janus Weil Date: Thu, 20 Dec 2012 19:15:13 +0100 Subject: re PR libfortran/36044 (user-requested backtrace) 2012-12-20 Janus Weil PR fortran/36044 * gfortran.h (gfc_isym_id): Add GFC_ISYM_BACKTRACE. * intrinsic.c (add_subroutines): Add "backtrace". * intrinsic.texi (BACKTRACE): Document BACKTRACE intrinsic. 2012-12-20 Janus Weil PR fortran/36044 * gfortran.map: Add _gfortran_backtrace. * libgfortran.h: Rename 'show_backtrace' and export. * runtime/backtrace.c (show_backtrace): Rename to 'backtrace'. Don't show message. Close file descriptor. Export. * runtime/compile_options.c (backtrace_handler): Renamed 'show_backtrace'. Move message outside. * runtime/error.c (sys_abort): Ditto. From-SVN: r194648 --- libgfortran/ChangeLog | 11 +++++++++++ libgfortran/gfortran.map | 1 + libgfortran/libgfortran.h | 4 ++-- libgfortran/runtime/backtrace.c | 6 +++--- libgfortran/runtime/compile_options.c | 3 ++- libgfortran/runtime/error.c | 3 ++- 6 files changed, 21 insertions(+), 7 deletions(-) (limited to 'libgfortran') diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index bea7c72970c..32f9bbe7fd9 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,14 @@ +2012-12-20 Janus Weil + + PR fortran/36044 + * gfortran.map: Add _gfortran_backtrace. + * libgfortran.h: Rename 'show_backtrace' and export. + * runtime/backtrace.c (show_backtrace): Rename to 'backtrace'. + Don't show message. Close file descriptor. Export. + * runtime/compile_options.c (backtrace_handler): Renamed + 'show_backtrace'. Move message outside. + * runtime/error.c (sys_abort): Ditto. + 2012-12-19 Paul Thomas * intrinsics/extends_type_of.c : Return correct results for diff --git a/libgfortran/gfortran.map b/libgfortran/gfortran.map index 217d2a3cf51..80a9a00071a 100644 --- a/libgfortran/gfortran.map +++ b/libgfortran/gfortran.map @@ -1192,6 +1192,7 @@ GFORTRAN_1.4 { GFORTRAN_1.5 { global: _gfortran_ftell2; + _gfortran_backtrace; } GFORTRAN_1.4; F2C_1.0 { diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h index a8c33636171..ae187527581 100644 --- a/libgfortran/libgfortran.h +++ b/libgfortran/libgfortran.h @@ -667,8 +667,8 @@ internal_proto(find_addr2line); /* backtrace.c */ -extern void show_backtrace (void); -internal_proto(show_backtrace); +extern void backtrace (void); +iexport_proto(backtrace); /* error.c */ diff --git a/libgfortran/runtime/backtrace.c b/libgfortran/runtime/backtrace.c index 9d88d136a8b..3e3e8441ea1 100644 --- a/libgfortran/runtime/backtrace.c +++ b/libgfortran/runtime/backtrace.c @@ -190,14 +190,12 @@ trace_function (struct _Unwind_Context *context, void *state_ptr) /* Display the backtrace. */ void -show_backtrace (void) +backtrace (void) { bt_state state; state.frame_number = 0; state.error = 0; - estr_write ("\nBacktrace for this error:\n"); - #if CAN_PIPE if (addr2line_path == NULL) @@ -261,6 +259,7 @@ show_backtrace (void) if (state.error) goto fallback; close (inp[1]); + close (f[0]); wait (NULL); return; @@ -277,3 +276,4 @@ fallback_noerr: state.direct_output = 1; _Unwind_Backtrace (trace_function, &state); } +iexport(backtrace); diff --git a/libgfortran/runtime/compile_options.c b/libgfortran/runtime/compile_options.c index 2ba1aedf5c5..1860edadf5c 100644 --- a/libgfortran/runtime/compile_options.c +++ b/libgfortran/runtime/compile_options.c @@ -126,7 +126,8 @@ backtrace_handler (int signum) fatal_error_in_progress = 1; show_signal (signum); - show_backtrace(); + estr_write ("\nBacktrace for this error:\n"); + backtrace (); /* Now reraise the signal. We reactivate the signal's default handling, which is to terminate the process. diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index 3955e44cea0..dfdfb4cbfe7 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -166,7 +166,8 @@ sys_abort (void) if (options.backtrace == 1 || (options.backtrace == -1 && compile_options.backtrace == 1)) { - show_backtrace (); + estr_write ("\nProgram aborted. Backtrace:\n"); + backtrace (); signal (SIGABRT, SIG_DFL); } -- cgit v1.2.3