From patchwork Thu Aug 16 15:31:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 43748 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 A07E04C8E; Thu, 16 Aug 2018 17:31:15 +0200 (CEST) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) by dpdk.org (Postfix) with ESMTP id 1AEA844C3 for ; Thu, 16 Aug 2018 17:31:11 +0200 (CEST) Received: by mail-pl0-f53.google.com with SMTP id j8-v6so2252956pll.12 for ; Thu, 16 Aug 2018 08:31:11 -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=G0voSONN9Y5814Lch2Ae9ypVIgYuPXbeatiJyfWKl1E=; b=tzQhlNvsTe78pyPEr7HNZ8Y8dGIUehOW6MWVt5e0+FQr9TQ3F1iWIDJdDzMfirCHh9 GO/0FN10z+kwUkLcjpRFTu3yP4YfGy6Gn1mfNJoJ4jo1T5ttygvFGg53Q/zfYB8BDKn7 tbtt8VUeRrJjargyzdAu1ecGfkZ7YW8/Grgi+WS91t8oGsWbd+f6cKh/qg4ot15Oa4AX bZFrhZ7SPyem/51FHfglxF/HOqm1HVhhNmbPEj4TX8aWuX87K1lN72WXuGKEi4a/npIz wVUaOIBtDrxHwNY+NSl/Nh7mhoyAhq8n3Tf15N2tvIuRwCYUPJcV4WTJIsDhvb+6wUju 3+Og== 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=G0voSONN9Y5814Lch2Ae9ypVIgYuPXbeatiJyfWKl1E=; b=Wkuy4cqPdwjn2SkBwenyH3SP7n83zAwdcOZAo8wD/HU2hOZ/RL51m+yUQJO0wjSs/g 9FE68hPJ7040yJELDQ9PGk32v0RwPzwYhcfhh+DgSeW9PD9CGAUssATL9582Mk3GLZ3O Pc/W9oTe3lIGLhYhz4JxRLlQO9EzmeXxRpjQOf+Ku/Z4e4trt4br/8tdDCvEhnMGCP6c e+p4G2f8uFb7u+RyJP3VUGSPvktPf2mctzmNQ9AiphagRH56SE//WhFgQWvDclfT7I98 XWQPIb+gEcrY33NIKJacLtVo+sqsCxVcIejCh4lA+4yHntwVZhCR78TEXI0rMScahIoi J2hg== X-Gm-Message-State: AOUpUlEpEe0/DjFMlk8vh9bJnV58rYZj4eJr4h+GqrgB5T8m75w1Pm9T e4kHNyHYjcd/3wESfjbPz2QBY0i80gv0og== X-Google-Smtp-Source: AA+uWPxeqpHSa3PjiwWHqDqY/q5WQbbYCoFKmMIqq3EMZ62A+Jxj01NNGhSugGoHKOQstVv7dI8/fA== X-Received: by 2002:a17:902:bd82:: with SMTP id q2-v6mr29508579pls.178.1534433470807; Thu, 16 Aug 2018 08:31:10 -0700 (PDT) Received: from xeon-e3.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p5-v6sm30002104pfn.57.2018.08.16.08.31.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 08:31:09 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 16 Aug 2018 08:31:05 -0700 Message-Id: <20180816153106.7608-2-stephen@networkplumber.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816153106.7608-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 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 --- lib/librte_eal/common/eal_common_hexdump.c | 109 ++++++++------------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/lib/librte_eal/common/eal_common_hexdump.c b/lib/librte_eal/common/eal_common_hexdump.c index 9ca7c511c062..980cf73ac337 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -10,82 +10,59 @@ #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) +void 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) ? 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) +void 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 Thu Aug 16 15:31:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 43749 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 5E6C64C99; Thu, 16 Aug 2018 17:31:17 +0200 (CEST) Received: from mail-pl0-f53.google.com (mail-pl0-f53.google.com [209.85.160.53]) by dpdk.org (Postfix) with ESMTP id 94BE94C88 for ; Thu, 16 Aug 2018 17:31:13 +0200 (CEST) Received: by mail-pl0-f53.google.com with SMTP id j8-v6so2252990pll.12 for ; Thu, 16 Aug 2018 08:31:13 -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=HyKyCEA9ATAGcXoMz8nXarftmoz8HvVZtolopxyL8io=; b=FGk1vWDIKevZXf4YcDSrwo0d7n5ogwil9bqP+8xVXimXwqVOJiV4Vu05Ph6xzwTxtf 9yxS0ZCn+PdPkbRBGIfN+DXOjCderZaJnAnPJQvVjW9Min9zN7y3K+P6cM0PintD19xe p8meHT09OHWZGsDf83op31T1gdd9LeL5UtWMkyt781p/6rY7Q6kD/C0Cmb3HD8hfrmpi QPZM9g+FD4iow5F29SuC8VRlLYMkfRhbT37pHkEkJ0SZ16WNW1EdIJSL+/Ng4EMI8yHr DDaqCj5ygrg8YfV3By+Lmn41Ny/8Fv7C1N4OFZy7oH6RY3HgOyPr0iFLvSfQ0VhXwXSG oM+A== 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=HyKyCEA9ATAGcXoMz8nXarftmoz8HvVZtolopxyL8io=; b=K7aHrvB6IAQhyG3ac7QLU0kDgX6ncKIdEHAk3BwkJ6VtHYhtQfcsRtAYnVAL4AUeU4 868tGz0v7l3mRfshPP7HDcpvXXIK5UTMLsjjGQ9zNyZXldKdDIDmHH9EXj5rx/gA6rYw Z6TWGGVCtfOmV03MrlFJNOCZznOIBBBF74GkFP6K/evRwQEDoz44DGR89FxgMIiHaxr/ 29TxetK2//b2dwJ4M+RYAglyFET5X7iYHQK6g6KhwsvDIK7i7YcDAOXPuPUl6TGLu7xy /93h0TiNA1ec7v5MJI/Cek+jhSA3jlzvf1XeeM3G2d77FTmU7P81kcyH1BGx1nbkQnR+ UY1Q== X-Gm-Message-State: AOUpUlGhezmifsw82F8TishtbS/Lq2wBOvE1oa6qqu8r0Lk6VKKLUg/6 l0KMU7OT/BB32dUa7g3gxPkcUvdzgoPqzg== X-Google-Smtp-Source: AA+uWPx0QPtp5BQZOOW+qTwHlvQPkZNqy4vsF69LBSEFhdhkpyS8VmLKEDK6K67hmd881t/iR1HqEg== X-Received: by 2002:a17:902:561:: with SMTP id 88-v6mr29191430plf.320.1534433472334; Thu, 16 Aug 2018 08:31:12 -0700 (PDT) Received: from xeon-e3.lan (204-195-22-127.wavecable.com. [204.195.22.127]) by smtp.gmail.com with ESMTPSA id p5-v6sm30002104pfn.57.2018.08.16.08.31.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Aug 2018 08:31:11 -0700 (PDT) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Thu, 16 Aug 2018 08:31:06 -0700 Message-Id: <20180816153106.7608-3-stephen@networkplumber.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180816153106.7608-1-stephen@networkplumber.org> References: <20180816153106.7608-1-stephen@networkplumber.org> Subject: [dpdk-dev] [PATCH 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 980cf73ac337..19c2d86c693e 100644 --- a/lib/librte_eal/common/eal_common_hexdump.c +++ b/lib/librte_eal/common/eal_common_hexdump.c @@ -22,9 +22,16 @@ void 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, " | ");