From e4be0f703ffc581c11c33bc3772eabd73a5e317e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 4 Apr 2003 18:40:57 +0000 Subject: [PATCH] Close #109729, better _dump_mem Original commit message from CVS: Close #109729, better _dump_mem --- gst/gstutils.c | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/gst/gstutils.c b/gst/gstutils.c index 3bb22d95ac..9f9c20da1a 100644 --- a/gst/gstutils.c +++ b/gst/gstutils.c @@ -208,34 +208,33 @@ gst_util_get_pointer_arg (GObject * object, const gchar * argname) * Dumps the memory block into a hex representation. Useful for debugging. */ void -gst_util_dump_mem (guchar * mem, guint size) +gst_util_dump_mem (guchar *mem, guint size) { guint i, j; + GString *string = g_string_sized_new (50); + GString *chars = g_string_sized_new (18); i = j = 0; while (i < size) { - if (j == 0) { - if (i != 0) { - guint k; + if (g_ascii_isprint (mem[i])) + g_string_append_printf (chars, "%c", mem[i]); + else + g_string_append_printf (chars, "."); - for (k = i - 16; k < i; k++) { - if (mem[k]>'a' && mem[k] < 'Z') - g_print ("%c", mem[k]); - else - g_print ("."); - } - g_print ("\n"); - } - g_print ("%08x (%p): ", i, mem+i); - j = 15; - } - else { - j--; - } - g_print ("%02x ", mem[i]); + g_string_append_printf (string, "%02x ", mem[i]); + + j++; i++; + + if (j == 16 || i == size) { + g_print ("%08x (%p): %-48.48s %-16.16s\n", i-j, mem+i-j, string->str, chars->str); + g_string_set_size (string, 0); + g_string_set_size (chars, 0); + j = 0; + } } - g_print ("\n"); + g_string_free (string, TRUE); + g_string_free (chars, TRUE); }