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] Deliminate some uses of errstring


This replaces a number of catch_exceptions calls with a catch_exception call along with code to directly print the error message including a prefix (errstring).

Doing this eliminates the very cumbersom:

 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
                            bpt->owner->number);
 struct cleanup *cleanups = make_cleanup (xfree, prefix);
 val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix,
                         RETURN_MASK_ERROR);
 do_cleanups (cleanups);

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

	* exceptions.h (exception_fprintf): Declare.
	(exception_print): Drop pre_print parameter.
	* mi/mi-main.c (mi_execute_command): Update exception_print call.
	* cli/cli-interp.c (safe_execute_command): Update exception_print
	call.
	* remote.c (remote_open_1): Instead of passing an error prefix to
	catch_exceptions, use catch_exceptions and exception_fprintf.
	(remote_start_remote): Change return type to void.
	* breakpoint.c (insert_bp_location): Instead of passing an error
	prefix to catch_exceptions, use catch_exceptions and
	exception_fprintf.
	(insert_catchpoint): Change return type to void.
	(break_command_1): Update exception_print call.
	* exceptions.c (exception_fprintf): New function.
	(print_exception): New function.
	(exception_print): Use print_exception.
	
Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.192
diff -p -u -r1.192 breakpoint.c
--- breakpoint.c	14 Jan 2005 20:24:19 -0000	1.192
+++ breakpoint.c	14 Jan 2005 22:32:59 -0000
@@ -709,7 +709,7 @@ deprecated_read_memory_nobpt (CORE_ADDR 
 
 
 /* A wrapper function for inserting catchpoints.  */
-static int
+static void
 insert_catchpoint (struct ui_out *uo, void *args)
 {
   struct breakpoint *b = (struct breakpoint *) args;
@@ -733,8 +733,6 @@ insert_catchpoint (struct ui_out *uo, vo
 
   if (val < 0)
     throw_reason (RETURN_ERROR);
-
-  return 0;
 }
 
 /* Helper routine: free the value chain for a breakpoint (watchpoint).  */
@@ -1073,13 +1071,11 @@ insert_bp_location (struct bp_location *
 	   || bpt->owner->type == bp_catch_vfork
 	   || bpt->owner->type == bp_catch_exec)
     {
-      char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
-				 bpt->owner->number);
-      struct cleanup *cleanups = make_cleanup (xfree, prefix);
-      val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix,
-			      RETURN_MASK_ERROR);
-      do_cleanups (cleanups);
-      if (val < 0)
+      struct exception e = catch_exception (uiout, insert_catchpoint,
+					    bpt->owner, RETURN_MASK_ERROR);
+      exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ",
+			 bpt->owner->number);
+      if (e.reason < 0)
 	bpt->owner->enable_state = bp_disabled;
       else
 	bpt->inserted = 1;
@@ -5134,7 +5130,7 @@ break_command_1 (char *arg, int flag, in
   switch (e.reason)
     {
     case RETURN_QUIT:
-      exception_print (gdb_stderr, NULL, e);
+      exception_print (gdb_stderr, e);
       return e.reason;
     case RETURN_ERROR:
       switch (e.error)
@@ -5145,7 +5141,7 @@ break_command_1 (char *arg, int flag, in
 	  if (pending_bp)
 	    return e.reason;
 
-	  exception_print (gdb_stderr, NULL, e);
+	  exception_print (gdb_stderr, e);
 
 	  /* If pending breakpoint support is turned off, throw
 	     error.  */
@@ -5171,7 +5167,7 @@ break_command_1 (char *arg, int flag, in
 	  pending = 1;
 	  break;
 	default:
-	  exception_print (gdb_stderr, NULL, e);
+	  exception_print (gdb_stderr, e);
 	  return e.reason;
 	}
     default:
Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.7
diff -p -u -r1.7 exceptions.c
--- exceptions.c	14 Jan 2005 20:24:20 -0000	1.7
+++ exceptions.c	14 Jan 2005 22:32:59 -0000
@@ -302,9 +302,28 @@ do_write (void *data, const char *buffer
 }
 
 
+static void
+print_exception (struct ui_file *file, struct exception e)
+{
+  /* KLUGE: cagney/2005-01-13: Write the string out one line at a time
+     as that way the MI's behavior is preserved.  */
+  const char *start;
+  const char *end;
+  for (start = e.message; start != NULL; start = end)
+    {
+      end = strchr (start, '\n');
+      if (end == NULL)
+	fputs_filtered (start, file);
+      else
+	{
+	  end++;
+	  ui_file_write (file, start, end - start);
+	}
+    }					    
+}
+
 void
-exception_print (struct ui_file *file, const char *pre_print,
-		 struct exception e)
+exception_print (struct ui_file *file, struct exception e)
 {
   if (e.reason < 0 && e.message != NULL)
     {
@@ -312,26 +331,29 @@ exception_print (struct ui_file *file, c
       wrap_here ("");		/* Force out any buffered output */
       gdb_flush (file);
       annotate_error_begin ();
-      if (pre_print)
-	fputs_filtered (pre_print, file);
+      print_exception (file, e);
+      fprintf_filtered (file, "\n");
+    }
+}
+
+void
+exception_fprintf (struct ui_file *file, struct exception e,
+		   const char *prefix, ...)
+{
+  if (e.reason < 0 && e.message != NULL)
+    {
+      va_list args;
+      target_terminal_ours ();
+      wrap_here ("");		/* Force out any buffered output */
+      gdb_flush (file);
+      annotate_error_begin ();
+
+      /* Print the prefix.  */
+      va_start (args, prefix);
+      vfprintf_filtered (file, prefix, args);
+      va_end (args);
 
-      /* KLUGE: cagney/2005-01-13: Write the string out one line at a
-	 time as that way the MI's behavior is preserved.  */
-      {
-	const char *start;
-	const char *end;
-	for (start = e.message; start != NULL; start = end)
-	  {
-	    end = strchr (start, '\n');
-	    if (end == NULL)
-	      fputs_filtered (start, file);
-	    else
-	      {
-		end++;
-		ui_file_write (file, start, end - start);
-	      }
-	  }					    
-      }
+      print_exception (file, e);
       fprintf_filtered (file, "\n");
     }
 }
Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.7
diff -p -u -r1.7 exceptions.h
--- exceptions.h	14 Jan 2005 20:24:20 -0000	1.7
+++ exceptions.h	14 Jan 2005 22:32:59 -0000
@@ -67,9 +67,11 @@ struct exception
 extern const struct exception exception_none;
 
 /* If E is an exception, print it's error message on the specified
-   stream.  */
-extern void exception_print (struct ui_file *file, const char *pre_print,
-			     struct exception e);
+   stream. for _fprintf, prefix the message with PREFIX...  */
+extern void exception_print (struct ui_file *file, struct exception e);
+extern void exception_fprintf (struct ui_file *file, struct exception e,
+			       const char *prefix,
+			       ...) ATTR_FORMAT (printf, 3, 4);
 
 /* Throw an exception (as described by "struct exception").  Will
    execute a LONG JUMP to the inner most containing exception handler
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.160
diff -p -u -r1.160 remote.c
--- remote.c	14 Jan 2005 01:46:07 -0000	1.160
+++ remote.c	14 Jan 2005 22:33:00 -0000
@@ -83,8 +83,6 @@ static void remote_resume (ptid_t ptid, 
                            enum target_signal siggnal);
 static void remote_async_resume (ptid_t ptid, int step,
 				 enum target_signal siggnal);
-static int remote_start_remote (struct ui_out *uiout, void *dummy);
-
 static void remote_open (char *name, int from_tty);
 static void remote_async_open (char *name, int from_tty);
 
@@ -2019,7 +2017,7 @@ remote_start_remote_dummy (struct ui_out
   return 1;
 }
 
-static int
+static void
 remote_start_remote (struct ui_out *uiout, void *dummy)
 {
   immediate_quit++;		/* Allow user to interrupt it.  */
@@ -2037,9 +2035,7 @@ remote_start_remote (struct ui_out *uiou
   putpkt ("?");			/* Initiate a query from remote machine.  */
   immediate_quit--;
 
-  /* NOTE: See comment above in remote_start_remote_dummy().  This
-     function returns something >=0.  */
-  return remote_start_remote_dummy (uiout, dummy);
+  remote_start_remote_dummy (uiout, dummy);
 }
 
 /* Open a connection to a remote debugger.
@@ -2157,7 +2153,7 @@ static void
 remote_open_1 (char *name, int from_tty, struct target_ops *target,
 	       int extended_p, int async_p)
 {
-  int ex;
+  struct exception ex;
   struct remote_state *rs = get_remote_state ();
   if (name == 0)
     error ("To open a remote debug connection, you need to specify what\n"
@@ -2260,17 +2256,15 @@ remote_open_1 (char *name, int from_tty,
      been fixed - the function set_cmd_context() makes it possible for
      all the ``target ....'' commands to share a common callback
      function.  See cli-dump.c.  */
-  ex = catch_exceptions (uiout,
-			 remote_start_remote, NULL,
-			 "Couldn't establish connection to remote"
-			 " target\n",
-			 RETURN_MASK_ALL);
-  if (ex < 0)
+  ex = catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
+  exception_fprintf (gdb_stderr, ex, "Couldn't establish connection to remote"
+		     " target\n");
+  if (ex.reason < 0)
     {
       pop_target ();
       if (async_p)
 	wait_forever_enabled_p = 1;
-      throw_reason (ex);
+      throw_reason (ex.reason);
     }
 
   if (async_p)
Index: cli/cli-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-interp.c,v
retrieving revision 1.8
diff -p -u -r1.8 cli-interp.c
--- cli/cli-interp.c	14 Jan 2005 18:55:32 -0000	1.8
+++ cli/cli-interp.c	14 Jan 2005 22:33:00 -0000
@@ -133,7 +133,7 @@ safe_execute_command (struct ui_out *uio
 		       RETURN_MASK_ALL);
   /* FIXME: cagney/2005-01-13: This shouldn't be needed.  Instead the
      caller should print the exception.  */
-  exception_print (gdb_stderr, NULL, e);
+  exception_print (gdb_stderr, e);
   return e;
 }
 
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.72
diff -p -u -r1.72 mi-main.c
--- mi/mi-main.c	14 Jan 2005 18:55:33 -0000	1.72
+++ mi/mi-main.c	14 Jan 2005 22:33:00 -0000
@@ -1156,7 +1156,7 @@ mi_execute_command (char *cmd, int from_
       args.command = command;
       result = catch_exception (uiout, captured_mi_execute_command, &args,
 				RETURN_MASK_ALL);
-      exception_print (gdb_stderr, NULL, result);
+      exception_print (gdb_stderr, result);
 
       if (args.action == EXECUTE_COMMAND_SUPRESS_PROMPT)
 	{

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