From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 59465 invoked by alias); 16 Oct 2017 23:38:26 -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 59455 invoked by uid 89); 16 Oct 2017 23:38:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,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, 16 Oct 2017 23:38:22 +0000 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 905FA4E90B; Mon, 16 Oct 2017 23:38:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 905FA4E90B Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.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 723E260852; Mon, 16 Oct 2017 23:38:20 +0000 (UTC) Subject: [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: Tom Tromey 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> Cc: Simon Marchi , gdb-patches@sourceware.org From: Pedro Alves Message-ID: <474c4998-c732-ad97-18ef-904170a68e53@redhat.com> Date: Mon, 16 Oct 2017 23:38: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: <87vajesnor.fsf@tromey.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-10/txt/msg00490.txt.bz2 On 10/17/2017 12:00 AM, Tom Tromey wrote: >>>>>> "Pedro" == Pedro Alves writes: > > Pedro> This suggests to me that we're missing a string_printf variant > Pedro> that appends to a preexisting string: > Pedro> void string_appendf (std::string &dest, const char* fmt, ...); > Pedro> See (untested) patch below. > > Seems like a good idea FWIW. And here's the remote.c bit making use of string_appendf, slit out as a proper patch. Forgot to mention in 1/2, but this applies on top of: https://sourceware.org/ml/gdb-patches/2017-10/msg00485.html >From 19283964911072c76ee530c58a46fd4b87dfbaae Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Tue, 17 Oct 2017 00:28:46 +0100 Subject: [PATCH] remote.c, QCatchSyscalls: Build std::string instead of unique_xmalloc_ptr Simplify the code a little bit using std::string + string_appendf. gdb/ChangeLog: yyyy-mm-dd Pedro Alves Simon Marchi * remote.c (remote_set_syscall_catchpoint): Build a std::string instead of a gdb::unique_xmalloc_ptr, using string_appendf. --- gdb/remote.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) 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 (); } else catch_packet = "QCatchSyscalls:0"; -- 2.5.5