diff options
author | Daniel Walton <dwalton@cumulusnetworks.com> | 2015-10-21 06:56:44 -0700 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2015-12-08 14:11:14 -0500 |
commit | c8af680df5beb613fd50c265773a6beb0f1768c9 (patch) | |
tree | e46da907fe4b493085d8e4bcb51d775cc32ef05b /lib | |
parent | 363c903435b154e989f0544d12d4ac8d50174c0b (diff) | |
download | quagga-c8af680df5beb613fd50c265773a6beb0f1768c9.tar.bz2 quagga-c8af680df5beb613fd50c265773a6beb0f1768c9.tar.xz |
lib: Add zlog_hexdump() for debugging
Signed-off-by: Daniel Walton <dwalton@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/log.c | 42 | ||||
-rw-r--r-- | lib/log.h | 2 |
2 files changed, 44 insertions, 0 deletions
@@ -1001,3 +1001,45 @@ proto_redistnum(int afi, const char *s) } return -1; } + +void +zlog_hexdump (void *mem, unsigned int len) { + unsigned long i = 0; + unsigned int j = 0; + unsigned int columns = 8; + char buf[(len * 4) + ((len/4) * 20) + 30]; + char *s = buf; + + for (i = 0; i < len + ((len % columns) ? (columns - len % columns) : 0); i++) + { + /* print offset */ + if (i % columns == 0) + s += sprintf(s, "0x%016lx: ", (unsigned long)mem + i); + + /* print hex data */ + if (i < len) + s += sprintf(s, "%02x ", 0xFF & ((char*)mem)[i]); + + /* end of block, just aligning for ASCII dump */ + else + s += sprintf(s, " "); + + /* print ASCII dump */ + if (i % columns == (columns - 1)) + { + for (j = i - (columns - 1); j <= i; j++) + { + if (j >= len) /* end of block, not really printing */ + s += sprintf(s, " "); + + else if(isprint(((char*)mem)[j])) /* printable char */ + s += sprintf(s, "%c", 0xFF & ((char*)mem)[j]); + + else /* other char */ + s += sprintf(s, "."); + } + s += sprintf(s, "\n"); + } + } + zlog_debug("\n%s", buf); +} @@ -189,6 +189,8 @@ extern void zlog_backtrace_sigsafe(int priority, void *program_counter); extern size_t quagga_timestamp(int timestamp_precision /* # subsecond digits */, char *buf, size_t buflen); +extern void zlog_hexdump(void *mem, unsigned int len); + /* structure useful for avoiding repeated rendering of the same timestamp */ struct timestamp_control { size_t len; /* length of rendered timestamp */ |