From patchwork Wed Apr 6 02:37:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 8757751 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 06AD49F36E for ; Wed, 6 Apr 2016 02:38:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5F0F1202F2 for ; Wed, 6 Apr 2016 02:38:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BF462035B for ; Wed, 6 Apr 2016 02:38:20 +0000 (UTC) Received: from localhost ([::1]:40306 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andMK-0000sn-0O for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Apr 2016 22:38:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andM8-0000qz-AY for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1andM6-0002dp-Lo for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33938) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1andM6-0002dc-F3 for qemu-devel@nongnu.org; Tue, 05 Apr 2016 22:38:06 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (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 E53367F0B4; Wed, 6 Apr 2016 02:38:05 +0000 (UTC) Received: from jason-ThinkPad-T430s.redhat.com (vpn1-7-238.pek2.redhat.com [10.72.7.238]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u362c1Ab016115; Tue, 5 Apr 2016 22:38:04 -0400 From: Jason Wang To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Wed, 6 Apr 2016 10:37:56 +0800 Message-Id: <1459910280-5101-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1459910280-5101-1-git-send-email-jasowang@redhat.com> References: <1459910280-5101-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Isaac Lozano <109lozanoi@gmail.com>, Jason Wang Subject: [Qemu-devel] [PULL 1/5] util: Improved qemu_hexmap() to include an ascii dump of the buffer 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Isaac Lozano <109lozanoi@gmail.com> qemu_hexdump() in util/hexdump.c has been changed to give also include a ascii dump of the buffer. Also, calls to hex_dump() in net/net.c have been replaced with calls to qemu_hexdump(). This takes care of two misc BiteSized Tasks. Reviewed-by: Thomas Huth Reviewed-by: Gerd Hoffmann Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> Signed-off-by: Jason Wang --- net/net.c | 30 +----------------------------- util/hexdump.c | 33 ++++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 40 deletions(-) diff --git a/net/net.c b/net/net.c index 594c3b8..0bc42a1 100644 --- a/net/net.c +++ b/net/net.c @@ -81,34 +81,6 @@ int default_net = 1; /***********************************************************/ /* network device redirectors */ -#if defined(DEBUG_NET) -static void hex_dump(FILE *f, const uint8_t *buf, int size) -{ - int len, i, j, c; - - for(i=0;i 16) - len = 16; - fprintf(f, "%08x ", i); - for(j=0;j<16;j++) { - if (j < len) - fprintf(f, " %02x", buf[i+j]); - else - fprintf(f, " "); - } - fprintf(f, " "); - for(j=0;j '~') - c = '.'; - fprintf(f, "%c", c); - } - fprintf(f, "\n"); - } -} -#endif - static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) { const char *p, *p1; @@ -664,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender, #ifdef DEBUG_NET printf("qemu_send_packet_async:\n"); - hex_dump(stdout, buf, size); + qemu_hexdump((const char *)buf, stdout, "net", size); #endif if (sender->link_down || !sender->peer) { diff --git a/util/hexdump.c b/util/hexdump.c index 1d9c129..f879ff0 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -18,21 +18,32 @@ void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size) { - unsigned int b; + unsigned int b, len, i, c; - for (b = 0; b < size; b++) { - if ((b % 16) == 0) { - fprintf(fp, "%s: %04x:", prefix, b); + for (b = 0; b < size; b += 16) { + len = size - b; + if (len > 16) { + len = 16; } - if ((b % 4) == 0) { - fprintf(fp, " "); + fprintf(fp, "%s: %04x:", prefix, b); + for (i = 0; i < 16; i++) { + if ((i % 4) == 0) { + fprintf(fp, " "); + } + if (i < len) { + fprintf(fp, " %02x", (unsigned char)buf[b + i]); + } else { + fprintf(fp, " "); + } } - fprintf(fp, " %02x", (unsigned char)buf[b]); - if ((b % 16) == 15) { - fprintf(fp, "\n"); + fprintf(fp, " "); + for (i = 0; i < len; i++) { + c = buf[b + i]; + if (c < ' ' || c > '~') { + c = '.'; + } + fprintf(fp, "%c", c); } - } - if ((b % 16) != 0) { fprintf(fp, "\n"); } }