From patchwork Fri Apr 12 07:33:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 788269 Delivered-To: patch@linaro.org Received: by 2002:adf:e6ca:0:b0:346:15ad:a2a with SMTP id y10csp591401wrm; Fri, 12 Apr 2024 00:37:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUw2SB9tsC0opGItEWryvYwgIpnW9dDKDyD5/Wf3biRU9Y19+tG6PW9eo786kDwRhw1qmQBTnIpnm8GssFvmzAk X-Google-Smtp-Source: AGHT+IHrVTovnM809YuSyO1qMbTHMWTpSnXYUsjPMZ89ed+Yph1m5b5N/dqBYV8siXc1h9RhaDlm X-Received: by 2002:a05:622a:50e:b0:434:921c:3169 with SMTP id l14-20020a05622a050e00b00434921c3169mr2049665qtx.39.1712907460727; Fri, 12 Apr 2024 00:37:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1712907460; cv=none; d=google.com; s=arc-20160816; b=ihT5hrKT3wOoO3nIngYMJKVMzo817lCQ5HVUUgPc7CU6OF0aPTmoRGLpMgEqVjEQV4 hWMTX0+fLSLuAU5avPvOGnqqnwi/wruqdjZp4Yor7XG/NUs9m5auXU5+HJsLCvHVppet w5EgB2ILYu4tIy3WhjC0D9bo0lbs7xu2K6vPAs2Za8c1pSlwQz153Fm/wS5Jmd4N7xfy JcTquXETylGa3mqT4w/xw9xENVGZ0hljnxy7B93DYu7TH3uaRfmGKni7LX+niXXQjd7e b8BDueK1S5aJ4WRfy1YmYRJQCibmYyh7diODItOnqLWwtgn0zWMnyYdXTbQDM8w7rEuO vQ3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=QYzl2xtlupH583p6wNi2Q7esWD8H9kcrEe3HL6WSapw=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=hHE3Dwq0WAHGPrIx/hwbK1NsLFvXR1L3cleJ/vjOdUkyLHMp9ycz24xOGmPPq+kdvU hhnuWyXcs1f3XWjd7cNi7G7Z2nFPtdB9fEshT+2LxIBweW0n8qBrI1PlkP2jKP3Wzw88 JhlLAdTIyFo/2rdShvljrxqS8Bv+qF3Ayo18LdF9AfNsB2mYB9HS+l9ODacFL2UpB7Cf FTJ/2cCh6fkdqyZCsoSkszoG3lV4CdrQ+jHlqoqwNaiRO2nUna27hiqThjaf+LQo1Wua onNKrHo/GCfIygkPCJ7aALHKqDqIM0DW/CQx9s+rNLD5cXp1dUkifWkSgRdoHiJkAwTx Qytg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uDszS8zS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id n15-20020a05622a040f00b00434f39f0037si3241597qtx.60.2024.04.12.00.37.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 12 Apr 2024 00:37:40 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uDszS8zS; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rvBQ4-0006zO-Ql; Fri, 12 Apr 2024 03:33:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rvBQ1-0006y7-Th for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:33:53 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rvBQ0-00075H-3C for qemu-devel@nongnu.org; Fri, 12 Apr 2024 03:33:53 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1e50a04c317so3846935ad.1 for ; Fri, 12 Apr 2024 00:33:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712907231; x=1713512031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=QYzl2xtlupH583p6wNi2Q7esWD8H9kcrEe3HL6WSapw=; b=uDszS8zSHNzzM33hEt1IjGa3vNQ74URtC5Fx7HvDS3j7WfRTwarpkwGfYRULr/lr1Z vPumyb9ifl6X3LubvPWkmn5CEIf1UCo2lxl5BBwCQYA8QrF9hokpASM/w18rQnLLJlr7 eXRMfSNrUOfv7bLwKHCLJtN3FPJpVW8HFci2HSQK47qmwOnk9hyDhpBQMzuDLEi/eHrD Ba6PFXjX6uhpWrypOldioR8o8zdMENhWxRg2ou0kdmaK+rNJ/uaXosL0Fqn+xbPOw771 k9mtUCJG4T6UDnLaWMZNOOzLJ2zauLf0nljC56GmVkTpZjn1KXnogqHakVdFw+88/8B2 sKMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712907231; x=1713512031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QYzl2xtlupH583p6wNi2Q7esWD8H9kcrEe3HL6WSapw=; b=CgBeT4JyOe/M9AW+nNUlIhftAi62lxWhHaeT9W1NBiH28amsKzn5js7NpsH/ksKtZR F1sdTSgg6iHLS3Vsmo6zOsSVFCMigPpMwKlZdpzKjWK5XQPCK4nNYwM6q2x8nBR2YAuH 2tSvECOokg5p3QnBDh6F40AVu0dOx3pXnySbeQNnRha8tMA8ClGjeRSoIEwuqALNcqRX J+aioka5j9npL+290kOXYaI6rvyj6lmkggIoHl+neh0OqLmiMojGDZeqzhDrmZfnlBuH M+KoIowBANaB7L9sgbVx8HOSD8N+wwBlZ4p8PlgvkpF1h8+2yBLk+YdxXyACezb4llRM QM6w== X-Gm-Message-State: AOJu0YwtnlDb6YHrgrLIhL49GXIbE5tRvzkIerwzVv7bPm9UrQFDIQ0Z xLDdbCqsfUSE6sxP+Ob6mvwMDYqk/vC5DgTfgVUyz/GHcMi0sasxOvTZHt1Cu3W+B8TK4CjfzgU t X-Received: by 2002:a17:902:f602:b0:1e0:b2d5:5f46 with SMTP id n2-20020a170902f60200b001e0b2d55f46mr2241118plg.46.1712907230749; Fri, 12 Apr 2024 00:33:50 -0700 (PDT) Received: from stoup.. (174-21-72-5.tukw.qwest.net. [174.21.72.5]) by smtp.gmail.com with ESMTPSA id e5-20020a17090301c500b001e556734814sm2206099plh.134.2024.04.12.00.33.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 00:33:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 04/27] util/hexdump: Add unit_len and block_len to qemu_hexdump_line Date: Fri, 12 Apr 2024 00:33:23 -0700 Message-Id: <20240412073346.458116-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412073346.458116-1-richard.henderson@linaro.org> References: <20240412073346.458116-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Generalize the current 1 byte unit and 4 byte blocking within the output. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daudé --- include/qemu/cutils.h | 6 +++++- hw/virtio/vhost-vdpa.c | 2 +- util/hexdump.c | 30 +++++++++++++++++++++--------- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index 7311fb36ca..e28adedab9 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -257,12 +257,16 @@ int parse_debug_env(const char *name, int max, int initial); * @str: GString into which to append * @buf: buffer to dump * @len: number of bytes to dump + * @unit_len: add a space between every @unit_len bytes + * @block_len: add an extra space between every @block_len bytes * * Append @len bytes of @buf as hexadecimal into @str. + * Add spaces between every @unit_len and @block_len bytes. * If @str is NULL, allocate a new string and return it; * otherwise return @str. */ -GString *qemu_hexdump_line(GString *str, const void *buf, size_t len); +GString *qemu_hexdump_line(GString *str, const void *buf, size_t len, + size_t unit_len, size_t block_len); /* * Hexdump a buffer to a file. An optional string prefix is added to every line diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ab047d8ee0..911742e291 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -948,7 +948,7 @@ static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config, len = MIN(config_len - b, 16); g_string_truncate(str, 0); - qemu_hexdump_line(str, config + b, len); + qemu_hexdump_line(str, config + b, len, 1, 4); trace_vhost_vdpa_dump_config(dev, b, str->str); } } diff --git a/util/hexdump.c b/util/hexdump.c index 521e346bc6..b29326b7f2 100644 --- a/util/hexdump.c +++ b/util/hexdump.c @@ -1,5 +1,5 @@ /* - * Helper to hexdump a buffer +* Helper to hexdump a buffer * * Copyright (c) 2013 Red Hat, Inc. * Copyright (c) 2013 Gerd Hoffmann @@ -16,22 +16,34 @@ #include "qemu/osdep.h" #include "qemu/cutils.h" -GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len) +GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len, + size_t unit_len, size_t block_len) { const uint8_t *buf = vbuf; - size_t i; + size_t u, b; if (str == NULL) { /* Estimate the length of the output to avoid reallocs. */ - i = len * 3 + len / 4; - str = g_string_sized_new(i + 1); + size_t est = len * 2; + if (unit_len) { + est += len / unit_len; + } + if (block_len) { + est += len / block_len; + } + str = g_string_sized_new(est + 1); } - for (i = 0; i < len; i++) { - if (i != 0 && (i % 4) == 0) { + for (u = 0, b = 0; len; u++, b++, len--, buf++) { + if (unit_len && u == unit_len) { g_string_append_c(str, ' '); + u = 0; } - g_string_append_printf(str, " %02x", buf[i]); + if (block_len && b == block_len) { + g_string_append_c(str, ' '); + b = 0; + } + g_string_append_printf(str, "%02x", *buf); } return str; @@ -67,7 +79,7 @@ void qemu_hexdump(FILE *fp, const char *prefix, len = MIN(size - b, QEMU_HEXDUMP_LINE_BYTES); g_string_truncate(str, 0); - qemu_hexdump_line(str, bufptr + b, len); + qemu_hexdump_line(str, bufptr + b, len, 1, 4); asciidump_line(ascii, bufptr + b, len); fprintf(fp, "%s: %04zx: %-*s %s\n",