From patchwork Thu Apr 25 16:52:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32412 Received: (qmail 97899 invoked by alias); 25 Apr 2019 16:53:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 97840 invoked by uid 89); 25 Apr 2019 16:53:05 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=return_reason X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 25 Apr 2019 16:53:04 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 8C93B1172D8; Thu, 25 Apr 2019 12:53:02 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id TUcuG7NbpEzA; Thu, 25 Apr 2019 12:53:02 -0400 (EDT) Received: from murgatroyd.Home (97-122-168-123.hlrn.qwest.net [97.122.168.123]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 36FD4116529; Thu, 25 Apr 2019 12:53:02 -0400 (EDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/5] Make SJLJ exceptions more efficient Date: Thu, 25 Apr 2019 10:52:53 -0600 Message-Id: <20190425165256.31226-3-tromey@adacore.com> In-Reply-To: <20190425165256.31226-1-tromey@adacore.com> References: <20190425165256.31226-1-tromey@adacore.com> MIME-Version: 1.0 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 * 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 | 10 ++++++++++ gdb/common/common-exceptions.c | 5 +++-- gdb/common/common-exceptions.h | 4 +++- gdb/event-top.c | 6 +++--- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c index 59c27ab52d4..0b96cc679da 100644 --- a/gdb/common/common-exceptions.c +++ b/gdb/common/common-exceptions.c @@ -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. */ diff --git a/gdb/common/common-exceptions.h b/gdb/common/common-exceptions.h index 33fa8a92ec2..d7b25502262 100644 --- a/gdb/common/common-exceptions.h +++ b/gdb/common/common-exceptions.h @@ -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 diff --git a/gdb/event-top.c b/gdb/event-top.c index 959792d9e7a..bb8ba5cfe57 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -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 (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