From patchwork Sun Apr 7 19:57:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 32191 Received: (qmail 5862 invoked by alias); 7 Apr 2019 20:02:21 -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 5848 invoked by uid 89); 7 Apr 2019 20:02:20 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.195.25) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 07 Apr 2019 20:02:19 +0000 Received: from cm10.websitewelcome.com (cm10.websitewelcome.com [100.42.49.4]) by gateway36.websitewelcome.com (Postfix) with ESMTP id CEEF7400F8CBB for ; Sun, 7 Apr 2019 14:14:42 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id DDuqh5BGF2PzODDuqhfbOk; Sun, 07 Apr 2019 14:57:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yrRq97LBnPWGCBuEioWFPwK0PNlyuHWcSOWFAsFHKv4=; b=aAbOThBZ0vHHd6fmeO5p8w6AUk EcXVPwl24dTdYrBZa6/kZfUpDbk5pUEPUFHend0H5a8mz4DKGE45anilBoWM1zzFKejTauQxjjPZW xtAFUqFu1yNujYf3p2yXRqi4J; Received: from 174-29-37-56.hlrn.qwest.net ([174.29.37.56]:51312 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1hDDuq-003h9z-9C; Sun, 07 Apr 2019 14:57:20 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH v3 6/7] Make exception throwing a bit more efficient Date: Sun, 7 Apr 2019 13:57:14 -0600 Message-Id: <20190407195715.24669-7-tom@tromey.com> In-Reply-To: <20190407195715.24669-1-tom@tromey.com> References: <20190407195715.24669-1-tom@tromey.com> This makes exception throwing a bit more efficient, by removing some copies. gdb/ChangeLog 2019-04-07 Tom Tromey * 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. (struct gdb_exception_error): Add constructor. (struct gdb_exception_quit): Add constructor. --- gdb/ChangeLog | 10 ++++++++++ gdb/common/common-exceptions.c | 33 ++++++++++++++++----------------- gdb/common/common-exceptions.h | 12 +++++++++++- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/gdb/common/common-exceptions.c b/gdb/common/common-exceptions.c index d3c01e53387..83f2c74bfd4 100644 --- a/gdb/common/common-exceptions.c +++ b/gdb/common/common-exceptions.c @@ -180,8 +180,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 gdb_exception &exception) { if (exception.reason == RETURN_QUIT) { @@ -197,25 +197,24 @@ 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; - - /* Create the exception. */ - e.reason = reason; - e.error = error; - e.message.reset (new std::string (string_vprintf (fmt, ap))); - - /* Throw the exception. */ - throw_exception (e); + if (reason == RETURN_QUIT) + { + gdb_exception_quit ex (reason, error); + ex.message.reset (new std::string (string_vprintf (fmt, ap))); + throw ex; + } + else if (reason == RETURN_ERROR) + { + gdb_exception_error ex (reason, error); + ex.message.reset (new std::string (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 b09a34b0a35..1aedb831a62 100644 --- a/gdb/common/common-exceptions.h +++ b/gdb/common/common-exceptions.h @@ -214,6 +214,11 @@ extern int exceptions_state_mc_catch (struct gdb_exception *, int); struct gdb_exception_error : public gdb_exception { + gdb_exception_error (enum return_reason r, enum errors e) + : gdb_exception (r, e) + { + } + explicit gdb_exception_error (const gdb_exception &ex) noexcept : gdb_exception (ex) { @@ -222,6 +227,11 @@ struct gdb_exception_error : public gdb_exception struct gdb_exception_quit : public gdb_exception { + gdb_exception_quit (enum return_reason r, enum errors e) + : gdb_exception (r, e) + { + } + explicit gdb_exception_quit (const gdb_exception &ex) noexcept : gdb_exception (ex) { @@ -250,7 +260,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 gdb_exception &exception) ATTRIBUTE_NORETURN; /* Throw an exception by executing a LONG JUMP to the inner most