This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[commit] Move error print to the catch code


Another design flaw. Given the nesting:

  catch/noprint FATAL
    catch/print ERROR
      fatal ("fatal message")

the message would be printed even though the applicable catcher didn't want it.

The attached moves the print code to the catch code so that the message is only printed if/when requested.

tested on ppc gnu/linux

committed,
Andrew
2005-01-14  Andrew Cagney  <cagney@gnu.org>

	* exceptions.c (print_and_throw): Delete, replaced by throw_it.
	(throw_reason): Leave the exception's message field blank.
	(throw_it): New function, create the exception and throw it.
	(throw_verror, throw_vfatal, throw_error): Call throw_it.
	(print_any_exception): New function.
	(catch_errors, catch_exceptions_with_msg): Call
	print_any_exception.
	(throw_exception): Move code calling annotate_error and
	annotate_quit from here ...
	(print_exception): ... to here.

Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.10
diff -p -u -r1.10 exceptions.c
--- exceptions.c	15 Jan 2005 04:31:10 -0000	1.10
+++ exceptions.c	15 Jan 2005 05:00:08 -0000
@@ -249,20 +249,6 @@ throw_exception (struct exception except
   if (sync_execution)
     do_exec_error_cleanups (ALL_CLEANUPS);
 
-  if (annotation_level > 1)
-    switch (exception.reason)
-      {
-      case RETURN_QUIT:
-	annotate_quit ();
-	break;
-      case RETURN_ERROR:
-	/* Assume that these are all errors.  */
-	annotate_error ();
-	break;
-      default:
-	internal_error (__FILE__, __LINE__, "Bad switch.");
-      }
-
   /* Jump to the containing catch_errors() call, communicating REASON
      to that call via setjmp's return value.  Note that REASON can't
      be zero, by definition in defs.h. */
@@ -286,7 +272,6 @@ throw_reason (enum return_reason reason)
       break;
     case RETURN_ERROR:
       exception.error = GENERIC_ERROR;
-      exception.message = last_message;
       break;
     default:
       internal_error (__FILE__, __LINE__, "bad switch");
@@ -325,6 +310,20 @@ print_exception (struct ui_file *file, s
 	}
     }					    
   fprintf_filtered (file, "\n");
+
+  /* Now append the annotation.  */
+  switch (e.reason)
+    {
+    case RETURN_QUIT:
+      annotate_quit ();
+      break;
+    case RETURN_ERROR:
+      /* Assume that these are all errors.  */
+      annotate_error ();
+      break;
+    default:
+      internal_error (__FILE__, __LINE__, _("Bad switch."));
+    }
 }
 
 void
@@ -356,13 +355,30 @@ exception_fprintf (struct ui_file *file,
     }
 }
 
+void
+print_any_exception (struct ui_file *file, const char *prefix,
+		     struct exception e)
+{
+  if (e.reason < 0 && e.message != NULL)
+    {
+      target_terminal_ours ();
+      wrap_here ("");		/* Force out any buffered output */
+      gdb_flush (gdb_stdout);
+      annotate_error_begin ();
+
+      /* Print the prefix.  */
+      if (prefix != NULL && prefix[0] != '\0')
+	fputs_filtered (prefix, file);
+      print_exception (file, e);
+    }
+}
+
 NORETURN static void
-print_and_throw (enum return_reason reason, enum errors error,
-		 const char *prefix, const char *fmt,
-		 va_list ap) ATTR_NORETURN;
+throw_it (enum return_reason reason, enum errors error, const char *prefix,
+	  const char *fmt, va_list ap) ATTR_NORETURN;
 NORETURN static void
-print_and_throw (enum return_reason reason, enum errors error,
-		 const char *prefix, const char *fmt, va_list ap)
+throw_it (enum return_reason reason, enum errors error, const char *prefix,
+	  const char *fmt, va_list ap)
 {
   struct exception e;
 
@@ -375,17 +391,6 @@ print_and_throw (enum return_reason reas
   e.error = error;
   e.message = last_message;
 
-  /* Print the mesage to stderr, but only if the catcher isn't going
-     to handle/print it locally.  */
-  if (current_catcher->print_message)
-    {
-      /* Write the message plus any pre_print to gdb_stderr.  */
-      print_flush ();
-      if (error_pre_print)
-	fputs_filtered (error_pre_print, gdb_stderr);
-      print_exception (gdb_stderr, e);
-    }
-
   /* Throw the exception.  */
   throw_exception (e);
 }
@@ -393,13 +398,13 @@ print_and_throw (enum return_reason reas
 NORETURN void
 throw_verror (enum errors error, const char *fmt, va_list ap)
 {
-  print_and_throw (RETURN_ERROR, error, error_pre_print, fmt, ap);
+  throw_it (RETURN_ERROR, error, error_pre_print, fmt, ap);
 }
 
 NORETURN void
 throw_vfatal (const char *fmt, va_list ap)
 {
-  print_and_throw (RETURN_QUIT, NO_ERROR, quit_pre_print, fmt, ap);
+  throw_it (RETURN_QUIT, NO_ERROR, quit_pre_print, fmt, ap);
 }
 
 NORETURN void
@@ -407,7 +412,7 @@ throw_error (enum errors error, const ch
 {
   va_list args;
   va_start (args, fmt);
-  print_and_throw (RETURN_ERROR, error, error_pre_print, fmt, args);
+  throw_it (RETURN_ERROR, error, error_pre_print, fmt, args);
   va_end (args);
 }
 
@@ -479,6 +484,7 @@ catch_exceptions_with_msg (struct ui_out
   SIGJMP_BUF *catch = catcher_init (uiout, NULL, &exception, mask, 1);
   for (SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
     val = (*func) (uiout, func_args);
+  print_any_exception (gdb_stderr, NULL, exception);
   gdb_assert (val >= 0);
   gdb_assert (exception.reason <= 0);
   if (exception.reason < 0)
@@ -510,6 +516,7 @@ catch_errors (catch_errors_ftype *func, 
      also catch "return".  */
   for (SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
     val = func (func_args);
+  print_any_exception (gdb_stderr, errstring, exception);
   if (exception.reason != 0)
     return 0;
   return val;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]