Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 29/36] Normalize TRY_CATCH exception handling block
Date: Mon, 09 Feb 2015 23:21:00 -0000	[thread overview]
Message-ID: <1423524046-20605-30-git-send-email-palves@redhat.com> (raw)
In-Reply-To: <1423524046-20605-1-git-send-email-palves@redhat.com>

This normalizes exception catch blocks that check for ex.reason to
look like this:

~~~
  volatile gdb_exception ex;

  TRY_CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  if (ex.reason < 0)
    {
      ...
    }
~~~

This is a preparation step for running a script that converts all
TRY_CATCH uses to look like this instead:

~~~
  TRY
    {
      ...
    }
  CATCH (ex, RETURN_MASK_ALL)
    {
      ...
    }
  END_CATCH
~~~

The motivation for that change is being able to reimplent TRY/CATCH in
terms of C++ try/catch.

This commit makes it so that:

 - no condition other than ex.reason < 0 is checked in the if
   predicate

 - there's no "else" block to check whether no exception was caught

 - there's no code between the TRY_CATCH (TRY) block and the
   'if (ex.reason < 0)' block (CATCH).

 - the exception object is no longer referred to outside the if/catch
   block.  Note the local volatile exception objects that are
   currently defined inside functions that use TRY_CATCH will
   disappear.  In cases it's more convenient to still refer to the
   exception outside the catch block, a new non-volatile local is
   added and copy to that object is made within the catch block.

The following patches may make this all clearer.

gdb/ChangeLog:
2015-02-09  Pedro Alves  <palves@redhat.com>

	* amd64-tdep.c (amd64_frame_cache, amd64_sigtramp_frame_cache)
	(amd64_epilogue_frame_cache): Normal exception handling code.
	* break-catch-throw.c (check_status_exception_catchpoint)
	(re_set_exception_catchpoint): Ditto.
	* cli/cli-interp.c (safe_execute_command):
	* cli/cli-script.c (script_from_file): Ditto.
	* compile/compile-c-symbols.c (generate_c_for_for_one_variable):
	Ditto.
	* compile/compile-object-run.c (compile_object_run): Ditto.
	* cp-abi.c (baseclass_offset): Ditto.
	* cp-valprint.c (cp_print_value): Ditto.
	* exceptions.c (catch_exceptions_with_msg):
	* frame-unwind.c (frame_unwind_try_unwinder): Ditto.
	* frame.c (get_frame_address_in_block_if_available): Ditto.
	* i386-tdep.c (i386_frame_cache, i386_epilogue_frame_cache)
	(i386_sigtramp_frame_cache): Ditto.
	* infcmd.c (post_create_inferior): Ditto.
	* linespec.c (parse_linespec, find_linespec_symbols):
	* p-valprint.c (pascal_object_print_value): Ditto.
	* parse.c (parse_expression_for_completion): Ditto.
	* python/py-finishbreakpoint.c (bpfinishpy_init): Ditto.
	* remote.c (remote_get_noisy_reply): Ditto.
	* s390-linux-tdep.c (s390_frame_unwind_cache): Ditto.
	* solib-svr4.c (solib_svr4_r_map): Ditto.
---
 gdb/amd64-tdep.c                 | 21 ++++++++++++++------
 gdb/break-catch-throw.c          | 23 +++++++++++++---------
 gdb/cli/cli-interp.c             |  9 +++++++--
 gdb/cli/cli-script.c             |  7 +------
 gdb/compile/compile-c-symbols.c  | 22 ++++++++++-----------
 gdb/compile/compile-object-run.c | 15 ++++++++-------
 gdb/cp-abi.c                     | 18 ++++++++++--------
 gdb/cp-valprint.c                | 18 ++++++++++--------
 gdb/exceptions.c                 |  9 +++++++--
 gdb/frame-unwind.c               | 23 ++++++++++++----------
 gdb/frame.c                      | 14 ++++++++------
 gdb/i386-tdep.c                  | 21 ++++++++++++++------
 gdb/infcmd.c                     |  7 +++++--
 gdb/linespec.c                   | 17 ++++++++++++-----
 gdb/p-valprint.c                 | 14 ++++++++------
 gdb/parse.c                      |  7 ++++++-
 gdb/python/py-finishbreakpoint.c |  9 +++++++--
 gdb/remote.c                     | 41 ++++++++++++++++++++++------------------
 gdb/rs6000-tdep.c                |  7 +++++--
 gdb/s390-linux-tdep.c            |  7 +++++--
 gdb/solib-svr4.c                 |  3 ++-
 21 files changed, 192 insertions(+), 120 deletions(-)

diff --git a/gdb/amd64-tdep.c b/gdb/amd64-tdep.c
index e9de0f6..51e79c7 100644
--- a/gdb/amd64-tdep.c
+++ b/gdb/amd64-tdep.c
@@ -2480,8 +2480,11 @@ amd64_frame_cache (struct frame_info *this_frame, void **this_cache)
     {
       amd64_frame_cache_1 (this_frame, cache);
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return cache;
 }
@@ -2605,8 +2608,11 @@ amd64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   *this_cache = cache;
   return cache;
@@ -2781,8 +2787,11 @@ amd64_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return cache;
 }
diff --git a/gdb/break-catch-throw.c b/gdb/break-catch-throw.c
index 2baf506..726825a 100644
--- a/gdb/break-catch-throw.c
+++ b/gdb/break-catch-throw.c
@@ -187,13 +187,16 @@ check_status_exception_catchpoint (struct bpstats *bs)
 	  type_name = canon;
 	}
     }
-
   if (e.reason < 0)
     exception_print (gdb_stderr, e);
-  else if (regexec (self->pattern, type_name, 0, NULL, 0) != 0)
-    bs->stop = 0;
 
-  xfree (type_name);
+  if (type_name != NULL)
+    {
+      if (regexec (self->pattern, type_name, 0, NULL, 0) != 0)
+	bs->stop = 0;
+
+      xfree (type_name);
+    }
 }
 
 /* Implement the 're_set' method.  */
@@ -227,11 +230,13 @@ re_set_exception_catchpoint (struct breakpoint *self)
 
 	  self->ops->decode_linespec (self, &spec, &sals);
 	}
-
-      /* NOT_FOUND_ERROR just means the breakpoint will be pending, so
-	 let it through.  */
-      if (ex.reason < 0 && ex.error != NOT_FOUND_ERROR)
-	throw_exception (ex);
+      if (ex.reason < 0)
+	{
+	  /* NOT_FOUND_ERROR just means the breakpoint will be
+	     pending, so let it through.  */
+	  if (ex.error != NOT_FOUND_ERROR)
+	    throw_exception (ex);
+	}
     }
 
   cleanup = make_cleanup (xfree, sals.sals);
diff --git a/gdb/cli/cli-interp.c b/gdb/cli/cli-interp.c
index d708a36..1069018 100644
--- a/gdb/cli/cli-interp.c
+++ b/gdb/cli/cli-interp.c
@@ -179,17 +179,22 @@ cli_interpreter_exec (void *data, const char *command_str)
 static struct gdb_exception
 safe_execute_command (struct ui_out *command_uiout, char *command, int from_tty)
 {
-  volatile struct gdb_exception e;
+  volatile struct gdb_exception exception;
+  struct gdb_exception e = exception_none;
   struct ui_out *saved_uiout;
 
   /* Save and override the global ``struct ui_out'' builder.  */
   saved_uiout = current_uiout;
   current_uiout = command_uiout;
 
-  TRY_CATCH (e, RETURN_MASK_ALL)
+  TRY_CATCH (exception, RETURN_MASK_ALL)
     {
       execute_command (command, from_tty);
     }
+  if (exception.reason < 0)
+    {
+      e = exception;
+    }
 
   /* Restore the global builder.  */
   current_uiout = saved_uiout;
diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c
index 65232da..4be7586 100644
--- a/gdb/cli/cli-script.c
+++ b/gdb/cli/cli-script.c
@@ -1706,18 +1706,13 @@ script_from_file (FILE *stream, const char *file)
       {
 	read_command_file (stream);
       }
-    switch (e.reason)
+    if (e.reason < 0)
       {
-      case 0:
-	break;
-      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"),
 		     source_file_name, source_line_number, e.message);
-      default:
-	internal_error (__FILE__, __LINE__, _("bad reason"));
       }
   }
 
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 6562f05..d8d2b2f 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -689,17 +689,17 @@ generate_c_for_for_one_variable (struct compile_c_instance *compiler,
 	}
     }
 
-  if (e.reason >= 0)
-    return;
-
-  if (compiler->symbol_err_map == NULL)
-    compiler->symbol_err_map = htab_create_alloc (10,
-						  hash_symbol_error,
-						  eq_symbol_error,
-						  del_symbol_error,
-						  xcalloc,
-						  xfree);
-  insert_symbol_error (compiler->symbol_err_map, sym, e.message);
+  if (e.reason < 0)
+    {
+      if (compiler->symbol_err_map == NULL)
+	compiler->symbol_err_map = htab_create_alloc (10,
+						      hash_symbol_error,
+						      eq_symbol_error,
+						      del_symbol_error,
+						      xcalloc,
+						      xfree);
+      insert_symbol_error (compiler->symbol_err_map, sym, e.message);
+    }
 }
 
 /* See compile-internal.h.  */
diff --git a/gdb/compile/compile-object-run.c b/gdb/compile/compile-object-run.c
index d34c9ed..c40de0e 100644
--- a/gdb/compile/compile-object-run.c
+++ b/gdb/compile/compile-object-run.c
@@ -121,18 +121,19 @@ compile_object_run (struct compile_module *module)
 				       do_module_cleanup, data);
 	}
     }
-  dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
-  if (!executed)
-    data->executedp = NULL;
-  if (ex.reason >= 0)
-    gdb_assert (!dtor_found && executed);
-  else
+  if (ex.reason < 0)
     {
-      /* In the case od DTOR_FOUND or in the case of EXECUTED nothing
+      /* In the case of DTOR_FOUND or in the case of EXECUTED nothing
 	 needs to be done.  */
+      dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
+      if (!executed)
+	data->executedp = NULL;
       gdb_assert (!(dtor_found && executed));
       if (!dtor_found && !executed)
 	do_module_cleanup (data);
       throw_exception (ex);
     }
+
+  dtor_found = find_dummy_frame_dtor (do_module_cleanup, data);
+  gdb_assert (!dtor_found && executed);
 }
diff --git a/gdb/cp-abi.c b/gdb/cp-abi.c
index 9316c4c..70a0528 100644
--- a/gdb/cp-abi.c
+++ b/gdb/cp-abi.c
@@ -80,15 +80,17 @@ baseclass_offset (struct type *type, int index, const gdb_byte *valaddr,
 						embedded_offset,
 						address, val);
     }
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+
+      throw_error (NOT_AVAILABLE_ERROR,
+		   _("Cannot determine virtual baseclass offset "
+		     "of incomplete object"));
+    }
 
-  if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
-    throw_error (NOT_AVAILABLE_ERROR,
-		 _("Cannot determine virtual baseclass offset "
-		   "of incomplete object"));
-  else if (ex.reason < 0)
-    throw_exception (ex);
-  else
-    return res;
+  return res;
 }
 
 struct value *
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 0ddc96e..deb0ed8 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -481,7 +481,7 @@ cp_print_value (struct type *type, struct type *real_type,
   for (i = 0; i < n_baseclasses; i++)
     {
       int boffset = 0;
-      int skip;
+      int skip = 0;
       struct type *baseclass = check_typedef (TYPE_BASECLASS (type, i));
       const char *basename = TYPE_NAME (baseclass);
       const gdb_byte *base_valaddr = NULL;
@@ -510,14 +510,16 @@ cp_print_value (struct type *type, struct type *real_type,
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
-	skip = -1;
-      else if (ex.reason < 0)
-	skip = 1;
-      else
- 	{
-	  skip = 0;
+      if (ex.reason < 0)
+	{
+	  if (ex.error == NOT_AVAILABLE_ERROR)
+	    skip = -1;
+	  else
+	    skip = 1;
+	}
 
+      if (skip == 0)
+	{
 	  if (BASETYPE_VIA_VIRTUAL (type, i))
 	    {
 	      /* The virtual base class pointer might have been
diff --git a/gdb/exceptions.c b/gdb/exceptions.c
index 0ca4c56..64a653a 100644
--- a/gdb/exceptions.c
+++ b/gdb/exceptions.c
@@ -174,7 +174,8 @@ catch_exceptions_with_msg (struct ui_out *func_uiout,
 			   char **gdberrmsg,
 		  	   return_mask mask)
 {
-  volatile struct gdb_exception exception;
+  volatile struct gdb_exception ex;
+  struct gdb_exception exception = exception_none;
   volatile int val = 0;
   struct ui_out *saved_uiout;
 
@@ -182,10 +183,14 @@ catch_exceptions_with_msg (struct ui_out *func_uiout,
   saved_uiout = current_uiout;
   current_uiout = func_uiout;
 
-  TRY_CATCH (exception, RETURN_MASK_ALL)
+  TRY_CATCH (ex, RETURN_MASK_ALL)
     {
       val = (*func) (current_uiout, func_args);
     }
+  if (ex.reason < 0)
+    {
+      exception = ex;
+    }
 
   /* Restore the global builder.  */
   current_uiout = saved_uiout;
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index e73650a..fcfedfd 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -105,18 +105,21 @@ frame_unwind_try_unwinder (struct frame_info *this_frame, void **this_cache,
     {
       res = unwinder->sniffer (unwinder, this_frame, this_cache);
     }
-  if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
+  if (ex.reason < 0)
     {
-      /* This usually means that not even the PC is available,
-        thus most unwinders aren't able to determine if they're
-        the best fit.  Keep trying.  Fallback prologue unwinders
-        should always accept the frame.  */
-      do_cleanups (old_cleanup);
-      return 0;
+      if (ex.error == NOT_AVAILABLE_ERROR)
+	{
+	  /* This usually means that not even the PC is available,
+	     thus most unwinders aren't able to determine if they're
+	     the best fit.  Keep trying.  Fallback prologue unwinders
+	     should always accept the frame.  */
+	  do_cleanups (old_cleanup);
+	  return 0;
+	}
+      throw_exception (ex);
     }
-  else if (ex.reason < 0)
-    throw_exception (ex);
-  else if (res)
+
+  if (res)
     {
       discard_cleanups (old_cleanup);
       return 1;
diff --git a/gdb/frame.c b/gdb/frame.c
index 6b1be94..7088f32 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2313,12 +2313,14 @@ get_frame_address_in_block_if_available (struct frame_info *this_frame,
     {
       *pc = get_frame_address_in_block (this_frame);
     }
-  if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
-    return 0;
-  else if (ex.reason < 0)
-    throw_exception (ex);
-  else
-    return 1;
+  if (ex.reason < 0)
+    {
+      if (ex.error == NOT_AVAILABLE_ERROR)
+	return 0;
+      throw_exception (ex);
+    }
+
+  return 1;
 }
 
 void
diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c
index 8c08f8b..fa3b841 100644
--- a/gdb/i386-tdep.c
+++ b/gdb/i386-tdep.c
@@ -2063,8 +2063,11 @@ i386_frame_cache (struct frame_info *this_frame, void **this_cache)
     {
       i386_frame_cache_1 (this_frame, cache);
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return cache;
 }
@@ -2238,8 +2241,11 @@ i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return cache;
 }
@@ -2431,8 +2437,11 @@ i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
 
       cache->base_p = 1;
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   *this_cache = cache;
   return cache;
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 9a1fb8d..5fa3ae5 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -430,8 +430,11 @@ post_create_inferior (struct target_ops *target, int from_tty)
     {
       stop_pc = regcache_read_pc (get_current_regcache ());
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   if (exec_bfd)
     {
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 0d012b4..70b50a0 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2154,7 +2154,7 @@ parse_linespec (linespec_parser *parser, const char **argptr)
 {
   linespec_token token;
   struct symtabs_and_lines values;
-  volatile struct gdb_exception file_exception;
+  struct gdb_exception file_exception = exception_none;
   struct cleanup *cleanup;
 
   /* A special case to start.  It has become quite popular for
@@ -2182,7 +2182,6 @@ parse_linespec (linespec_parser *parser, const char **argptr)
 
   parser->lexer.saved_arg = *argptr;
   parser->lexer.stream = argptr;
-  file_exception.reason = 0;
 
   /* Initialize the default symtab and line offset.  */
   initialize_defaults (&PARSER_STATE (parser)->default_symtab,
@@ -2262,17 +2261,22 @@ parse_linespec (linespec_parser *parser, const char **argptr)
   if (token.type == LSTOKEN_COLON)
     {
       char *user_filename;
+      volatile struct gdb_exception ex;
 
       /* Get the current token again and extract the filename.  */
       token = linespec_lexer_lex_one (parser);
       user_filename = copy_token_string (token);
 
       /* Check if the input is a filename.  */
-      TRY_CATCH (file_exception, RETURN_MASK_ERROR)
+      TRY_CATCH (ex, RETURN_MASK_ERROR)
 	{
 	  PARSER_RESULT (parser)->file_symtabs
 	    = symtabs_from_filename (user_filename);
 	}
+      if (ex.reason < 0)
+	{
+	  file_exception = ex;
+	}
 
       if (file_exception.reason >= 0)
 	{
@@ -3199,8 +3203,11 @@ find_linespec_symbols (struct linespec_state *state,
 
 	  /* If successful, we're done.  If NOT_FOUND_ERROR
 	     was not thrown, rethrow the exception that we did get.  */
-	  if (except.reason < 0 && except.error != NOT_FOUND_ERROR)
-	    throw_exception (except);
+	  if (except.reason < 0)
+	    {
+	      if (except.error != NOT_FOUND_ERROR)
+		throw_exception (except);
+	    }
 	}
     }
 
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index f7e2aae..043f98b 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -749,14 +749,16 @@ pascal_object_print_value (struct type *type, const gdb_byte *valaddr,
 	{
 	  boffset = baseclass_offset (type, i, valaddr, offset, address, val);
 	}
-      if (ex.reason < 0 && ex.error == NOT_AVAILABLE_ERROR)
-	skip = -1;
-      else if (ex.reason < 0)
-	skip = 1;
-      else
+      if (ex.reason < 0)
 	{
-	  skip = 0;
+	  if (ex.error == NOT_AVAILABLE_ERROR)
+	    skip = -1;
+	  else
+	    skip = 1;
+	}
 
+      if (skip == 0)
+	{
 	  /* The virtual base class pointer might have been clobbered by the
 	     user program. Make sure that it still points to a valid memory
 	     location.  */
diff --git a/gdb/parse.c b/gdb/parse.c
index af01947..09fb0b3 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1290,8 +1290,13 @@ parse_expression_for_completion (const char *string, char **name,
       parse_completion = 1;
       exp = parse_exp_in_context (&string, 0, 0, 0, 0, &subexp);
     }
+  if (except.reason < 0)
+    {
+      /* Nothing, EXP remains NULL.  */
+    }
+
   parse_completion = 0;
-  if (except.reason < 0 || ! exp)
+  if (exp == NULL)
     return NULL;
 
   if (expout_tag_completion_type != TYPE_CODE_UNDEF)
diff --git a/gdb/python/py-finishbreakpoint.c b/gdb/python/py-finishbreakpoint.c
index 9b5e3c7..43f6807 100644
--- a/gdb/python/py-finishbreakpoint.c
+++ b/gdb/python/py-finishbreakpoint.c
@@ -269,8 +269,13 @@ bpfinishpy_init (PyObject *self, PyObject *args, PyObject *kwargs)
             }
         }
     }
-  if (except.reason < 0
-      || !self_bpfinish->return_type || !self_bpfinish->function_value)
+  if (except.reason < 0)
+    {
+      /* Just swallow.  Either the return type or the function value
+	 remain NULL.  */
+    }
+
+  if (self_bpfinish->return_type == NULL || self_bpfinish->function_value == NULL)
     {
       /* Won't be able to compute return value.  */
       Py_XDECREF (self_bpfinish->return_type);
diff --git a/gdb/remote.c b/gdb/remote.c
index 48dfc5b..45d3bda 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -498,6 +498,7 @@ remote_get_noisy_reply (char **buf_p,
 	  char *p, *pp;
 	  int adjusted_size = 0;
 	  volatile struct gdb_exception ex;
+	  int relocated = 0;
 
 	  p = buf + strlen ("qRelocInsn:");
 	  pp = unpack_varlen_hex (p, &ul);
@@ -514,31 +515,35 @@ remote_get_noisy_reply (char **buf_p,
 	  TRY_CATCH (ex, RETURN_MASK_ALL)
 	    {
 	      gdbarch_relocate_instruction (target_gdbarch (), &to, from);
+	      relocated = 1;
 	    }
-	  if (ex.reason >= 0)
+	  if (ex.reason < 0)
+	    {
+	      if (ex.error == MEMORY_ERROR)
+		{
+		  /* Propagate memory errors silently back to the
+		     target.  The stub may have limited the range of
+		     addresses we can write to, for example.  */
+		}
+	      else
+		{
+		  /* Something unexpectedly bad happened.  Be verbose
+		     so we can tell what, and propagate the error back
+		     to the stub, so it doesn't get stuck waiting for
+		     a response.  */
+		  exception_fprintf (gdb_stderr, ex,
+				     _("warning: relocating instruction: "));
+		}
+	      putpkt ("E01");
+	    }
+
+	  if (relocated)
 	    {
 	      adjusted_size = to - org_to;
 
 	      xsnprintf (buf, *sizeof_buf, "qRelocInsn:%x", adjusted_size);
 	      putpkt (buf);
 	    }
-	  else if (ex.reason < 0 && ex.error == MEMORY_ERROR)
-	    {
-	      /* Propagate memory errors silently back to the target.
-		 The stub may have limited the range of addresses we
-		 can write to, for example.  */
-	      putpkt ("E01");
-	    }
-	  else
-	    {
-	      /* Something unexpectedly bad happened.  Be verbose so
-		 we can tell what, and propagate the error back to the
-		 stub, so it doesn't get stuck waiting for a
-		 response.  */
-	      exception_fprintf (gdb_stderr, ex,
-				 _("warning: relocating instruction: "));
-	      putpkt ("E01");
-	    }
 	}
       else if (buf[0] == 'O' && buf[1] != 'K')
 	remote_console_output (buf + 1);	/* 'O' message from stub */
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index 46f6e41..1e469cf 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -3382,8 +3382,11 @@ rs6000_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
       trad_frame_set_value (cache->saved_regs,
 			    gdbarch_pc_regnum (gdbarch), lr);
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return cache;
 }
diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c
index 5c28d0a..3b6c329 100644
--- a/gdb/s390-linux-tdep.c
+++ b/gdb/s390-linux-tdep.c
@@ -1836,8 +1836,11 @@ s390_frame_unwind_cache (struct frame_info *this_frame,
       if (!s390_prologue_frame_unwind_cache (this_frame, info))
 	s390_backchain_frame_unwind_cache (this_frame, info);
     }
-  if (ex.reason < 0 && ex.error != NOT_AVAILABLE_ERROR)
-    throw_exception (ex);
+  if (ex.reason < 0)
+    {
+      if (ex.error != NOT_AVAILABLE_ERROR)
+	throw_exception (ex);
+    }
 
   return info;
 }
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2143021..3fa8d6f 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -881,7 +881,8 @@ solib_svr4_r_map (struct svr4_info *info)
       addr = read_memory_typed_address (info->debug_base + lmo->r_map_offset,
                                         ptr_type);
     }
-  exception_print (gdb_stderr, ex);
+  if (ex.reason < 0)
+    exception_print (gdb_stderr, ex);
   return addr;
 }
 
-- 
1.9.3


  parent reply	other threads:[~2015-02-09 23:21 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-09 23:20 [PATCH 00/36] Support building GDB as a C++ program Pedro Alves
2015-02-09 23:20 ` [PATCH 02/36] Add --enable-build-with-cxx configure switch Pedro Alves
2015-02-10 22:11   ` Yao Qi
2015-02-27 13:24     ` Pedro Alves
2015-02-27 14:20       ` Yao Qi
2015-02-27 16:29         ` Pedro Alves
2015-02-09 23:21 ` Pedro Alves [this message]
2015-02-09 23:21 ` [PATCH 27/36] catch_command_errors: Remove 'mask' parameter Pedro Alves
2015-02-09 23:21 ` [PATCH 04/36] Fix struct, union, and enum nesting in C++ Pedro Alves
2015-02-09 23:21 ` [PATCH 26/36] Adjust self tests to cope with GDB built as a C++ program Pedro Alves
2015-02-09 23:21 ` [PATCH 03/36] C++ keyword cleanliness, mostly auto-generated Pedro Alves
2015-02-11  7:57   ` Joel Brobecker
2015-02-11  8:52     ` Phil Muldoon
2015-02-11 10:27     ` Pedro Alves
2015-02-11 10:51       ` Pedro Alves
2015-02-12 12:19         ` Joel Brobecker
2015-02-12 13:14           ` Pedro Alves
2015-02-12 14:43             ` Pedro Alves
2015-02-12 14:59               ` Joel Brobecker
2015-02-27 17:41         ` Pedro Alves
2015-02-09 23:21 ` [PATCH 19/36] Exported const objects Pedro Alves
2015-02-09 23:21 ` [PATCH 16/36] x86 Linux/ptrace: fix offsetof usage in C++ mode Pedro Alves
2015-02-09 23:21 ` [PATCH 25/36] python/python-internal.h: enum ‘ext_lang_rc’ not defined Pedro Alves
2015-02-09 23:21 ` [PATCH 28/36] Move exception_none to common code, and use it Pedro Alves
2015-02-09 23:21 ` [PATCH 17/36] mi/mi-cmd-stack.c|frame filters: print_values <-> ext_lang_frame_args Pedro Alves
2015-02-09 23:21 ` [PATCH 11/36] Make functions and variables exported by the IPA be extern "C" Pedro Alves
2015-02-09 23:21 ` [PATCH 22/36] Remove duplicate const Pedro Alves
2015-02-09 23:21 ` [PATCH 23/36] gdbarch.h: include regcache.h Pedro Alves
2015-02-09 23:21 ` [PATCH 15/36] Don't forward declare enum target_hw_bp_type Pedro Alves
2015-02-09 23:21 ` [PATCH 31/36] Split TRY_CATCH into TRY + CATCH Pedro Alves
2015-03-07 15:58   ` Pedro Alves
2015-02-09 23:21 ` [PATCH 12/36] proc-service, extern "C" Pedro Alves
2015-02-09 23:21 ` [PATCH 05/36] Fix redefinition errors in C++ mode Pedro Alves
2015-02-11 10:09   ` Yao Qi
2015-02-11 11:30     ` Pedro Alves
2015-02-11 11:39       ` [PATCH] xcoffread.c: delete 'within_function' definition (Re: [PATCH 05/36] Fix redefinition errors in C++ mode) Pedro Alves
2015-02-09 23:21 ` [PATCH 09/36] floatformat.h: Wrap in extern "C" Pedro Alves
2015-02-09 23:35   ` Andrew Pinski
2015-02-09 23:49     ` Pedro Alves
2015-02-12 11:49       ` Pedro Alves
2015-02-18 19:55         ` Jakub Jelinek
2015-02-14 17:29       ` Doug Evans
2015-02-14 18:36         ` Pedro Alves
2015-02-14 22:46           ` Doug Evans
2015-02-09 23:21 ` [PATCH 20/36] gdbserver/tracepoint: Add cast sockaddr_un/sockaddr cast Pedro Alves
2015-02-09 23:21 ` [PATCH 08/36] elf-bfd.h: Wrap in extern "C" Pedro Alves
2015-02-09 23:33   ` Andrew Pinski
2015-02-10 12:05     ` [PATCH v2] Wrap BFD headers " Pedro Alves
2015-02-11  0:36       ` Alan Modra
2015-02-11 10:08         ` Pedro Alves
2015-02-09 23:21 ` [PATCH 13/36] target.h: Include infrun.h Pedro Alves
2015-02-09 23:21 ` [PATCH 21/36] opcodes/microblaze: Rename 'or', 'and', 'xor' to avoid C++ conflict Pedro Alves
2015-02-10 15:05   ` Michael Eager
2015-02-10 18:11     ` Pedro Alves
2015-02-09 23:22 ` [PATCH 36/36] Make TRY/CATCH use real C++ try/catch in C++ mode Pedro Alves
2015-02-09 23:22 ` [PATCH 32/36] TRY_CATCH -> TRY+CATCH+END_CATCH everywhere Pedro Alves
2015-02-09 23:22 ` [PATCH 33/36] TRY_CATCH -> TRY+CATCH+END_CATCH, the manual conversions Pedro Alves
2015-02-09 23:35 ` [PATCH 18/36] Rename struct lzma_stream to avoid clash with system header Pedro Alves
2015-02-09 23:45 ` [PATCH 06/36] record-btrace.c: Remove redefinitions Pedro Alves
2015-02-09 23:46 ` [PATCH 35/36] kill volatile struct gdb_exception Pedro Alves
2015-02-09 23:49 ` [PATCH 00/36] Support building GDB as a C++ program Doug Evans
2015-02-09 23:50 ` [PATCH 34/36] more making TRY/CATCH callers look more like real C++ try/catch blocks Pedro Alves
2015-03-07 15:59   ` Pedro Alves
2015-02-09 23:51 ` [PATCH 14/36] Do not do arithmetic on enum types Pedro Alves
2015-02-09 23:51 ` [PATCH 07/36] Make array object extern Pedro Alves
2015-02-27 22:47   ` Simon Marchi
2015-02-27 22:58     ` Pedro Alves
2015-02-27 23:04       ` Simon Marchi
2015-02-09 23:53 ` [PATCH 01/36] Create libiberty/libiberty.m4, have GDB and GDBserver use it Pedro Alves
2015-02-09 23:35   ` Pedro Alves
2015-02-27 16:23   ` Pedro Alves
2015-02-09 23:54 ` [PATCH 30/36] quit_force: Replace TRY_CATCH wrapper macros Pedro Alves
2015-02-09 23:54 ` [PATCH 10/36] Add extern "C" to declarations of C symbols Pedro Alves
2015-02-11 11:51   ` Pedro Alves
2015-02-10  0:21 ` [PATCH 24/36] breakpoint.h: move enum ‘print_stop_action’ Pedro Alves
2015-02-11 12:28   ` Yao Qi
2015-02-10 15:07 ` [PATCH 00/36] Support building GDB as a C++ program Michael Eager
2015-02-11 17:15 ` Yao Qi
2015-02-12 11:34   ` Pedro Alves
2015-02-17 23:19 ` Patrick Palka
2015-02-18 21:54   ` Yao Qi
2015-02-18 23:49     ` Patrick Palka
2015-02-27 18:19 ` Pedro Alves
2015-02-27 23:52   ` Patrick Palka
2015-02-28  0:09     ` Pedro Alves
2015-03-07 16:01   ` Pedro Alves
2015-03-07 17:58     ` [all pushed] " Pedro Alves
2015-03-16  4:42       ` asmwarrior
2015-03-16  5:05         ` asmwarrior
2015-03-16  5:22           ` asmwarrior
2015-03-16  7:15             ` asmwarrior
2015-03-16  8:20               ` asmwarrior
2015-03-16 11:43                 ` [pushed] stub-termcap.c: prototype tputs's parameter's parameter, for C++ mode (Re: [all pushed] Re: [PATCH 00/36] Support building GDB as a C++ program) Pedro Alves
2015-03-16 11:46                 ` [pushed] stub termcap, add extern "C" " Pedro Alves
2015-03-16 11:55                 ` [all pushed] Re: [PATCH 00/36] Support building GDB as a C++ program Pedro Alves
2015-03-16 11:42           ` Pedro Alves
2015-05-15  8:13             ` asmwarrior
2015-05-15  8:24               ` asmwarrior
2015-05-15 15:09                 ` Pedro Alves
2015-05-15 15:04               ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423524046-20605-30-git-send-email-palves@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox