From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 38788 invoked by alias); 30 Oct 2017 11:49:07 -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 38067 invoked by uid 89); 30 Oct 2017 11:49:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Oct 2017 11:49:05 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8E20D267C3; Mon, 30 Oct 2017 11:49:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8E20D267C3 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=palves@redhat.com Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id D087E95B24; Mon, 30 Oct 2017 11:49:02 +0000 (UTC) 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) To: Simon Marchi 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> Cc: Tom Tromey , Simon Marchi , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <025c9d37-d341-5ed7-ae02-7f2348a864d1@redhat.com> Date: Mon, 30 Oct 2017 11:49:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-10/txt/msg00883.txt.bz2 On 10/19/2017 04:17 AM, Simon Marchi wrote: > 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. The reason I didn't do that is because that'd introduce an allocation + one deep string copy in the '!needed' case: else catch_packet = "QCatchSyscalls:0"; when it's very easy to avoid. So I pushed the patch in as is. Thanks, Pedro Alves