All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer
@ 2016-03-25 10:42 Isaac Lozano
  2016-03-30  7:18 ` Thomas Huth
  2016-03-30  9:27 ` Gerd Hoffmann
  0 siblings, 2 replies; 4+ messages in thread
From: Isaac Lozano @ 2016-03-25 10:42 UTC (permalink / raw)
  To: qemu-devel
  Cc: peter.crosthwaite, jasowang, thuth, kraxel, Isaac Lozano, jsnow

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.

Signed-off-by: Isaac Lozano <109lozanoi@gmail.com>
---

v2: Fixed code-style and made debug line smaller.

 net/net.c      | 30 +-----------------------------
 util/hexdump.c | 33 ++++++++++++++++++++++-----------
 2 files changed, 23 insertions(+), 40 deletions(-)

diff --git a/net/net.c b/net/net.c
index 1a78edf..9bc9ad3 100644
--- a/net/net.c
+++ b/net/net.c
@@ -79,34 +79,6 @@ int default_net = 1;
 /***********************************************************/
 /* network device redirectors */
 
-#if defined(DEBUG_NET)
-static void hex_dump(FILE *f, const uint8_t *buf, int size)
-{
-    int len, i, j, c;
-
-    for(i=0;i<size;i+=16) {
-        len = size - i;
-        if (len > 16)
-            len = 16;
-        fprintf(f, "%08x ", i);
-        for(j=0;j<16;j++) {
-            if (j < len)
-                fprintf(f, " %02x", buf[i+j]);
-            else
-                fprintf(f, "   ");
-        }
-        fprintf(f, " ");
-        for(j=0;j<len;j++) {
-            c = buf[i+j];
-            if (c < ' ' || c > '~')
-                c = '.';
-            fprintf(f, "%c", c);
-        }
-        fprintf(f, "\n");
-    }
-}
-#endif
-
 static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
 {
     const char *p, *p1;
@@ -662,7 +634,7 @@ static ssize_t qemu_send_packet_async_with_flags(NetClientState *sender,
 
 #ifdef DEBUG_NET
     printf("qemu_send_packet_async:\n");
-    hex_dump(stdout, buf, size);
+    qemu_hexdump((const char *)buf, stdout, "net", size);
 #endif
 
     if (sender->link_down || !sender->peer) {
diff --git a/util/hexdump.c b/util/hexdump.c
index 1d9c129..f879ff0 100644
--- a/util/hexdump.c
+++ b/util/hexdump.c
@@ -18,21 +18,32 @@
 
 void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_t size)
 {
-    unsigned int b;
+    unsigned int b, len, i, c;
 
-    for (b = 0; b < size; b++) {
-        if ((b % 16) == 0) {
-            fprintf(fp, "%s: %04x:", prefix, b);
+    for (b = 0; b < size; b += 16) {
+        len = size - b;
+        if (len > 16) {
+            len = 16;
         }
-        if ((b % 4) == 0) {
-            fprintf(fp, " ");
+        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, "   ");
+            }
         }
-        fprintf(fp, " %02x", (unsigned char)buf[b]);
-        if ((b % 16) == 15) {
-            fprintf(fp, "\n");
+        fprintf(fp, " ");
+        for (i = 0; i < len; i++) {
+            c = buf[b + i];
+            if (c < ' ' || c > '~') {
+                c = '.';
+            }
+            fprintf(fp, "%c", c);
         }
-    }
-    if ((b % 16) != 0) {
         fprintf(fp, "\n");
     }
 }
-- 
2.7.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer
  2016-03-25 10:42 [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer Isaac Lozano
@ 2016-03-30  7:18 ` Thomas Huth
  2016-04-01  1:51   ` Jason Wang
  2016-03-30  9:27 ` Gerd Hoffmann
  1 sibling, 1 reply; 4+ messages in thread
From: Thomas Huth @ 2016-03-30  7:18 UTC (permalink / raw)
  To: Isaac Lozano, qemu-devel, jasowang; +Cc: Peter Crosthwaite, jsnow, kraxel


There's a typo in the title: qemu_hexmap should be qemu_hexdump/ instead.

On 25.03.2016 11:42, Isaac Lozano wrote:
> 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.
> 
> Signed-off-by: Isaac Lozano <109lozanoi@gmail.com>
> ---
> 
> v2: Fixed code-style and made debug line smaller.
> 
>  net/net.c      | 30 +-----------------------------
>  util/hexdump.c | 33 ++++++++++++++++++++++-----------
>  2 files changed, 23 insertions(+), 40 deletions(-)
[...]

Code looks fine now, thanks for taking care of this!

Reviewed-by: Thomas Huth <thuth@redhat.com>

Jason, since there is no explicit maintainer for util/hexdump.c, could
you maybe take this through your net tree, since this patch touches
net/net.c as well?

 Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer
  2016-03-25 10:42 [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer Isaac Lozano
  2016-03-30  7:18 ` Thomas Huth
@ 2016-03-30  9:27 ` Gerd Hoffmann
  1 sibling, 0 replies; 4+ messages in thread
From: Gerd Hoffmann @ 2016-03-30  9:27 UTC (permalink / raw)
  To: Isaac Lozano; +Cc: jasowang, thuth, peter.crosthwaite, jsnow, qemu-devel

On Fr, 2016-03-25 at 03:42 -0700, Isaac Lozano wrote:
> 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.
> 
> Signed-off-by: Isaac Lozano <109lozanoi@gmail.com>

Reviewed-by: Gerd Hoffmann <kraxel@redhat.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer
  2016-03-30  7:18 ` Thomas Huth
@ 2016-04-01  1:51   ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2016-04-01  1:51 UTC (permalink / raw)
  To: Thomas Huth, Isaac Lozano, qemu-devel; +Cc: Peter Crosthwaite, jsnow, kraxel



On 03/30/2016 03:18 PM, Thomas Huth wrote:
> There's a typo in the title: qemu_hexmap should be qemu_hexdump/ instead.
>
> On 25.03.2016 11:42, Isaac Lozano wrote:
>> 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.
>>
>> Signed-off-by: Isaac Lozano <109lozanoi@gmail.com>
>> ---
>>
>> v2: Fixed code-style and made debug line smaller.
>>
>>  net/net.c      | 30 +-----------------------------
>>  util/hexdump.c | 33 ++++++++++++++++++++++-----------
>>  2 files changed, 23 insertions(+), 40 deletions(-)
> [...]
>
> Code looks fine now, thanks for taking care of this!
>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
>
> Jason, since there is no explicit maintainer for util/hexdump.c, could
> you maybe take this through your net tree, since this patch touches
> net/net.c as well?

Yes, applied in -net.

Thanks

>
>  Thomas
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-04-01  1:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-25 10:42 [Qemu-devel] [PATCH v2] util: Improved qemu_hexmap() to include an ascii dump of the buffer Isaac Lozano
2016-03-30  7:18 ` Thomas Huth
2016-04-01  1:51   ` Jason Wang
2016-03-30  9:27 ` Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.