]> granicus.if.org Git - strace/commitdiff
Add a enum for decoding to tprint_iov() and tprint_iov_upto()
authorFabien Siron <fabien.siron@epita.fr>
Wed, 22 Jun 2016 13:27:03 +0000 (13:27 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 22 Jun 2016 14:40:57 +0000 (14:40 +0000)
Introduce 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.
* net.c (do_msghdr): Adapt call of tprint_iov_upto().

aio.c
defs.h
io.c
keyctl.c
net.c
process.c
process_vm.c
scsi.c

diff --git a/aio.c b/aio.c
index e02af7d21feb7e47c9f2272b8c12bc572169fb2c..29562d2d6b37ed034e3747b61d750af3f1e205b8 100644 (file)
--- 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 8672f963a2eba9d3c80c513b25baf9e0d8edabab..99447e6592c567b0101be7d30e67988abd52b197 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -447,6 +447,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 3025486bed60535a62245e36388077bf1c71005b..da8b9d25fe8c83cfeb763b87b447afb897b70785 100644 (file)
--- 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;
 };
 
@@ -66,7 +66,7 @@ static bool
 print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
 {
        const unsigned long *iov;
-       unsigned long iov_buf[2];
+       unsigned long iov_buf[2], len;
        struct print_iovec_config *c = data;
 
         if (elem_size < sizeof(iov_buf)) {
@@ -79,14 +79,18 @@ 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]);
+       len = iov[1];
+
+       switch (c->decode_iov) {
+               case IOV_DECODE_STR:
+                       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 +104,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 +115,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 +127,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 +138,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 +229,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 +256,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 +323,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_???");
index 50d6fb482b07af976e75224be64c7d3682fcba52..456649e56e406546ac02809a3b8055e6d7e62a5c 100644 (file)
--- 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 51c3961a1117322186dc35e49b4d8112c5f53cd6..a55fb640d4c79050dab27b8ce38d692feb666937 100644 (file)
--- a/net.c
+++ b/net.c
@@ -582,8 +582,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);
index 3aecf088d36b1b9d89207601a02d8eea0f876070..32dcfe253739cda3eed79391ad812f5dc799739b 100644 (file)
--- 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);
index 82e1e16a1b45b5739f30d9711fa60364e8a91f5c..0a9dcd21de1e3d34a4a78e8e19f40c57d8f34a38 100644 (file)
@@ -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 83ff8fe0e9da04c9a55b70431ee88e45fb013ac3..dc51dd571cd6af16da0953cd9229255110a4c212 100644 (file)
--- 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);