iov: Factor out hexdumper
Ping!
Any issues here? Peter wanted to give this list time so it missed the last arm-devs.
Regards,
Peter
Quoted 138 lines · Peter Crosthwaite
Factor out the hexdumper functionality from iov for all to use. Useful for creating verbose debug printfery that dumps packet data.
Signed-off-by Peter Crosthwaite <[email protected]>---
changed from v10:
Added Gerd and Red Hat to (c)
reworked iov hexdumper to useiov_to_buf(Gerd Review)
changed from v9:
changed original source info in header to point to Gerds hexdump commit toiov.cMoved header prototype toqemu-common.h(MJT review)
Added brief comment in header forhexdump()include/qemu-common.h | 6 ++++++ util/Makefile.objs | 1 + util/hexdump.c | 37 +++++++++++++++++++++++++++++++++++++ util/iov.c | 36 +++++++++++------------------------- 4 files changed, 55 insertions(+), 25 deletions(-) create mode 100644 util/hexdump.cinclude/qemu-common.h +6
-0@@ -430,4 +430,10 @@ int64_t pow2floor(int64_t value);int uleb128_encode_small (uint8_t *out,uint32_t n);int uleb128_decode_small (const uint8_t *in,uint32_t *n); +/* +* Hexdump a buffer to a file. An optional string prefix is added to every line +*/ + +void hexdump (const char *buf,FILE *fp,const char *prefix,size_t size); +#endif util/Makefile.objs +1
-0@@ -8,3 +8,4 @@ util-obj-y += error.o qemu-error.o util-obj-$(CONFIG_POSIX) += compatfd.o util-obj-y += iov.o aes.o qemu-config.o qemu-sockets.o uri.o notify.o util-obj-y += qemu-option.o qemu-progress.o +util-obj-y += hexdump.outil/hexdump.c new file +37
-0@@ -0,0 +1,37 @@ +/* +* Helper to hexdump a buffer +* +* Copyright (c) 2013 Red Hat, Inc. +* Copyright (c) 2013 Gerd Hoffmann <[email protected]> +* Copyright (c) 2013 Peter Crosthwaite <[email protected]> +* 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. +*/ + +#include "qemu-common.h" + +void hexdump (const char *buf,FILE *fp,const char *prefix,size_t size) +{ +unsigned int b; + +for (b =0 ; b < size; b++) { +if ((b %16 ) ==0 ) { +fprintf (fp,"%s: %04x:" , prefix, b); + } +if ((b %4 ) ==0 ) { +fprintf (fp," " ); + } +fprintf (fp," %02x" , (unsigned char )buf[b]); +if ((b %16 ) ==15 ) { +fprintf (fp,"\n" ); + } + } +if ((b %16 ) !=0 ) { +fprintf (fp,"\n" ); + } +}util/iov.c +11
-26@@ -201,32 +201,18 @@ ssize_t iov_send_recv(int sockfd, struct iovec *iov, unsigned iov_cnt,void iov_hexdump (const struct iovec *iov,const unsigned int iov_cnt,FILE *fp,const char *prefix,size_t limit) { -unsigned int i, v, b; -uint8_t *c; - - c = iov[0 ].iov_base; -for (i =0 , v =0 , b =0 ; b < limit; i++, b++) { -if (i == iov[v].iov_len) { - i =0 ; v++; -if (v == iov_cnt) { -break ; - } - c = iov[v].iov_base; - } -if ((b %16 ) ==0 ) { -fprintf (fp,"%s: %04x:" , prefix, b); - } -if ((b %4 ) ==0 ) { -fprintf (fp," " ); - } -fprintf (fp," %02x" , c[i]); -if ((b %16 ) ==15 ) { -fprintf (fp,"\n" ); - } - } -if ((b %16 ) !=0 ) { -fprintf (fp,"\n" ); +int v; +size_t size =0 ; +char *buf; + +for (v =0 ; v < iov_cnt; v++) { + size += iov[v].iov_len; } + size = size > limit ? limit : size; + buf =g_malloc (size); +iov_to_buf (iov, iov_cnt,0 , buf, size); +hexdump (buf, fp, prefix, size); +g_free (buf); } unsigned iov_copy(struct iovec *dst_iov, unsigned int dst_iov_cnt, --1.7.0.4
Peter Maydell
Reviewed-byQuoted 4 lines · Peter Crosthwaite
Factor out the hexdumper functionality from iov for all to use. Useful for creating verbose debug printfery that dumps packet data.
Signed-off-by Peter Crosthwaite <[email protected]>
-- PMM
Peter Maydell
AppliedRe: [Qemu-devel] [PATCH v11 0/3] Xilinx Zynq PL330 support
In reply to a message not in the archiveQuoted 3 lines · Peter Crosthwaite
These patches add support for the Primcell PL330 DMA controller and add it to the Xilinx Zynq machine model. Patch 2 is the device model. Patch 3 is the machine model update. Patch 1 is a helper function for debug mode.
Thanks, applied to arm-devs.next.
(Patch 3 had a trivial conflict with the addition of the sdhci device to the xilinx board model but I just fixed it up to save you doing another round of patches.)
-- PMM
Re: [Qemu-devel] [PATCH v11 0/3] Xilinx Zynq PL330 support
Hi Peter,
Quoted 6 lines · Peter Maydell
Quoted 3 lines · Peter Crosthwaite
These patches add support for the Primcell PL330 DMA controller and add it to the Xilinx Zynq machine model. Patch 2 is the device model. Patch 3 is the machine model update. Patch 1 is a helper function for debug mode.
Quoted 6 lines
Thanks, applied to arm-devs.next.
(Patch 3 had a trivial conflict with the addition of the sdhci device to the xilinx board model but I just fixed it up to save you doing another round of patches.)
Thanks for the help,
Greatly appreciated.
Regards,
Peter
Quoted 2 lines
-- PMM