From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130528 invoked by alias); 3 Nov 2017 01:43:03 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 129967 invoked by uid 89); 3 Nov 2017 01:43:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.polymtl.ca Received: from smtp.polymtl.ca (HELO smtp.polymtl.ca) (132.207.4.11) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 01:43:01 +0000 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id vA31gsYQ023407 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 2 Nov 2017 21:42:59 -0400 Received: by simark.ca (Postfix, from userid 112) id B405F1E533; Thu, 2 Nov 2017 21:42:54 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 255D11E4C4; Thu, 2 Nov 2017 21:42:43 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Fri, 03 Nov 2017 01:43:00 -0000 From: Simon Marchi To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [RFA 10/13] Remove cleanups from linux-tdep.c In-Reply-To: <20171102223612.3642-11-tom@tromey.com> References: <20171102223612.3642-1-tom@tromey.com> <20171102223612.3642-11-tom@tromey.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.2 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Fri, 3 Nov 2017 01:42:54 +0000 X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00061.txt.bz2 On 2017-11-02 18:36, Tom Tromey wrote: > This removes some cleanups from linux-tdep.c, replacing them with > def_vector or unique_xmalloc_ptr as appropriate. > > gdb/ChangeLog > 2017-11-02 Tom Tromey > > * linux-tdep.c (linux_core_info_proc_mappings): Use > gdb::def_vector. > (linux_get_siginfo_data): Return gdb::unique_xmalloc_ptr. > (linux_corefile_thread): Update. Just to be pedantic, you should mention the change to linux_make_mappings_corefile_notes. > --- > gdb/ChangeLog | 7 +++++++ > gdb/linux-tdep.c | 45 ++++++++++++++------------------------------- > 2 files changed, 21 insertions(+), 31 deletions(-) > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index 83ff59faee..0350ccea16 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -998,10 +998,9 @@ linux_core_info_proc_mappings (struct gdbarch > *gdbarch, const char *args) > { > asection *section; > ULONGEST count, page_size; > - unsigned char *descdata, *filenames, *descend, *contents; > + unsigned char *descdata, *filenames, *descend; > size_t note_size; > unsigned int addr_size_bits, addr_size; > - struct cleanup *cleanup; > struct gdbarch *core_gdbarch = gdbarch_from_bfd (core_bfd); > /* We assume this for reading 64-bit core files. */ > gdb_static_assert (sizeof (ULONGEST) >= 8); > @@ -1020,12 +1019,12 @@ linux_core_info_proc_mappings (struct gdbarch > *gdbarch, const char *args) > if (note_size < 2 * addr_size) > error (_("malformed core note - too short for header")); > > - contents = (unsigned char *) xmalloc (note_size); > - cleanup = make_cleanup (xfree, contents); > - if (!bfd_get_section_contents (core_bfd, section, contents, 0, > note_size)) > + gdb::def_vector contents (note_size); > + if (!bfd_get_section_contents (core_bfd, section, contents.data (), > + 0, note_size)) > error (_("could not get core note contents")); > > - descdata = contents; > + descdata = contents.data (); > descend = descdata + note_size; > > if (descdata[note_size - 1] != '\0') > @@ -1090,8 +1089,6 @@ linux_core_info_proc_mappings (struct gdbarch > *gdbarch, const char *args) > > filenames += 1 + strlen ((char *) filenames); > } > - > - do_cleanups (cleanup); > } > > /* Implement "info proc" for a corefile. */ > @@ -1516,7 +1513,6 @@ static char * > linux_make_mappings_corefile_notes (struct gdbarch *gdbarch, bfd > *obfd, > char *note_data, int *note_size) > { > - struct cleanup *cleanup; > struct linux_make_mappings_data mapping_data; > struct type *long_type > = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), 0, > "long"); > @@ -1646,14 +1642,12 @@ linux_collect_thread_registers (const struct > regcache *regcache, > with the size of the data. The caller is responsible for freeing > the data. */ > > -static gdb_byte * > +static gdb::unique_xmalloc_ptr > linux_get_siginfo_data (thread_info *thread, struct gdbarch *gdbarch, > LONGEST *size) > { > struct type *siginfo_type; > - gdb_byte *buf; > LONGEST bytes_read; > - struct cleanup *cleanups; > > if (!gdbarch_get_siginfo_type_p (gdbarch)) > return NULL; > @@ -1663,21 +1657,15 @@ linux_get_siginfo_data (thread_info *thread, > struct gdbarch *gdbarch, > > siginfo_type = gdbarch_get_siginfo_type (gdbarch); > > - buf = (gdb_byte *) xmalloc (TYPE_LENGTH (siginfo_type)); > - cleanups = make_cleanup (xfree, buf); > + gdb::unique_xmalloc_ptr buf > + ((gdb_byte *) xmalloc (TYPE_LENGTH (siginfo_type))); > > bytes_read = target_read (¤t_target, > TARGET_OBJECT_SIGNAL_INFO, NULL, > - buf, 0, TYPE_LENGTH (siginfo_type)); > + buf.get (), 0, TYPE_LENGTH (siginfo_type)); > if (bytes_read == TYPE_LENGTH (siginfo_type)) > - { > - discard_cleanups (cleanups); > - *size = bytes_read; > - } > + *size = bytes_read; > else > - { > - do_cleanups (cleanups); > - buf = NULL; > - } > + return NULL; > > return buf; I think this could return a gdb::byte_vector, with an empty vector meaning that there is no value, the equivalent of NULL currently (I don't think we can have a siginfo type with size 0...). Simon