Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [commit] Add "struct exception"
@ 2005-01-12 23:59 Andrew Cagney
  2005-01-13  4:55 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2005-01-12 23:59 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1060 bytes --]

If this were Java, we'd be writing:

   class ErrorException extends Exception ...;
   class NoSourceFileErrorException extends ErrorException ...;
   ...;

and then

   try {
     ...
   } catch (ErrorException e) {
     System.out.println (e.toString ());
   }

but it isn't so we can't.

The attached patch establishes a framework that makes it possible to 
work around this limitation of C.  It adds:

	struct exception;
	struct exception catch_exception(...)
	throw_exception(struct exception)

(The existing throw_exception is renamed to throw_reason to avoid a name 
clash, callers updated).   This lets users write a rough equivalent:

   struct exception e = catch_exceptions (....)
   switch (exception.reason)
     ...
     case ERROR_RETURN:
       print (exception.message);

and even opens the possibility of:

   TRY_CATCH (e)
     {
       ...
     }
   switch (e.reason)
     ...

The hacks error_silent and error_last_message can now be eliminated.

exceptions.[hc]'s has been rewritten to use it; tested on ppc gnu/linux.

committed,
Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 14316 bytes --]

Index: ChangeLog
2005-01-12  Andrew Cagney  <cagney@gnu.org>

	* exceptions.h (throw_reason): Rename throw_exception.
	(enum errors, struct exception): Define.
	(catch_exception_ftype): Define.
	(catch_exception, throw_exception): Declare.
	* exceptions.c (throw_exception): Rewrite.
	(throw_reason): New function.
	(struct catcher, catcher_state_machine): Replace "reason" with
	"exception", delete "gdberrmsg".
	(catch_exception): New function.
	(catcher_init): Replace "gdberrmsg" parameter with "exception".
	(catch_errors, catch_exceptions_with_msg): Re-implement passing
	exception to catcher_init.
	* utils.c (error_silent, error_stream_1): Use throw_reason.
	(internal_verror, quit): Ditto.
	* breakpoint.c (insert_catchpoint, break_command_1): Ditto.
	* remote-fileio.c (remote_fileio_ctrl_c_signal_handler): Ditto.
	* remote.c (remote_open_1, interrupt_query): Ditto.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.188
diff -p -u -r1.188 breakpoint.c
--- breakpoint.c	12 Jan 2005 18:31:30 -0000	1.188
+++ breakpoint.c	12 Jan 2005 23:41:25 -0000
@@ -734,7 +734,7 @@ insert_catchpoint (struct ui_out *uo, vo
     }
 
   if (val < 0)
-    throw_exception (RETURN_ERROR);
+    throw_reason (RETURN_ERROR);
 
   return 0;
 }
@@ -5153,7 +5153,7 @@ break_command_1 (char *arg, int flag, in
 	  /* If pending breakpoint support is turned off, throw error.  */
 
 	  if (pending_break_support == AUTO_BOOLEAN_FALSE)
-	    throw_exception (RETURN_ERROR);
+	    throw_reason (RETURN_ERROR);
 
           /* If pending breakpoint support is auto query and the user selects 
 	     no, then simply return the error code.  */
Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.2
diff -p -u -r1.2 exceptions.c
--- exceptions.c	12 Jan 2005 19:12:29 -0000	1.2
+++ exceptions.c	12 Jan 2005 23:41:25 -0000
@@ -65,17 +65,16 @@ enum catcher_action {
 struct catcher
 {
   enum catcher_state state;
-  /* Scratch variables used when transitioning a state.  */
+  /* Jump buffer pointing back at the exception handler.  */
   SIGJMP_BUF buf;
-  int reason;
-  int val;
+  /* Status buffer belonging to that exception handler.  */
+  volatile struct exception *exception;
   /* Saved/current state.  */
   int mask;
   char *saved_error_pre_print;
   char *saved_quit_pre_print;
   struct ui_out *saved_uiout;
   struct cleanup *saved_cleanup_chain;
-  char **gdberrmsg;
   /* Back link.  */
   struct catcher *prev;
 };
@@ -86,12 +85,17 @@ static struct catcher *current_catcher;
 static SIGJMP_BUF *
 catcher_init (struct ui_out *func_uiout,
 	      char *errstring,
-	      char **gdberrmsg,
+	      volatile struct exception *exception,
 	      return_mask mask)
 {
   struct catcher *new_catcher = XZALLOC (struct catcher);
 
-  new_catcher->gdberrmsg = gdberrmsg;
+  /* Start with no exception, save it's address.  */
+  exception->reason = 0;
+  exception->error = NO_ERROR;
+  exception->message = NULL;
+  new_catcher->exception = exception;
+
   new_catcher->mask = mask;
 
   /* Override error/quit messages during FUNC. */
@@ -194,14 +198,8 @@ catcher_state_machine (enum catcher_acti
 	{
 	case CATCH_ITER:
 	  {
-	    int reason = current_catcher->reason;
-	    /* If caller wants a copy of the low-level error message,
-	       make one.  This is used in the case of a silent error
-	       whereby the caller may optionally want to issue the
-	       message.  */
-	    if (current_catcher->gdberrmsg != NULL)
-	      *(current_catcher->gdberrmsg) = error_last_message ();
-	    if (current_catcher->mask & RETURN_MASK (reason))
+	    struct exception exception = *current_catcher->exception;
+	    if (current_catcher->mask & RETURN_MASK (exception.reason))
 	      {
 		/* Exit normally if this catcher can handle this
 		   exception.  The caller analyses the func return
@@ -213,7 +211,7 @@ catcher_state_machine (enum catcher_acti
 	       relay the event to the next containing
 	       catch_errors(). */
 	    catcher_pop ();
-	    throw_exception (reason);
+	    throw_exception (exception);
 	  }
 	default:
 	  internal_error (__FILE__, __LINE__, "bad state");
@@ -223,10 +221,10 @@ catcher_state_machine (enum catcher_acti
     }
 }
 
-/* Return for reason REASON to the nearest containing catch_errors().  */
+/* Return EXCEPTION to the nearest containing catch_errors().  */
 
 NORETURN void
-throw_exception (enum return_reason reason)
+throw_exception (struct exception exception)
 {
   quit_flag = 0;
   immediate_quit = 0;
@@ -243,22 +241,47 @@ throw_exception (enum return_reason reas
     do_exec_error_cleanups (ALL_CLEANUPS);
 
   if (annotation_level > 1)
-    switch (reason)
+    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. */
   catcher_state_machine (CATCH_THROWING);
-  current_catcher->reason = reason;
-  SIGLONGJMP (current_catcher->buf, current_catcher->reason);
+  *current_catcher->exception = exception;
+  SIGLONGJMP (current_catcher->buf, exception.reason);
+}
+
+NORETURN void
+throw_reason (enum return_reason reason)
+{
+  struct exception exception;
+  memset (&exception, 0, sizeof exception);
+
+  exception.reason = reason;
+  switch (reason)
+    {
+    case RETURN_QUIT:
+      break;
+    case RETURN_ERROR:
+      exception.error = GENERIC_ERROR;
+      exception.message = error_last_message ();
+      break;
+    default:
+      internal_error (__FILE__, __LINE__, "bad switch");
+    }
+  
+  throw_exception (exception);
 }
 
 /* Call FUNC() with args FUNC_UIOUT and FUNC_ARGS, catching any
@@ -304,6 +327,21 @@ catch_exceptions (struct ui_out *uiout,
 				    NULL, mask);
 }
 
+struct exception
+catch_exception (struct ui_out *uiout,
+		 catch_exception_ftype *func,
+		 void *func_args,
+		 return_mask mask)
+{
+  volatile struct exception exception;
+  SIGJMP_BUF *catch;
+  catch = catcher_init (uiout, NULL, &exception, mask);
+  for (SIGSETJMP ((*catch));
+       catcher_state_machine (CATCH_ITER);)
+    (*func) (uiout, func_args);
+  return exception;
+}
+
 int
 catch_exceptions_with_msg (struct ui_out *uiout,
 		  	   catch_exceptions_ftype *func,
@@ -312,17 +350,22 @@ catch_exceptions_with_msg (struct ui_out
 			   char **gdberrmsg,
 		  	   return_mask mask)
 {
-  int val = 0;
-  enum return_reason caught;
-  SIGJMP_BUF *catch;
-  catch = catcher_init (uiout, errstring, gdberrmsg, mask);
-  for (caught = SIGSETJMP ((*catch));
-       catcher_state_machine (CATCH_ITER);)
+  volatile struct exception exception;
+  volatile int val = 0;
+  SIGJMP_BUF *catch = catcher_init (uiout, errstring, &exception, mask);
+  for (SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
     val = (*func) (uiout, func_args);
   gdb_assert (val >= 0);
-  gdb_assert (caught <= 0);
-  if (caught < 0)
-    return caught;
+  gdb_assert (exception.reason <= 0);
+  if (exception.reason < 0)
+    {
+      /* If caller wants a copy of the low-level error message, make
+	 one.  This is used in the case of a silent error whereby the
+	 caller may optionally want to issue the message.  */
+      if (gdberrmsg != NULL)
+	*gdberrmsg = exception.message;
+      return exception.reason;
+    }
   return val;
 }
 
@@ -330,20 +373,15 @@ int
 catch_errors (catch_errors_ftype *func, void *func_args, char *errstring,
 	      return_mask mask)
 {
-  int val = 0;
-  enum return_reason caught;
-  SIGJMP_BUF *catch;
-  catch = catcher_init (uiout, errstring, NULL, mask);
+  volatile int val = 0;
+  volatile struct exception exception;
+  SIGJMP_BUF *catch = catcher_init (uiout, errstring, &exception, mask);
   /* This illustrates how it is possible to nest the mechanism and
      hence catch "break".  Of course this doesn't address the need to
      also catch "return".  */
-  for (caught = SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
-    for (; catcher_state_machine (CATCH_ITER_1);)
-      {
-	val = func (func_args);
-	break;
-      }
-  if (caught != 0)
+  for (SIGSETJMP ((*catch)); catcher_state_machine (CATCH_ITER);)
+    val = func (func_args);
+  if (exception.reason != 0)
     return 0;
   return val;
 }
Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.1
diff -p -u -r1.1 exceptions.h
--- exceptions.h	12 Jan 2005 18:31:31 -0000	1.1
+++ exceptions.h	12 Jan 2005 23:41:25 -0000
@@ -24,7 +24,7 @@
 #ifndef EXCEPTIONS_H
 #define EXCEPTIONS_H
 
-/* Reasons for calling throw_exception().  NOTE: all reason values
+/* Reasons for calling throw_exceptions().  NOTE: all reason values
    must be less than zero.  enum value 0 is reserved for internal use
    as the return value from an initial setjmp().  The function
    catch_exceptions() reserves values >= 0 as legal results from its
@@ -44,17 +44,38 @@ enum return_reason
 #define RETURN_MASK_ALL		(RETURN_MASK_QUIT | RETURN_MASK_ERROR)
 typedef int return_mask;
 
-/* Throw an exception of type RETURN_REASON.  Will execute a LONG JUMP
-   to the inner most containing exception handler established using
-   catch_exceptions() (or the legacy catch_errors()).
+/* Describe all exceptions.  */
+
+enum errors {
+  NO_ERROR,
+  /* Any generic error, the corresponding text is in
+     exception.message.  */
+  GENERIC_ERROR,
+  /* Add more errors here.  */
+  NR_ERRORS
+};
+
+struct exception
+{
+  enum return_reason reason;
+  enum errors error;
+  char *message;
+};
+
+/* Throw an exception (as described by "struct exception").  Will
+   execute a LONG JUMP to the inner most containing exception handler
+   established using catch_exceptions() (or similar).
 
    Code normally throws an exception using error() et.al.  For various
    reaons, GDB also contains code that throws an exception directly.
    For instance, the remote*.c targets contain CNTRL-C signal handlers
    that propogate the QUIT event up the exception chain.  ``This could
-   be a good thing or a dangerous thing.'' -- the Existential Wombat.  */
+   be a good thing or a dangerous thing.'' -- the Existential
+   Wombat.  */
+
+extern NORETURN void throw_exception (struct exception exception) ATTR_NORETURN;
+extern NORETURN void throw_reason (enum return_reason reason) ATTR_NORETURN;
 
-extern NORETURN void throw_exception (enum return_reason) ATTR_NORETURN;
 
 /* Call FUNC(UIOUT, FUNC_ARGS) but wrapped within an exception
    handler.  If an exception (enum return_reason) is thrown using
@@ -87,11 +108,16 @@ typedef int (catch_exceptions_ftype) (st
 extern int catch_exceptions (struct ui_out *uiout,
 			     catch_exceptions_ftype *func, void *func_args,
 			     char *errstring, return_mask mask);
+typedef void (catch_exception_ftype) (struct ui_out *ui_out, void *args);
 extern int catch_exceptions_with_msg (struct ui_out *uiout,
 			     	      catch_exceptions_ftype *func, 
 			     	      void *func_args,
 			     	      char *errstring, char **gdberrmsg,
 				      return_mask mask);
+extern struct 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
Index: remote-fileio.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-fileio.c,v
retrieving revision 1.7
diff -p -u -r1.7 remote-fileio.c
--- remote-fileio.c	12 Jan 2005 18:31:32 -0000	1.7
+++ remote-fileio.c	12 Jan 2005 23:41:25 -0000
@@ -480,7 +480,7 @@ remote_fileio_ctrl_c_signal_handler (int
   remote_fileio_sig_set (SIG_IGN);
   remote_fio_ctrl_c_flag = 1;
   if (!remote_fio_no_longjmp)
-    throw_exception (RETURN_QUIT);
+    throw_reason (RETURN_QUIT);
   remote_fileio_sig_set (remote_fileio_ctrl_c_signal_handler);
 }
 
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.158
diff -p -u -r1.158 remote.c
--- remote.c	12 Jan 2005 18:31:32 -0000	1.158
+++ remote.c	12 Jan 2005 23:41:26 -0000
@@ -2257,7 +2257,7 @@ remote_open_1 (char *name, int from_tty,
       pop_target ();
       if (async_p)
 	wait_forever_enabled_p = 1;
-      throw_exception (ex);
+      throw_reason (ex);
     }
 
   if (async_p)
@@ -2723,7 +2723,7 @@ interrupt_query (void)
 Give up (and stop debugging it)? "))
     {
       target_mourn_inferior ();
-      throw_exception (RETURN_QUIT);
+      throw_reason (RETURN_QUIT);
     }
 
   target_terminal_inferior ();
Index: utils.c
===================================================================
RCS file: /cvs/src/src/gdb/utils.c,v
retrieving revision 1.140
diff -p -u -r1.140 utils.c
--- utils.c	12 Jan 2005 18:31:34 -0000	1.140
+++ utils.c	12 Jan 2005 23:41:26 -0000
@@ -674,7 +674,7 @@ error_silent (const char *string, ...)
   ui_file_put (tmp_stream, do_write, gdb_lasterr);
   va_end (args);
 
-  throw_exception (RETURN_ERROR);
+  throw_reason (RETURN_ERROR);
 }
 
 /* Output an error message including any pre-print text to gdb_stderr.  */
@@ -711,7 +711,7 @@ error_stream_1 (struct ui_file *stream, 
   ui_file_put (stream, do_write, gdb_stderr);
   fprintf_filtered (gdb_stderr, "\n");
 
-  throw_exception (reason);
+  throw_reason (reason);
 }
 
 NORETURN void
@@ -866,7 +866,7 @@ NORETURN void
 internal_verror (const char *file, int line, const char *fmt, va_list ap)
 {
   internal_vproblem (&internal_error_problem, file, line, fmt, ap);
-  throw_exception (RETURN_ERROR);
+  throw_reason (RETURN_ERROR);
 }
 
 NORETURN void
@@ -1007,7 +1007,7 @@ quit (void)
     fprintf_unfiltered (gdb_stderr,
 			"Quit (expect signal SIGINT when the program is resumed)\n");
 #endif
-  throw_exception (RETURN_QUIT);
+  throw_reason (RETURN_QUIT);
 }
 
 /* Control C comes here */

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [commit] Add "struct exception"
  2005-01-12 23:59 [commit] Add "struct exception" Andrew Cagney
@ 2005-01-13  4:55 ` Eli Zaretskii
  2005-01-14  1:34   ` Andrew Cagney
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2005-01-13  4:55 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

> Date: Wed, 12 Jan 2005 18:57:52 -0500
> From: Andrew Cagney <cagney@gnu.org>
> 
> clash, callers updated).   This lets users write a rough equivalent:
> 
>    struct exception e = catch_exceptions (....)
>    switch (exception.reason)

Please don't call it ``struct exception'', as that clashes with the
same struct defined by math.h and used by library function `matherr',
and would not compile in C++ at all.

Something like ``struct gdb_exception'' would probably be better.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [commit] Add "struct exception"
  2005-01-13  4:55 ` Eli Zaretskii
@ 2005-01-14  1:34   ` Andrew Cagney
  2005-04-26  5:06     ` Andrew Cagney
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2005-01-14  1:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

Eli Zaretskii wrote:
>>Date: Wed, 12 Jan 2005 18:57:52 -0500
>>From: Andrew Cagney <cagney@gnu.org>
>>
>>clash, callers updated).   This lets users write a rough equivalent:
>>
>>   struct exception e = catch_exceptions (....)
>>   switch (exception.reason)
> 
> 
> Please don't call it ``struct exception'', as that clashes with the
> same struct defined by math.h and used by library function `matherr',
> and would not compile in C++ at all.
> 
> Something like ``struct gdb_exception'' would probably be better.

Ah, thanks.  I'll rename it.

Andrew


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [commit] Add "struct exception"
  2005-01-14  1:34   ` Andrew Cagney
@ 2005-04-26  5:06     ` Andrew Cagney
  2005-04-26 18:08       ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Cagney @ 2005-04-26  5:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 657 bytes --]

Andrew Cagney wrote:
> Eli Zaretskii wrote:
> 
>>> Date: Wed, 12 Jan 2005 18:57:52 -0500
>>> From: Andrew Cagney <cagney@gnu.org>
>>>
>>> clash, callers updated).   This lets users write a rough equivalent:
>>>
>>>   struct exception e = catch_exceptions (....)
>>>   switch (exception.reason)
>>
>>
>>
>> Please don't call it ``struct exception'', as that clashes with the
>> same struct defined by math.h and used by library function `matherr',
>> and would not compile in C++ at all.
>>
>> Something like ``struct gdb_exception'' would probably be better.
> 
> 
> Ah, thanks.  I'll rename it.

Sorry to take so long, I've committed the attached.

Andrew

[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 23011 bytes --]

2005-04-26  Andrew Cagney  <cagney@gnu.org>

	Rename 'struct exception' to 'struct gdb_exception'.
	* wrapper.c: Update.
	* varobj.c: Update.
	* tui/tui-interp.c: Update.
	* remote.c: Update.
	* mi/mi-main.c: Update.
	* mi/mi-interp.c: Update.
	* linux-thread-db.c: Update.
	* interps.h: Update.
	* interps.c: Update.
	* exceptions.h: Update.
	* exceptions.c: Update.
	* dwarf2loc.c: Update.
	* cli/cli-interp.c: Update.
	* cli/cli-script.c: Update.
	* breakpoint.c: Update.

Index: breakpoint.c
===================================================================
RCS file: /cvs/src/src/gdb/breakpoint.c,v
retrieving revision 1.212
diff -p -u -r1.212 breakpoint.c
--- breakpoint.c	24 Feb 2005 13:51:30 -0000	1.212
+++ breakpoint.c	26 Apr 2005 05:01:57 -0000
@@ -1088,8 +1088,8 @@ in which its expression is valid.\n"),
 	   || bpt->owner->type == bp_catch_vfork
 	   || bpt->owner->type == bp_catch_exec)
     {
-      struct exception e = catch_exception (uiout, insert_catchpoint,
-					    bpt->owner, RETURN_MASK_ERROR);
+      struct gdb_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)
@@ -5105,7 +5105,7 @@ do_captured_parse_breakpoint (struct ui_
 static int
 break_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp)
 {
-  struct exception e;
+  struct gdb_exception e;
   int tempflag, hardwareflag;
   struct symtabs_and_lines sals;
   struct expression **cond = 0;
Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.26
diff -p -u -r1.26 dwarf2loc.c
--- dwarf2loc.c	31 Mar 2005 19:58:24 -0000	1.26
+++ dwarf2loc.c	26 Apr 2005 05:01:58 -0000
@@ -193,7 +193,7 @@ dwarf_expr_tls_address (void *baton, COR
     {
       ptid_t ptid = inferior_ptid;
       struct objfile *objfile = debaton->objfile;
-      volatile struct exception ex;
+      volatile struct gdb_exception ex;
 
       TRY_CATCH (ex, RETURN_MASK_ALL)
 	{
@@ -205,7 +205,7 @@ dwarf_expr_tls_address (void *baton, COR
 	  /* If it's 0, throw the appropriate exception.  */
 	  if (lm_addr == 0)
 	    {
-	      struct exception e
+	      struct gdb_exception e
 		= { RETURN_ERROR, TLS_LOAD_MODULE_NOT_FOUND_ERROR, 0 };
 
 	      throw_exception (e);
Index: exceptions.c
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.c,v
retrieving revision 1.19
diff -p -u -r1.19 exceptions.c
--- exceptions.c	11 Feb 2005 18:13:49 -0000	1.19
+++ exceptions.c	26 Apr 2005 05:01:58 -0000
@@ -32,7 +32,7 @@
 #include "gdb_string.h"
 #include "serial.h"
 
-const struct exception exception_none = { 0, NO_ERROR, NULL };
+const struct gdb_exception exception_none = { 0, NO_ERROR, NULL };
 
 /* Possible catcher states.  */
 enum catcher_state {
@@ -58,7 +58,7 @@ struct catcher
   /* Jump buffer pointing back at the exception handler.  */
   EXCEPTIONS_SIGJMP_BUF buf;
   /* Status buffer belonging to the exception handler.  */
-  volatile struct exception *exception;
+  volatile struct gdb_exception *exception;
   /* Saved/current state.  */
   int mask;
   struct ui_out *saved_uiout;
@@ -72,7 +72,7 @@ static struct catcher *current_catcher;
 
 EXCEPTIONS_SIGJMP_BUF *
 exceptions_state_mc_init (struct ui_out *func_uiout,
-			  volatile struct exception *exception,
+			  volatile struct gdb_exception *exception,
 			  return_mask mask)
 {
   struct catcher *new_catcher = XZALLOC (struct catcher);
@@ -174,7 +174,7 @@ exceptions_state_mc (enum catcher_action
 	{
 	case CATCH_ITER:
 	  {
-	    struct exception exception = *current_catcher->exception;
+	    struct gdb_exception exception = *current_catcher->exception;
 	    if (current_catcher->mask & RETURN_MASK (exception.reason))
 	      {
 		/* Exit normally if this catcher can handle this
@@ -212,7 +212,7 @@ exceptions_state_mc_action_iter_1 (void)
 /* Return EXCEPTION to the nearest containing catch_errors().  */
 
 NORETURN void
-throw_exception (struct exception exception)
+throw_exception (struct gdb_exception exception)
 {
   quit_flag = 0;
   immediate_quit = 0;
@@ -241,7 +241,7 @@ static char *last_message;
 NORETURN void
 deprecated_throw_reason (enum return_reason reason)
 {
-  struct exception exception;
+  struct gdb_exception exception;
   memset (&exception, 0, sizeof exception);
 
   exception.reason = reason;
@@ -289,7 +289,7 @@ print_flush (void)
 }
 
 static void
-print_exception (struct ui_file *file, struct exception e)
+print_exception (struct ui_file *file, struct gdb_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.  */
@@ -324,7 +324,7 @@ print_exception (struct ui_file *file, s
 }
 
 void
-exception_print (struct ui_file *file, struct exception e)
+exception_print (struct ui_file *file, struct gdb_exception e)
 {
   if (e.reason < 0 && e.message != NULL)
     {
@@ -334,7 +334,7 @@ exception_print (struct ui_file *file, s
 }
 
 void
-exception_fprintf (struct ui_file *file, struct exception e,
+exception_fprintf (struct ui_file *file, struct gdb_exception e,
 		   const char *prefix, ...)
 {
   if (e.reason < 0 && e.message != NULL)
@@ -354,7 +354,7 @@ exception_fprintf (struct ui_file *file,
 
 void
 print_any_exception (struct ui_file *file, const char *prefix,
-		     struct exception e)
+		     struct gdb_exception e)
 {
   if (e.reason < 0 && e.message != NULL)
     {
@@ -377,7 +377,7 @@ NORETURN static void
 throw_it (enum return_reason reason, enum errors error, const char *fmt,
 	  va_list ap)
 {
-  struct exception e;
+  struct gdb_exception e;
   char *new_message;
 
   /* Save the message.  Create the new message before deleting the
@@ -457,13 +457,13 @@ catch_exceptions (struct ui_out *uiout,
   return catch_exceptions_with_msg (uiout, func, func_args, NULL, mask);
 }
 
-struct exception
+struct gdb_exception
 catch_exception (struct ui_out *uiout,
 		 catch_exception_ftype *func,
 		 void *func_args,
 		 return_mask mask)
 {
-  volatile struct exception exception;
+  volatile struct gdb_exception exception;
   TRY_CATCH (exception, mask)
     {
       (*func) (uiout, func_args);
@@ -478,7 +478,7 @@ catch_exceptions_with_msg (struct ui_out
 			   char **gdberrmsg,
 		  	   return_mask mask)
 {
-  volatile struct exception exception;
+  volatile struct gdb_exception exception;
   volatile int val = 0;
   TRY_CATCH (exception, mask)
     {
@@ -509,7 +509,7 @@ catch_errors (catch_errors_ftype *func, 
 	      return_mask mask)
 {
   volatile int val = 0;
-  volatile struct exception exception;
+  volatile struct gdb_exception exception;
   TRY_CATCH (exception, mask)
     {
       val = func (func_args);
@@ -524,7 +524,7 @@ int
 catch_command_errors (catch_command_errors_ftype * command,
 		      char *arg, int from_tty, return_mask mask)
 {
-  volatile struct exception e;
+  volatile struct gdb_exception e;
   TRY_CATCH (e, mask)
     {
       command (arg, from_tty);
Index: exceptions.h
===================================================================
RCS file: /cvs/src/src/gdb/exceptions.h,v
retrieving revision 1.13
diff -p -u -r1.13 exceptions.h
--- exceptions.h	18 Mar 2005 21:03:39 -0000	1.13
+++ exceptions.h	26 Apr 2005 05:01:58 -0000
@@ -68,15 +68,15 @@ enum errors {
   TLS_NOT_ALLOCATED_YET_ERROR,
 
   /* Something else went wrong while attempting to find thread local
-     storage.  The ``struct exception'' message field provides more
-     detail.  */
+     storage.  The ``struct gdb_exception'' message field provides
+     more detail.  */
   TLS_GENERIC_ERROR,
 
   /* Add more errors here.  */
   NR_ERRORS
 };
 
-struct exception
+struct gdb_exception
 {
   enum return_reason reason;
   enum errors error;
@@ -84,7 +84,7 @@ struct exception
 };
 
 /* A pre-defined non-exception.  */
-extern const struct exception exception_none;
+extern const struct gdb_exception exception_none;
 
 /* Wrap set/long jmp so that it's more portable (internal to
    exceptions).  */
@@ -102,7 +102,7 @@ extern const struct exception exception_
 /* Functions to drive the exceptions state m/c (internal to
    exceptions).  */
 EXCEPTIONS_SIGJMP_BUF *exceptions_state_mc_init (struct ui_out *func_uiout,
-						 volatile struct exception *
+						 volatile struct gdb_exception *
 						 exception,
 						 return_mask mask);
 int exceptions_state_mc_action_iter (void);
@@ -119,7 +119,7 @@ int exceptions_state_mc_action_iter_1 (v
 
    *INDENT-OFF*
 
-   volatile struct exception e;
+   volatile struct gdb_exception e;
    TRY_CATCH (e, RETURN_MASK_ERROR)
      {
      }
@@ -144,12 +144,12 @@ int exceptions_state_mc_action_iter_1 (v
 
 /* If E is an exception, print it's error message on the specified
    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,
+extern void exception_print (struct ui_file *file, struct gdb_exception e);
+extern void exception_fprintf (struct ui_file *file, struct gdb_exception e,
 			       const char *prefix,
 			       ...) ATTR_FORMAT (printf, 3, 4);
 
-/* Throw an exception (as described by "struct exception").  Will
+/* Throw an exception (as described by "struct gdb_exception").  Will
    execute a LONG JUMP to the inner most containing exception handler
    established using catch_exceptions() (or similar).
 
@@ -160,7 +160,7 @@ extern void exception_fprintf (struct ui
    be a good thing or a dangerous thing.'' -- the Existential
    Wombat.  */
 
-extern NORETURN void throw_exception (struct exception exception) ATTR_NORETURN;
+extern NORETURN void throw_exception (struct gdb_exception exception) ATTR_NORETURN;
 extern NORETURN void throw_verror (enum errors, const char *fmt,
 				   va_list ap) ATTR_NORETURN;
 extern NORETURN void throw_vfatal (const char *fmt, va_list ap) ATTR_NORETURN;
@@ -212,10 +212,10 @@ extern int catch_exceptions_with_msg (st
 /* This function, in addition, suppresses the printing of the captured
    error message.  It's up to the client to print it.  */
 
-extern struct exception catch_exception (struct ui_out *uiout,
-					 catch_exception_ftype *func,
-					 void *func_args,
-					 return_mask mask);
+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
Index: interps.c
===================================================================
RCS file: /cvs/src/src/gdb/interps.c,v
retrieving revision 1.14
diff -p -u -r1.14 interps.c
--- interps.c	14 Feb 2005 18:10:08 -0000	1.14
+++ interps.c	26 Apr 2005 05:01:58 -0000
@@ -305,7 +305,7 @@ interp_exec_p (struct interp *interp)
   return interp->procs->exec_proc != NULL;
 }
 
-struct exception
+struct gdb_exception
 interp_exec (struct interp *interp, const char *command_str)
 {
   if (interp->procs->exec_proc != NULL)
@@ -398,7 +398,7 @@ interpreter_exec_cmd (char *args, int fr
 
   for (i = 1; i < nrules; i++)
     {
-      struct exception e = interp_exec (interp_to_use, prules[i]);
+      struct gdb_exception e = interp_exec (interp_to_use, prules[i]);
       if (e.reason < 0)
 	{
 	  interp_set (old_interp);
Index: interps.h
===================================================================
RCS file: /cvs/src/src/gdb/interps.h,v
retrieving revision 1.7
diff -p -u -r1.7 interps.h
--- interps.h	13 Jan 2005 02:35:37 -0000	1.7
+++ interps.h	26 Apr 2005 05:01:58 -0000
@@ -33,15 +33,16 @@ extern int interp_resume (struct interp 
 extern int interp_suspend (struct interp *interp);
 extern int interp_prompt_p (struct interp *interp);
 extern int interp_exec_p (struct interp *interp);
-extern struct exception interp_exec (struct interp *interp,
-				     const char *command);
+extern struct gdb_exception interp_exec (struct interp *interp,
+					 const char *command);
 extern int interp_quiet_p (struct interp *interp);
 
 typedef void *(interp_init_ftype) (void);
 typedef int (interp_resume_ftype) (void *data);
 typedef int (interp_suspend_ftype) (void *data);
 typedef int (interp_prompt_p_ftype) (void *data);
-typedef struct exception (interp_exec_ftype) (void *data, const char *command);
+typedef struct gdb_exception (interp_exec_ftype) (void *data,
+						  const char *command);
 typedef void (interp_command_loop_ftype) (void *data);
 
 struct interp_procs
Index: linux-thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-thread-db.c,v
retrieving revision 1.6
diff -p -u -r1.6 linux-thread-db.c
--- linux-thread-db.c	31 Mar 2005 19:58:25 -0000	1.6
+++ linux-thread-db.c	26 Apr 2005 05:01:58 -0000
@@ -1247,7 +1247,7 @@ thread_db_get_thread_local_address (ptid
       /* glibc doesn't provide the needed interface.  */
       if (!td_thr_tls_get_addr_p)
 	{
-	  struct exception e 
+	  struct gdb_exception e 
 	    = { RETURN_ERROR, TLS_NO_LIBRARY_SUPPORT_ERROR, 0 };
 
 	  throw_exception (e);
@@ -1272,7 +1272,7 @@ thread_db_get_thread_local_address (ptid
 	     address, we *could* try to build a non-lvalue value from
 	     the initialization image.  */
 
-	  struct exception e
+	  struct gdb_exception e
 	    = { RETURN_ERROR, TLS_NOT_ALLOCATED_YET_ERROR, 0 };
 
 	  throw_exception (e);
@@ -1282,7 +1282,7 @@ thread_db_get_thread_local_address (ptid
       /* Something else went wrong.  */
       if (err != TD_OK)
 	{
-	  struct exception e
+	  struct gdb_exception e
 	    = { RETURN_ERROR, TLS_GENERIC_ERROR, thread_db_err_str (err) };
 
 	  throw_exception (e);
@@ -1296,7 +1296,7 @@ thread_db_get_thread_local_address (ptid
     return target_beneath->to_get_thread_local_address (ptid, lm, offset);
   else
     {
-      struct exception e
+      struct gdb_exception e
 	= { RETURN_ERROR, TLS_GENERIC_ERROR,
 	    "TLS not supported on this target" };
 
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.184
diff -p -u -r1.184 remote.c
--- remote.c	15 Apr 2005 21:16:09 -0000	1.184
+++ remote.c	26 Apr 2005 05:01:59 -0000
@@ -2179,7 +2179,7 @@ static void
 remote_open_1 (char *name, int from_tty, struct target_ops *target,
 	       int extended_p, int async_p)
 {
-  struct exception ex;
+  struct gdb_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"
@@ -5358,14 +5358,14 @@ remote_get_thread_local_address (ptid_t 
 	}
       else if (result == PACKET_UNKNOWN)
 	{
-	  struct exception e
+	  struct gdb_exception e
 	    = { RETURN_ERROR, TLS_GENERIC_ERROR,
 		"Remote target doesn't support qGetTLSAddr packet" };
 	  throw_exception (e);
 	}
       else
 	{
-	  struct exception e
+	  struct gdb_exception e
 	    = { RETURN_ERROR, TLS_GENERIC_ERROR,
 		"Remote target failed to process qGetTLSAddr request" };
 	  throw_exception (e);
@@ -5374,7 +5374,7 @@ remote_get_thread_local_address (ptid_t 
     }
   else
     {
-      struct exception e
+      struct gdb_exception e
 	= { RETURN_ERROR, TLS_GENERIC_ERROR,
 	    "TLS not supported or disabled on this target" };
       throw_exception (e);
Index: varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.53
diff -p -u -r1.53 varobj.c
--- varobj.c	20 Mar 2005 20:30:35 -0000	1.53
+++ varobj.c	26 Apr 2005 05:02:00 -0000
@@ -1452,7 +1452,7 @@ variable_default_display (struct varobj 
 static int
 my_value_equal (struct value *val1, struct value *volatile val2, int *error2)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   /* As a special case, if both are null, we say they're equal.  */
   if (val1 == NULL && val2 == NULL)
Index: wrapper.c
===================================================================
RCS file: /cvs/src/src/gdb/wrapper.c,v
retrieving revision 1.17
diff -p -u -r1.17 wrapper.c
--- wrapper.c	16 Feb 2005 13:21:48 -0000	1.17
+++ wrapper.c	26 Apr 2005 05:02:00 -0000
@@ -27,7 +27,7 @@ int
 gdb_parse_exp_1 (char **stringptr, struct block *block, int comma,
 		 struct expression **expression)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -42,7 +42,7 @@ gdb_parse_exp_1 (char **stringptr, struc
 int
 gdb_evaluate_expression (struct expression *exp, struct value **value)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -57,7 +57,7 @@ gdb_evaluate_expression (struct expressi
 int
 gdb_value_fetch_lazy (struct value *val)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -72,7 +72,7 @@ gdb_value_fetch_lazy (struct value *val)
 int
 gdb_value_equal (struct value *val1, struct value *val2, int *result)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -88,7 +88,7 @@ int
 gdb_value_assign (struct value *val1, struct value *val2,
 		  struct value **result)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -104,7 +104,7 @@ int
 gdb_value_subscript (struct value *val1, struct value *val2,
 		     struct value **result)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -119,7 +119,7 @@ gdb_value_subscript (struct value *val1,
 int
 gdb_value_ind (struct value *val, struct value **result)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -134,7 +134,7 @@ gdb_value_ind (struct value *val, struct
 int
 gdb_parse_and_eval_type (char *p, int length, struct type **type)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
@@ -151,7 +151,7 @@ gdb_value_struct_elt (struct ui_out *uio
 		      struct value **argp, struct value **args, char *name,
 		      int *static_memfuncp, char *err)
 {
-  volatile struct exception except;
+  volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
Index: cli/cli-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-interp.c,v
retrieving revision 1.9
diff -p -u -r1.9 cli-interp.c
--- cli/cli-interp.c	14 Jan 2005 22:59:36 -0000	1.9
+++ cli/cli-interp.c	26 Apr 2005 05:02:00 -0000
@@ -34,8 +34,8 @@ struct ui_out *cli_uiout;
 /* These are the ui_out and the interpreter for the console interpreter.  */
 
 /* Longjmp-safe wrapper for "execute_command".  */
-static struct exception safe_execute_command (struct ui_out *uiout,
-					      char *command, int from_tty);
+static struct gdb_exception safe_execute_command (struct ui_out *uiout,
+						  char *command, int from_tty);
 struct captured_execute_command_args
 {
   char *command;
@@ -92,11 +92,11 @@ cli_interpreter_display_prompt_p (void *
     return 1;
 }
 
-static struct exception
+static struct gdb_exception
 cli_interpreter_exec (void *data, const char *command_str)
 {
   struct ui_file *old_stream;
-  struct exception result;
+  struct gdb_exception result;
 
   /* FIXME: cagney/2003-02-01: Need to const char *propogate
      safe_execute_command.  */
@@ -122,10 +122,10 @@ do_captured_execute_command (struct ui_o
   execute_command (args->command, args->from_tty);
 }
 
-static struct exception
+static struct gdb_exception
 safe_execute_command (struct ui_out *uiout, char *command, int from_tty)
 {
-  struct exception e;
+  struct gdb_exception e;
   struct captured_execute_command_args args;
   args.command = command;
   args.from_tty = from_tty;
Index: cli/cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.28
diff -p -u -r1.28 cli-script.c
--- cli/cli-script.c	11 Feb 2005 18:13:55 -0000	1.28
+++ cli/cli-script.c	26 Apr 2005 05:02:00 -0000
@@ -1274,7 +1274,7 @@ script_from_file (FILE *stream, char *fi
   error_pre_print = "";
 
   {
-    struct exception e;
+    struct gdb_exception e;
     struct wrapped_read_command_file_args args;
     args.stream = stream;
     e = catch_exception (uiout, wrapped_read_command_file, &args,
Index: mi/mi-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-interp.c,v
retrieving revision 1.13
diff -p -u -r1.13 mi-interp.c
--- mi/mi-interp.c	14 Jan 2005 01:20:38 -0000	1.13
+++ mi/mi-interp.c	26 Apr 2005 05:02:00 -0000
@@ -145,10 +145,10 @@ mi_interpreter_suspend (void *data)
   return 1;
 }
 
-static struct exception
+static struct gdb_exception
 mi_interpreter_exec (void *data, const char *command)
 {
-  static struct exception ok;
+  static struct gdb_exception ok;
   char *tmp = alloca (strlen (command) + 1);
   strcpy (tmp, command);
   mi_execute_command_wrapper (tmp);
@@ -238,7 +238,7 @@ mi_cmd_interpreter_exec (char *command, 
          and then set it back to 0 when we are done. */
       sync_execution = 1;
       {
-	struct exception e = interp_exec (interp_to_use, argv[i]);
+	struct gdb_exception e = interp_exec (interp_to_use, argv[i]);
 	if (e.reason < 0)
 	  {
 	    mi_error_message = xstrdup (e.message);
Index: mi/mi-main.c
===================================================================
RCS file: /cvs/src/src/gdb/mi/mi-main.c,v
retrieving revision 1.76
diff -p -u -r1.76 mi-main.c
--- mi/mi-main.c	21 Feb 2005 03:59:23 -0000	1.76
+++ mi/mi-main.c	26 Apr 2005 05:02:00 -0000
@@ -1156,7 +1156,7 @@ mi_execute_command (char *cmd, int from_
 
   if (command != NULL)
     {
-      struct exception result;
+      struct gdb_exception result;
       /* FIXME: cagney/1999-11-04: Can this use of catch_exceptions either
          be pushed even further down or even eliminated? */
       args.command = command;
Index: tui/tui-interp.c
===================================================================
RCS file: /cvs/src/src/gdb/tui/tui-interp.c,v
retrieving revision 1.8
diff -p -u -r1.8 tui-interp.c
--- tui/tui-interp.c	11 Feb 2005 18:13:55 -0000	1.8
+++ tui/tui-interp.c	26 Apr 2005 05:02:01 -0000
@@ -106,7 +106,7 @@ tui_display_prompt_p (void *data)
     return 1;
 }
 
-static struct exception
+static struct gdb_exception
 tui_exec (void *data, const char *command_str)
 {
   internal_error (__FILE__, __LINE__, _("tui_exec called"));

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [commit] Add "struct exception"
  2005-04-26  5:06     ` Andrew Cagney
@ 2005-04-26 18:08       ` Eli Zaretskii
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2005-04-26 18:08 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches

> Date: Tue, 26 Apr 2005 00:57:59 -0400
> From: Andrew Cagney <cagney@gnu.org>
> CC: gdb-patches@sources.redhat.com
> 
> >> Something like ``struct gdb_exception'' would probably be better.
> > 
> > 
> > Ah, thanks.  I'll rename it.
> 
> Sorry to take so long, I've committed the attached.

Thanks!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-04-26 18:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-12 23:59 [commit] Add "struct exception" Andrew Cagney
2005-01-13  4:55 ` Eli Zaretskii
2005-01-14  1:34   ` Andrew Cagney
2005-04-26  5:06     ` Andrew Cagney
2005-04-26 18:08       ` Eli Zaretskii

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox