[PATCH v5 1/4] Add a enum for decoding to tprint_iov() and tprint_iov_upto().

Fabien Siron fabien.siron at epita.fr
Mon Jun 20 14:34:21 UTC 2016


This commit introduces a new type iov_decode which will be used instead
of the integer "decode" as a parameter.

* defs.h (iov_decode): New enum.
(tprint_iov, tprint_iov_upto): Change type of "decode_iov" to enum iov_decode.
* aio.c (print_iocb): Change type of "decode_iov" to enum iov_decode in
tprint_iov() call.
* keyctl.c (keyctl_instantiate_key_iov): Likewise.
* process.c (ptrace): Likewise.
* process_vm.c (process_vm_readv, process_vm_writev): Likewise.
* io.c (writev, do_pwritev, vmsplice): Likewise.
(print_iovec): Replace the condition with a switch.
(tprint_iov_upto): Change type of "decode_iov" to enum iov_decode.
(readv, do_preadv): Change type of "decode_iov" to enum iov_decode in
tprint_iov_upto() call.
* scsi.c (print_sg_io_v3_req, print_sg_io_v3_res, print_sg_io_v4_req,
print_sg_io_v4_res): Likewise.
---
 aio.c        |  4 +++-
 defs.h       | 10 ++++++++--
 io.c         | 42 +++++++++++++++++++++++++-----------------
 keyctl.c     |  2 +-
 net.c        |  3 ++-
 process.c    |  4 ++--
 process_vm.c | 10 ++++++----
 scsi.c       | 10 ++++++----
 8 files changed, 53 insertions(+), 32 deletions(-)

diff --git a/aio.c b/aio.c
index e02af7d..7580785 100644
--- a/aio.c
+++ b/aio.c
@@ -140,7 +140,9 @@ print_iocb(struct tcb *tcp, const struct iocb *cb)
 		if (iocb_is_valid(cb)) {
 			tprints(", iovec=");
 			tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
-				   cb->aio_lio_opcode == 8);
+                                  cb->aio_lio_opcode == 8
+                                  ? IOV_DECODE_STR
+                                  : IOV_DECODE_ADDR);
 		} else {
 			tprintf(", buf=%#" PRIx64 ", nbytes=%" PRIu64,
 				(uint64_t) cb->aio_buf,
diff --git a/defs.h b/defs.h
index f40842d..6f54598 100644
--- a/defs.h
+++ b/defs.h
@@ -448,6 +448,11 @@ enum sock_proto {
 };
 extern enum sock_proto get_proto_by_name(const char *);
 
+enum iov_decode {
+       IOV_DECODE_ADDR,
+       IOV_DECODE_STR
+};
+
 typedef enum {
 	CFLAG_NONE = 0,
 	CFLAG_ONLY_STATS,
@@ -665,8 +670,9 @@ extern const char *sprintsigmask_n(const char *, const void *, unsigned int);
 #define tprintsigmask_addr(prefix, mask) \
 	tprints(sprintsigmask_n((prefix), (mask), sizeof(mask)))
 extern void printsignal(int);
-extern void tprint_iov(struct tcb *, unsigned long, unsigned long, int decode_iov);
-extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long, int decode_iov, unsigned long);
+extern void tprint_iov(struct tcb *, unsigned long, unsigned long, enum iov_decode);
+extern void tprint_iov_upto(struct tcb *, unsigned long, unsigned long,
+                           enum iov_decode, unsigned long);
 extern void tprint_open_modes(unsigned int);
 extern const char *sprint_open_modes(unsigned int);
 extern void print_seccomp_filter(struct tcb *, unsigned long);
diff --git a/io.c b/io.c
index 3025486..d37d61a 100644
--- a/io.c
+++ b/io.c
@@ -58,7 +58,7 @@ SYS_FUNC(write)
 }
 
 struct print_iovec_config {
-	int decode_iov;
+	enum iov_decode decode_iov;
 	unsigned long data_size;
 };
 
@@ -79,14 +79,21 @@ print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 
 	tprints("{");
 
-	if (c->decode_iov) {
-		unsigned long len = iov[1];
-		if (len > c->data_size)
-			len = c->data_size;
-		c->data_size -= len;
-		printstr(tcp, iov[0], len);
-	} else {
-		printaddr(iov[0]);
+	switch (c->decode_iov) {
+		case IOV_DECODE_STR:
+		{
+			unsigned long len = iov[1];
+			if (len > c->data_size)
+				len = c->data_size;
+			c->data_size -= len;
+			printstr(tcp, iov[0], len);
+			break;
+		}
+		default:
+		{
+			printaddr(iov[0]);
+			break;
+		}
 	}
 
 	tprintf(", %lu}", iov[1]);
@@ -100,7 +107,7 @@ print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  */
 void
 tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr,
-		int decode_iov, unsigned long data_size)
+               enum iov_decode decode_iov, unsigned long data_size)
 {
 	unsigned long iov[2];
 	struct print_iovec_config config =
@@ -111,7 +118,8 @@ tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr,
 }
 
 void
-tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_iov)
+tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr,
+          enum iov_decode decode_iov)
 {
 	tprint_iov_upto(tcp, len, addr, decode_iov, (unsigned long) -1L);
 }
@@ -122,8 +130,8 @@ SYS_FUNC(readv)
 		printfd(tcp, tcp->u_arg[0]);
 		tprints(", ");
 	} else {
-		tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1], 1,
-				tcp->u_rval);
+               tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1],
+                               IOV_DECODE_STR, tcp->u_rval);
 		tprintf(", %lu", tcp->u_arg[2]);
 	}
 	return 0;
@@ -133,7 +141,7 @@ SYS_FUNC(writev)
 {
 	printfd(tcp, tcp->u_arg[0]);
 	tprints(", ");
-	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
 	tprintf(", %lu", tcp->u_arg[2]);
 
 	return RVAL_DECODED;
@@ -224,7 +232,7 @@ do_preadv(struct tcb *tcp, const int flags_arg)
 		printfd(tcp, tcp->u_arg[0]);
 		tprints(", ");
 	} else {
-		tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1], 1,
+		tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR,
 				tcp->u_rval);
 		tprintf(", %lu, ", tcp->u_arg[2]);
 		print_lld_from_low_high_val(tcp, 3);
@@ -251,7 +259,7 @@ do_pwritev(struct tcb *tcp, const int flags_arg)
 {
 	printfd(tcp, tcp->u_arg[0]);
 	tprints(", ");
-	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
 	tprintf(", %lu, ", tcp->u_arg[2]);
 	print_lld_from_low_high_val(tcp, 3);
 	if (flags_arg >= 0) {
@@ -318,7 +326,7 @@ SYS_FUNC(vmsplice)
 	printfd(tcp, tcp->u_arg[0]);
 	tprints(", ");
 	/* const struct iovec *iov, unsigned long nr_segs */
-	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
 	tprintf(", %lu, ", tcp->u_arg[2]);
 	/* unsigned int flags */
 	printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
diff --git a/keyctl.c b/keyctl.c
index 50d6fb4..2a09109 100644
--- a/keyctl.c
+++ b/keyctl.c
@@ -156,7 +156,7 @@ keyctl_instantiate_key_iov(struct tcb *tcp, key_serial_t id1,
 {
 	print_keyring_serial_number(id1);
 	tprints(", ");
-	tprint_iov(tcp, len, addr, 1);
+       tprint_iov(tcp, len, addr, IOV_DECODE_STR);
 	tprintf(", %lu, ", len);
 	print_keyring_serial_number(id2);
 }
diff --git a/net.c b/net.c
index 124ac8d..ee04af0 100644
--- a/net.c
+++ b/net.c
@@ -580,8 +580,9 @@ do_msghdr(struct tcb *tcp, struct msghdr *msg, unsigned long data_size)
 	printsock(tcp, (long)msg->msg_name, msg->msg_namelen);
 
 	tprintf(", msg_iov(%lu)=", (unsigned long)msg->msg_iovlen);
+
 	tprint_iov_upto(tcp, (unsigned long)msg->msg_iovlen,
-		   (unsigned long)msg->msg_iov, 1, data_size);
+                  (unsigned long)msg->msg_iov, IOV_DECODE_STR, data_size);
 
 #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
 	tprintf(", msg_controllen=%lu", (unsigned long)msg->msg_controllen);
diff --git a/process.c b/process.c
index 3aecf08..53b369a 100644
--- a/process.c
+++ b/process.c
@@ -201,7 +201,7 @@ SYS_FUNC(ptrace)
 			print_sigset_addr_len(tcp, data, addr);
 			break;
 		case PTRACE_SETREGSET:
-			tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
+                       tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
 			break;
 #ifndef IA64
 		case PTRACE_PEEKDATA:
@@ -238,7 +238,7 @@ SYS_FUNC(ptrace)
 			printnum_ulong(tcp, data);
 			break;
 		case PTRACE_GETREGSET:
-			tprint_iov(tcp, /*len:*/ 1, data, /*as string:*/ 0);
+                       tprint_iov(tcp, /*len:*/ 1, data, IOV_DECODE_ADDR);
 			break;
 		case PTRACE_GETSIGINFO:
 			printsiginfo_at(tcp, data);
diff --git a/process_vm.c b/process_vm.c
index 82e1e16..904bc3a 100644
--- a/process_vm.c
+++ b/process_vm.c
@@ -38,7 +38,8 @@ SYS_FUNC(process_vm_readv)
 		if (syserror(tcp)) {
 			printaddr(tcp->u_arg[1]);
 		} else {
-			tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+                       tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1],
+                               IOV_DECODE_STR);
 		}
 		/* arg 3: local iovcnt */
 		tprintf(", %lu, ", tcp->u_arg[2]);
@@ -46,7 +47,8 @@ SYS_FUNC(process_vm_readv)
 		if (syserror(tcp)) {
 			printaddr(tcp->u_arg[3]);
 		} else {
-			tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
+                       tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3],
+                               IOV_DECODE_ADDR);
 		}
 		/* arg 5: remote iovcnt */
 		/* arg 6: flags */
@@ -60,11 +62,11 @@ SYS_FUNC(process_vm_writev)
 	/* arg 1: pid */
 	tprintf("%ld, ", tcp->u_arg[0]);
 	/* arg 2: local iov */
-	tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
+       tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
 	/* arg 3: local iovcnt */
 	tprintf(", %lu, ", tcp->u_arg[2]);
 	/* arg 4: remote iov */
-	tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], 0);
+       tprint_iov(tcp, tcp->u_arg[4], tcp->u_arg[3], IOV_DECODE_ADDR);
 	/* arg 5: remote iovcnt */
 	/* arg 6: flags */
 	tprintf(", %lu, %lu", tcp->u_arg[4], tcp->u_arg[5]);
diff --git a/scsi.c b/scsi.c
index 83ff8fe..4dde0a6 100644
--- a/scsi.c
+++ b/scsi.c
@@ -84,7 +84,8 @@ print_sg_io_v3_req(struct tcb *tcp, const long arg)
 		tprintf(", data[%u]=", sg_io.dxfer_len);
 		if (sg_io.iovec_count)
 			tprint_iov_upto(tcp, sg_io.iovec_count,
-					(unsigned long) sg_io.dxferp, 1,
+                                       (unsigned long) sg_io.dxferp,
+                                       IOV_DECODE_STR,
 					sg_io.dxfer_len);
 		else
 			print_sg_io_buffer(tcp, (unsigned long) sg_io.dxferp,
@@ -112,7 +113,8 @@ print_sg_io_v3_res(struct tcb *tcp, const long arg)
 		tprintf(", data[%u]=", din_len);
 		if (sg_io.iovec_count)
 			tprint_iov_upto(tcp, sg_io.iovec_count,
-					(unsigned long) sg_io.dxferp, 1,
+                                       (unsigned long) sg_io.dxferp,
+                                       IOV_DECODE_STR,
 					din_len);
 		else
 			print_sg_io_buffer(tcp, (unsigned long) sg_io.dxferp,
@@ -163,7 +165,7 @@ print_sg_io_v4_req(struct tcb *tcp, const long arg)
 	tprintf(", dout[%u]=", sg_io.dout_xfer_len);
 	if (sg_io.dout_iovec_count)
 		tprint_iov_upto(tcp, sg_io.dout_iovec_count, sg_io.dout_xferp,
-				1, sg_io.dout_xfer_len);
+                               IOV_DECODE_STR, sg_io.dout_xfer_len);
 	else
 		print_sg_io_buffer(tcp, sg_io.dout_xferp, sg_io.dout_xfer_len);
 	return 1;
@@ -188,7 +190,7 @@ print_sg_io_v4_res(struct tcb *tcp, const long arg)
 	tprintf(", din[%u]=", din_len);
 	if (sg_io.din_iovec_count)
 		tprint_iov_upto(tcp, sg_io.din_iovec_count, sg_io.din_xferp,
-				1, din_len);
+                               IOV_DECODE_STR, din_len);
 	else
 		print_sg_io_buffer(tcp, sg_io.din_xferp, din_len);
 	tprintf(", driver_status=%u", sg_io.driver_status);
-- 
2.8.3





More information about the Strace-devel mailing list