From patchwork Thu May 3 21:50:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 27099 Received: (qmail 24936 invoked by alias); 3 May 2018 21:50:19 -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 24844 invoked by uid 89); 3 May 2018 21:50:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 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.2 spammy= X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.193.12) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 03 May 2018 21:50:16 +0000 Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway36.websitewelcome.com (Postfix) with ESMTP id A909C40146C85 for ; Thu, 3 May 2018 16:50:15 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id EM7DfM8QBy2aLEM7DfgUGk; Thu, 03 May 2018 16:50:15 -0500 X-Authority-Reason: nr=8 Received: from 97-122-176-117.hlrn.qwest.net ([97.122.176.117]:51044 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1fEM7D-003kgF-Fm; Thu, 03 May 2018 16:50:15 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFA 2/3] Return std::string from ada_exception_catchpoint_cond_string Date: Thu, 3 May 2018 15:50:12 -0600 Message-Id: <20180503215013.19891-3-tom@tromey.com> In-Reply-To: <20180503215013.19891-1-tom@tromey.com> References: <20180503215013.19891-1-tom@tromey.com> X-BWhitelist: no X-Source-L: No X-Exim-ID: 1fEM7D-003kgF-Fm X-Source-Sender: 97-122-176-117.hlrn.qwest.net (bapiya.Home) [97.122.176.117]:51044 X-Source-Auth: tom+tromey.com X-Email-Count: 3 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes This changes ada_exception_catchpoint_cond_string to return a std::string, allowing for the removal of a cleanup in create_excep_cond_exprs. ChangeLog 2018-05-03 Tom Tromey * ada-lang.c (create_excep_cond_exprs): Update. (ada_exception_catchpoint_cond_string): Use std::string. --- gdb/ChangeLog | 5 +++++ gdb/ada-lang.c | 36 ++++++++++++++---------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index d086240459..1af09bc00e 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -12431,7 +12431,7 @@ ada_exception_name_addr (enum ada_exception_catchpoint_kind ex, return result; } -static char *ada_exception_catchpoint_cond_string +static std::string ada_exception_catchpoint_cond_string (const char *excep_string, enum ada_exception_catchpoint_kind ex); @@ -12499,9 +12499,7 @@ static void create_excep_cond_exprs (struct ada_catchpoint *c, enum ada_exception_catchpoint_kind ex) { - struct cleanup *old_chain; struct bp_location *bl; - char *cond_string; /* Nothing to do if there's no specific exception to catch. */ if (c->excep_string == NULL) @@ -12513,8 +12511,8 @@ create_excep_cond_exprs (struct ada_catchpoint *c, /* Compute the condition expression in text form, from the specific expection we want to catch. */ - cond_string = ada_exception_catchpoint_cond_string (c->excep_string, ex); - old_chain = make_cleanup (xfree, cond_string); + std::string cond_string + = ada_exception_catchpoint_cond_string (c->excep_string, ex); /* Iterate over all the catchpoint's locations, and parse an expression for each. */ @@ -12528,7 +12526,7 @@ create_excep_cond_exprs (struct ada_catchpoint *c, { const char *s; - s = cond_string; + s = cond_string.c_str (); TRY { exp = parse_exp_1 (&s, bl->address, @@ -12546,8 +12544,6 @@ create_excep_cond_exprs (struct ada_catchpoint *c, ada_loc->excep_cond_expr = std::move (exp); } - - do_cleanups (old_chain); } /* ada_catchpoint destructor. */ @@ -13248,29 +13244,25 @@ ada_exception_breakpoint_ops (enum ada_exception_catchpoint_kind ex) being raised with the exception that the user wants to catch. This assumes that this condition is used when the inferior just triggered an exception catchpoint. - EX: the type of catchpoints used for catching Ada exceptions. - - The string returned is a newly allocated string that needs to be - deallocated later. */ + EX: the type of catchpoints used for catching Ada exceptions. */ -static char * +static std::string ada_exception_catchpoint_cond_string (const char *excep_string, enum ada_exception_catchpoint_kind ex) { int i; bool is_standard_exc = false; - const char *actual_exc_expr; - char *ref_exc_expr; + std::string result; if (ex == ada_catch_handlers) { /* For exception handlers catchpoints, the condition string does not use the same parameter as for the other exceptions. */ - actual_exc_expr = ("long_integer (GNAT_GCC_exception_Access" - "(gcc_exception).all.occurrence.id)"); + result = ("long_integer (GNAT_GCC_exception_Access" + "(gcc_exception).all.occurrence.id)"); } else - actual_exc_expr = "long_integer (e)"; + result = "long_integer (e)"; /* The standard exceptions are a special case. They are defined in runtime units that have been compiled without debugging info; if @@ -13300,13 +13292,13 @@ ada_exception_catchpoint_cond_string (const char *excep_string, } } + result += " = "; + if (is_standard_exc) - ref_exc_expr = xstrprintf ("long_integer (&standard.%s)", excep_string); + string_appendf (result, "long_integer (&standard.%s)", excep_string); else - ref_exc_expr = xstrprintf ("long_integer (&%s)", excep_string); + string_appendf (result, "long_integer (&%s)", excep_string); - char *result = xstrprintf ("%s = %s", actual_exc_expr, ref_exc_expr); - xfree (ref_exc_expr); return result; }