diff options
author | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-18 12:54:11 +0000 |
---|---|---|
committer | burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-01-18 12:54:11 +0000 |
commit | b7fcd3f95fa452127c1b12fdc0d702784bccff60 (patch) | |
tree | 35528f51b61de752d5ace70f20f9840ecaf371df /libgfortran/runtime | |
parent | 9acadc12bc67e6cdb73fd376f3087e49b2919e23 (diff) | |
download | gcc-b7fcd3f95fa452127c1b12fdc0d702784bccff60.tar.gz |
2007-01-18 Francois-Xavier Coudert <coudert@clipper.ens.fr>
Tobias Burnus <burnus@net-b.de>
PR libfortran/29649
* gfortran.h (gfc_option_t): Add flag_dump_core.
* lang.opt: Add -fdump-core option.
* invoke.texi: Document the new options.
* trans-decl.c (gfc_build_builtin_function_decls): Add new
options to the call to set_std.
* options.c (gfc_init_options, gfc_handle_option): Set the
new options.
2007-01-18 Francois-Xavier Coudert <coudert@clipper.ens.fr>
Tobias Burnus <burnus@net-b.de>
PR libfortran/29649
* runtime/environ.c (variable_table): New GFORTRAN_ERROR_DUMPCORE
environment variable.
* runtime/compile_options.c (set_std): Add new argument.
* runtime/error.c (sys_exit): Move from io/unix.c. Add coredump functionality.
* libgfortran.h (options_t): New dump_core and backtrace members.
(sys_exit): Move prototype.
* io/unix.c (sys_exit): Move to runtime/error.c.
* configure.ac: Add check for getrlimit.
* configure: Regenerate.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@120897 138bc75d-0d04-0410-961f-82ee72b054a4
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, |