From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48912 invoked by alias); 19 Oct 2017 03:17:29 -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 48880 invoked by uid 89); 19 Oct 2017 03:17:28 -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; Thu, 19 Oct 2017 03:17:23 +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 v9J3HH7j003947 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 18 Oct 2017 23:17:21 -0400 Received: by simark.ca (Postfix, from userid 112) id EBDE41E541; Wed, 18 Oct 2017 23:17:16 -0400 (EDT) Received: from simark.ca (localhost [127.0.0.1]) by simark.ca (Postfix) with ESMTP id 16A9D1E055; Wed, 18 Oct 2017 23:17:16 -0400 (EDT) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 19 Oct 2017 03:17:00 -0000 From: Simon Marchi To: Pedro Alves Cc: Tom Tromey , Simon Marchi , gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr (Re: [RFA 4/6] Simple cleanup removals in remote.c) In-Reply-To: <474c4998-c732-ad97-18ef-904170a68e53@redhat.com> References: <20171016030427.21349-1-tom@tromey.com> <20171016030427.21349-5-tom@tromey.com> <07804bc3-a6c5-2c0f-5730-5dd12fccafbe@ericsson.com> <87fuaipzgg.fsf@tromey.com> <97a40149-a30f-b2af-4441-6945b1d29cf1@redhat.com> <87vajesnor.fsf@tromey.com> <474c4998-c732-ad97-18ef-904170a68e53@redhat.com> Message-ID: X-Sender: simon.marchi@polymtl.ca User-Agent: Roundcube Webmail/1.3.0 X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 19 Oct 2017 03:17:17 +0000 X-IsSubscribed: yes X-SW-Source: 2017-10/txt/msg00589.txt.bz2 On 2017-10-16 19:38, Pedro Alves wrote: > diff --git a/gdb/remote.c b/gdb/remote.c > index 6b77a9f..a6cb724 100644 > --- a/gdb/remote.c > +++ b/gdb/remote.c > @@ -2086,40 +2086,32 @@ remote_set_syscall_catchpoint (struct > target_ops *self, > pid, needed, any_count, n_sysno); > } > > - gdb::unique_xmalloc_ptr built_packet; > + std::string built_packet; > if (needed) > { > /* Prepare a packet with the sysno list, assuming max 8+1 > characters for a sysno. If the resulting packet size is too > big, fallback on the non-selective packet. */ > const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + > 1; > - > - built_packet.reset ((char *) xmalloc (maxpktsz)); > - strcpy (built_packet.get (), "QCatchSyscalls:1"); > + built_packet.reserve (maxpktsz); > + built_packet = "QCatchSyscalls:1"; > if (!any_count) > { > - int i; > - char *p; > - > - p = built_packet.get (); > - p += strlen (p); > - > /* Add in catch_packet each syscall to be caught (table[i] != 0). > */ > - for (i = 0; i < table_size; i++) > + for (int i = 0; i < table_size; i++) > { > if (table[i] != 0) > - p += xsnprintf (p, built_packet.get () + maxpktsz - p, > - ";%x", i); > + string_appendf (built_packet, ";%x", i); > } > } > - if (strlen (built_packet.get ()) > get_remote_packet_size ()) > + if (built_packet.size () > get_remote_packet_size ()) > { > /* catch_packet too big. Fallback to less efficient > non selective mode, with GDB doing the filtering. */ > catch_packet = "QCatchSyscalls:1"; > } > else > - catch_packet = built_packet.get (); > + catch_packet = built_packet.c_str (); You can get rid of built_packet, and make catch_packet the std::string. And then this last else branch can be removed. Simon