This is the mail archive of the gdb-patches@sourceware.org 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]

FYI: remove catch_exception


I'm checking this in on the trunk.

As discussed in another thread today, this patch removes
catch_exception.  TRY_CATCH is easier to understand and requires much
less code (no helper structs and functions).

Built and regtested on x86-64 (compile farm).

Tom

2011-04-04  Tom Tromey  <tromey@redhat.com>

	* cli/cli-interp.c (struct captured_execute_command_args):
	Remove.
	(do_captured_execute_command): Remove.
	(safe_execute_command): Use TRY_CATCH.
	* cli/cli-script.c (struct wrapped_read_command_file_args):
	Remove.
	(wrapped_read_command_file): Remove.
	(script_from_file): Use TRY_CATCH.
	* exceptions.c (catch_exception): Remove.
	* exceptions.h (catch_exception): Remove.
	(deprecated_throw_reason): Update comment.
	* mi/mi-main.c (captured_mi_execute_command): Change 'data'
	argument to 'context'.
	(mi_execute_command): Use TRY_CATCH.
	* remote.c (struct start_remote_args): Remove.
	(remote_start_remote): Update; change arguments.
	(remote_open_1): Use TRY_CATCH.

Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.41
diff -u -r1.41 exceptions.c
--- exceptions.c	7 Jan 2011 19:36:16 -0000	1.41
+++ exceptions.c	4 Apr 2011 18:10:29 -0000
@@ -458,21 +458,6 @@
   return catch_exceptions_with_msg (uiout, func, func_args, NULL, mask);
 }
 
-struct gdb_exception
-catch_exception (struct ui_out *uiout,
-		 catch_exception_ftype *func,
-		 void *func_args,
-		 return_mask mask)
-{
-  volatile struct gdb_exception exception;
-
-  TRY_CATCH (exception, mask)
-    {
-      (*func) (uiout, func_args);
-    }
-  return exception;
-}
-
 int
 catch_exceptions_with_msg (struct ui_out *uiout,
 		  	   catch_exceptions_ftype *func,
Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.33
diff -u -r1.33 exceptions.h
--- exceptions.h	14 Feb 2011 11:35:44 -0000	1.33
+++ exceptions.h	4 Apr 2011 18:10:29 -0000
@@ -182,8 +182,8 @@
 extern void throw_error (enum errors error, const char *fmt, ...)
      ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
 
-/* Instead of deprecated_throw_reason, code should use catch_exception
-   and throw_exception.  */
+/* Instead of deprecated_throw_reason, code should use
+   throw_exception.  */
 extern void deprecated_throw_reason (enum return_reason reason)
      ATTRIBUTE_NORETURN;
 
@@ -234,14 +234,6 @@
 			     	      char **gdberrmsg,
 				      return_mask mask);
 
-/* This function, in addition, suppresses the printing of the captured
-   error message.  It's up to the client to print it.  */
-
-extern struct gdb_exception catch_exception (struct ui_out *uiout,
-					     catch_exception_ftype *func,
-					     void *func_args,
-					     return_mask mask);
-
 /* If CATCH_ERRORS_FTYPE throws an error, catch_errors() returns zero
    otherwize the result from CATCH_ERRORS_FTYPE is returned.  It is
    probably useful for CATCH_ERRORS_FTYPE to always return a non-zero
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.441
diff -u -r1.441 remote.c
--- remote.c	18 Mar 2011 14:22:34 -0000	1.441
+++ remote.c	4 Apr 2011 18:10:31 -0000
@@ -3097,19 +3097,6 @@
   return 0;
 }
 
-/* Stub for catch_exception.  */
-
-struct start_remote_args
-{
-  int from_tty;
-
-  /* The current target.  */
-  struct target_ops *target;
-
-  /* Non-zero if this is an extended-remote target.  */
-  int extended_p;
-};
-
 /* Send interrupt_sequence to remote target.  */
 static void
 send_interrupt_sequence (void)
@@ -3130,9 +3117,8 @@
 }
 
 static void
-remote_start_remote (struct ui_out *uiout, void *opaque)
+remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
 {
-  struct start_remote_args *args = opaque;
   struct remote_state *rs = get_remote_state ();
   struct packet_config *noack_config;
   char *wait_status = NULL;
@@ -3179,7 +3165,7 @@
 	rs->noack_mode = 1;
     }
 
-  if (args->extended_p)
+  if (extended_p)
     {
       /* Tell the remote that we are using the extended protocol.  */
       putpkt ("!");
@@ -3197,7 +3183,7 @@
   /* On OSs where the list of libraries is global to all
      processes, we fetch them early.  */
   if (gdbarch_has_global_solist (target_gdbarch))
-    solib_add (NULL, args->from_tty, args->target, auto_solib_add);
+    solib_add (NULL, from_tty, target, auto_solib_add);
 
   if (non_stop)
     {
@@ -3215,7 +3201,7 @@
 	 controlling.  We default to adding them in the running state.
 	 The '?' query below will then tell us about which threads are
 	 stopped.  */
-      remote_threads_info (args->target);
+      remote_threads_info (target);
     }
   else if (rs->non_stop_aware)
     {
@@ -3236,7 +3222,7 @@
     {
       if (rs->buf[0] == 'W' || rs->buf[0] == 'X')
 	{
-	  if (!args->extended_p)
+	  if (!extended_p)
 	    error (_("The target is not running (try extended-remote?)"));
 
 	  /* We're connected, but not running.  Drop out before we
@@ -3276,7 +3262,7 @@
 	 how to do it some other way, try again.  This is not
 	 supported for non-stop; it could be, but it is tricky if
 	 there are no stopped threads when we connect.  */
-      if (remote_read_description_p (args->target)
+      if (remote_read_description_p (target)
 	  && gdbarch_target_desc (target_gdbarch) == NULL)
 	{
 	  target_clear_description ();
@@ -3289,7 +3275,7 @@
       rs->cached_wait_status = 1;
 
       immediate_quit--;
-      start_remote (args->from_tty); /* Initialize gdb process mechanisms.  */
+      start_remote (from_tty); /* Initialize gdb process mechanisms.  */
     }
   else
     {
@@ -3331,7 +3317,7 @@
 
       if (thread_count () == 0)
 	{
-	  if (!args->extended_p)
+	  if (!extended_p)
 	    error (_("The target is not running (try extended-remote?)"));
 
 	  /* We're connected, but not running.  Drop out before we
@@ -4060,14 +4046,12 @@
      all the ``target ....'' commands to share a common callback
      function.  See cli-dump.c.  */
   {
-    struct gdb_exception ex;
-    struct start_remote_args args;
-
-    args.from_tty = from_tty;
-    args.target = target;
-    args.extended_p = extended_p;
+    volatile struct gdb_exception ex;
 
-    ex = catch_exception (uiout, remote_start_remote, &args, RETURN_MASK_ALL);
+    TRY_CATCH (ex, RETURN_MASK_ALL)
+      {
+	remote_start_remote (from_tty, target, extended_p);
+      }
     if (ex.reason < 0)
       {
 	/* Pop the partially set up target - unless something else did
Index: cli/cli-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-interp.c,v
retrieving revision 1.20
diff -u -r1.20 cli-interp.c
--- cli/cli-interp.c	1 Jan 2011 15:33:20 -0000	1.20
+++ cli/cli-interp.c	4 Apr 2011 18:10:31 -0000
@@ -37,12 +37,6 @@
 static struct gdb_exception safe_execute_command (struct ui_out *uiout,
 						  char *command, 
 						  int from_tty);
-struct captured_execute_command_args
-{
-  char *command;
-  int from_tty;
-};
-
 /* These implement the cli out interpreter: */
 
 static void *
@@ -117,25 +111,15 @@
   return result;
 }
 
-static void
-do_captured_execute_command (struct ui_out *uiout, void *data)
-{
-  struct captured_execute_command_args *args =
-    (struct captured_execute_command_args *) data;
-
-  execute_command (args->command, args->from_tty);
-}
-
 static struct gdb_exception
 safe_execute_command (struct ui_out *uiout, char *command, int from_tty)
 {
-  struct gdb_exception e;
-  struct captured_execute_command_args args;
+  volatile struct gdb_exception e;
 
-  args.command = command;
-  args.from_tty = from_tty;
-  e = catch_exception (uiout, do_captured_execute_command, &args,
-		       RETURN_MASK_ALL);
+  TRY_CATCH (e, RETURN_MASK_ALL)
+    {
+      execute_command (command, from_tty);
+    }
   /* FIXME: cagney/2005-01-13: This shouldn't be needed.  Instead the
      caller should print the exception.  */
   exception_print (gdb_stderr, e);
Index: cli/cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.68
diff -u -r1.68 cli-script.c
--- cli/cli-script.c	4 Mar 2011 18:20:43 -0000	1.68
+++ cli/cli-script.c	4 Apr 2011 18:10:31 -0000
@@ -1589,19 +1589,6 @@
   source_file_name = p->old_file;
 }
 
-struct wrapped_read_command_file_args
-{
-  FILE *stream;
-};
-
-static void
-wrapped_read_command_file (struct ui_out *uiout, void *data)
-{
-  struct wrapped_read_command_file_args *args = data;
-
-  read_command_file (args->stream);
-}
-
 /* Used to implement source_command.  */
 
 void
@@ -1625,12 +1612,12 @@
   error_pre_print = "";
 
   {
-    struct gdb_exception e;
-    struct wrapped_read_command_file_args args;
+    volatile struct gdb_exception e;
 
-    args.stream = stream;
-    e = catch_exception (uiout, wrapped_read_command_file, &args,
-			 RETURN_MASK_ERROR);
+    TRY_CATCH (e, RETURN_MASK_ERROR)
+      {
+	read_command_file (stream);
+      }
     switch (e.reason)
       {
       case 0:
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.195
diff -u -r1.195 mi-main.c
--- mi/mi-main.c	18 Mar 2011 18:40:08 -0000	1.195
+++ mi/mi-main.c	4 Apr 2011 18:10:38 -0000
@@ -1816,10 +1816,9 @@
    prompt, display error). */
 
 static void
-captured_mi_execute_command (struct ui_out *uiout, void *data)
+captured_mi_execute_command (struct ui_out *uiout, struct mi_parse *context)
 {
   struct cleanup *cleanup;
-  struct mi_parse *context = (struct mi_parse *) data;
 
   if (do_timings)
     current_command_ts = context->cmd_start;
@@ -1947,7 +1946,7 @@
     }
   else
     {
-      struct gdb_exception result;
+      volatile struct gdb_exception result;
       ptid_t previous_ptid = inferior_ptid;
 
       command->token = token;
@@ -1959,8 +1958,10 @@
 	  timestamp (command->cmd_start);
 	}
 
-      result = catch_exception (uiout, captured_mi_execute_command, command,
-				RETURN_MASK_ALL);
+      TRY_CATCH (result, RETURN_MASK_ALL)
+	{
+	  captured_mi_execute_command (uiout, command);
+	}
       if (result.reason < 0)
 	{
 	  /* The command execution failed and error() was called


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