Skip to contentSkip to conversation

util/hexdump: Cleanup qemu_hexdump()

PATCH Applied Philippe Mathieu-Daudé 7 participants 13 messages Aug 22, 2020 – Sep 11, 2020 Networking

lore
Share & tools
lore
#0 lore raw

v2 cover util/hexdump: Cleanup qemu_hexdump()

- Pass const void* buffer
- Reorder arguments

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (2):
util/hexdump: Convert to take a void pointer argument util/hexdump: Reorder qemu_hexdump() arguments

 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/net/fsl_etsec/rings.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 24 ++++++++++++------------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 util/iov.c               |  2 +-
 10 files changed, 24 insertions(+), 21 deletions(-)
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/2 util/hexdump: Convert to take a void pointer argument

Most uses of qemu_hexdump() do not take an array of char as input, forcing use of cast. Since we can use this helper to dump any kind of buffer, use a pointer to void argument instead.

---
Since v1:
- renamed argument 'bufptr' (Peter Maydell)

---
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 12 ++++++------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 8 files changed, 16 insertions(+), 13 deletions(-)
include/qemu-common.h +2 -1
index bb9496bd80f..6834883822f 100644
@@ -138,7 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index b40c897de2c..d75a8069426 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump((char *)desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index 7035cf4eb97..c817a28decd 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump((void *)buf, stderr, "", size);
+    qemu_hexdump(buf, stderr, "", size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/sd/sd.c +1 -1
index fad9cf1ee7a..190e4cf1232 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump((const char *)response, stderr, "Response", rsplen);
+    qemu_hexdump(response, stderr, "Response", rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 417a60a2e68..09edb0d81c0 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump((char *)data, stderr, desc, len);
+    qemu_hexdump(data, stderr, desc, len);
 }
 
 /*
net/colo-compare.c +6 -6
index 2c20de1537d..550272b3baa 100644
@@ -494,9 +494,9 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
+            qemu_hexdump(ppkt->data, stderr,
                         "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
+            qemu_hexdump(spkt->data, stderr,
                         "colo-compare spkt", spkt->size);
         }
 
@@ -535,9 +535,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
@@ -578,9 +578,9 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
net/net.c +1 -1
index bbaedb3c7a6..f3e5d533fd7 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump((const char *)buf, stdout, "net", size);
+    qemu_hexdump(buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +3 -1
index f879ff0ad6b..053f05d4160 100644
@@ -16,8 +16,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size)
 {
+    const char *buf = bufptr;
     unsigned int b, len, i, c;
 
     for (b = 0; b < size; b += 16) {
Signature · 1 line
2.26.2
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] util/hexdump: Convert to take a void pointer argument

Quoted 7 lines · Philippe Mathieu-Daudé

Most uses of qemu_hexdump() do not take an array of char as input, forcing use of cast. Since we can use this helper to dump any kind of buffer, use a pointer to void argument instead.

Alistair

Quoted 153 lines

---
Since v1:
- renamed argument 'bufptr' (Peter Maydell)

---
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 12 ++++++------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 8 files changed, 16 insertions(+), 13 deletions(-)
include/qemu-common.h +2 -1
index bb9496bd80f..6834883822f 100644
@@ -138,7 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index b40c897de2c..d75a8069426 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump((char *)desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index 7035cf4eb97..c817a28decd 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump((void *)buf, stderr, "", size);
+    qemu_hexdump(buf, stderr, "", size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/sd/sd.c +1 -1
index fad9cf1ee7a..190e4cf1232 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump((const char *)response, stderr, "Response", rsplen);
+    qemu_hexdump(response, stderr, "Response", rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 417a60a2e68..09edb0d81c0 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump((char *)data, stderr, desc, len);
+    qemu_hexdump(data, stderr, desc, len);
 }
 
 /*
net/colo-compare.c +6 -6
index 2c20de1537d..550272b3baa 100644
@@ -494,9 +494,9 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
+            qemu_hexdump(ppkt->data, stderr,
                         "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
+            qemu_hexdump(spkt->data, stderr,
                         "colo-compare spkt", spkt->size);
         }
 
@@ -535,9 +535,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
@@ -578,9 +578,9 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
net/net.c +1 -1
index bbaedb3c7a6..f3e5d533fd7 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump((const char *)buf, stdout, "net", size);
+    qemu_hexdump(buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +3 -2
index f879ff0ad6b..053f05d4160 100644
@@ -16,8 +16,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size)
 {
+    const char *buf = bufptr;
     unsigned int b, len, i, c;
 
     for (b = 0; b < size; b += 16) {
--

2.26.2

Reviewed-by on v2 1/2
#3 lore raw

Re: [PATCH v2 1/2] util/hexdump: Convert to take a void pointer argument

In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

Most uses of qemu_hexdump() do not take an array of char as input, forcing use of cast. Since we can use this helper to dump any kind of buffer, use a pointer to void argument instead.

Quoted 152 lines

---
Since v1:
- renamed argument 'bufptr' (Peter Maydell)

---
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 12 ++++++------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 8 files changed, 16 insertions(+), 13 deletions(-)
include/qemu-common.h +2 -1
index bb9496bd80f..6834883822f 100644
@@ -138,7 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index b40c897de2c..d75a8069426 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump((char *)desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index 7035cf4eb97..c817a28decd 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump((void *)buf, stderr, "", size);
+    qemu_hexdump(buf, stderr, "", size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/sd/sd.c +1 -1
index fad9cf1ee7a..190e4cf1232 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump((const char *)response, stderr, "Response", rsplen);
+    qemu_hexdump(response, stderr, "Response", rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 417a60a2e68..09edb0d81c0 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump((char *)data, stderr, desc, len);
+    qemu_hexdump(data, stderr, desc, len);
 }
 
 /*
net/colo-compare.c +6 -6
index 2c20de1537d..550272b3baa 100644
@@ -494,9 +494,9 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
+            qemu_hexdump(ppkt->data, stderr,
                         "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
+            qemu_hexdump(spkt->data, stderr,
                         "colo-compare spkt", spkt->size);
         }
 
@@ -535,9 +535,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
@@ -578,9 +578,9 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
net/net.c +1 -1
index bbaedb3c7a6..f3e5d533fd7 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump((const char *)buf, stdout, "net", size);
+    qemu_hexdump(buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +3 -1
index f879ff0ad6b..053f05d4160 100644
@@ -16,8 +16,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size)
 {
+    const char *buf = bufptr;
     unsigned int b, len, i, c;
 
     for (b = 0; b < size; b += 16) {
Signature · 1 line
2.26.2
Reviewed-by on v2 1/2
#4 lore raw

Re: [PATCH v2 1/2] util/hexdump: Convert to take a void pointer argument

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé <[email protected]> 于2020年8月23日周日 上午2:11写道:

Most uses of qemu_hexdump() do not take an array of char as input, forcing use of cast. Since we can use this helper to dump any kind of buffer, use a pointer to void argument instead.

Quoted 153 lines

---
Since v1:
- renamed argument 'bufptr' (Peter Maydell)

---
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 12 ++++++------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 8 files changed, 16 insertions(+), 13 deletions(-)
include/qemu-common.h +2 -1
index bb9496bd80f..6834883822f 100644
@@ -138,7 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index b40c897de2c..d75a8069426 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump((char *)desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index 7035cf4eb97..c817a28decd 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump((void *)buf, stderr, "", size);
+    qemu_hexdump(buf, stderr, "", size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/sd/sd.c +1 -1
index fad9cf1ee7a..190e4cf1232 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump((const char *)response, stderr, "Response", rsplen);
+    qemu_hexdump(response, stderr, "Response", rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 417a60a2e68..09edb0d81c0 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump((char *)data, stderr, desc, len);
+    qemu_hexdump(data, stderr, desc, len);
 }
 
 /*
net/colo-compare.c +6 -6
index 2c20de1537d..550272b3baa 100644
@@ -494,9 +494,9 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
+            qemu_hexdump(ppkt->data, stderr,
                         "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
+            qemu_hexdump(spkt->data, stderr,
                         "colo-compare spkt", spkt->size);
         }
 
@@ -535,9 +535,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
@@ -578,9 +578,9 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
net/net.c +1 -1
index bbaedb3c7a6..f3e5d533fd7 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump((const char *)buf, stdout, "net", size);
+    qemu_hexdump(buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +3 -2
index f879ff0ad6b..053f05d4160 100644
@@ -16,8 +16,10 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size)
 {
+    const char *buf = bufptr;
     unsigned int b, len, i, c;
 
     for (b = 0; b < size; b += 16) {
--

2.26.2

#5 lore raw

Re: [PATCH v2 1/2] util/hexdump: Convert to take a void pointer argument

In reply to Philippe Mathieu-Daudé

Le 22/08/2020 à 20:09, Philippe Mathieu-Daudé a écrit :

Quoted 146 lines

Most uses of qemu_hexdump() do not take an array of char as input, forcing use of cast. Since we can use this helper to dump any kind of buffer, use a pointer to void argument instead.

---
Since v1:
- renamed argument 'bufptr' (Peter Maydell)

---
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 12 ++++++------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 8 files changed, 16 insertions(+), 13 deletions(-)
include/qemu-common.h +2 -1
index bb9496bd80f..6834883822f 100644
@@ -138,7 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size);
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index b40c897de2c..d75a8069426 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump((char *)desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index 7035cf4eb97..c817a28decd 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump((void *)buf, stderr, "", size);
+    qemu_hexdump(buf, stderr, "", size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/sd/sd.c +1 -1
index fad9cf1ee7a..190e4cf1232 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump((const char *)response, stderr, "Response", rsplen);
+    qemu_hexdump(response, stderr, "Response", rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 417a60a2e68..09edb0d81c0 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump((char *)data, stderr, desc, len);
+    qemu_hexdump(data, stderr, desc, len);
 }
 
 /*
net/colo-compare.c +6 -6
index 2c20de1537d..550272b3baa 100644
@@ -494,9 +494,9 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr,
+            qemu_hexdump(ppkt->data, stderr,
                         "colo-compare ppkt", ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr,
+            qemu_hexdump(spkt->data, stderr,
                         "colo-compare spkt", spkt->size);
         }
 
@@ -535,9 +535,9 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
@@ -578,9 +578,9 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump((char *)ppkt->data, stderr, "colo-compare pri pkt",
+            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
                          ppkt->size);
-            qemu_hexdump((char *)spkt->data, stderr, "colo-compare sec pkt",
+            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
                          spkt->size);
         }
         return -1;
net/net.c +1 -1
index bbaedb3c7a6..f3e5d533fd7 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump((const char *)buf, stdout, "net", size);
+    qemu_hexdump(buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +0 -0
index f879ff0ad6b..053f05d4160 100644
@@ -16,8 +16,10 @@
 #include "qemu/osdep.h"

util/hexdump.c line 25

Quoted 10 lines
util/hexdump.c +3 -1
 #include "qemu-common.h"
 
-void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
+void qemu_hexdump(const void *bufptr, FILE *fp,
+                  const char *prefix, size_t size)
 {
+    const char *buf = bufptr;
     unsigned int b, len, i, c;
 
     for (b = 0; b < size; b += 16) {

Applied to my trivial-patches branch.

Thanks,
Laurent

#6 lore raw

PATCH v2 2/2 util/hexdump: Reorder qemu_hexdump() arguments

In reply to Philippe Mathieu-Daudé

qemu_hexdump()'s pointer to the buffer and length of the buffer are closely related arguments but are widely separated in the argument list order (also, the format of <stdio.h> function prototypes is usually to have the FILE* argument coming first).

Reorder the arguments as "fp, prefix, buf, size" which is more logical.

---
 include/qemu-common.h    |  4 ++--
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/net/fsl_etsec/rings.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 24 ++++++++++++------------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 ++--
 util/iov.c               |  2 +-
 10 files changed, 23 insertions(+), 23 deletions(-)
include/qemu-common.h +2 -2
index 6834883822f..9cfd62669bf 100644
@@ -138,8 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size);
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index d75a8069426..967548abd31 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(stdout, "", desc, sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index c817a28decd..c5edb25dc9f 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump(buf, stderr, "", size);
+    qemu_hexdump(stderr, "", buf, size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/net/fsl_etsec/rings.c +1 -1
index 337a55fc957..628648a9c37 100644
@@ -269,7 +269,7 @@ static void process_tx_bd(eTSEC         *etsec,
 
 #if defined(HEX_DUMP)
             qemu_log("eTSEC Send packet size:%d\n", etsec->tx_buffer_len);
-            qemu_hexdump(etsec->tx_buffer, stderr, "", etsec->tx_buffer_len);
+            qemu_hexdump(stderr, "", etsec->tx_buffer, etsec->tx_buffer_len);
 #endif  /* ETSEC_RING_DEBUG */
 
             if (etsec->first_bd.flags & BD_TX_TOEUN) {
hw/sd/sd.c +1 -1
index 190e4cf1232..6508939b1f4 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump(response, stderr, "Response", rsplen);
+    qemu_hexdump(stderr, "Response", response, rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 09edb0d81c0..48f38d33912 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump(data, stderr, desc, len);
+    qemu_hexdump(stderr, desc, data, len);
 }
 
 /*
net/colo-compare.c +12 -12
index 550272b3baa..4a5ed642e9a 100644
@@ -494,10 +494,10 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump(spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
+            qemu_hexdump(stderr, "colo-compare ppkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare spkt",
+                         spkt->data, spkt->size);
         }
 
         colo_compare_inconsistency_notify(s);
@@ -535,10 +535,10 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
@@ -578,10 +578,10 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
net/net.c +1 -1
index f3e5d533fd7..7a2a0fb5ac6 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump(buf, stdout, "net", size);
+    qemu_hexdump(stdout, "net", buf, size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +2 -2
index 053f05d4160..0b4662e701d 100644
@@ -16,8 +16,8 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size)
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size)
 {
     const char *buf = bufptr;
     unsigned int b, len, i, c;
util/iov.c +1 -1
index 45ef3043eec..ae61d696aae 100644
@@ -237,7 +237,7 @@ void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
     size = size > limit ? limit : size;
     buf = g_malloc(size);
     iov_to_buf(iov, iov_cnt, 0, buf, size);
-    qemu_hexdump(buf, fp, prefix, size);
+    qemu_hexdump(fp, prefix, buf, size);
     g_free(buf);
 }
 
Signature · 1 line
2.26.2
Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] util/hexdump: Reorder qemu_hexdump() arguments

Quoted 11 lines · Philippe Mathieu-Daudé

qemu_hexdump()'s pointer to the buffer and length of the buffer are closely related arguments but are widely separated in the argument list order (also, the format of <stdio.h> function prototypes is usually to have the FILE* argument coming first).

Reorder the arguments as "fp, prefix, buf, size" which is more logical.

Quoted 186 lines
---
 include/qemu-common.h    |  4 ++--
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/net/fsl_etsec/rings.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 24 ++++++++++++------------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 ++--
 util/iov.c               |  2 +-
 10 files changed, 23 insertions(+), 23 deletions(-)
include/qemu-common.h +2 -2
index 6834883822f..9cfd62669bf 100644
@@ -138,8 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size);
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index d75a8069426..967548abd31 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(stdout, "", desc, sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index c817a28decd..c5edb25dc9f 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump(buf, stderr, "", size);
+    qemu_hexdump(stderr, "", buf, size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/net/fsl_etsec/rings.c +1 -1
index 337a55fc957..628648a9c37 100644
@@ -269,7 +269,7 @@ static void process_tx_bd(eTSEC         *etsec,
 
 #if defined(HEX_DUMP)
             qemu_log("eTSEC Send packet size:%d\n", etsec->tx_buffer_len);
-            qemu_hexdump(etsec->tx_buffer, stderr, "", etsec->tx_buffer_len);
+            qemu_hexdump(stderr, "", etsec->tx_buffer, etsec->tx_buffer_len);
 #endif  /* ETSEC_RING_DEBUG */
 
             if (etsec->first_bd.flags & BD_TX_TOEUN) {
hw/sd/sd.c +1 -1
index 190e4cf1232..6508939b1f4 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump(response, stderr, "Response", rsplen);
+    qemu_hexdump(stderr, "Response", response, rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 09edb0d81c0..48f38d33912 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump(data, stderr, desc, len);
+    qemu_hexdump(stderr, desc, data, len);
 }
 
 /*
net/colo-compare.c +12 -12
index 550272b3baa..4a5ed642e9a 100644
@@ -494,10 +494,10 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump(spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
+            qemu_hexdump(stderr, "colo-compare ppkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare spkt",
+                         spkt->data, spkt->size);
         }
 
         colo_compare_inconsistency_notify(s);
@@ -535,10 +535,10 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
@@ -578,10 +578,10 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
net/net.c +1 -1
index f3e5d533fd7..7a2a0fb5ac6 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump(buf, stdout, "net", size);
+    qemu_hexdump(stdout, "net", buf, size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +2 -2
index 053f05d4160..0b4662e701d 100644
@@ -16,8 +16,8 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size)
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size)
 {
     const char *buf = bufptr;
     unsigned int b, len, i, c;
util/iov.c +1 -1
index 45ef3043eec..ae61d696aae 100644
@@ -237,7 +237,7 @@ void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
     size = size > limit ? limit : size;
     buf = g_malloc(size);
     iov_to_buf(iov, iov_cnt, 0, buf, size);
-    qemu_hexdump(buf, fp, prefix, size);
+    qemu_hexdump(fp, prefix, buf, size);
     g_free(buf);
 }
 
Signature · 1 line
2.26.2
#8 lore raw

Re: [PATCH v2 2/2] util/hexdump: Reorder qemu_hexdump() arguments

In reply to Philippe Mathieu-Daudé

Le 22/08/2020 à 20:09, Philippe Mathieu-Daudé a écrit :

Quoted 187 lines

qemu_hexdump()'s pointer to the buffer and length of the buffer are closely related arguments but are widely separated in the argument list order (also, the format of <stdio.h> function prototypes is usually to have the FILE* argument coming first).

Reorder the arguments as "fp, prefix, buf, size" which is more logical.

---
 include/qemu-common.h    |  4 ++--
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/net/fsl_etsec/rings.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 24 ++++++++++++------------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 ++--
 util/iov.c               |  2 +-
 10 files changed, 23 insertions(+), 23 deletions(-)
include/qemu-common.h +2 -2
index 6834883822f..9cfd62669bf 100644
@@ -138,8 +138,8 @@ int os_parse_cmd_args(int index, const char *optarg);
  * Hexdump a buffer to a file. An optional string prefix is added to every line
  */
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size);
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size);
 
 /*
  * helper to parse debug environment variables
hw/dma/xlnx_dpdma.c +1 -1
index d75a8069426..967548abd31 100644
@@ -388,7 +388,7 @@ static void xlnx_dpdma_dump_descriptor(DPDMADescriptor *desc)
 {
     if (DEBUG_DPDMA) {
         qemu_log("DUMP DESCRIPTOR:\n");
-        qemu_hexdump(desc, stdout, "", sizeof(DPDMADescriptor));
+        qemu_hexdump(stdout, "", desc, sizeof(DPDMADescriptor));
     }
 }
 
hw/net/fsl_etsec/etsec.c +1 -1
index c817a28decd..c5edb25dc9f 100644
@@ -357,7 +357,7 @@ static ssize_t etsec_receive(NetClientState *nc,
 
 #if defined(HEX_DUMP)
     fprintf(stderr, "%s receive size:%zd\n", nc->name, size);
-    qemu_hexdump(buf, stderr, "", size);
+    qemu_hexdump(stderr, "", buf, size);
 #endif
     /* Flush is unnecessary as are already in receiving path */
     etsec->need_flush = false;
hw/net/fsl_etsec/rings.c +1 -1
index 337a55fc957..628648a9c37 100644
@@ -269,7 +269,7 @@ static void process_tx_bd(eTSEC         *etsec,
 
 #if defined(HEX_DUMP)
             qemu_log("eTSEC Send packet size:%d\n", etsec->tx_buffer_len);
-            qemu_hexdump(etsec->tx_buffer, stderr, "", etsec->tx_buffer_len);
+            qemu_hexdump(stderr, "", etsec->tx_buffer, etsec->tx_buffer_len);
 #endif  /* ETSEC_RING_DEBUG */
 
             if (etsec->first_bd.flags & BD_TX_TOEUN) {
hw/sd/sd.c +1 -1
index 190e4cf1232..6508939b1f4 100644
@@ -1781,7 +1781,7 @@ send_response:
     }
 
 #ifdef DEBUG_SD
-    qemu_hexdump(response, stderr, "Response", rsplen);
+    qemu_hexdump(stderr, "Response", response, rsplen);
 #endif
 
     return rsplen;
hw/usb/redirect.c +1 -1
index 09edb0d81c0..48f38d33912 100644
@@ -240,7 +240,7 @@ static void usbredir_log_data(USBRedirDevice *dev, const char *desc,
     if (dev->debug < usbredirparser_debug_data) {
         return;
     }
-    qemu_hexdump(data, stderr, desc, len);
+    qemu_hexdump(stderr, desc, data, len);
 }
 
 /*
net/colo-compare.c +12 -12
index 550272b3baa..4a5ed642e9a 100644
@@ -494,10 +494,10 @@ sec:
         g_queue_push_head(&conn->secondary_list, spkt);
 
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr,
-                        "colo-compare ppkt", ppkt->size);
-            qemu_hexdump(spkt->data, stderr,
-                        "colo-compare spkt", spkt->size);
+            qemu_hexdump(stderr, "colo-compare ppkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare spkt",
+                         spkt->data, spkt->size);
         }
 
         colo_compare_inconsistency_notify(s);
@@ -535,10 +535,10 @@ static int colo_packet_compare_udp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_udp_miscompare("primary pkt size", ppkt->size);
         trace_colo_compare_udp_miscompare("Secondary pkt size", spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
@@ -578,10 +578,10 @@ static int colo_packet_compare_icmp(Packet *spkt, Packet *ppkt)
         trace_colo_compare_icmp_miscompare("Secondary pkt size",
                                            spkt->size);
         if (trace_event_get_state_backends(TRACE_COLO_COMPARE_MISCOMPARE)) {
-            qemu_hexdump(ppkt->data, stderr, "colo-compare pri pkt",
-                         ppkt->size);
-            qemu_hexdump(spkt->data, stderr, "colo-compare sec pkt",
-                         spkt->size);
+            qemu_hexdump(stderr, "colo-compare pri pkt",
+                         ppkt->data, ppkt->size);
+            qemu_hexdump(stderr, "colo-compare sec pkt",
+                         spkt->data, spkt->size);
         }
         return -1;
     } else {
net/net.c +1 -1
index f3e5d533fd7..7a2a0fb5ac6 100644
@@ -636,7 +636,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    qemu_hexdump(buf, stdout, "net", size);
+    qemu_hexdump(stdout, "net", buf, size);
 #endif
 
     if (sender->link_down || !sender->peer) {
util/hexdump.c +2 -2
index 053f05d4160..0b4662e701d 100644
@@ -16,8 +16,8 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-void qemu_hexdump(const void *bufptr, FILE *fp,
-                  const char *prefix, size_t size)
+void qemu_hexdump(FILE *fp, const char *prefix,
+                  const void *bufptr, size_t size)
 {
     const char *buf = bufptr;
     unsigned int b, len, i, c;
util/iov.c +0 -0
index 45ef3043eec..ae61d696aae 100644

util/iov.c void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt, · line 243

Quoted 8 lines
util/iov.c +1 -1
@@ -237,7 +237,7 @@ void iov_hexdump(const struct iovec *iov, const unsigned int iov_cnt,
     size = size > limit ? limit : size;
     buf = g_malloc(size);
     iov_to_buf(iov, iov_cnt, 0, buf, size);
-    qemu_hexdump(buf, fp, prefix, size);
+    qemu_hexdump(fp, prefix, buf, size);
     g_free(buf);
 }
 

Applied to my trivial-patches branch.

Thanks,
Laurent

Reviewed-by on the v2 series
#9 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

- Pass const void* buffer
- Reorder arguments

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (2):
util/hexdump: Convert to take a void pointer argument util/hexdump: Reorder qemu_hexdump() arguments

Quoted 16 lines
 include/qemu-common.h    |  3 ++-
 hw/dma/xlnx_dpdma.c      |  2 +-
 hw/net/fsl_etsec/etsec.c |  2 +-
 hw/net/fsl_etsec/rings.c |  2 +-
 hw/sd/sd.c               |  2 +-
 hw/usb/redirect.c        |  2 +-
 net/colo-compare.c       | 24 ++++++++++++------------
 net/net.c                |  2 +-
 util/hexdump.c           |  4 +++-
 util/iov.c               |  2 +-
 10 files changed, 24 insertions(+), 21 deletions(-)
Signature · 1 line
2.26.2
Applied
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 9 lines · Philippe Mathieu-Daudé

- Pass const void* buffer
- Reorder arguments

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (2):
util/hexdump: Convert to take a void pointer argument util/hexdump: Reorder qemu_hexdump() arguments

Quoted 12 lines
  include/qemu-common.h    |  3 ++-
  hw/dma/xlnx_dpdma.c      |  2 +-
  hw/net/fsl_etsec/etsec.c |  2 +-
  hw/net/fsl_etsec/rings.c |  2 +-
  hw/sd/sd.c               |  2 +-
  hw/usb/redirect.c        |  2 +-
  net/colo-compare.c       | 24 ++++++++++++------------
  net/net.c                |  2 +-
  util/hexdump.c           |  4 +++-
  util/iov.c               |  2 +-
  10 files changed, 24 insertions(+), 21 deletions(-)

Applied.

Thanks

#11 lore raw
In reply to Philippe Mathieu-Daudé

Hi Laurent,

Quoted 8 lines · Philippe Mathieu-Daudé

- Pass const void* buffer
- Reorder arguments

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (2):
util/hexdump: Convert to take a void pointer argument util/hexdump: Reorder qemu_hexdump() arguments

This series is fully reviewed, can it go via
your qemu-trivial tree?

Thanks,

Phil.

#12 lore raw

Le 11/09/2020 à 16:35, Philippe Mathieu-Daudé a écrit :

Quoted 6 lines

Hi Laurent,

Quoted 3 lines · Philippe Mathieu-Daudé

- Pass const void* buffer
- Reorder arguments

Quoted 8 lines
Quoted 5 lines

Supersedes: <[email protected]>

Philippe Mathieu-Daudé (2):
util/hexdump: Convert to take a void pointer argument util/hexdump: Reorder qemu_hexdump() arguments

This series is fully reviewed, can it go via
your qemu-trivial tree?

Done.

Thanks,
Laurent