From patchwork Tue Oct 15 17:42:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Simon Marchi (Code Review)" X-Patchwork-Id: 34989 Received: (qmail 31178 invoked by alias); 15 Oct 2019 17:42:10 -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 31165 invoked by uid 89); 15 Oct 2019 17:42:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: mx1.osci.io Received: from polly.osci.io (HELO mx1.osci.io) (8.43.85.229) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2019 17:42:07 +0000 Received: by mx1.osci.io (Postfix, from userid 994) id 0B26F208F0; Tue, 15 Oct 2019 13:42:05 -0400 (EDT) Received: from gnutoolchain-gerrit.osci.io (gnutoolchain-gerrit.osci.io [IPv6:2620:52:3:1:5054:ff:fe06:16ca]) by mx1.osci.io (Postfix) with ESMTP id 73F0A20806; Tue, 15 Oct 2019 13:42:04 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by gnutoolchain-gerrit.osci.io (Postfix) with ESMTP id 429AA29ECF; Tue, 15 Oct 2019 13:42:04 -0400 (EDT) X-Gerrit-PatchSet: 1 Date: Tue, 15 Oct 2019 13:42:04 -0400 From: "Sourceware to Gerrit sync (Code Review)" To: Tom Tromey , gdb-patches@sourceware.org Cc: Andrew Burgess Auto-Submitted: auto-generated X-Gerrit-MessageType: merged Subject: Change in binutils-gdb[master]: Change gcc_target_options to return std::string X-Gerrit-Change-Id: I51f61703426a323089e646da8f22320a2cafbc1f X-Gerrit-Change-Number: 83 X-Gerrit-ChangeURL: X-Gerrit-Commit: 953cff563058831ab0bf863c7655d23b5e6a5989 In-Reply-To: References: Reply-To: noreply@gnutoolchain-gerrit.osci.io, tromey@sourceware.org, andrew.burgess@embecosm.com, gdb-patches@sourceware.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Gerrit/3.0.3 Message-Id: <20191015174204.429AA29ECF@gnutoolchain-gerrit.osci.io> Sourceware to Gerrit sync has submitted this change. Change URL: https://gnutoolchain-gerrit.osci.io/r/c/binutils-gdb/+/83 ...................................................................... Change gcc_target_options to return std::string This patch was inspired by a recent review that recommended using std::string in a new implementation of the gcc_target_options gdbarch function. It changes this function to return std::string rather than an ordinary xmalloc'd string. I believe this caught a latent memory leak in compile.c:get_args. Tested on x86-64 Fedora 29. gdb/ChangeLog 2019-10-15 Tom Tromey * gdbarch.h, gdbarch.c: Rebuild. * gdbarch.sh (gcc_target_options): Change return type to std::string. * compile/compile.c (get_args): Update. * nios2-tdep.c (nios2_gcc_target_options): Return std::string. * arm-linux-tdep.c (arm_linux_gcc_target_options): Return std::string. * aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return std::string. * arch-utils.c (default_gcc_target_options): Return std::string. * arch-utils.h (default_gcc_target_options): Return std::string. * s390-tdep.c (s390_gcc_target_options): Return std::string. Change-Id: I51f61703426a323089e646da8f22320a2cafbc1f --- M gdb/ChangeLog M gdb/aarch64-linux-tdep.c M gdb/arch-utils.c M gdb/arch-utils.h M gdb/arm-linux-tdep.c M gdb/compile/compile.c M gdb/gdbarch.c M gdb/gdbarch.h M gdb/gdbarch.sh M gdb/nios2-tdep.c M gdb/s390-tdep.c 11 files changed, 35 insertions(+), 19 deletions(-) Approvals: Andrew Burgess: Looks good to me, approved diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 9d3ec1f..e52ec3f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2019-10-15 Tom Tromey + + * gdbarch.h, gdbarch.c: Rebuild. + * gdbarch.sh (gcc_target_options): Change return type to + std::string. + * compile/compile.c (get_args): Update. + * nios2-tdep.c (nios2_gcc_target_options): Return std::string. + * arm-linux-tdep.c (arm_linux_gcc_target_options): Return + std::string. + * aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return + std::string. + * arch-utils.c (default_gcc_target_options): Return std::string. + * arch-utils.h (default_gcc_target_options): Return std::string. + * s390-tdep.c (s390_gcc_target_options): Return std::string. + 2019-10-15 Christian Biesinger * breakpoint.c (breakpoint_chain): Make static. diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index a375c3b..3ec08d1 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -1429,11 +1429,11 @@ /* Implement the "gcc_target_options" gdbarch method. */ -static char * +static std::string aarch64_linux_gcc_target_options (struct gdbarch *gdbarch) { /* GCC doesn't know "-m64". */ - return NULL; + return {}; } static void diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index c61fa6f..571646e 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -903,11 +903,12 @@ /* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be created in inferior memory by GDB (normally it is set by ld.so). */ -char * +std::string default_gcc_target_options (struct gdbarch *gdbarch) { - return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch), - gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : ""); + return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch), + (gdbarch_ptr_bit (gdbarch) == 64 + ? " -mcmodel=large" : "")); } /* gdbarch gnu_triplet_regexp method. */ diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index e5bbcd1..48ff3bb 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -247,7 +247,7 @@ extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot); extern void default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size); -extern char *default_gcc_target_options (struct gdbarch *gdbarch); +extern std::string default_gcc_target_options (struct gdbarch *gdbarch); extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch); extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch); diff --git a/gdb/arm-linux-tdep.c b/gdb/arm-linux-tdep.c index 54ea851..32c1ef3 100644 --- a/gdb/arm-linux-tdep.c +++ b/gdb/arm-linux-tdep.c @@ -1710,11 +1710,11 @@ /* Implement the gcc_target_options gdbarch method. */ -static char * +static std::string arm_linux_gcc_target_options (struct gdbarch *gdbarch) { /* GCC doesn't know "-m32". */ - return NULL; + return {}; } static void diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c index 5c3400f..94942db 100644 --- a/gdb/compile/compile.c +++ b/gdb/compile/compile.c @@ -635,7 +635,7 @@ int argc_compiler; char **argv_compiler; - build_argc_argv (gdbarch_gcc_target_options (gdbarch), + build_argc_argv (gdbarch_gcc_target_options (gdbarch).c_str (), argcp, argvp); cs_producer_options = get_selected_pc_producer_options (); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 7b93d00..fa6be50 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -5043,7 +5043,7 @@ gdbarch->infcall_munmap = infcall_munmap; } -char * +std::string gdbarch_gcc_target_options (struct gdbarch *gdbarch) { gdb_assert (gdbarch != NULL); diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h index 3c6efae..01b5aef 100644 --- a/gdb/gdbarch.h +++ b/gdb/gdbarch.h @@ -1596,10 +1596,10 @@ /* Return string (caller has to use xfree for it) with options for GCC to produce code for this target, typically "-m64", "-m32" or "-m31". These options are put before CU's DW_AT_producer compilation options so that - they can override it. Method may also return NULL. */ + they can override it. */ -typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch); -extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch); +typedef std::string (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch); +extern std::string gdbarch_gcc_target_options (struct gdbarch *gdbarch); extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options); /* Return a regular expression that matches names used by this diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh index d589b2c..62f68dc 100755 --- a/gdb/gdbarch.sh +++ b/gdb/gdbarch.sh @@ -1184,8 +1184,8 @@ # Return string (caller has to use xfree for it) with options for GCC # to produce code for this target, typically "-m64", "-m32" or "-m31". # These options are put before CU's DW_AT_producer compilation options so that -# they can override it. Method may also return NULL. -m;char *;gcc_target_options;void;;;default_gcc_target_options;;0 +# they can override it. +m;std::string;gcc_target_options;void;;;default_gcc_target_options;;0 # Return a regular expression that matches names used by this # architecture in GNU configury triplets. The result is statically diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c index cb17e4f..c2683b5 100644 --- a/gdb/nios2-tdep.c +++ b/gdb/nios2-tdep.c @@ -2260,11 +2260,11 @@ } /* Implement the gcc_target_options gdbarch method. */ -static char * +static std::string nios2_gcc_target_options (struct gdbarch *gdbarch) { /* GCC doesn't know "-m32". */ - return NULL; + return {}; } /* Initialize the Nios II gdbarch. */ diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c index 6bd0528..329a122 100644 --- a/gdb/s390-tdep.c +++ b/gdb/s390-tdep.c @@ -6779,10 +6779,10 @@ /* Implement gdbarch_gcc_target_options. GCC does not know "-m32" or "-mcmodel=large". */ -static char * +static std::string s390_gcc_target_options (struct gdbarch *gdbarch) { - return xstrdup (gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31"); + return gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31"; } /* Implement gdbarch_gnu_triplet_regexp. Target triplets are "s390-*"