From patchwork Tue Apr 2 15:23:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 52117 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9AAB94C93; Tue, 2 Apr 2019 17:24:00 +0200 (CEST) Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by dpdk.org (Postfix) with ESMTP id D4609316B for ; Tue, 2 Apr 2019 17:23:57 +0200 (CEST) Received: by mail-pg1-f193.google.com with SMTP id 85so6746379pgc.3 for ; Tue, 02 Apr 2019 08:23:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RAWcnhNKVBXceKuUJeKnwvxh3JIqXUY8sWg5IGiiKDo=; b=idMXxf4XrMOfeoFwkbakY2o8x87rONaDgfVeIv+uwwyVQ7NcxkPTLFSmdMvvFuXWYT B2P2O7Yb47yH605vgPBvmCeI8EeVwmNL1ivGQvSBbF06exlRwx52AwQyk7uDDebhgKb3 PP8UF+Ni00lvSe8QUxJ9bLSm8cZxmoB3JiVrCYvi0M99zWtf6+AnC7uLj9loT3BJ+u7K lwjyGUN99bjx9B7Ux7oLqBAJ6ZVlWbnSluoMIdNV00zQw1B00LEy7Yb7OWxbWUwSZcic zRnhz8BTAMPpa/DE7iyXAGDHyKtQbWZ+3fH+qHuzBHgLE3ElOmjO6Xm8yUS+gRKIng+u tO4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RAWcnhNKVBXceKuUJeKnwvxh3JIqXUY8sWg5IGiiKDo=; b=ZVAPJhJGQf/5WLqcKcz+l+XcuoX7QeEqmsAJlebQCAhJRd1lVIE60RR0GD4crBCmAn XLfxiTlEhMUz5c8xwBRpiGCOYwbL1BOEgALI3ralf2jsCE+Qr3e7ZXWQVqAptFOhUBY4 NT1exiMNoIWZLCK0Ll5RVGK1TOWxAdNtxn09RUyf4mlKycfjk99tXOTLX7HCiXBofD5d amcWGOZ34oEhFjJcuvNBEjVvGMjbckZ/9JznnSfWeh0GCEVyjeyqEznaWdCnspRqLHT3 5oppUfbfpHZK3Htq63WhgRX9DSMyp1D/qxW9eJ+CY/TLBoFq1HMaglqZGTkr+nwY1gaV uJxA== X-Gm-Message-State: APjAAAX2spDSTz2rGGK0poF9sdigEeFHux8lQoWX+zdCFqzOKnqCDqZs IYZ9LyiZC/A4080tMF1QPqhB4iV6XenNIQ== X-Google-Smtp-Source: APXvYqwdp6twUtV27nDkFxsktXEEJA/nu+rmIM51VBIOIQMh7vkxIkuAds0Bx8KJfHhwy+q1Ctc2yA== X-Received: by 2002:a62:b61a:: with SMTP id j26mr12113001pff.203.1554218636689; Tue, 02 Apr 2019 08:23:56 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p6sm5302514pfd.122.2019.04.02.08.23.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 08:23:55 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 2 Apr 2019 08:23:49 -0700 Message-Id: <20190402152350.17572-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190402152350.17572-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> <20190402152350.17572-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 1/2] hexdump: whitespace cleanup X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The hexdump code obviously came from somewhere else originally. It is not formatted according to DPDK coding style. Also, drop the comment which is not useful the docbock comment is already in the rte_hexdump.h Signed-off-by: Stephen Hemminger --- v2 - keep BSD style function definition lib/librte_eal/common/eal_common_hexdump.c | 107 +++++++++------------ 1 file changed, 43 insertions(+), 64 deletions(-) diff --git a/lib/librte_eal/common/eal_common_hexdump.c b/lib/librte_eal/common/eal_common_hexdump.c index 9ca7c511c062..6af818beb3cb 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -10,82 +10,61 @@ #define LINE_LEN 128 -/**************************************************************************//** -* -* rte_hexdump - Dump out memory in a special hex dump format. -* -* DESCRIPTION -* Dump out the message buffer in a special hex dump output format with characters -* printed for each line of 16 hex values. -* -* RETURNS: N/A -* -* SEE ALSO: -*/ - void -rte_hexdump(FILE *f, const char * title, const void * buf, unsigned int len) +rte_hexdump(FILE *f, const char *title, const void *buf, unsigned int len) { - unsigned int i, out, ofs; - const unsigned char *data = buf; - char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */ + unsigned int i, out, ofs; + const unsigned char *data = buf; + char line[LINE_LEN]; /* space needed 8+16*3+3+16 == 75 */ - fprintf(f, "%s at [%p], len=%u\n", (title)? title : " Dump data", data, len); - ofs = 0; - while (ofs < len) { - /* format the line in the buffer, then use printf to output to screen */ - out = snprintf(line, LINE_LEN, "%08X:", ofs); - for (i = 0; ((ofs + i) < len) && (i < 16); i++) - out += snprintf(line+out, LINE_LEN - out, " %02X", (data[ofs+i] & 0xff)); - for(; i <= 16; i++) - out += snprintf(line+out, LINE_LEN - out, " | "); - for(i = 0; (ofs < len) && (i < 16); i++, ofs++) { - unsigned char c = data[ofs]; - if ( (c < ' ') || (c > '~')) - c = '.'; - out += snprintf(line+out, LINE_LEN - out, "%c", c); - } - fprintf(f, "%s\n", line); - } - fflush(f); -} + fprintf(f, "%s at [%p], len=%u\n", + title ? : " Dump data", data, len); + ofs = 0; + while (ofs < len) { + /* format the line in the buffer */ + out = snprintf(line, LINE_LEN, "%08X:", ofs); + for (i = 0; i < 16 && ofs + i < len; i++) + out += snprintf(line + out, LINE_LEN - out, + " %02X", (data[ofs + i] & 0xff)); + for (; i <= 16; i++) + out += snprintf(line + out, LINE_LEN - out, " | "); + + for (i = 0; ofs < len && i < 16; i++, ofs++) { + unsigned char c = data[ofs]; -/**************************************************************************//** -* -* rte_memdump - Dump out memory in hex bytes with colons. -* -* DESCRIPTION -* Dump out the message buffer in hex bytes with colons xx:xx:xx:xx:... -* -* RETURNS: N/A -* -* SEE ALSO: -*/ + if (c < ' ' || c > '~') + c = '.'; + out += snprintf(line + out, LINE_LEN - out, "%c", c); + } + fprintf(f, "%s\n", line); + } + fflush(f); +} void -rte_memdump(FILE *f, const char * title, const void * buf, unsigned int len) +rte_memdump(FILE *f, const char *title, const void *buf, unsigned int len) { - unsigned int i, out; - const unsigned char *data = buf; - char line[LINE_LEN]; + unsigned int i, out; + const unsigned char *data = buf; + char line[LINE_LEN]; - if ( title ) - fprintf(f, "%s: ", title); + if (title) + fprintf(f, "%s: ", title); - line[0] = '\0'; - for (i = 0, out = 0; i < len; i++) { - // Make sure we do not overrun the line buffer length. - if ( out >= (LINE_LEN - 4) ) { + line[0] = '\0'; + for (i = 0, out = 0; i < len; i++) { + /* Make sure we do not overrun the line buffer length. */ + if (out >= LINE_LEN - 4) { fprintf(f, "%s", line); out = 0; line[out] = '\0'; } - out += snprintf(line+out, LINE_LEN - out, "%02x%s", - (data[i] & 0xff), ((i+1) < len)? ":" : ""); - } - if ( out > 0 ) - fprintf(f, "%s", line); - fprintf(f, "\n"); + out += snprintf(line + out, LINE_LEN - out, "%02x%s", + (data[i] & 0xff), ((i + 1) < len) ? ":" : ""); + } + if (out > 0) + fprintf(f, "%s", line); + fprintf(f, "\n"); - fflush(f); + fflush(f); } From patchwork Tue Apr 2 15:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 52118 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A2FF94CA0; Tue, 2 Apr 2019 17:24:02 +0200 (CEST) Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by dpdk.org (Postfix) with ESMTP id 60716378B for ; Tue, 2 Apr 2019 17:23:59 +0200 (CEST) Received: by mail-pg1-f195.google.com with SMTP id v12so6757639pgq.1 for ; Tue, 02 Apr 2019 08:23:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=ubPA/8053IwZkL+2t2PFqCitHDhPrZZoqIxJDW1vV/Fdz+c9yz1YdotCudrLvccbm0 GJDFvSrsIL6feI7eaKvyhR98vi1ZuUBdfDI3LeWpfIQB5L3uF18Jqbjo/bKHHI0Md/m7 c4rov/UAAcybUqzMr82/zLcNKrbN93XEHSH6Elv7HYvj5YmLmNNGDXOjllX4fKzDTrbN tHlsAhoupmyYz4w5rE8An7dZzAhByzCs+uzCQ94itS1CEc0P1yo51gJ7RD3HE9O0gW4c 14IHV+1nH+H3no03IPrHbWKjuzgM85I/pwtB2hIBeA/dswVjVbCYvy4hIv//eUxRPj9k VS1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1iTJ2Ft983o/dXIRYncBU1LPb5ON3q3vZlUq5R1N/Bo=; b=gvZUNN95MWrkoJY/9cYZwlort9wtPwi3Fcqj0ijM7g9M+TdVy11nT5e1TWjy98tsag 6SWY2ILgBrW4v+7ucKKbpZBKFYhwbyvp1KoEMLJSWUdjFJ47zdqFbx/nTVgRBsCH/JpE xfebP3N6QhHsalcoR2fFh7/nsOqi1r65pa8FMEcOUjd5H4UZRpqa0ZK/TUJDsv3MND1x /L+KdX/gbSIhuQ4Rk7CMIZrzRHuCSAfZTN1dzvI6MMVOTjXZuG69N6ChNwGEn4XDhqVC NLXee4WiT/S2Dg6vAluKo1oVzIT4Yw3JZ6uG/KFBNL4GXMYCdrJ8ELmF1AYcsK3GcYO6 0hGw== X-Gm-Message-State: APjAAAXZE6e33iVv3mgLesfqs1f7Rs4+O6pxo/OmdWZ4LTQKOJot2aRL kRY7CZ3De6+ZjeTce0uMFBKVHzjbOx63VQ== X-Google-Smtp-Source: APXvYqysmkIYYJdRbvKTYIw0Sors0iw1AgXOYf7dkx0RNbZsj7UhWJYUSNQjS+5PUkzGRgNyY0FRzg== X-Received: by 2002:aa7:9095:: with SMTP id i21mr47432676pfa.134.1554218638153; Tue, 02 Apr 2019 08:23:58 -0700 (PDT) Received: from shemminger-XPS-13-9360.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p6sm5302514pfd.122.2019.04.02.08.23.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 08:23:56 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Tue, 2 Apr 2019 08:23:50 -0700 Message-Id: <20190402152350.17572-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190402152350.17572-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> <20190402152350.17572-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH v2 2/2] hexdump: align output of string X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This fixes the issue where if the length of the output is not a multiple of 16 the formatting was off. Before: 00000000: 45 00 00 1C 12 34 2C E0 40 06 B8 2E C0 A8 01 12 | E....4,.@....... 00000010: C0 A8 01 37 | | | | | | | | | | | | | ...7 After: 00000000: 45 00 00 1C 12 34 2C E0 40 06 B8 2E C0 A8 01 12 | E....4,.@....... 00000010: C0 A8 01 37 | ...7 Signed-off-by: Stephen Hemminger --- lib/librte_eal/common/eal_common_hexdump.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/eal_common_hexdump.c b/lib/librte_eal/common/eal_common_hexdump.c index 6af818beb3cb..2d2179d4114e 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -23,9 +23,16 @@ rte_hexdump(FILE *f, const char *title, const void *buf, unsigned int len) while (ofs < len) { /* format the line in the buffer */ out = snprintf(line, LINE_LEN, "%08X:", ofs); - for (i = 0; i < 16 && ofs + i < len; i++) - out += snprintf(line + out, LINE_LEN - out, + for (i = 0; i < 16; i++) { + if (ofs + i < len) + snprintf(line + out, LINE_LEN - out, " %02X", (data[ofs + i] & 0xff)); + else + strcpy(line + out, " "); + out += 3; + } + + for (; i <= 16; i++) out += snprintf(line + out, LINE_LEN - out, " | ");