2018-11-08 16:22:26 +01: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 21:59:01 +01:00
|
|
|
uint8_t c;
|
2018-11-08 16:22:26 +01:00
|
|
|
size_t i;
|
2018-11-09 21:59:01 +01:00
|
|
|
size_t j;
|
2018-11-08 16:22:26 +01:00
|
|
|
|
2019-05-09 22:49:00 +02:00
|
|
|
assert(ptr != NULL || nbytes == 0);
|
2018-11-08 16:22:26 +01:00
|
|
|
|
|
|
|
if (nbytes == 0) {
|
|
|
|
dprintf("\t--- Empty ---\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
bytes = ptr;
|
|
|
|
|
2018-11-09 21:59:01 +01:00
|
|
|
for (i = 0 ; i < nbytes ; i += 16) {
|
2018-12-17 23:34:15 +01:00
|
|
|
dprintf(" %08x:", (int) i);
|
2018-11-09 21:59:01 +01:00
|
|
|
|
|
|
|
for (j = 0 ; i + j < nbytes && j < 16 ; j++) {
|
|
|
|
dprintf(" %02x", bytes[i + j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (j < 16) {
|
|
|
|
dprintf(" ");
|
|
|
|
j++;
|
2018-11-08 16:22:26 +01:00
|
|
|
}
|
|
|
|
|
2018-11-09 21:59:01 +01:00
|
|
|
dprintf(" ");
|
2018-11-08 16:22:26 +01:00
|
|
|
|
2018-11-09 21:59:01 +01: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 16:22:26 +01:00
|
|
|
}
|
2018-11-09 21:59:01 +01:00
|
|
|
|
|
|
|
dprintf("\n");
|
2018-11-08 16:22:26 +01: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
|