]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libfortran/36044 (user-requested backtrace)
authorJanus Weil <janus@gcc.gnu.org>
Thu, 20 Dec 2012 18:15:13 +0000 (19:15 +0100)
committerJanus Weil <janus@gcc.gnu.org>
Thu, 20 Dec 2012 18:15:13 +0000 (19:15 +0100)
2012-12-20  Janus Weil  <janus@gcc.gnu.org>

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  <janus@gcc.gnu.org>

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

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/intrinsic.c
gcc/fortran/intrinsic.texi
libgfortran/ChangeLog
libgfortran/gfortran.map
libgfortran/libgfortran.h
libgfortran/runtime/backtrace.c
libgfortran/runtime/compile_options.c
libgfortran/runtime/error.c

index 5a72e8a8bdade41021acd54586023b1795372278..db7383c57f259aef309714ce242c6408b12ca43f 100644 (file)
@@ -1,3 +1,10 @@
+2012-12-20  Janus Weil  <janus@gcc.gnu.org>
+
+       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  Tobias Burnus  <burnus@net-b.de>
 
        PR fortran/54818
index 5eda83989da786ab652ecf2063cc84f9ba109287..ec0c61f09c9950ba9fe9be80312a796ecbec3e09 100644 (file)
@@ -505,6 +505,7 @@ enum gfc_isym_id
   GFC_ISYM_SHIFTA,
   GFC_ISYM_SHIFTL,
   GFC_ISYM_SHIFTR,
+  GFC_ISYM_BACKTRACE,
   GFC_ISYM_SIGN,
   GFC_ISYM_SIGNAL,
   GFC_ISYM_SI_KIND,
index 95a0f500bc25043c574ea94ce8f69b0148085c8e..274c921c8a8e8b570a195f9e1f37ba4e6f400361 100644 (file)
@@ -2896,6 +2896,8 @@ add_subroutines (void)
              "value", BT_INTEGER, di, REQUIRED, INTENT_OUT,
              "atom", BT_INTEGER, di, REQUIRED, INTENT_IN);
 
+  add_sym_0s ("backtrace", GFC_ISYM_BACKTRACE, GFC_STD_GNU, NULL);
+
   add_sym_1s ("cpu_time", GFC_ISYM_CPU_TIME, CLASS_IMPURE, BT_UNKNOWN, 0,
              GFC_STD_F95, gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
              tm, BT_REAL, dr, REQUIRED, INTENT_OUT);
index 3390959e20b410da058466d31a1902e2e71f92bb..fc256cb9e8be63b4ff11f1600bfa7edf5aacf42f 100644 (file)
@@ -63,6 +63,7 @@ Some basic guidelines for editing this document:
 * @code{ATANH}:         ATANH,     Inverse hyperbolic tangent function
 * @code{ATOMIC_DEFINE}: ATOMIC_DEFINE, Setting a variable atomically
 * @code{ATOMIC_REF}:    ATOMIC_REF, Obtaining the value of a variable atomically
+* @code{BACKTRACE}:     BACKTRACE, Show a backtrace
 * @code{BESSEL_J0}:     BESSEL_J0, Bessel function of the first kind of order 0
 * @code{BESSEL_J1}:     BESSEL_J1, Bessel function of the first kind of order 1
 * @code{BESSEL_JN}:     BESSEL_JN, Bessel function of the first kind
@@ -349,6 +350,7 @@ the applicable standard for each intrinsic procedure is noted.
 @item @emph{Description}:
 @code{ABORT} causes immediate termination of the program.  On operating
 systems that support a core dump, @code{ABORT} will produce a core dump.
+It will also print a backtrace, unless @code{-fno-backtrace} is given.
 
 @item @emph{Standard}:
 GNU extension
@@ -371,7 +373,7 @@ end program test_abort
 @end smallexample
 
 @item @emph{See also}:
-@ref{EXIT}, @ref{KILL}
+@ref{EXIT}, @ref{KILL}, @ref{BACKTRACE}
 
 @end table
 
@@ -1644,6 +1646,35 @@ end program atomic
 
 
 
+@node BACKTRACE
+@section @code{BACKTRACE} --- Show a backtrace
+@fnindex BACKTRACE
+@cindex backtrace
+
+@table @asis
+@item @emph{Description}:
+@code{BACKTRACE} shows a backtrace at an arbitrary place in user code. Program
+execution continues normally afterwards. The backtrace information is printed
+to the unit corresponding to @code{ERROR_UNIT} in @code{ISO_FORTRAN_ENV}.
+
+@item @emph{Standard}:
+GNU Extension
+
+@item @emph{Class}:
+Subroutine
+
+@item @emph{Syntax}:
+@code{CALL BACKTRACE}
+
+@item @emph{Arguments}:
+None
+
+@item @emph{See also}:
+@ref{ABORT}
+@end table
+
+
+
 @node BESSEL_J0
 @section @code{BESSEL_J0} --- Bessel function of the first kind of order 0
 @fnindex BESSEL_J0
index bea7c72970cea427315018d5c3a6d3a7dd5a8eac..32f9bbe7fd9632c8e40131420543d2c95f639a1b 100644 (file)
@@ -1,3 +1,14 @@
+2012-12-20  Janus Weil  <janus@gcc.gnu.org>
+
+       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  <pault@gcc.gnu.org>
 
        * intrinsics/extends_type_of.c : Return correct results for
index 217d2a3cf51a76966617ade0aabd945227f98a14..80a9a00071a69e159848059702fc6feedf5f7758 100644 (file)
@@ -1192,6 +1192,7 @@ GFORTRAN_1.4 {
 GFORTRAN_1.5 {
   global:
     _gfortran_ftell2;
+    _gfortran_backtrace;
 } GFORTRAN_1.4; 
 
 F2C_1.0 {
index a8c33636171453c575afbd6fc6ec55d896e5edf4..ae18752758122ad94c5697ffad278a508c6565b8 100644 (file)
@@ -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 */
 
index 9d88d136a8b06051401531d489fc0c8c68472af2..3e3e8441ea1bf97dfeff4c6b7b1dc03257deba45 100644 (file)
@@ -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);
index 2ba1aedf5c5a1d56dcd2a7ac2fa716247c6da26d..1860edadf5c6cfd1b1b280c68ba1dd43fef10164 100644 (file)
@@ -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.
index 3955e44cea068d8fd0c22d8087f14a0f5e3c8447..dfdfb4cbfe7c8e73a16916ae65fbb8bd792fc344 100644 (file)
@@ -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);
     }