Commit de8bd142 by Janne Blomqvist

PR 48915 Abort handling

From-SVN: r173750
parent 1028b2bd
2011-05-14 Janne Blomqvist <jb@gcc.gnu.org> 2011-05-14 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/48915
* gfortran.h (gfc_option_t): Remove flag_dump_core.
* gfortran.texi (GFORTRAN_ERROR_DUMPCORE): Remove section.
(GFORTRAN_ERROR_BACKTRACE): Document that it's enabled by default.
* intrinsic.texi (ABORT): Remove explanation of -fdump-core.
* invoke.texi: Remove -fdump-core, document that -fbacktrace is
enabled by default.
* lang.opt: Remove -fdump-core.
* options.c (gfc_init_options): Make backtrace default to enabled,
remove dump_core.
(gfc_handle_option): Remove OPT_fdump-core.
* trans-decl.c: Pass a 0 to preserve ABI.
2011-05-14 Janne Blomqvist <jb@gcc.gnu.org>
* gfortran.texi: Remove GFORTRAN_USE_STDERR documentation. * gfortran.texi: Remove GFORTRAN_USE_STDERR documentation.
2011-05-13 Tobias Burnus <burnus@net-b.de> 2011-05-13 Tobias Burnus <burnus@net-b.de>
......
...@@ -2212,7 +2212,6 @@ typedef struct ...@@ -2212,7 +2212,6 @@ typedef struct
int flag_backslash; int flag_backslash;
int flag_backtrace; int flag_backtrace;
int flag_allow_leading_underscore; int flag_allow_leading_underscore;
int flag_dump_core;
int flag_external_blas; int flag_external_blas;
int blas_matmul_limit; int blas_matmul_limit;
int flag_cray_pointer; int flag_cray_pointer;
......
...@@ -587,7 +587,6 @@ Malformed environment variables are silently ignored. ...@@ -587,7 +587,6 @@ Malformed environment variables are silently ignored.
* GFORTRAN_DEFAULT_RECL:: Default record length for new files * GFORTRAN_DEFAULT_RECL:: Default record length for new files
* GFORTRAN_LIST_SEPARATOR:: Separator for list output * GFORTRAN_LIST_SEPARATOR:: Separator for list output
* GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O * GFORTRAN_CONVERT_UNIT:: Set endianness for unformatted I/O
* GFORTRAN_ERROR_DUMPCORE:: Dump core on run-time errors
* GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors * GFORTRAN_ERROR_BACKTRACE:: Show backtrace on run-time errors
@end menu @end menu
...@@ -745,26 +744,15 @@ environment variable will override the CONVERT specifier in the ...@@ -745,26 +744,15 @@ environment variable will override the CONVERT specifier in the
open statement}. This is to give control over data formats to open statement}. This is to give control over data formats to
users who do not have the source code of their program available. users who do not have the source code of their program available.
@node GFORTRAN_ERROR_DUMPCORE
@section @env{GFORTRAN_ERROR_DUMPCORE}---Dump core on run-time errors
If the @env{GFORTRAN_ERROR_DUMPCORE} variable is set to
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant)
then library run-time errors cause core dumps. To disable the core
dumps, set the variable to @samp{n}, @samp{N}, @samp{0}. Default
is not to core dump unless the @option{-fdump-core} compile option
was used.
@node GFORTRAN_ERROR_BACKTRACE @node GFORTRAN_ERROR_BACKTRACE
@section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors @section @env{GFORTRAN_ERROR_BACKTRACE}---Show backtrace on run-time errors
If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to If the @env{GFORTRAN_ERROR_BACKTRACE} variable is set to @samp{y},
@samp{y}, @samp{Y} or @samp{1} (only the first letter is relevant) @samp{Y} or @samp{1} (only the first letter is relevant) then a
then a backtrace is printed when a run-time error occurs. backtrace is printed when a serious run-time error occurs. To disable
To disable the backtracing, set the variable to the backtracing, set the variable to @samp{n}, @samp{N}, @samp{0}.
@samp{n}, @samp{N}, @samp{0}. Default is not to print a backtrace Default is to print a backtrace unless the @option{-fno-backtrace}
unless the @option{-fbacktrace} compile option compile option was used.
was used.
@c ===================================================================== @c =====================================================================
@c PART II: LANGUAGE REFERENCE @c PART II: LANGUAGE REFERENCE
......
...@@ -345,10 +345,7 @@ the applicable standard for each intrinsic procedure is noted. ...@@ -345,10 +345,7 @@ the applicable standard for each intrinsic procedure is noted.
@table @asis @table @asis
@item @emph{Description}: @item @emph{Description}:
@code{ABORT} causes immediate termination of the program. On operating @code{ABORT} causes immediate termination of the program. On operating
systems that support a core dump, @code{ABORT} will produce a core dump even if systems that support a core dump, @code{ABORT} will produce a core dump.
the option @option{-fno-dump-core} is in effect, which is suitable for debugging
purposes.
@c TODO: Check if this (with -fno-dump-core) is correct.
@item @emph{Standard}: @item @emph{Standard}:
GNU extension GNU extension
......
...@@ -145,7 +145,7 @@ and warnings}. ...@@ -145,7 +145,7 @@ and warnings}.
@item Debugging Options @item Debugging Options
@xref{Debugging Options,,Options for debugging your program or GNU Fortran}. @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
@gccoptlist{-fdump-fortran-original -fdump-fortran-optimized @gol @gccoptlist{-fdump-fortran-original -fdump-fortran-optimized @gol
-ffpe-trap=@var{list} -fdump-core -fbacktrace -fdump-parse-tree} -ffpe-trap=@var{list} -fbacktrace -fdump-parse-tree}
@item Directory Options @item Directory Options
@xref{Directory Options,,Options for directory search}. @xref{Directory Options,,Options for directory search}.
...@@ -935,22 +935,18 @@ Some of the routines in the Fortran runtime library, like ...@@ -935,22 +935,18 @@ Some of the routines in the Fortran runtime library, like
@code{ffpe-trap=precision} is used. For this reason, the use of @code{ffpe-trap=precision} is used. For this reason, the use of
@code{ffpe-trap=precision} is not recommended. @code{ffpe-trap=precision} is not recommended.
@item -fbacktrace @item -fno-backtrace
@opindex @code{fbacktrace} @opindex @code{fno-backtrace}
@cindex backtrace @cindex backtrace
@cindex trace @cindex trace
Specify that, when a runtime error is encountered or a deadly signal is When a serious runtime error is encountered or a deadly signal is
emitted (segmentation fault, illegal instruction, bus error or emitted (segmentation fault, illegal instruction, bus error,
floating-point exception), the Fortran runtime floating-point exception, and the other POSIX signals that have the
library should output a backtrace of the error. This option action @samp{core}), the Fortran runtime library tries to output a
only has influence for compilation of the Fortran main program. backtrace of the error. @code{-fno-backtrace} disables the backtrace
generation. This option only has influence for compilation of the
@item -fdump-core Fortran main program.
@cindex core, dump
@opindex @code{fdump-core}
Request that a core-dump file is written to disk when a runtime error
is encountered on systems that support core dumps. This option is
only effective for the compilation of the Fortran main program.
@end table @end table
@xref{Debugging Options,,Options for Debugging Your Program or GCC, @xref{Debugging Options,,Options for Debugging Your Program or GCC,
......
...@@ -366,10 +366,6 @@ fdollar-ok ...@@ -366,10 +366,6 @@ fdollar-ok
Fortran Fortran
Allow dollar signs in entity names Allow dollar signs in entity names
fdump-core
Fortran
Dump a core file when a runtime error occurs
fdump-fortran-original fdump-fortran-original
Fortran Fortran
Display the code tree after parsing Display the code tree after parsing
......
...@@ -134,9 +134,8 @@ gfc_init_options (unsigned int decoded_options_count, ...@@ -134,9 +134,8 @@ gfc_init_options (unsigned int decoded_options_count,
gfc_option.flag_automatic = 1; gfc_option.flag_automatic = 1;
gfc_option.flag_backslash = 0; gfc_option.flag_backslash = 0;
gfc_option.flag_module_private = 0; gfc_option.flag_module_private = 0;
gfc_option.flag_backtrace = 0; gfc_option.flag_backtrace = 1;
gfc_option.flag_allow_leading_underscore = 0; gfc_option.flag_allow_leading_underscore = 0;
gfc_option.flag_dump_core = 0;
gfc_option.flag_external_blas = 0; gfc_option.flag_external_blas = 0;
gfc_option.blas_matmul_limit = 30; gfc_option.blas_matmul_limit = 30;
gfc_option.flag_cray_pointer = 0; gfc_option.flag_cray_pointer = 0;
...@@ -697,10 +696,6 @@ gfc_handle_option (size_t scode, const char *arg, int value, ...@@ -697,10 +696,6 @@ gfc_handle_option (size_t scode, const char *arg, int value,
gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS; gfc_option.rtcheck |= GFC_RTCHECK_ARRAY_TEMPS;
break; break;
case OPT_fdump_core:
gfc_option.flag_dump_core = value;
break;
case OPT_fcray_pointer: case OPT_fcray_pointer:
gfc_option.flag_cray_pointer = value; gfc_option.flag_cray_pointer = value;
break; break;
......
...@@ -4636,9 +4636,12 @@ create_main_function (tree fndecl) ...@@ -4636,9 +4636,12 @@ create_main_function (tree fndecl)
gfc_option.allow_std)); gfc_option.allow_std));
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
build_int_cst (integer_type_node, pedantic)); build_int_cst (integer_type_node, pedantic));
/* TODO: This is the old -fdump-core option, which is unused but
passed due to ABI compatibility; remove when bumping the
library ABI. */
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
build_int_cst (integer_type_node, build_int_cst (integer_type_node,
gfc_option.flag_dump_core)); 0));
CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, CONSTRUCTOR_APPEND_ELT (v, NULL_TREE,
build_int_cst (integer_type_node, build_int_cst (integer_type_node,
gfc_option.flag_backtrace)); gfc_option.flag_backtrace));
......
2011-05-14 Janne Blomqvist <jb@gcc.gnu.org> 2011-05-14 Janne Blomqvist <jb@gcc.gnu.org>
PR libfortran/48915
* intrinsics/abort.c (abort): Call sys_abort().
* io/unix.c (st_vprintf): Call sys_abort().
* libgfortran.h (options_t): Remove dump_core member.
(handler): Rename to backtrace_handler.
(compile_options_t): Remove dump_core member.
(sys_exit): Remove.
(sys_abort): New function.
* runtime/backtrace.c (show_backtrace): Print a message if
backtrace is not available on target, update filter symbol name
due to backtrace_handler renaming.
* runtime/compile_options.c (backtrace_handler): New
implementation based on example in Glibc manual.
(set_options): Remove dump_core handling, make signal handler
handle more signals.
(init_compile_options): Remove dump_core.
* runtime/environ.c (variable_table[]): Remove
GFORTRAN_ERROR_DUMPCORE element.
(show_variables): Update name, call exit().
* runtime/error.c (sys_exit): Remove.
(sys_abort): New function.
(recursion_check): Call sys_abort().
(os_error): Call exit().
(runtime_error): Likewise.
(runtime_error_at): Likewise.
(internal_error): Likewise.
(generate_error): Likewise.
(notify_std): Likewise.
* runtime/stop.c (stop_numeric): Call exit().
(stop_numeric_f08): Likewise.
(stop_string): Likewise.
(error_stop_string): Call sys_abort().
(error_stop_numeric): Print backtrace, exit with provided code.
2011-05-14 Janne Blomqvist <jb@gcc.gnu.org>
* io/unix.c (st_vprintf,st_printf): Move to runtime/error.c. * io/unix.c (st_vprintf,st_printf): Move to runtime/error.c.
* libgfortran.h (struct options_t): Remove use_stderr field. * libgfortran.h (struct options_t): Remove use_stderr field.
(st_vprintf,st_printf): Move prototypes. (st_vprintf,st_printf): Move prototypes.
......
...@@ -30,6 +30,5 @@ export_proto_np(PREFIX(abort)); ...@@ -30,6 +30,5 @@ export_proto_np(PREFIX(abort));
void PREFIX(abort) (void) void PREFIX(abort) (void)
{ {
close_units (); sys_abort ();
abort ();
} }
...@@ -509,15 +509,15 @@ typedef struct ...@@ -509,15 +509,15 @@ typedef struct
const char *separator; const char *separator;
int all_unbuffered, unbuffered_preconnected, default_recl; int all_unbuffered, unbuffered_preconnected, default_recl;
int fpe, dump_core, backtrace; int fpe, backtrace;
} }
options_t; options_t;
extern options_t options; extern options_t options;
internal_proto(options); internal_proto(options);
extern void handler (int); extern void backtrace_handler (int);
internal_proto(handler); internal_proto(backtrace_handler);
/* Compile-time options that will influence the library. */ /* Compile-time options that will influence the library. */
...@@ -528,7 +528,6 @@ typedef struct ...@@ -528,7 +528,6 @@ typedef struct
int allow_std; int allow_std;
int pedantic; int pedantic;
int convert; int convert;
int dump_core;
int backtrace; int backtrace;
int sign_zero; int sign_zero;
size_t record_marker; size_t record_marker;
...@@ -688,8 +687,8 @@ internal_proto(show_backtrace); ...@@ -688,8 +687,8 @@ internal_proto(show_backtrace);
#define GFC_OTOA_BUF_SIZE (GFC_LARGEST_BUF * 3 + 1) #define GFC_OTOA_BUF_SIZE (GFC_LARGEST_BUF * 3 + 1)
#define GFC_BTOA_BUF_SIZE (GFC_LARGEST_BUF * 8 + 1) #define GFC_BTOA_BUF_SIZE (GFC_LARGEST_BUF * 8 + 1)
extern void sys_exit (int) __attribute__ ((noreturn)); extern void sys_abort (void) __attribute__ ((noreturn));
internal_proto(sys_exit); internal_proto(sys_abort);
extern ssize_t estr_write (const char *); extern ssize_t estr_write (const char *);
internal_proto(estr_write); internal_proto(estr_write);
......
...@@ -214,7 +214,7 @@ show_backtrace (void) ...@@ -214,7 +214,7 @@ show_backtrace (void)
if (strncasecmp (func, "*_gfortran", 10) == 0 if (strncasecmp (func, "*_gfortran", 10) == 0
|| strncasecmp (func, "_gfortran", 9) == 0 || strncasecmp (func, "_gfortran", 9) == 0
|| strcmp (func, "main") == 0 || strcmp (func, "_start") == 0 || strcmp (func, "main") == 0 || strcmp (func, "_start") == 0
|| strcmp (func, "_gfortrani_handler") == 0) || strcmp (func, "_gfortrani_backtrace_handler") == 0)
continue; continue;
if (local_strcasestr (str[i], "libgfortran.so") != NULL if (local_strcasestr (str[i], "libgfortran.so") != NULL
...@@ -334,5 +334,7 @@ fallback: ...@@ -334,5 +334,7 @@ fallback:
/* Fallback to the glibc backtrace. */ /* Fallback to the glibc backtrace. */
estr_write ("\nBacktrace for this error:\n"); estr_write ("\nBacktrace for this error:\n");
dump_glibc_backtrace (depth, str); dump_glibc_backtrace (depth, str);
return;
#endif #endif
estr_write ("\nBacktrace not yet available on this platform, sorry!\n");
} }
...@@ -33,49 +33,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see ...@@ -33,49 +33,28 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
compile_options_t compile_options; compile_options_t compile_options;
volatile sig_atomic_t fatal_error_in_progress = 0;
/* A signal handler to allow us to output a backtrace. */ /* A signal handler to allow us to output a backtrace. */
void void
handler (int signum) backtrace_handler (int signum)
{ {
const char * name = NULL, * desc = NULL; /* Since this handler is established for more than one kind of signal,
it might still get invoked recursively by delivery of some other kind
switch (signum) of signal. Use a static variable to keep track of that. */
{ if (fatal_error_in_progress)
#if defined(SIGSEGV) raise (signum);
case SIGSEGV: fatal_error_in_progress = 1;
name = "SIGSEGV";
desc = "Segmentation fault"; show_backtrace();
break;
#endif /* Now reraise the signal. We reactivate the signal's
default handling, which is to terminate the process.
#if defined(SIGBUS) We could just call exit or abort,
case SIGBUS: but reraising the signal sets the return status
name = "SIGBUS"; from the process correctly. */
desc = "Bus error"; signal (signum, SIG_DFL);
break; raise (signum);
#endif
#if defined(SIGILL)
case SIGILL:
name = "SIGILL";
desc = "Illegal instruction";
break;
#endif
#if defined(SIGFPE)
case SIGFPE:
name = "SIGFPE";
desc = "Floating-point exception";
break;
#endif
}
if (name)
st_printf ("\nProgram received signal %d (%s): %s.\n", signum, name, desc);
else
st_printf ("\nProgram received signal %d.\n", signum);
sys_exit (5);
} }
...@@ -92,8 +71,9 @@ set_options (int num, int options[]) ...@@ -92,8 +71,9 @@ set_options (int num, int options[])
compile_options.allow_std = options[1]; compile_options.allow_std = options[1];
if (num >= 3) if (num >= 3)
compile_options.pedantic = options[2]; compile_options.pedantic = options[2];
if (num >= 4) /* options[3] is the removed -fdump-core option. It's place in the
compile_options.dump_core = options[3]; options array is retained due to ABI compatibility. Remove when
bumping the library ABI. */
if (num >= 5) if (num >= 5)
compile_options.backtrace = options[4]; compile_options.backtrace = options[4];
if (num >= 6) if (num >= 6)
...@@ -103,26 +83,53 @@ set_options (int num, int options[]) ...@@ -103,26 +83,53 @@ set_options (int num, int options[])
if (num >= 8) if (num >= 8)
compile_options.range_check = options[7]; compile_options.range_check = options[7];
/* If backtrace is required, we set signal handlers on most common /* If backtrace is required, we set signal handlers on the POSIX
signals. */ 2001 signals with core action. */
#if defined(HAVE_SIGNAL) && (defined(SIGSEGV) || defined(SIGBUS) \ #if defined(HAVE_SIGNAL) && (defined(SIGQUIT) || defined(SIGILL) \
|| defined(SIGILL) || defined(SIGFPE)) || defined(SIGABRT) || defined(SIGFPE) \
|| defined(SIGSEGV) || defined(SIGBUS) \
|| defined(SIGSYS) || defined(SIGTRAP) \
|| defined(SIGXCPU) || defined(SIGXFSZ))
if (compile_options.backtrace) if (compile_options.backtrace)
{ {
#if defined(SIGQUIT)
signal (SIGQUIT, backtrace_handler);
#endif
#if defined(SIGILL)
signal (SIGILL, backtrace_handler);
#endif
#if defined(SIGABRT)
signal (SIGABRT, backtrace_handler);
#endif
#if defined(SIGFPE)
signal (SIGFPE, backtrace_handler);
#endif
#if defined(SIGSEGV) #if defined(SIGSEGV)
signal (SIGSEGV, handler); signal (SIGSEGV, backtrace_handler);
#endif #endif
#if defined(SIGBUS) #if defined(SIGBUS)
signal (SIGBUS, handler); signal (SIGBUS, backtrace_handler);
#endif #endif
#if defined(SIGILL) #if defined(SIGSYS)
signal (SIGILL, handler); signal (SIGSYS, backtrace_handler);
#endif #endif
#if defined(SIGFPE) #if defined(SIGTRAP)
signal (SIGFPE, handler); signal (SIGTRAP, backtrace_handler);
#endif
#if defined(SIGXCPU)
signal (SIGXCPU, backtrace_handler);
#endif
#if defined(SIGXFSZ)
signal (SIGXFSZ, backtrace_handler);
#endif #endif
} }
#endif #endif
...@@ -140,7 +147,6 @@ init_compile_options (void) ...@@ -140,7 +147,6 @@ init_compile_options (void)
| GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
| GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY; | GFC_STD_F2008_OBS | GFC_STD_GNU | GFC_STD_LEGACY;
compile_options.pedantic = 0; compile_options.pedantic = 0;
compile_options.dump_core = 0;
compile_options.backtrace = 0; compile_options.backtrace = 0;
compile_options.sign_zero = 1; compile_options.sign_zero = 1;
compile_options.range_check = 1; compile_options.range_check = 1;
......
...@@ -318,11 +318,6 @@ static variable variable_table[] = { ...@@ -318,11 +318,6 @@ static variable variable_table[] = {
{"GFORTRAN_CONVERT_UNIT", 0, 0, init_unformatted, show_string, {"GFORTRAN_CONVERT_UNIT", 0, 0, init_unformatted, show_string,
"Set format for unformatted files", 0}, "Set format for unformatted files", 0},
/* Behaviour when encoutering a runtime error. */
{"GFORTRAN_ERROR_DUMPCORE", -1, &options.dump_core,
init_boolean, show_boolean,
"Dump a core file (if possible) on runtime error", -1},
{"GFORTRAN_ERROR_BACKTRACE", -1, &options.backtrace, {"GFORTRAN_ERROR_BACKTRACE", -1, &options.backtrace,
init_boolean, show_boolean, init_boolean, show_boolean,
"Print out a backtrace (if possible) on runtime error", -1}, "Print out a backtrace (if possible) on runtime error", -1},
...@@ -388,7 +383,7 @@ show_variables (void) ...@@ -388,7 +383,7 @@ show_variables (void)
estr_write ("\nCommand line arguments:\n"); estr_write ("\nCommand line arguments:\n");
estr_write (" --help Print this list\n"); estr_write (" --help Print this list\n");
sys_exit (0); exit (0);
} }
/* This is the handling of the GFORTRAN_CONVERT_UNITS environment variable. /* This is the handling of the GFORTRAN_CONVERT_UNITS environment variable.
......
...@@ -58,44 +58,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see ...@@ -58,44 +58,32 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#endif #endif
/* sys_exit()-- Terminate the program with an exit code. */ /* Termination of a program: F2008 2.3.5 talks about "normal
termination" and "error termination". Normal termination occurs as
void a result of e.g. executing the end program statement, and executing
sys_exit (int code) the STOP statement. It includes the effect of the C exit()
{ function.
/* Show error backtrace if possible. */
if (code != 0 && code != 4 Error termination is initiated when the ERROR STOP statement is
&& (options.backtrace == 1 executed, when ALLOCATE/DEALLOCATE fails without STAT= being
|| (options.backtrace == -1 && compile_options.backtrace == 1))) specified, when some of the co-array synchronization statements
show_backtrace (); fail without STAT= being specified, and some I/O errors if
ERR/IOSTAT/END/EOR is not present, and finally EXECUTE_COMMAND_LINE
/* Dump core if requested. */ failure without CMDSTAT=.
if (code != 0
&& (options.dump_core == 1 2.3.5 also explains how co-images synchronize during termination.
|| (options.dump_core == -1 && compile_options.dump_core == 1)))
{ In libgfortran we have two ways of ending a program. exit(code) is
#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) a normal exit; calling exit() also causes open units to be
/* Warn if a core file cannot be produced because closed. No backtrace or core dump is needed here. When something
of core size limit. */ goes wrong, we have sys_abort() which tries to print the backtrace
if -fbacktrace is enabled, and then dumps core; whether a core file
struct rlimit core_limit; is generated is system dependent. When aborting, we don't flush and
close open units, as program memory might be corrupted and we'd
if (getrlimit (RLIMIT_CORE, &core_limit) == 0 && core_limit.rlim_cur == 0) rather risk losing dirty data in the buffers rather than corrupting
estr_write ("** Warning: a core dump was requested, but the core size" files on disk.
"limit\n** is currently zero.\n\n");
#endif */
#if defined(HAVE_KILL) && defined(HAVE_GETPID) && defined(SIGQUIT)
kill (getpid (), SIGQUIT);
#else
estr_write ("Core dump not possible, sorry.");
#endif
}
exit (code);
}
/* Error conditions. The tricky part here is printing a message when /* Error conditions. The tricky part here is printing a message when
* it is the I/O subsystem that is severely wounded. Our goal is to * it is the I/O subsystem that is severely wounded. Our goal is to
...@@ -107,7 +95,6 @@ sys_exit (int code) ...@@ -107,7 +95,6 @@ sys_exit (int code)
* 1 Terminated because of operating system error. * 1 Terminated because of operating system error.
* 2 Error in the runtime library * 2 Error in the runtime library
* 3 Internal error in runtime library * 3 Internal error in runtime library
* 4 Error during error processing (very bad)
* *
* Other error returns are reserved for the STOP statement with a numeric code. * Other error returns are reserved for the STOP statement with a numeric code.
*/ */
...@@ -150,7 +137,7 @@ st_vprintf (const char *format, va_list ap) ...@@ -150,7 +137,7 @@ st_vprintf (const char *format, va_list ap)
#define ERROR_MESSAGE "Internal error: buffer overrun in st_vprintf()\n" #define ERROR_MESSAGE "Internal error: buffer overrun in st_vprintf()\n"
write (STDERR_FILENO, buffer, ST_VPRINTF_SIZE - 1); write (STDERR_FILENO, buffer, ST_VPRINTF_SIZE - 1);
write (STDERR_FILENO, ERROR_MESSAGE, strlen(ERROR_MESSAGE)); write (STDERR_FILENO, ERROR_MESSAGE, strlen(ERROR_MESSAGE));
sys_exit(2); sys_abort ();
#undef ERROR_MESSAGE #undef ERROR_MESSAGE
} }
...@@ -173,6 +160,27 @@ st_printf (const char * format, ...) ...@@ -173,6 +160,27 @@ st_printf (const char * format, ...)
} }
/* sys_abort()-- Terminate the program showing backtrace and dumping
core. */
void
sys_abort ()
{
/* If backtracing is enabled, print backtrace and disable signal
handler for ABRT. */
if (options.backtrace == 1
|| (options.backtrace == -1 && compile_options.backtrace == 1))
{
show_backtrace ();
#if defined(HAVE_SIGNAL) && defined(SIGABRT)
signal (SIGABRT, SIG_DFL);
#endif
}
abort();
}
/* gfc_xtoa()-- Integer to hexadecimal conversion. */ /* gfc_xtoa()-- Integer to hexadecimal conversion. */
const char * const char *
...@@ -278,7 +286,7 @@ recursion_check (void) ...@@ -278,7 +286,7 @@ recursion_check (void)
/* Don't even try to print something at this point */ /* Don't even try to print something at this point */
if (magic == MAGIC) if (magic == MAGIC)
sys_exit (4); sys_abort ();
magic = MAGIC; magic = MAGIC;
} }
...@@ -300,7 +308,7 @@ os_error (const char *message) ...@@ -300,7 +308,7 @@ os_error (const char *message)
estr_write ("\n"); estr_write ("\n");
estr_write (message); estr_write (message);
estr_write ("\n"); estr_write ("\n");
sys_exit (1); exit (1);
} }
iexport(os_error); iexport(os_error);
...@@ -319,7 +327,7 @@ runtime_error (const char *message, ...) ...@@ -319,7 +327,7 @@ runtime_error (const char *message, ...)
st_vprintf (message, ap); st_vprintf (message, ap);
va_end (ap); va_end (ap);
estr_write ("\n"); estr_write ("\n");
sys_exit (2); exit (2);
} }
iexport(runtime_error); iexport(runtime_error);
...@@ -338,7 +346,7 @@ runtime_error_at (const char *where, const char *message, ...) ...@@ -338,7 +346,7 @@ runtime_error_at (const char *where, const char *message, ...)
st_vprintf (message, ap); st_vprintf (message, ap);
va_end (ap); va_end (ap);
estr_write ("\n"); estr_write ("\n");
sys_exit (2); exit (2);
} }
iexport(runtime_error_at); iexport(runtime_error_at);
...@@ -376,7 +384,7 @@ internal_error (st_parameter_common *cmp, const char *message) ...@@ -376,7 +384,7 @@ internal_error (st_parameter_common *cmp, const char *message)
because hopefully it doesn't happen too often). */ because hopefully it doesn't happen too often). */
stupid_function_name_for_static_linking(); stupid_function_name_for_static_linking();
sys_exit (3); exit (3);
} }
...@@ -544,7 +552,7 @@ generate_error (st_parameter_common *cmp, int family, const char *message) ...@@ -544,7 +552,7 @@ generate_error (st_parameter_common *cmp, int family, const char *message)
estr_write ("Fortran runtime error: "); estr_write ("Fortran runtime error: ");
estr_write (message); estr_write (message);
estr_write ("\n"); estr_write ("\n");
sys_exit (2); exit (2);
} }
iexport(generate_error); iexport(generate_error);
...@@ -606,7 +614,7 @@ notify_std (st_parameter_common *cmp, int std, const char * message) ...@@ -606,7 +614,7 @@ notify_std (st_parameter_common *cmp, int std, const char * message)
estr_write ("Fortran runtime error: "); estr_write ("Fortran runtime error: ");
estr_write (message); estr_write (message);
estr_write ("\n"); estr_write ("\n");
sys_exit (2); exit (2);
} }
else else
{ {
......
...@@ -41,7 +41,7 @@ stop_numeric (GFC_INTEGER_4 code) ...@@ -41,7 +41,7 @@ stop_numeric (GFC_INTEGER_4 code)
else else
st_printf ("STOP %d\n", (int)code); st_printf ("STOP %d\n", (int)code);
sys_exit (code); exit (code);
} }
...@@ -55,7 +55,7 @@ void ...@@ -55,7 +55,7 @@ void
stop_numeric_f08 (GFC_INTEGER_4 code) stop_numeric_f08 (GFC_INTEGER_4 code)
{ {
st_printf ("STOP %d\n", (int)code); st_printf ("STOP %d\n", (int)code);
sys_exit (code); exit (code);
} }
...@@ -71,7 +71,7 @@ stop_string (const char *string, GFC_INTEGER_4 len) ...@@ -71,7 +71,7 @@ stop_string (const char *string, GFC_INTEGER_4 len)
(void) sizeof (w); /* Avoid compiler warning about not using w. */ (void) sizeof (w); /* Avoid compiler warning about not using w. */
estr_write ("\n"); estr_write ("\n");
} }
sys_exit (0); exit (0);
} }
...@@ -92,7 +92,7 @@ error_stop_string (const char *string, GFC_INTEGER_4 len) ...@@ -92,7 +92,7 @@ error_stop_string (const char *string, GFC_INTEGER_4 len)
(void) sizeof (w); /* Avoid compiler warning about not using w. */ (void) sizeof (w); /* Avoid compiler warning about not using w. */
estr_write ("\n"); estr_write ("\n");
sys_exit (1); sys_abort ();
} }
...@@ -106,5 +106,8 @@ void ...@@ -106,5 +106,8 @@ void
error_stop_numeric (GFC_INTEGER_4 code) error_stop_numeric (GFC_INTEGER_4 code)
{ {
st_printf ("ERROR STOP %d\n", (int) code); st_printf ("ERROR STOP %d\n", (int) code);
sys_exit (code); if (options.backtrace == 1
|| (options.backtrace == -1 && compile_options.backtrace == 1))
show_backtrace ();
exit (code);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment