qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "Alistair Francis" <alistair.francis@xilinx.com>,
	"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
	"Isaac Lozano" <109lozanoi@gmail.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Eduardo Habkost" <ehabkost@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 01/11] util/cutils: add qemu_hexbuf_strdup(), yet another hexdump()
Date: Wed, 13 Dec 2017 17:44:26 -0300	[thread overview]
Message-ID: <20171213204436.5379-2-f4bug@amsat.org> (raw)
In-Reply-To: <20171213204436.5379-1-f4bug@amsat.org>

This will be helpful for tracing() API.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
"yet", so probably duplicating a better way to do it :|

 include/qemu/cutils.h |  3 +++
 util/hexdump.c        | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
index f0878eaafa..2966cd5d64 100644
--- a/include/qemu/cutils.h
+++ b/include/qemu/cutils.h
@@ -164,4 +164,7 @@ bool test_buffer_is_zero_next_accel(void);
 int uleb128_encode_small(uint8_t *out, uint32_t n);
 int uleb128_decode_small(const uint8_t *in, uint32_t *n);
 
+char *qemu_hexbuf_strdup(const void *buf, size_t size,
+                         const char *str_hdr, const char *desc_if_empty);
+
 #endif
diff --git a/util/hexdump.c b/util/hexdump.c
index f879ff0ad6..cabf33b2b8 100644
--- a/util/hexdump.c
+++ b/util/hexdump.c
@@ -15,6 +15,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu-common.h"
+#include "qemu/cutils.h"
 
 void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
 {
@@ -47,3 +48,21 @@ void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
         fprintf(fp, "\n");
     }
 }
+
+char *qemu_hexbuf_strdup(const void *buf, size_t size,
+                         const char *str_hdr, const char *desc_if_empty)
+{
+    const uint8_t *u8 = (uint8_t *)buf;
+    GString *s;
+    int i;
+
+    if (!size) {
+        return g_strdup(desc_if_empty ? desc_if_empty : "");
+    }
+    s = g_string_new(str_hdr ? : "");
+    for (i = 0; i < size; i++) {
+        g_string_append_printf(s, "%02x ", u8[i]);
+    }
+
+    return g_string_free(s, FALSE);
+}
-- 
2.15.1

  reply	other threads:[~2017-12-13 20:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 20:44 [Qemu-devel] [PATCH 00/11] QOM'ify SDBus, housekeeping Philippe Mathieu-Daudé
2017-12-13 20:44 ` Philippe Mathieu-Daudé [this message]
2017-12-13 20:44 ` [Qemu-devel] [PATCH 02/11] bcm2835_peripherals: move GPIO 'sdbus' property link from init() -> realize() Philippe Mathieu-Daudé
2017-12-15  0:58   ` Alistair Francis
2017-12-13 20:44 ` [Qemu-devel] [PATCH 03/11] sdbus: add trace events Philippe Mathieu-Daudé
2017-12-13 20:44 ` [Qemu-devel] [PATCH 04/11] sdbus: add sdbus_create_bus() to replace qbus_create_inplace() Philippe Mathieu-Daudé
2017-12-15  1:02   ` Alistair Francis
2017-12-13 20:44 ` [Qemu-devel] [PATCH 05/11] sdbus: add sdbus_create_slave() Philippe Mathieu-Daudé
2017-12-15  1:03   ` Alistair Francis
2017-12-13 20:44 ` [Qemu-devel] [PATCH 06/11] sdbus: rename SDCardClass -> SDSlaveClass Philippe Mathieu-Daudé
2017-12-15  1:04   ` Alistair Francis
2017-12-13 20:44 ` [Qemu-devel] [PATCH 07/11] sdbus: add a SD_BUS_SLAVE interface Philippe Mathieu-Daudé
2017-12-20 17:31   ` Philippe Mathieu-Daudé
2017-12-13 20:44 ` [Qemu-devel] [PATCH 08/11] sdbus: add a SD_BUS_MASTER interface Philippe Mathieu-Daudé
2017-12-13 20:44 ` [Qemu-devel] [PATCH 09/11] sdhci: implement the " Philippe Mathieu-Daudé
2017-12-13 20:44 ` [Qemu-devel] [PATCH 10/11] hw/sd/pxa2xx: " Philippe Mathieu-Daudé
2017-12-13 20:44 ` [Qemu-devel] [PATCH 11/11] hw/arm/xilinx_zynq: use sdbus_create_slave() to name the different SD busses Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171213204436.5379-2-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=109lozanoi@gmail.com \
    --cc=alistair.francis@xilinx.com \
    --cc=armbru@redhat.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).