]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make SJLJ exceptions more efficient
authorTom Tromey <tromey@adacore.com>
Tue, 23 Apr 2019 13:29:49 +0000 (07:29 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 25 Apr 2019 18:59:35 +0000 (12:59 -0600)
This changes the SJLJ exception handling code to be a bit more
efficient, by using rvalue references and move assignment when
possible.

Tested by the buildbot.

gdb/ChangeLog
2019-04-25  Tom Tromey  <tromey@adacore.com>

* event-top.c (gdb_rl_callback_read_char_wrapper_noexcept)
(gdb_rl_callback_handler): Use std::move.
* common/common-exceptions.h (struct gdb_exception): Add move
assignment operator.
(throw_exception_sjlj): Change "exception" to const reference.
* common/common-exceptions.c (exceptions_state_mc_catch): Update.
(throw_exception_sjlj): Change "exception" to const reference.

gdb/ChangeLog
gdb/common/common-exceptions.c
gdb/common/common-exceptions.h
gdb/event-top.c

index 106f0e65bbecfe50e3e03369c38195f1e57cafa9..809df468443cdf6dc0ad05b648e8dfcacc6b5761 100644 (file)
@@ -1,3 +1,13 @@
+2019-04-25  Tom Tromey  <tromey@adacore.com>
+
+       * event-top.c (gdb_rl_callback_read_char_wrapper_noexcept)
+       (gdb_rl_callback_handler): Use std::move.
+       * common/common-exceptions.h (struct gdb_exception): Add move
+       assignment operator.
+       (throw_exception_sjlj): Change "exception" to const reference.
+       * common/common-exceptions.c (exceptions_state_mc_catch): Update.
+       (throw_exception_sjlj): Change "exception" to const reference.
+
 2019-04-25  Tom Tromey  <tromey@adacore.com>
 
        * xml-support.c (gdb_xml_parser::gdb_xml_parser): Update.
index 59c27ab52d44acfc9a6d4758fcd57756854e8afe..0b96cc679da5a3609e8e082dc7ec22275168fb09 100644 (file)
@@ -166,14 +166,15 @@ exceptions_state_mc_action_iter_1 (void)
 /* Return EXCEPTION to the nearest containing CATCH_SJLJ block.  */
 
 void
-throw_exception_sjlj (struct gdb_exception exception)
+throw_exception_sjlj (const struct gdb_exception &exception)
 {
   /* Jump to the nearest CATCH_SJLJ block, communicating REASON to
      that call via setjmp's return value.  Note that REASON can't be
      zero, by definition in common-exceptions.h.  */
   exceptions_state_mc (CATCH_THROWING);
+  enum return_reason reason = exception.reason;
   catchers.front ().exception = exception;
-  longjmp (catchers.front ().buf, exception.reason);
+  longjmp (catchers.front ().buf, reason);
 }
 
 /* Implementation of throw_exception that uses C++ try/catch.  */
index 33fa8a92ec26693b69d94ffa55fbc144b578afbb..d7b25502262e671e1c965699f4072d2a330b6062 100644 (file)
@@ -152,6 +152,8 @@ struct gdb_exception
     return *this;
   }
 
+  gdb_exception &operator= (gdb_exception &&other) noexcept = default;
+
   /* Return the contents of the exception message, as a C string.  The
      string remains owned by the exception object.  */
   const char *what () const noexcept
@@ -281,7 +283,7 @@ extern void throw_exception (const gdb_exception &exception)
    containing exception handler established using TRY_SJLJ.  Necessary
    in some cases where we need to throw GDB exceptions across
    third-party library code (e.g., readline).  */
-extern void throw_exception_sjlj (struct gdb_exception exception)
+extern void throw_exception_sjlj (const struct gdb_exception &exception)
      ATTRIBUTE_NORETURN;
 
 /* Convenience wrappers around throw_exception that throw GDB
index 959792d9e7a9edb2a1aade231bb6fb445bdedb8b..bb8ba5cfe5779747f59d95db40280c4faba3a4b1 100644 (file)
@@ -178,7 +178,7 @@ gdb_rl_callback_read_char_wrapper_noexcept () noexcept
     }
   CATCH_SJLJ (ex, RETURN_MASK_ALL)
     {
-      gdb_expt = ex;
+      gdb_expt = std::move (ex);
     }
   END_CATCH_SJLJ
 
@@ -212,9 +212,9 @@ gdb_rl_callback_handler (char *rl) noexcept
     {
       ui->input_handler (gdb::unique_xmalloc_ptr<char> (rl));
     }
-  catch (const gdb_exception &ex)
+  catch (gdb_exception &ex)
     {
-      gdb_rl_expt = ex;
+      gdb_rl_expt = std::move (ex);
     }
 
   /* If we caught a GDB exception, longjmp out of the readline