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] exception cleanup


This cleans up the following:

- uses throw_error() instead of struct gdb_exception
Code throwing exceptions need to be careful that it avoids making hard-wired assumptions about the internals of that struct.


- always include an exception message
We need to be careful that we don't make assumptions about what catches the exception, and hence ensure that it is always printable.


- mark up the messages
going forward, we'll want to all keep an eye on this one - making certain that we all mark up new text (and grab the oportunity to fix any existing text)
2005-04-26  Andrew Cagney  <cagney@gnu.org>

	* remote.c (remote_open_1): Move "ex"'s declaration to where it is
	used.
	(remote_get_thread_local_address): Use throw_error, include a
	printed string.
	* linux-thread-db.c (thread_db_get_thread_local_address): Ditto.
	* dwarf2loc.c (dwarf_expr_tls_address): Ditto.
	* cli/cli-script.c (script_from_file): Mark up throw_error message.
	* linespec.c (symtab_from_filename, decode_variable): Ditto.

Index: dwarf2loc.c
===================================================================
RCS file: /cvs/src/src/gdb/dwarf2loc.c,v
retrieving revision 1.27
diff -p -u -r1.27 dwarf2loc.c
--- dwarf2loc.c	26 Apr 2005 05:03:36 -0000	1.27
+++ dwarf2loc.c	26 Apr 2005 14:55:30 -0000
@@ -204,12 +204,8 @@ dwarf_expr_tls_address (void *baton, COR
 	                                                   objfile);
 	  /* If it's 0, throw the appropriate exception.  */
 	  if (lm_addr == 0)
-	    {
-	      struct gdb_exception e
-		= { RETURN_ERROR, TLS_LOAD_MODULE_NOT_FOUND_ERROR, 0 };
-
-	      throw_exception (e);
-	    }
+	    throw_error (TLS_LOAD_MODULE_NOT_FOUND_ERROR,
+			 _("TLS load module not found"));
 
 	  addr = target_get_thread_local_address (ptid, lm_addr, offset);
 	}
Index: linespec.c
===================================================================
RCS file: /cvs/src/src/gdb/linespec.c,v
retrieving revision 1.62
diff -p -u -r1.62 linespec.c
--- linespec.c	12 Feb 2005 00:39:20 -0000	1.62
+++ linespec.c	26 Apr 2005 14:55:30 -0000
@@ -1529,7 +1529,7 @@ symtab_from_filename (char **argptr, cha
 	error (_("No symbol table is loaded.  Use the \"file\" command."));
       if (not_found_ptr)
 	*not_found_ptr = 1;
-      throw_error (NOT_FOUND_ERROR, "No source file named %s.", copy);
+      throw_error (NOT_FOUND_ERROR, _("No source file named %s."), copy);
     }
 
   /* Discard the file name from the arg.  */
@@ -1741,7 +1741,7 @@ decode_variable (char *copy, int funfirs
 
   if (not_found_ptr)
     *not_found_ptr = 1;
-  throw_error (NOT_FOUND_ERROR, "Function \"%s\" not defined.", copy);
+  throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined."), copy);
 }
 
 
Index: linux-thread-db.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-thread-db.c,v
retrieving revision 1.7
diff -p -u -r1.7 linux-thread-db.c
--- linux-thread-db.c	26 Apr 2005 05:03:36 -0000	1.7
+++ linux-thread-db.c	26 Apr 2005 14:55:30 -0000
@@ -1246,12 +1246,8 @@ thread_db_get_thread_local_address (ptid
 
       /* glibc doesn't provide the needed interface.  */
       if (!td_thr_tls_get_addr_p)
-	{
-	  struct gdb_exception e 
-	    = { RETURN_ERROR, TLS_NO_LIBRARY_SUPPORT_ERROR, 0 };
-
-	  throw_exception (e);
-	}
+	throw_error (TLS_NO_LIBRARY_SUPPORT_ERROR,
+		     _("No TLS library support"));
 
       /* Caller should have verified that lm != 0.  */
       gdb_assert (lm != 0);
@@ -1267,26 +1263,17 @@ thread_db_get_thread_local_address (ptid
 #ifdef THREAD_DB_HAS_TD_NOTALLOC
       /* The memory hasn't been allocated, yet.  */
       if (err == TD_NOTALLOC)
-	{
 	  /* Now, if libthread_db provided the initialization image's
 	     address, we *could* try to build a non-lvalue value from
 	     the initialization image.  */
-
-	  struct gdb_exception e
-	    = { RETURN_ERROR, TLS_NOT_ALLOCATED_YET_ERROR, 0 };
-
-	  throw_exception (e);
-	}
+        throw_error (TLS_NOT_ALLOCATED_YET_ERROR,
+                     _("TLS not allocated yet"));
 #endif
 
       /* Something else went wrong.  */
       if (err != TD_OK)
-	{
-	  struct gdb_exception e
-	    = { RETURN_ERROR, TLS_GENERIC_ERROR, thread_db_err_str (err) };
-
-	  throw_exception (e);
-	}
+        throw_error (TLS_GENERIC_ERROR,
+                     (("%s")), thread_db_err_str (err));
 
       /* Cast assuming host == target.  Joy.  */
       return (CORE_ADDR) address;
@@ -1295,13 +1282,8 @@ thread_db_get_thread_local_address (ptid
   if (target_beneath->to_get_thread_local_address)
     return target_beneath->to_get_thread_local_address (ptid, lm, offset);
   else
-    {
-      struct gdb_exception e
-	= { RETURN_ERROR, TLS_GENERIC_ERROR,
-	    "TLS not supported on this target" };
-
-      throw_exception (e);
-    }
+    throw_error (TLS_GENERIC_ERROR,
+	         _("TLS not supported on this target"));
 }
 
 static void
Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.185
diff -p -u -r1.185 remote.c
--- remote.c	26 Apr 2005 05:03:36 -0000	1.185
+++ remote.c	26 Apr 2005 14:55:32 -0000
@@ -2179,7 +2179,6 @@ static void
 remote_open_1 (char *name, int from_tty, struct target_ops *target,
 	       int extended_p, int async_p)
 {
-  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"
@@ -2282,14 +2281,17 @@ 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_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
-  if (ex.reason < 0)
-    {
-      pop_target ();
-      if (async_p)
-	wait_forever_enabled_p = 1;
-      throw_exception (ex);
-    }
+  {
+    struct gdb_exception ex
+      = catch_exception (uiout, remote_start_remote, NULL, RETURN_MASK_ALL);
+    if (ex.reason < 0)
+      {
+	pop_target ();
+	if (async_p)
+	  wait_forever_enabled_p = 1;
+	throw_exception (ex);
+      }
+  }
 
   if (async_p)
     wait_forever_enabled_p = 1;
@@ -5357,28 +5359,15 @@ remote_get_thread_local_address (ptid_t 
 	  return result;
 	}
       else if (result == PACKET_UNKNOWN)
-	{
-	  struct gdb_exception e
-	    = { RETURN_ERROR, TLS_GENERIC_ERROR,
-		"Remote target doesn't support qGetTLSAddr packet" };
-	  throw_exception (e);
-	}
+	throw_error (TLS_GENERIC_ERROR,
+		     _("Remote target doesn't support qGetTLSAddr packet"));
       else
-	{
-	  struct gdb_exception e
-	    = { RETURN_ERROR, TLS_GENERIC_ERROR,
-		"Remote target failed to process qGetTLSAddr request" };
-	  throw_exception (e);
-
-	}
+	throw_error (TLS_GENERIC_ERROR,
+		     _("Remote target failed to process qGetTLSAddr request"));
     }
   else
-    {
-      struct gdb_exception e
-	= { RETURN_ERROR, TLS_GENERIC_ERROR,
-	    "TLS not supported or disabled on this target" };
-      throw_exception (e);
-    }
+    throw_error (TLS_GENERIC_ERROR,
+		 _("TLS not supported or disabled on this target"));
   /* Not reached.  */
   return 0;
 }
Index: cli/cli-script.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-script.c,v
retrieving revision 1.29
diff -p -u -r1.29 cli-script.c
--- cli/cli-script.c	26 Apr 2005 05:03:39 -0000	1.29
+++ cli/cli-script.c	26 Apr 2005 14:55:32 -0000
@@ -1286,7 +1286,8 @@ script_from_file (FILE *stream, char *fi
       case RETURN_ERROR:
 	/* Re-throw the error, but with the file name information
 	   prepended.  */
-	throw_error (e.error, "%s:%d: Error in sourced command file:\n%s",
+	throw_error (e.error,
+		     _("%s:%d: Error in sourced command file:\n%s"),
 		     source_file_name, source_line_number, e.message);
       default:
 	internal_error (__FILE__, __LINE__, _("bad reason"));

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