diff options
Diffstat (limited to 'libgfortran/runtime')
-rw-r--r-- | libgfortran/runtime/compile_options.c | 7 | ||||
-rw-r--r-- | libgfortran/runtime/environ.c | 5 | ||||
-rw-r--r-- | libgfortran/runtime/error.c | 59 |
3 files changed, 69 insertions, 2 deletions
diff --git a/libgfortran/runtime/compile_options.c b/libgfortran/runtime/compile_options.c index b2aef05a832..06ebc4d9023 100644 --- a/libgfortran/runtime/compile_options.c +++ b/libgfortran/runtime/compile_options.c @@ -37,17 +37,19 @@ compile_options_t compile_options; /* Prototypes */ -extern void set_std (GFC_INTEGER_4, GFC_INTEGER_4, GFC_INTEGER_4); +extern void set_std (GFC_INTEGER_4, GFC_INTEGER_4, GFC_INTEGER_4, + GFC_INTEGER_4); export_proto(set_std); void set_std (GFC_INTEGER_4 warn_std, GFC_INTEGER_4 allow_std, - GFC_INTEGER_4 pedantic) + GFC_INTEGER_4 pedantic, GFC_INTEGER_4 dump_core) { compile_options.pedantic = pedantic; compile_options.warn_std = warn_std; compile_options.allow_std = allow_std; + compile_options.dump_core = dump_core; } @@ -61,6 +63,7 @@ init_compile_options (void) compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY; compile_options.pedantic = 0; + compile_options.dump_core = 0; } /* Function called by the front-end to tell us the diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c index 21c2cc9f717..cc3be215c36 100644 --- a/libgfortran/runtime/environ.c +++ b/libgfortran/runtime/environ.c @@ -537,6 +537,11 @@ static variable variable_table[] = { {"GFORTRAN_CONVERT_UNIT", 0, 0, init_unformatted, show_string, "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}, + {NULL, 0, NULL, NULL, NULL, NULL, 0} }; diff --git a/libgfortran/runtime/error.c b/libgfortran/runtime/error.c index c0787dead66..e6713d2cc4d 100644 --- a/libgfortran/runtime/error.c +++ b/libgfortran/runtime/error.c @@ -36,8 +36,67 @@ Boston, MA 02110-1301, USA. */ #include <float.h> #include <errno.h> +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif + +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif + +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif + +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif + #include "libgfortran.h" +#ifdef __MINGW32__ +#define HAVE_GETPID 1 +#include <process.h> +#endif + + +/* sys_exit()-- Terminate the program with an exit code. */ + +void +sys_exit (int code) +{ + /* Dump core if requested. */ + if (code != 0 + && (options.dump_core == 1 + || (options.dump_core == -1 && compile_options.dump_core == 1))) + { +#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_CORE) + /* Warn if a core file cannot be produced because + of core size limit. */ + + struct rlimit core_limit; + + if (getrlimit (RLIMIT_CORE, &core_limit) == 0 && core_limit.rlim_cur == 0) + st_printf ("** Warning: a core dump was requested, but the core size" + "limit\n** is currently zero.\n\n"); +#endif + + +#if defined(HAVE_KILL) && defined(HAVE_GETPID) && defined(SIGQUIT) + kill (getpid (), SIGQUIT); +#else + st_printf ("Core dump not possible, sorry."); +#endif + } + + exit (code); +} + + /* 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 * try and print something making the fewest assumptions possible, |