uniform handling of fatal signals

Zack Weinberg zack@wolery.cumb.org
Mon Jul 24 14:32:00 GMT 2000


The C++ front end catches segmentation faults and the like, and turns
them into ICE messages.  This is preferable to letting the driver do
it, because the front end can tell you where in the input file it blew
up.

This patch moves the signal handler up to toplev.c so all front ends
get the feature.

Also, we don't print any message if the compiler gets SIGPIPE, which
is consistent with the preprocessor.

Bootstrapped i386-linux.  No regressions, I think (the tree is a bit
shaky right now).

zw

	* toplev.c (pipe_closed): Delete.
	(crash_signal): New.  Generate ICE for a fatal signal.
	(float_signal): Call crash_signal outside a float-handler
	block, not abort.
	(main): Install crash_signal as handler for core-dumping signals.

cp:
	* decl.c: Remove all signal handling code, now done in toplev.c.

===================================================================
Index: toplev.c
--- toplev.c	2000/07/10 20:10:14	1.354
+++ toplev.c	2000/07/24 21:27:14
@@ -160,7 +160,7 @@ static void set_target_switch PARAMS ((c
 static const char *decl_name PARAMS ((tree, int));
 
 static void float_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
-static void pipe_closed PARAMS ((int)) ATTRIBUTE_NORETURN;
+static void crash_signal PARAMS ((int)) ATTRIBUTE_NORETURN;
 #ifdef ASM_IDENTIFY_LANGUAGE
 /* This might or might not be used in ASM_IDENTIFY_LANGUAGE. */
 static void output_lang_identify PARAMS ((FILE *)) ATTRIBUTE_UNUSED;
@@ -1543,7 +1543,7 @@ float_signal (signo)
      int signo ATTRIBUTE_UNUSED;
 {
   if (float_handled == 0)
-    abort ();
+    crash_signal (signo);
 #if defined (USG) || defined (hpux)
   signal (SIGFPE, float_signal);  /* re-enable the signal catcher */
 #endif
@@ -1629,14 +1629,17 @@ pop_float_handler (handled, handler)
     bcopy ((char *) handler, (char *) float_handler, sizeof (float_handler));
 }
 
-/* Handler for SIGPIPE.  */
+/* Handler for fatal signals, such as SIGSEGV.  These are transformed
+   into ICE messages, which is much more user friendly.  */
 
 static void
-pipe_closed (signo)
+crash_signal (signo)
      /* If this is missing, some compilers complain.  */
-     int signo ATTRIBUTE_UNUSED;
+     int signo;
 {
-  fatal ("output pipe has been closed");
+  fatal ("Internal error: %s.\n\
+Please submit a full bug report.\n\
+See %s for instructions.", strsignal (signo), GCCBUGURL);
 }
 
 /* Strip off a legitimate source ending from the input string NAME of
@@ -4431,12 +4434,27 @@ main (argc, argv)
   (void) bindtextdomain (PACKAGE, localedir);
   (void) textdomain (PACKAGE);
 
+  /* Install handler for SIGFPE, which may be received while we do
+     compile-time floating point arithmetic.  */
   signal (SIGFPE, float_signal);
 
-#ifdef SIGPIPE
-  signal (SIGPIPE, pipe_closed);
+  /* Trap fatal signals, e.g. SIGSEGV, and convert them to ICE messages.  */
+#ifdef SIGSEGV
+  signal (SIGSEGV, crash_signal);
 #endif
-
+#ifdef SIGILL
+  signal (SIGILL, crash_signal);
+#endif
+#ifdef SIGBUS
+  signal (SIGBUS, crash_signal);
+#endif
+#ifdef SIGABRT
+  signal (SIGABRT, crash_signal);
+#endif
+#if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
+  signal (SIGIOT, crash_signal);
+#endif
+  
   decl_printable_name = decl_name;
   lang_expand_expr = (lang_expand_expr_t) do_abort;
 
===================================================================
Index: cp/decl.c
--- cp/decl.c	2000/07/23 19:59:41	1.658
+++ cp/decl.c	2000/07/24 21:27:18
@@ -37,7 +37,6 @@ Boston, MA 02111-1307, USA.  */
 #include "cp-tree.h"
 #include "decl.h"
 #include "lex.h"
-#include <signal.h>
 #include "defaults.h"
 #include "output.h"
 #include "except.h"
@@ -105,7 +104,6 @@ static void suspend_binding_level PARAMS
 static void resume_binding_level PARAMS ((struct binding_level *));
 static struct binding_level *make_binding_level PARAMS ((void));
 static void declare_namespace_level PARAMS ((void));
-static void signal_catch PARAMS ((int)) ATTRIBUTE_NORETURN;
 static int decl_jump_unsafe PARAMS ((tree));
 static void storedecls PARAMS ((tree));
 static void require_complete_types_for_parms PARAMS ((tree));
@@ -6096,36 +6094,6 @@ end_only_namespace_names ()
   only_namespace_names = 0;
 }
 
-/* Arrange for the user to get a source line number, even when the
-   compiler is going down in flames, so that she at least has a
-   chance of working around problems in the compiler.  We used to
-   call error(), but that let the segmentation fault continue
-   through; now, it's much more passive by asking them to send the
-   maintainers mail about the problem.  */
-
-static void
-signal_catch (sig)
-     int sig;
-{
-  signal (SIGSEGV, SIG_DFL);
-#ifdef SIGIOT
-  signal (SIGIOT, SIG_DFL);
-#endif
-#ifdef SIGILL
-  signal (SIGILL, SIG_DFL);
-#endif
-#ifdef SIGABRT
-  signal (SIGABRT, SIG_DFL);
-#endif
-#ifdef SIGBUS
-  signal (SIGBUS, SIG_DFL);
-#endif
-
-  fatal ("Internal error: %s\n\
-Please submit a full bug report.\n\
-See %s for instructions.", strsignal (sig), GCCBUGURL);
-}
-
 /* Push the declarations of builtin types into the namespace.
    RID_INDEX, if < CP_RID_MAX is the index of the builtin type
    in the array RID_POINTERS.  NAME is the name used when looking
@@ -6333,28 +6301,6 @@ init_decl_processing ()
   current_function_decl = NULL_TREE;
   current_binding_level = NULL_BINDING_LEVEL;
   free_binding_level = NULL_BINDING_LEVEL;
-
-  /* Because most segmentation signals can be traced back into user
-     code, catch them and at least give the user a chance of working
-     around compiler bugs.  */
-  signal (SIGSEGV, signal_catch);
-
-  /* We will also catch aborts in the back-end through signal_catch and
-     give the user a chance to see where the error might be, and to defeat
-     aborts in the back-end when there have been errors previously in their
-     code.  */
-#ifdef SIGIOT
-  signal (SIGIOT, signal_catch);
-#endif
-#ifdef SIGILL
-  signal (SIGILL, signal_catch);
-#endif
-#ifdef SIGABRT
-  signal (SIGABRT, signal_catch);
-#endif
-#ifdef SIGBUS
-  signal (SIGBUS, signal_catch);
-#endif
 
   build_common_tree_nodes (flag_signed_char);
 


More information about the Gcc-patches mailing list