2018-11-08 15:22:26 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include "hook/iobuf.h"
|
|
|
|
|
|
|
|
#include "util/dprintf.h"
|
|
|
|
#include "util/dump.h"
|
|
|
|
|
|
|
|
void dump(const void *ptr, size_t nbytes)
|
|
|
|
{
|
|
|
|
const uint8_t *bytes;
|
2018-11-09 20:59:01 +00:00
|
|
|
uint8_t c;
|
2018-11-08 15:22:26 +00:00
|
|
|
size_t i;
|
2018-11-09 20:59:01 +00:00
|
|
|
size_t j;
|
2018-11-08 15:22:26 +00:00
|
|
|
|
|
|
|
assert(ptr != NULL);
|
|
|
|
|
|
|
|
if (nbytes == 0) {
|
|
|
|
dprintf("\t--- Empty ---\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = ptr;
|
|
|
|
|
2018-11-09 20:59:01 +00:00
|
|
|
for (i = 0 ; i < nbytes ; i += 16) {
|
2018-12-17 22:34:15 +00:00
|
|
|
dprintf(" %08x:", (int) i);
|
2018-11-09 20:59:01 +00:00
|
|
|
|
|
|
|
for (j = 0 ; i + j < nbytes && j < 16 ; j++) {
|
|
|
|
dprintf(" %02x", bytes[i + j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (j < 16) {
|
|
|
|
dprintf(" ");
|
|
|
|
j++;
|
2018-11-08 15:22:26 +00:00
|
|
|
}
|
|
|
|
|
2018-11-09 20:59:01 +00:00
|
|
|
dprintf(" ");
|
2018-11-08 15:22:26 +00:00
|
|
|
|
2018-11-09 20:59:01 +00:00
|
|
|
for (j = 0 ; i + j < nbytes && j < 16 ; j++) {
|
|
|
|
c = bytes[i + j];
|
|
|
|
|
|
|
|
if (c < 0x20 || c >= 0x7F) {
|
|
|
|
c = '.';
|
|
|
|
}
|
|
|
|
|
|
|
|
dprintf("%c", c);
|
2018-11-08 15:22:26 +00:00
|
|
|
}
|
2018-11-09 20:59:01 +00:00
|
|
|
|
|
|
|
dprintf("\n");
|
2018-11-08 15:22:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dprintf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_iobuf(const struct iobuf *iobuf)
|
|
|
|
{
|
|
|
|
assert(iobuf != NULL);
|
|
|
|
assert(iobuf->bytes != NULL || iobuf->nbytes == 0);
|
|
|
|
assert(iobuf->pos <= iobuf->nbytes);
|
|
|
|
|
|
|
|
dump(iobuf->bytes, iobuf->pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump_const_iobuf(const struct const_iobuf *iobuf)
|
|
|
|
{
|
|
|
|
assert(iobuf != NULL);
|
|
|
|
assert(iobuf->bytes != NULL || iobuf->nbytes == 0);
|
|
|
|
assert(iobuf->pos <= iobuf->nbytes);
|
|
|
|
|
|
|
|
dump(&iobuf->bytes[iobuf->pos], iobuf->nbytes - iobuf->pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|