From patchwork Wed Oct 19 01:12:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 16639 Received: (qmail 124642 invoked by alias); 19 Oct 2016 01:12:41 -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 124587 invoked by uid 89); 19 Oct 2016 01:12:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=BAYES_00, 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; Wed, 19 Oct 2016 01:12:38 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9947CC00B701 for ; Wed, 19 Oct 2016 01:12:37 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9J1CJjo019701 for ; Tue, 18 Oct 2016 21:12:37 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH v2 19/31] Use ui_file_as_string in gdb/remote.c Date: Wed, 19 Oct 2016 02:12:07 +0100 Message-Id: <1476839539-8374-20-git-send-email-palves@redhat.com> In-Reply-To: <1476839539-8374-1-git-send-email-palves@redhat.com> References: <1476839539-8374-1-git-send-email-palves@redhat.com> gdb/ChangeLog: yyyy-mm-yy Pedro Alves * remote.c (escape_buffer): Use ui_file_as_string and return std::string. (putpkt_binary, read_frame): Adjust to use std::string. --- gdb/remote.c | 54 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/gdb/remote.c b/gdb/remote.c index e8cb560..e741a58 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -8220,23 +8220,20 @@ remote_send (char **buf, error (_("Remote failure reply: %s"), *buf); } -/* Return a pointer to an xmalloc'ed string representing an escaped - version of BUF, of len N. E.g. \n is converted to \\n, \t to \\t, - etc. The caller is responsible for releasing the returned - memory. */ +/* Return a string representing an escaped version of BUF, of len N. + E.g. \n is converted to \\n, \t to \\t, etc. */ -static char * +static std::string escape_buffer (const char *buf, int n) { struct cleanup *old_chain; struct ui_file *stb; - char *str; stb = mem_fileopen (); old_chain = make_cleanup_ui_file_delete (stb); fputstrn_unfiltered (buf, n, '\\', stb); - str = ui_file_xstrdup (stb, NULL); + std::string str = ui_file_as_string (stb); do_cleanups (old_chain); return str; } @@ -8320,15 +8317,12 @@ putpkt_binary (const char *buf, int cnt) if (remote_debug) { - struct cleanup *old_chain; - char *str; - *p = '\0'; - str = escape_buffer (buf2, p - buf2); - old_chain = make_cleanup (xfree, str); - fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str); + + std::string str = escape_buffer (buf2, p - buf2); + + fprintf_unfiltered (gdb_stdlog, "Sending packet: %s...", str.c_str ()); gdb_flush (gdb_stdlog); - do_cleanups (old_chain); } remote_serial_write (buf2, p - buf2); @@ -8406,15 +8400,11 @@ putpkt_binary (const char *buf, int cnt) { if (remote_debug) { - struct cleanup *old_chain; - char *str; + std::string str = escape_buffer (rs->buf, val); - str = escape_buffer (rs->buf, val); - old_chain = make_cleanup (xfree, str); fprintf_unfiltered (gdb_stdlog, " Notification received: %s\n", - str); - do_cleanups (old_chain); + str.c_str ()); } handle_notification (rs->notif_state, rs->buf); /* We're in sync now, rewait for the ack. */ @@ -8580,16 +8570,12 @@ read_frame (char **buf_p, if (remote_debug) { - struct cleanup *old_chain; - char *str; + std::string str = escape_buffer (buf, bc); - str = escape_buffer (buf, bc); - old_chain = make_cleanup (xfree, str); fprintf_unfiltered (gdb_stdlog, "Bad checksum, sentsum=0x%x, " "csum=0x%x, buf=%s\n", - pktcsum, csum, str); - do_cleanups (old_chain); + pktcsum, csum, str.c_str ()); } /* Number of characters in buffer ignoring trailing NULL. */ @@ -8763,13 +8749,9 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever, { if (remote_debug) { - struct cleanup *old_chain; - char *str; + std::string str = escape_buffer (*buf, val); - str = escape_buffer (*buf, val); - old_chain = make_cleanup (xfree, str); - fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str); - do_cleanups (old_chain); + fprintf_unfiltered (gdb_stdlog, "Packet received: %s\n", str.c_str ()); } /* Skip the ack char if we're in no-ack mode. */ @@ -8788,15 +8770,11 @@ getpkt_or_notif_sane_1 (char **buf, long *sizeof_buf, int forever, if (remote_debug) { - struct cleanup *old_chain; - char *str; + std::string str = escape_buffer (*buf, val); - str = escape_buffer (*buf, val); - old_chain = make_cleanup (xfree, str); fprintf_unfiltered (gdb_stdlog, " Notification received: %s\n", - str); - do_cleanups (old_chain); + str.c_str ()); } if (is_notif != NULL) *is_notif = 1;