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]

[PATCH v2 19/22] Make exception throwing a bit more efficient


This makes exception throwing a bit more efficient, by removing some
copies.  This is good now that exceptions are more expensive to copy.

gdb/ChangeLog
2019-02-27  Tom Tromey  <tom@tromey.com>

	* common/common-exceptions.c (throw_exception): Rename from
	throw_exception_cxx.  Remove old copy.  Make argument const.
	(throw_it): Create and throw exception objects directly.
	* common/common-exceptions.h (throw_exception): Make argument
	const.
---
 gdb/ChangeLog                  |  8 ++++++++
 gdb/common/common-exceptions.c | 37 ++++++++++++++++++++--------------
 gdb/common/common-exceptions.h |  2 +-
 3 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c
index 4feb80731ac..99a6267c163 100644
--- a/gdb/common/common-exceptions.c
+++ b/gdb/common/common-exceptions.c
@@ -188,8 +188,8 @@ throw_exception_sjlj (struct gdb_exception exception)
 
 /* Implementation of throw_exception that uses C++ try/catch.  */
 
-static ATTRIBUTE_NORETURN void
-throw_exception_cxx (struct gdb_exception exception)
+void
+throw_exception (const struct gdb_exception &exception)
 {
   if (exception.reason == RETURN_QUIT)
     {
@@ -209,25 +209,32 @@ throw_exception_cxx (struct gdb_exception exception)
     gdb_assert_not_reached ("invalid return reason");
 }
 
-void
-throw_exception (struct gdb_exception exception)
-{
-  throw_exception_cxx (exception);
-}
-
 static void ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (3, 0)
 throw_it (enum return_reason reason, enum errors error, const char *fmt,
 	  va_list ap)
 {
-  struct gdb_exception e;
+  if (reason == RETURN_QUIT)
+    {
+      gdb_exception_quit ex;
 
-  /* Create the exception.  */
-  e.reason = reason;
-  e.error = error;
-  e.message = string_vprintf (fmt, ap);
+      ex.reason = reason;
+      ex.error = error;
+      ex.message = string_vprintf (fmt, ap);
 
-  /* Throw the exception.  */
-  throw_exception (e);
+      throw ex;
+    }
+  else if (reason == RETURN_ERROR)
+    {
+      gdb_exception_error ex;
+
+      ex.reason = reason;
+      ex.error = error;
+      ex.message = string_vprintf (fmt, ap);
+
+      throw ex;
+    }
+  else
+    gdb_assert_not_reached ("invalid return reason");
 }
 
 void
diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h
index c6a8fa66ad6..9d83cad6bec 100644
--- a/gdb/common/common-exceptions.h
+++ b/gdb/common/common-exceptions.h
@@ -205,7 +205,7 @@ struct gdb_quit_bad_alloc
 /* Throw an exception (as described by "struct gdb_exception"),
    landing in the inner most containing exception handler established
    using TRY/CATCH.  */
-extern void throw_exception (struct gdb_exception exception)
+extern void throw_exception (const struct gdb_exception &exception)
      ATTRIBUTE_NORETURN;
 
 /* Throw an exception by executing a LONG JUMP to the inner most
-- 
2.17.2


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