@@ -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
@@ -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);
+}
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(+)