From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35667) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aidtd-0004X1-6U for qemu-devel@nongnu.org; Wed, 23 Mar 2016 04:12:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aidtZ-0007FQ-Vp for qemu-devel@nongnu.org; Wed, 23 Mar 2016 04:12:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aidtZ-0007FJ-O1 for qemu-devel@nongnu.org; Wed, 23 Mar 2016 04:12:01 -0400 References: <1458632497-27173-1-git-send-email-109lozanoi@gmail.com> From: Thomas Huth Message-ID: <56F24FCE.4080800@redhat.com> Date: Wed, 23 Mar 2016 09:11:58 +0100 MIME-Version: 1.0 In-Reply-To: <1458632497-27173-1-git-send-email-109lozanoi@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] util: Improved qemu_hexmap() to include an ascii dump of the buffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaac Lozano <109lozanoi@gmail.com>, qemu-devel@nongnu.org Cc: Peter Crosthwaite , Jason Wang , John Snow , Gerd Hoffmann Hi Isaac, thanks for taking care of this! Comments below... On 22.03.2016 08:41, 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. >=20 > Signed-off-by: Isaac Lozano <109lozanoi@gmail.com> > --- > net/net.c | 31 +------------------------------ > util/hexdump.c | 35 ++++++++++++++++++++++++----------- > 2 files changed, 25 insertions(+), 41 deletions(-) >=20 > diff --git a/net/net.c b/net/net.c > index 1a78edf..8d51ffb 100644 > --- a/net/net.c > +++ b/net/net.c > @@ -79,34 +79,6 @@ int default_net =3D 1; > /***********************************************************/ > /* network device redirectors */ > =20 > -#if defined(DEBUG_NET) > -static void hex_dump(FILE *f, const uint8_t *buf, int size) > -{ > - int len, i, j, c; > - > - for(i=3D0;i - len =3D size - i; > - if (len > 16) > - len =3D 16; > - fprintf(f, "%08x ", i); > - for(j=3D0;j<16;j++) { > - if (j < len) > - fprintf(f, " %02x", buf[i+j]); > - else > - fprintf(f, " "); > - } > - fprintf(f, " "); > - for(j=3D0;j - c =3D buf[i+j]; > - if (c < ' ' || c > '~') > - c =3D '.'; > - fprintf(f, "%c", c); > - } > - fprintf(f, "\n"); > - } > -} > -#endif > - > static int get_str_sep(char *buf, int buf_size, const char **pp, int s= ep) > { > const char *p, *p1; > @@ -661,8 +633,7 @@ static ssize_t qemu_send_packet_async_with_flags(Ne= tClientState *sender, > int ret; > =20 > #ifdef DEBUG_NET > - printf("qemu_send_packet_async:\n"); > - hex_dump(stdout, buf, size); > + qemu_hexdump((const char*)buf, stdout, "qemu_send_packet_async", s= ize); Since the third parameter of qemu_hexdump() is used as a prefix for each line, I'd maybe use a shorter string here instead, like "net", and keep the printf("qemu_send_packet_async:\n") in front of it. > #endif > =20 > if (sender->link_down || !sender->peer) { > diff --git a/util/hexdump.c b/util/hexdump.c > index 1d9c129..886e53c 100644 > --- a/util/hexdump.c > +++ b/util/hexdump.c > @@ -18,21 +18,34 @@ > =20 > void qemu_hexdump(const char *buf, FILE *fp, const char *prefix, size_= t size) > { > - unsigned int b; > + unsigned int b, len, i, c; > =20 > - for (b =3D 0; b < size; b++) { > - if ((b % 16) =3D=3D 0) { > - fprintf(fp, "%s: %04x:", prefix, b); > + for (b =3D 0; b < size; b +=3D 16) { > + len =3D size - b; > + if (len > 16) { > + len =3D 16; > } > - if ((b % 4) =3D=3D 0) { > - fprintf(fp, " "); > + fprintf(fp, "%s: %04x:", prefix, b); > + for (i =3D 0; i < 16; i++) { > + if ((i % 4) =3D=3D 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) =3D=3D 15) { > - fprintf(fp, "\n"); > + fprintf(fp, " "); > + for (i =3D 0; i < len; i++) { > + c =3D buf[b+i]; > + if (c < ' ' || c > '~') { > + c =3D '.'; > + } > + fprintf(fp, "%c", c); > } > - } > - if ((b % 16) !=3D 0) { > fprintf(fp, "\n"); > } > } >=20 The code looks basically fine to me, but scripts/checkpatch.pl complains about some style issues: ERROR: "(foo*)" should be "(foo *)" #59: FILE: net/net.c:636: + qemu_hexdump((const char*)buf, stdout, "qemu_send_packet_async", siz= e); ERROR: that open brace { should be on the previous line #92: FILE: util/hexdump.c:36: + else + { ERROR: else should follow close brace '}' #92: FILE: util/hexdump.c:36: + } + else ERROR: spaces required around that '+' (ctx:VxV) #102: FILE: util/hexdump.c:43: + c =3D buf[b+i]; ^ Thomas