2013-03-15 20:41:58 +04:00
|
|
|
/*
|
|
|
|
* Helper to hexdump a buffer
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Red Hat, Inc.
|
|
|
|
* Copyright (c) 2013 Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
* Copyright (c) 2013 Peter Crosthwaite <peter.crosthwaite@xilinx.com>
|
|
|
|
* Copyright (c) 2013 Xilinx, Inc
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2. See
|
|
|
|
* the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
2016-01-29 20:49:55 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-03-15 20:41:58 +04:00
|
|
|
#include "qemu-common.h"
|
|
|
|
|
2020-08-22 21:09:50 +03:00
|
|
|
void qemu_hexdump(FILE *fp, const char *prefix,
|
|
|
|
const void *bufptr, size_t size)
|
2013-03-15 20:41:58 +04:00
|
|
|
{
|
2020-08-22 21:09:49 +03:00
|
|
|
const char *buf = bufptr;
|
2016-03-25 13:42:15 +03:00
|
|
|
unsigned int b, len, i, c;
|
2013-03-15 20:41:58 +04:00
|
|
|
|
2016-03-25 13:42:15 +03:00
|
|
|
for (b = 0; b < size; b += 16) {
|
|
|
|
len = size - b;
|
|
|
|
if (len > 16) {
|
|
|
|
len = 16;
|
2013-03-15 20:41:58 +04:00
|
|
|
}
|
2016-03-25 13:42:15 +03:00
|
|
|
fprintf(fp, "%s: %04x:", prefix, b);
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
if ((i % 4) == 0) {
|
|
|
|
fprintf(fp, " ");
|
|
|
|
}
|
|
|
|
if (i < len) {
|
|
|
|
fprintf(fp, " %02x", (unsigned char)buf[b + i]);
|
|
|
|
} else {
|
|
|
|
fprintf(fp, " ");
|
|
|
|
}
|
2013-03-15 20:41:58 +04:00
|
|
|
}
|
2016-03-25 13:42:15 +03:00
|
|
|
fprintf(fp, " ");
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
c = buf[b + i];
|
|
|
|
if (c < ' ' || c > '~') {
|
|
|
|
c = '.';
|
|
|
|
}
|
|
|
|
fprintf(fp, "%c", c);
|
2013-03-15 20:41:58 +04:00
|
|
|
}
|
|
|
|
fprintf(fp, "\n");
|
|
|
|
}
|
|
|
|
}
|