From patchwork Wed Feb 6 20:27:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 218771 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AB6F2C02F2 for ; Thu, 7 Feb 2013 08:47:23 +1100 (EST) Received: from localhost ([::1]:51739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3BbD-0007uM-6G for incoming@patchwork.ozlabs.org; Wed, 06 Feb 2013 15:28:07 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3Baf-00071g-Ug for qemu-devel@nongnu.org; Wed, 06 Feb 2013 15:27:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U3Bab-00053A-OU for qemu-devel@nongnu.org; Wed, 06 Feb 2013 15:27:33 -0500 Received: from oxygen.pond.sub.org ([2a01:4f8:121:10e4::3]:59089) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U3Bab-00052d-H4 for qemu-devel@nongnu.org; Wed, 06 Feb 2013 15:27:29 -0500 Received: from blackfin.pond.sub.org (p5B32B9A6.dip.t-dialin.net [91.50.185.166]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 269A7A460F; Wed, 6 Feb 2013 21:27:28 +0100 (CET) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0676E200B7; Wed, 6 Feb 2013 21:27:26 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 6 Feb 2013 21:27:26 +0100 Message-Id: <1360182446-1502-14-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1360182446-1502-1-git-send-email-armbru@redhat.com> References: <1360182446-1502-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:4f8:121:10e4::3 Cc: lilei@linux.vnet.ibm.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH for-1.4 v2 13/13] hmp: make memchar-read escape ASCII control chars except \n and \t X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Markus Armbruster --- hmp-commands.hx | 2 ++ hmp.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/hmp-commands.hx b/hmp-commands.hx index 66ec716..4c100d7 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -869,6 +869,8 @@ STEXI @findex ringbuf_read Read and print up to @var{size} bytes from ring buffer character device @var{device}. +Certain non-printable characters are printed \uXXXX, where XXXX is the +character code in hexadecimal. Character \ is printed \\. Bug: can screw up when the buffer contains invalid UTF-8 sequences, NUL characters, after the ring buffer lost data, and when reading stops because the size limit is reached. diff --git a/hmp.c b/hmp.c index cbd5727..420d48b 100644 --- a/hmp.c +++ b/hmp.c @@ -679,6 +679,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) const char *chardev = qdict_get_str(qdict, "device"); char *data; Error *errp = NULL; + int i; data = qmp_ringbuf_read(chardev, size, false, 0, &errp); if (errp) { @@ -687,7 +688,19 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict) return; } - monitor_printf(mon, "%s\n", data); + for (i = 0; data[i]; i++) { + unsigned char ch = data[i]; + + if (ch == '\\') { + monitor_printf(mon, "\\\\"); + } else if ((ch < 0x20 && ch != '\n' && ch != '\t') || ch == 0x7F) { + monitor_printf(mon, "\\u%04X", ch); + } else { + monitor_printf(mon, "%c", ch); + } + + } + monitor_printf(mon, "\n"); g_free(data); }