* [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)
@ 2007-01-05 21:24 Tobias Burnus
[not found] ` <6113E044-201A-4840-8134-FAE8C096A185@gmail.com>
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Tobias Burnus @ 2007-01-05 21:24 UTC (permalink / raw)
To: gcc-patches, 'fortran@gcc.gnu.org'
:ADDPATCH fortran:
Currently, when errors are detected in libgfortran, an error message is
shown; depending on the kind of error, it can be rather difficult to
find the place where the error occurred. And fiddling with the debugger
is also not easy (which symbol do you use for the break point?)
This patch adds the -fdump-core option, which causes libgfortran to
SIGQUIT itself (coredump).
This patch was extracted from Francois-Xavier's patch, posted at
http://gcc.gnu.org/ml/fortran/2006-11/msg00634.html
which also implemented backtracing.
The default setting is off. The setting can be changed both at compile
time (-fdump-core) and overwritten at run time via
the GFORTRAN_ERROR_DUMPCORE variable.
As set_std is modified, this makes the library incompatible with
previously compiled gfortran programs. One should thus either bump the
library version or consider to backport it to 4.2. (Suggestions?)
The initial patch was bootstrapped and regtested on x86_64-linux and
built and tested on sparc-solaris2.9 by FX.
This patch was bootstrapped and regtested by me on x86_64-linux.
Tobias
("configure" regenerated using autoconf 2.59 using --enable-maintainer-mode)
libgfortran/
2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
Tobias Burnus <burnus@net-b.de>
PR fortran/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.
fortran/
2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
Tobias Burnus <burnus@net-b.de>
PR fortran/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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)
[not found] ` <6113E044-201A-4840-8134-FAE8C096A185@gmail.com>
@ 2007-01-06 10:21 ` Tobias Burnus
0 siblings, 0 replies; 5+ messages in thread
From: Tobias Burnus @ 2007-01-06 10:21 UTC (permalink / raw)
To: gcc-patches, burnus
[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]
FX Coudert schrieb:
>> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
>> Tobias Burnus <burnus@net-b.de>
>>
>> PR fortran/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.
>>
>>
>> fortran/
>> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
>> Tobias Burnus <burnus@net-b.de>
>>
>> PR fortran/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.
>>
>
> I believe you forgot the patch itself :)
Good point!
Tobias
[-- Attachment #2: core-dump.diff --]
[-- Type: text/x-patch, Size: 9803 bytes --]
Index: libgfortran/runtime/environ.c
===================================================================
--- libgfortran/runtime/environ.c (Revision 120491)
+++ libgfortran/runtime/environ.c (Arbeitskopie)
@@ -538,6 +538,11 @@
unformatted I/O. */
{"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}
};
Index: libgfortran/runtime/compile_options.c
===================================================================
--- libgfortran/runtime/compile_options.c (Revision 120491)
+++ libgfortran/runtime/compile_options.c (Arbeitskopie)
@@ -37,17 +37,19 @@
/* 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 @@
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
Index: libgfortran/runtime/error.c
===================================================================
--- libgfortran/runtime/error.c (Revision 120491)
+++ libgfortran/runtime/error.c (Arbeitskopie)
@@ -36,10 +36,69 @@
#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"
#include "../io/io.h"
#include "../io/unix.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,
Index: libgfortran/libgfortran.h
===================================================================
--- libgfortran/libgfortran.h (Revision 120491)
+++ libgfortran/libgfortran.h (Arbeitskopie)
@@ -354,6 +354,7 @@
int fpu_round, fpu_precision, fpe;
int sighup, sigint;
+ int dump_core;
}
options_t;
@@ -369,6 +370,7 @@
int allow_std;
int pedantic;
int convert;
+ int dump_core;
size_t record_marker;
int max_subrecord_length;
}
@@ -493,6 +495,9 @@
#define GFC_OTOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 3 + 1)
#define GFC_BTOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 8 + 1)
+extern void sys_exit (int) __attribute__ ((noreturn));
+internal_proto(sys_exit);
+
extern const char *gfc_itoa (GFC_INTEGER_LARGEST, char *, size_t);
internal_proto(gfc_itoa);
@@ -515,9 +520,6 @@
extern const char *get_oserror (void);
internal_proto(get_oserror);
-extern void sys_exit (int) __attribute__ ((noreturn));
-internal_proto(sys_exit);
-
extern int st_printf (const char *, ...)
__attribute__ ((format (printf, 1, 2)));
internal_proto(st_printf);
Index: libgfortran/configure.ac
===================================================================
--- libgfortran/configure.ac (Revision 120491)
+++ libgfortran/configure.ac (Arbeitskopie)
@@ -172,7 +172,7 @@
AC_CHECK_FUNCS(getrusage times mkstemp strtof strtold snprintf ftruncate chsize)
AC_CHECK_FUNCS(chdir strerror getlogin gethostname kill link symlink perror)
AC_CHECK_FUNCS(sleep time ttyname signal alarm ctime clock access fork execl)
-AC_CHECK_FUNCS(wait setmode)
+AC_CHECK_FUNCS(wait setmode getrlimit)
# Check for types
AC_CHECK_TYPES([intptr_t])
Index: libgfortran/io/unix.c
===================================================================
--- libgfortran/io/unix.c (Revision 120491)
+++ libgfortran/io/unix.c (Arbeitskopie)
@@ -327,15 +327,6 @@
}
-/* sys_exit()-- Terminate the program with an exit code */
-
-void
-sys_exit (int code)
-{
- exit (code);
-}
-
-
/*********************************************************************
File descriptor stream functions
*********************************************************************/
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h (Revision 120491)
+++ gcc/fortran/gfortran.h (Arbeitskopie)
@@ -1656,6 +1656,7 @@
int flag_f2c;
int flag_automatic;
int flag_backslash;
+ int flag_dump_core;
int flag_external_blas;
int blas_matmul_limit;
int flag_cray_pointer;
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt (Revision 120491)
+++ gcc/fortran/lang.opt (Arbeitskopie)
@@ -133,6 +133,10 @@
Fortran
Allow dollar signs in entity names
+fdump-core
+Fortran
+Dump a core file when a runtime error occurs
+
fdump-parse-tree
Fortran
Display the code tree after parsing
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi (Revision 120491)
+++ gcc/fortran/invoke.texi (Arbeitskopie)
@@ -121,7 +121,7 @@
-ffixed-line-length-@var{n} -ffixed-line-length-none @gol
-ffree-line-length-@var{n} -ffree-line-length-none @gol
-fdefault-double-8 -fdefault-integer-8 -fdefault-real-8 @gol
--fcray-pointer -fopenmp -frange-check }
+-fcray-pointer -fopenmp -frange-check -fno-backslash }
@item Error and Warning Options
@xref{Error and Warning Options,,Options to Request or Suppress Errors
@@ -134,7 +134,8 @@
@item Debugging Options
@xref{Debugging Options,,Options for Debugging Your Program or GCC}.
-@gccoptlist{-fdump-parse-tree -ffpe-trap=@var{list}}
+@gccoptlist{-fdump-parse-tree -ffpe-trap=@var{list}
+-fdump-core}
@item Directory Options
@xref{Directory Options,,Options for Directory Search}.
@@ -559,6 +560,15 @@
@samp{underflow} (underflow in a floating point operation),
@samp{precision} (loss of precision during operation) and @samp{denormal}
(operation produced a denormal value).
+
+@cindex -fdump-core option
+@cindex options, -fdump-core
+@item -fdump-core
+@cindex 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
@xref{Debugging Options,,Options for Debugging Your Program or GCC,
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (Revision 120491)
+++ gcc/fortran/trans-decl.c (Arbeitskopie)
@@ -2374,9 +2374,10 @@
gfor_fndecl_set_std =
gfc_build_library_function_decl (get_identifier (PREFIX("set_std")),
void_type_node,
- 3,
+ 4,
gfc_int4_type_node,
gfc_int4_type_node,
+ gfc_int4_type_node,
gfc_int4_type_node);
gfor_fndecl_set_convert =
@@ -3142,6 +3143,10 @@
arglist = gfc_chainon_list (arglist,
build_int_cst (gfc_int4_type_node,
pedantic));
+ arglist = gfc_chainon_list (arglist,
+ build_int_cst (gfc_int4_type_node,
+ gfc_option.flag_dump_core));
+
tmp = build_function_call_expr (gfor_fndecl_set_std, arglist);
gfc_add_expr_to_block (&body, tmp);
}
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c (Revision 120491)
+++ gcc/fortran/options.c (Arbeitskopie)
@@ -83,6 +83,7 @@
gfc_option.flag_preprocessed = 0;
gfc_option.flag_automatic = 1;
gfc_option.flag_backslash = 1;
+ gfc_option.flag_dump_core = 0;
gfc_option.flag_external_blas = 0;
gfc_option.blas_matmul_limit = 30;
gfc_option.flag_cray_pointer = 0;
@@ -446,6 +447,10 @@
gfc_option.flag_backslash = value;
break;
+ case OPT_fdump_core:
+ gfc_option.flag_dump_core = value;
+ break;
+
case OPT_fcray_pointer:
gfc_option.flag_cray_pointer = value;
break;
Index: configure
===================================================================
--- configure (Revision 120496)
+++ configure (Arbeitskopie)
@@ -10095,7 +10095,8 @@
-for ac_func in wait setmode
+
+for ac_func in wait setmode getrlimit
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
^ permalink raw reply [flat|nested] 5+ messages in thread
* libgfortran ABI compatibility / stability (was: Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649))
2007-01-05 21:24 [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649) Tobias Burnus
[not found] ` <6113E044-201A-4840-8134-FAE8C096A185@gmail.com>
@ 2007-01-06 14:48 ` FX Coudert
2007-01-06 17:08 ` Steve Kargl
2007-01-12 6:45 ` [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649) FX Coudert
2 siblings, 1 reply; 5+ messages in thread
From: FX Coudert @ 2007-01-06 14:48 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'
> As set_std is modified, this makes the library incompatible with
> previously compiled gfortran programs. One should thus either bump the
> library version or consider to backport it to 4.2. (Suggestions?)
I've been inactive in gfortran devel recently, so I'd like to know
what is the consensus reached on that point. My own opinion is that
it's too late for strict 4.2/4.3 ABI compatibility, and also too late
for backporting the versioning patch to 4.2, so we might as well
declare 4.3 incompatible with 4.2 & bump the version number.
It should be noted that once this decision is made, I'll resubmit a
"complete libgfortran namespace separation" patch (the one using -
fallow-leading-underscore), separately from the versioning stuff
(which I don't understand enough myself to work on it). Finally, that
gives us time (during the 4.3 stages 1 & 2) to work on the remaining
rough spots for ABI compatibility (for example, _libgfortran_set_std
will need to be adapted so that adding fields can be done without
breaking the ABI every time).
> libgfortran/
>
> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
> Tobias Burnus <burnus@net-b.de>
>
> PR fortran/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.
>
>
> fortran/
> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
> Tobias Burnus <burnus@net-b.de>
>
> PR fortran/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.
When there is general agreement on the point about ABI, then the
patch is OK.
Thanks Tobias,
FX
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: libgfortran ABI compatibility / stability (was: Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649))
2007-01-06 14:48 ` libgfortran ABI compatibility / stability (was: Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)) FX Coudert
@ 2007-01-06 17:08 ` Steve Kargl
0 siblings, 0 replies; 5+ messages in thread
From: Steve Kargl @ 2007-01-06 17:08 UTC (permalink / raw)
To: FX Coudert; +Cc: Tobias Burnus, gcc-patches, 'fortran@gcc.gnu.org'
On Sat, Jan 06, 2007 at 03:47:52PM +0100, FX Coudert wrote:
> >As set_std is modified, this makes the library incompatible with
> >previously compiled gfortran programs. One should thus either bump the
> >library version or consider to backport it to 4.2. (Suggestions?)
>
> I've been inactive in gfortran devel recently, so I'd like to know
> what is the consensus reached on that point. My own opinion is that
> it's too late for strict 4.2/4.3 ABI compatibility, and also too late
> for backporting the versioning patch to 4.2, so we might as well
> declare 4.3 incompatible with 4.2 & bump the version number.
>
I agree that it is too late to back port to 4.2. This
then suggests that a library version bump is needed.
However, I've never gotten the versioning patch to work
on FreeBSD, and my attempts to fix all failed.
--
Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)
2007-01-05 21:24 [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649) Tobias Burnus
[not found] ` <6113E044-201A-4840-8134-FAE8C096A185@gmail.com>
2007-01-06 14:48 ` libgfortran ABI compatibility / stability (was: Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)) FX Coudert
@ 2007-01-12 6:45 ` FX Coudert
2 siblings, 0 replies; 5+ messages in thread
From: FX Coudert @ 2007-01-12 6:45 UTC (permalink / raw)
To: Tobias Burnus; +Cc: gcc-patches, 'fortran@gcc.gnu.org'
> libgfortran/
>
> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
> Tobias Burnus <burnus@net-b.de>
>
> PR fortran/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.
>
>
> fortran/
> 2006-11-24 Francois-Xavier Coudert <coudert@clipper.ens.fr>
> Tobias Burnus <burnus@net-b.de>
>
> PR fortran/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.
I think we've let enough time for people to object the library
version bump and the plans for converging the ABI. So, your patch is
OK, Tobias!
Thanks for taking care of this coredump patch,
FX
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-01-12 6:45 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-05 21:24 [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649) Tobias Burnus
[not found] ` <6113E044-201A-4840-8134-FAE8C096A185@gmail.com>
2007-01-06 10:21 ` Tobias Burnus
2007-01-06 14:48 ` libgfortran ABI compatibility / stability (was: Re: [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649)) FX Coudert
2007-01-06 17:08 ` Steve Kargl
2007-01-12 6:45 ` [patch,fortran] Add -fdump-core option to coredump at library run-time errors (PR29649) FX Coudert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).