From nobody Mon Nov 25 05:16:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1717622180; cv=none; d=zohomail.com; s=zohoarc; b=V6E21dUSusn0tLMnS6Ntf83Sij9w7FfVQGJ4iWWEDKslQKsx22pKatZsUI+EysBoXGBIwtZgxq2XHt/cGld4wJV8ne7wCsTlz6JASo/BF6apQIL+6vEQZ2iEo7qHZ256mgHzMSqLw/rIBgXOI7n7RCWbxkEL/0M0dl/d+Qp/a9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1717622180; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; b=iPvn78nRzQdCd/S6hUnY2RXG0vBerKW9oNelvo0p+Qz+mEEsvkHJi6RSGs5uiQgoTP7a6w01RdX1b49qulGGxk6Xl8eZKF+eNHs/SVKoMW2JfdXyKfmnI/ASF+8LqA1fr1ZB7zBSk5hW4AOreG4CdBHBSvTUUWJHAbIul7cyOkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717622180389173.1810876861855; Wed, 5 Jun 2024 14:16:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sExyq-0000bg-VH; Wed, 05 Jun 2024 17:15:37 -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 1sExyn-0000bA-NN for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:33 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sExyh-0003PB-8M for qemu-devel@nongnu.org; Wed, 05 Jun 2024 17:15:32 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-70260814b2dso170306b3a.1 for ; Wed, 05 Jun 2024 14:15:26 -0700 (PDT) Received: from stoup.. ([71.212.132.216]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-70242aec7d0sm9347538b3a.99.2024.06.05.14.15.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 14:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1717622125; x=1718226925; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; b=tLWVGEFcmkPuQeLPS498yUhqhZXKb4+MiiblCrqAyfRjGW4vIrd8GCxBqts6RtUw6s 2apYz6d7f8JL2Qv98PPCFU6loZdKCMC5zl6wmLcpC7q11J5/RWzWzjib2S1MJ9CU93Zm /E+M0oB9EW0W62ZgiWCvdfwTneGbZHMphzf6Y5QEW8iLhoun+NXib2VMPU6aL7dA2GNF 2RnzeDyiNqU8JaUcM2spKZVjQD76wZIKSrHZnV/cQuZVWsrF+WseFfdMj8lk75rX77f2 J3wDkSK5E15HcpRfWV5mQkTSRgLuTTkh/58RtIKPgOzdHflB90ZM6ZXv0JFF6NmM4Lfr FSCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717622125; x=1718226925; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bXrzk8wYIq+rswdQhA3YXFWLO6A516BGL94YqrvehJo=; b=KgTiFyBGw4aef3gE9RUmMK9wcKrQODOTf1lZp7L2L3OzUVkv3yW3sIyLvRiGGxRi/J ZEZsJxY/eVnszZWQS8+QFq+ozAKK1VwCAnqXBBE85SM1oreUZdBIF4rOVM8/2c6Ln81C /lgoM+Xa7FSUz9x2VU6KBiMBQoPKFAwsn+x3qus9AQj6Cr2I0bdLavZvXKWWE6uZVUey YicEG8xuqV4liHsgojZ2wzUV6JRU+zdQbdTsRCe4y0uAA9VC4C3JdLa2imkBkAK4V5zb M16o1LqqgsLVnLUo1AgucmseFSpru4Gg3NcTC5OrYq/2CcGpA5meBNbu6ACfbDwYTOEN g0vA== X-Gm-Message-State: AOJu0YxVKt5lNUgjnIqfB+GReO2jHhdvhz+5+zuWcNJUntEgsi46bzu6 KZOi4sUgTVURx+j2U4ILGc/auOphmrZUPWoUmb9VdcsVAbRm4YOY8pbCrxIXIStJImuoSkw24bT c X-Google-Smtp-Source: AGHT+IFv8vEzY1vGmI7K8azhFY/xc85oJ3OtlrbPUM/sT0bW+D0Im3e5c081hi5PC9pAW/HWKHd2Cg== X-Received: by 2002:a05:6a00:4fd4:b0:6f6:76c8:122c with SMTP id d2e1a72fcca58-703f88a3f75mr997990b3a.16.1717622124539; Wed, 05 Jun 2024 14:15:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 02/16] util/hexdump: Add unit_len and block_len to qemu_hexdump_line Date: Wed, 5 Jun 2024 14:15:07 -0700 Message-Id: <20240605211521.577094-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240605211521.577094-1-richard.henderson@linaro.org> References: <20240605211521.577094-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.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, T_SCC_BODY_TEXT_LINE=-0.01 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1717622181232100010 Generalize the current 1 byte unit and 4 byte blocking within the output. Signed-off-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20240412073346.458116-5-richard.henderson@linaro.org> --- 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 14a3285343..da15547bfb 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -287,12 +287,16 @@ int parse_debug_env(const char *name, int max, int in= itial); * @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); =20 /* * 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 419463c154..3cdaa12ed5 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -951,7 +951,7 @@ static void vhost_vdpa_dump_config(struct vhost_dev *de= v, const uint8_t *config, len =3D MIN(config_len - b, 16); =20 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" =20 -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 =3D vbuf; - size_t i; + size_t u, b; =20 if (str =3D=3D NULL) { /* Estimate the length of the output to avoid reallocs. */ - i =3D len * 3 + len / 4; - str =3D g_string_sized_new(i + 1); + size_t est =3D len * 2; + if (unit_len) { + est +=3D len / unit_len; + } + if (block_len) { + est +=3D len / block_len; + } + str =3D g_string_sized_new(est + 1); } =20 - for (i =3D 0; i < len; i++) { - if (i !=3D 0 && (i % 4) =3D=3D 0) { + for (u =3D 0, b =3D 0; len; u++, b++, len--, buf++) { + if (unit_len && u =3D=3D unit_len) { g_string_append_c(str, ' '); + u =3D 0; } - g_string_append_printf(str, " %02x", buf[i]); + if (block_len && b =3D=3D block_len) { + g_string_append_c(str, ' '); + b =3D 0; + } + g_string_append_printf(str, "%02x", *buf); } =20 return str; @@ -67,7 +79,7 @@ void qemu_hexdump(FILE *fp, const char *prefix, len =3D MIN(size - b, QEMU_HEXDUMP_LINE_BYTES); =20 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); =20 fprintf(fp, "%s: %04zx: %-*s %s\n", --=20 2.34.1