From patchwork Mon Sep 3 19:02:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29174 Received: (qmail 65161 invoked by alias); 3 Sep 2018 19:03: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 64929 invoked by uid 89); 3 Sep 2018 19:03:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 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=clock X-HELO: gateway32.websitewelcome.com Received: from gateway32.websitewelcome.com (HELO gateway32.websitewelcome.com) (192.185.145.122) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 03 Sep 2018 19:03:17 +0000 Received: from cm15.websitewelcome.com (cm15.websitewelcome.com [100.42.49.9]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 0B493DE37 for ; Mon, 3 Sep 2018 14:03:16 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id wu7hfhHP2bXuJwu7uf1hFD; Mon, 03 Sep 2018 14:03:15 -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=6FSdhPPZccH+Z92CQvxi65TLwHvtAhjhV3Hnfa7EUXQ=; b=SvZQglo/ZHHCU5jpPgzH2oiYaN gbBIwHZhylTIgaog0C+j9NFU9baE1p+w6Vv3V8uAOLZZlC/vxv+eEMBMMsDTD9IcPLCwcANflHkCA S1VmOOPEeQxNJNGLaaP+zUuma; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:58120 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fwu7g-002juS-Pn; Mon, 03 Sep 2018 14:02:52 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 3/4] Return std::string from gdb_bfd_errmsg Date: Mon, 3 Sep 2018 13:02:49 -0600 Message-Id: <20180903190250.11599-4-tom@tromey.com> In-Reply-To: <20180903190250.11599-1-tom@tromey.com> References: <20180903190250.11599-1-tom@tromey.com> This changes gdb_bfd_errmsg to return a std::string, removing a cleanup. This approach may be slightly less efficient than the previous code, but I don't believe this is very important in this situation. gdb/ChangeLog 2018-09-03 Tom Tromey * utils.h (gdb_bfd_errmsg): Return std::string. * exec.c (exec_file_attach): Update. * compile/compile-object-load.c (compile_object_load): Update. * utils.c (gdb_bfd_errmsg): Return std::string. --- gdb/ChangeLog | 7 +++++++ gdb/compile/compile-object-load.c | 3 ++- gdb/exec.c | 2 +- gdb/utils.c | 27 +++++++-------------------- gdb/utils.h | 2 +- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 873750b9440..40053d281a1 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -638,7 +638,8 @@ compile_object_load (const compile_file_names &file_names, if (!bfd_check_format_matches (abfd.get (), bfd_object, &matching)) error (_("\"%s\": not in loadable format: %s"), - filename.get (), gdb_bfd_errmsg (bfd_get_error (), matching)); + filename.get (), + gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); if ((bfd_get_file_flags (abfd.get ()) & (EXEC_P | DYNAMIC)) != 0) error (_("\"%s\": not in object format."), filename.get ()); diff --git a/gdb/exec.c b/gdb/exec.c index 3023ff7e5aa..6e44b0e821b 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -362,7 +362,7 @@ exec_file_attach (const char *filename, int from_tty) exec_close (); error (_("\"%s\": not in executable format: %s"), scratch_pathname, - gdb_bfd_errmsg (bfd_get_error (), matching)); + gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); } if (build_section_table (exec_bfd, §ions, §ions_end)) diff --git a/gdb/utils.c b/gdb/utils.c index 7a8c80c64ed..d7980fe3a18 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -2921,39 +2921,26 @@ compare_positive_ints (const void *ap, const void *bp) #define AMBIGUOUS_MESS2 \ ".\nUse \"set gnutarget format-name\" to specify the format." -const char * +std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching) { - char *ret, *retp; - int ret_len; char **p; /* Check if errmsg just need simple return. */ if (error_tag != bfd_error_file_ambiguously_recognized || matching == NULL) return bfd_errmsg (error_tag); - ret_len = strlen (bfd_errmsg (error_tag)) + strlen (AMBIGUOUS_MESS1) - + strlen (AMBIGUOUS_MESS2); - for (p = matching; *p; p++) - ret_len += strlen (*p) + 1; - ret = (char *) xmalloc (ret_len + 1); - retp = ret; - make_cleanup (xfree, ret); - - strcpy (retp, bfd_errmsg (error_tag)); - retp += strlen (retp); - - strcpy (retp, AMBIGUOUS_MESS1); - retp += strlen (retp); + std::string ret (bfd_errmsg (error_tag)); + ret += AMBIGUOUS_MESS1; for (p = matching; *p; p++) { - sprintf (retp, " %s", *p); - retp += strlen (retp); + ret += " "; + ret += *p; } - xfree (matching); + ret += AMBIGUOUS_MESS2; - strcpy (retp, AMBIGUOUS_MESS2); + xfree (matching); return ret; } diff --git a/gdb/utils.h b/gdb/utils.h index 68523994b94..fa9a59087da 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -115,7 +115,7 @@ compare_cstrings (const char *str1, const char *str2) MATCHING, if non-NULL, is the corresponding argument to bfd_check_format_matches, and will be freed. */ -extern const char *gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); +extern std::string gdb_bfd_errmsg (bfd_error_type error_tag, char **matching); /* Reset the prompt_for_continue clock. */ void reset_prompt_for_continue_wait_time (void);