qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

util: Improved qemu_hexmap() to include an ascii dump of the buffer

qemu_hexdump() in util/hexdump.c has been changed to give also include a
ascii dump of the buffer. Also, calls to hex_dump() in net/net.c have
been replaced with calls to qemu_hexdump(). This takes care of two misc
BiteSized Tasks.

Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Isaac Lozano <109lozanoi@gmail.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>

authored by

Isaac Lozano and committed by
Jason Wang
a1555559 7acbff99

+23 -40
+1 -29
net/net.c
··· 81 81 /***********************************************************/ 82 82 /* network device redirectors */ 83 83 84 - #if defined(DEBUG_NET) 85 - static void hex_dump(FILE *f, const uint8_t *buf, int size) 86 - { 87 - int len, i, j, c; 88 - 89 - for(i=0;i<size;i+=16) { 90 - len = size - i; 91 - if (len > 16) 92 - len = 16; 93 - fprintf(f, "%08x ", i); 94 - for(j=0;j<16;j++) { 95 - if (j < len) 96 - fprintf(f, " %02x", buf[i+j]); 97 - else 98 - fprintf(f, " "); 99 - } 100 - fprintf(f, " "); 101 - for(j=0;j<len;j++) { 102 - c = buf[i+j]; 103 - if (c < ' ' || c > '~') 104 - c = '.'; 105 - fprintf(f, "%c", c); 106 - } 107 - fprintf(f, "\n"); 108 - } 109 - } 110 - #endif 111 - 112 84 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep) 113 85 { 114 86 const char *p, *p1; ··· 664 636 665 637 #ifdef DEBUG_NET 666 638 printf("qemu_send_packet_async:\n"); 667 - hex_dump(stdout, buf, size); 639 + qemu_hexdump((const char *)buf, stdout, "net", size); 668 640 #endif 669 641 670 642 if (sender->link_down || !sender->peer) {
+22 -11
util/hexdump.c
··· 18 18 19 19 void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size) 20 20 { 21 - unsigned int b; 21 + unsigned int b, len, i, c; 22 22 23 - for (b = 0; b < size; b++) { 24 - if ((b % 16) == 0) { 25 - fprintf(fp, "%s: %04x:", prefix, b); 23 + for (b = 0; b < size; b += 16) { 24 + len = size - b; 25 + if (len > 16) { 26 + len = 16; 26 27 } 27 - if ((b % 4) == 0) { 28 - fprintf(fp, " "); 28 + fprintf(fp, "%s: %04x:", prefix, b); 29 + for (i = 0; i < 16; i++) { 30 + if ((i % 4) == 0) { 31 + fprintf(fp, " "); 32 + } 33 + if (i < len) { 34 + fprintf(fp, " %02x", (unsigned char)buf[b + i]); 35 + } else { 36 + fprintf(fp, " "); 37 + } 29 38 } 30 - fprintf(fp, " %02x", (unsigned char)buf[b]); 31 - if ((b % 16) == 15) { 32 - fprintf(fp, "\n"); 39 + fprintf(fp, " "); 40 + for (i = 0; i < len; i++) { 41 + c = buf[b + i]; 42 + if (c < ' ' || c > '~') { 43 + c = '.'; 44 + } 45 + fprintf(fp, "%c", c); 33 46 } 34 - } 35 - if ((b % 16) != 0) { 36 47 fprintf(fp, "\n"); 37 48 } 38 49 }