]> granicus.if.org Git - strace/blobdiff - desc.c
2005-05-31 Dmitry V. Levin <ldv@altlinux.org>
[strace] / desc.c
diff --git a/desc.c b/desc.c
index bc86a5dfe9cece0dcfb8d2eec3db311f91cbf84d..bb30b6f0082b3b796d6b057aa917b4517a789ed1 100644 (file)
--- a/desc.c
+++ b/desc.c
@@ -40,6 +40,9 @@
 #ifdef HAVE_SYS_EPOLL_H
 #include <sys/epoll.h>
 #endif
+#ifdef HAVE_LIBAIO_H
+#include <libaio.h>
+#endif
 
 #if HAVE_LONG_LONG_OFF_T
 /*
@@ -275,16 +278,14 @@ struct tcb *tcp;
                switch (tcp->u_arg[1]) {
                case F_SETFD:
                        tprintf(", ");
-                       if (printflags(fdflags, tcp->u_arg[2]) == 0)
-                               tprintf("0");
+                       printflags(fdflags, tcp->u_arg[2], "FD_???");
                        break;
                case F_SETOWN: case F_DUPFD:
                        tprintf(", %ld", tcp->u_arg[2]);
                        break;
                case F_SETFL:
                        tprintf(", ");
-                       if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
-                               tprintf("0");
+                       printflags(openmodes, tcp->u_arg[2] + 1, "O_???");
                        break;
                case F_SETLK: case F_SETLKW:
 #ifdef F_FREESP
@@ -354,8 +355,7 @@ struct tcb *tcp;
 {
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
-               if (!printflags(flockcmds, tcp->u_arg[1]))
-                       tprintf("LOCK_???");
+               printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
        }
        return 0;
 }
@@ -421,10 +421,8 @@ int bitness;
 
        if (entering(tcp)) {
                fds = (fd_set *) malloc(fdsize);
-               if (fds == NULL) {
-                       tprintf("out of memory\n");
-                       return 0;
-               }
+               if (fds == NULL)
+                       fprintf(stderr, "out of memory\n");
                nfds = args[0];
                tprintf("%d", nfds);
                for (i = 0; i < 3; i++) {
@@ -433,7 +431,7 @@ int bitness;
                                tprintf(", NULL");
                                continue;
                        }
-                       if (!verbose(tcp)) {
+                       if (fds == NULL || !verbose(tcp)) {
                                tprintf(", %#lx", arg);
                                continue;
                        }
@@ -482,10 +480,8 @@ int bitness;
                }
 
                fds = (fd_set *) malloc(fdsize);
-               if (fds == NULL) {
-                       tprintf("out of memory\n");
-                       return 0;
-               }
+               if (fds == NULL)
+                       fprintf(stderr, "out of memory\n");
 
                outstr[0] = '\0';
                for (i = 0; i < 3; i++) {
@@ -494,7 +490,8 @@ int bitness;
 
                        tcp->auxstr = outstr;
                        arg = args[i+1];
-                       if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
+                       if (fds == NULL || !arg ||
+                           umoven(tcp, arg, fdsize, (char *) fds) < 0)
                                continue;
                        for (j = 0; j < args[0]; j++) {
                                if (FD_ISSET(j, fds)) {
@@ -523,7 +520,7 @@ int bitness;
 #ifdef LINUX
                /* This contains no useful information on SunOS.  */
                if (args[4]) {
-                       char str[20];
+                       char str[64];
 
                        if (umove(tcp, args[4], &tv) >= 0) {
 #ifdef ALPHA
@@ -639,8 +636,7 @@ print_epoll_event(ev)
 struct epoll_event *ev;
 {
        tprintf("{");
-       if (printflags(epollevents, ev->events) == 0)
-               tprintf("0");
+       printflags(epollevents, ev->events, "EPOLL???");
        /* We cannot know what format the program uses, so print u32 and u64
           which will cover every value.  */
        tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
@@ -684,22 +680,188 @@ struct tcb *tcp;
                        tprintf("{}");
                else {
 #ifdef HAVE_SYS_EPOLL_H
-                       struct epoll_event evs[tcp->u_rval];
-                       if (umove(tcp, tcp->u_arg[1], evs) == 0) {
-                               unsigned long i;
-                               tprintf("{");
-                               for (i = 0; i < tcp->u_rval; ++i) {
-                                       if (i > 0)
-                                               tprintf(", ");
-                                       print_epoll_event(&evs[i]);
+                       struct epoll_event ev, *start, *cur, *end;
+                       int failed = 0;
+
+                       tprintf("{");
+                       start = (struct epoll_event *) tcp->u_arg[1];
+                       end = start + tcp->u_rval;
+                       for (cur = start; cur < end; ++cur) {
+                               if (cur > start)
+                                       tprintf(", ");
+                               if (umove(tcp, (long) cur, &ev) == 0)
+                                       print_epoll_event(&ev);
+                               else {
+                                       tprintf("?");
+                                       failed = 1;
+                                       break;
                                }
-                               tprintf("}");
                        }
+                       tprintf("}");
+                       if (failed)
+                               tprintf(" %#lx", (long) start);
+#else
+                       tprintf("{...}");
+#endif
+               }
+               tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
+       }
+       return 0;
+}
+
+int
+sys_io_setup(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp))
+               tprintf("%ld, ", tcp->u_arg[0]);
+       else {
+               if (syserror(tcp))
+                       tprintf("0x%0lx", tcp->u_arg[1]);
+               else {
+                       unsigned long user_id;
+                       if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
+                               tprintf("{%lu}", user_id);
                        else
+                               tprintf("{...}");
+               }
+       }
+       return 0;
+}
+
+int
+sys_io_destroy(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp))
+               tprintf("%lu", tcp->u_arg[0]);
+       return 0;
+}
+
+int
+sys_io_submit(tcp)
+struct tcb *tcp;
+{
+       long nr;
+       if (entering(tcp)) {
+               tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
+               nr = tcp->u_arg[1];
+               /* and if nr is negative? */
+               if (nr == 0)
+                       tprintf("{}");
+               else {
+#ifdef HAVE_LIBAIO_H
+                       long i;
+                       struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
+
+                       for (i = 0; i < nr; i++, iocbs++) {
+                               struct iocb iocb;
+                               if (i == 0)
+                                       tprintf("{");
+                               else
+                                       tprintf(", ");
+
+                               if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
+                                   umove(tcp, (unsigned long)iocbp, &iocb)) {
+                                       tprintf("{...}");
+                                       continue;
+                               }
+                               tprintf("{%p, %u, %hu, %hu, %d}",
+                                       iocb.data, iocb.key,
+                                       iocb.aio_lio_opcode,
+                                       iocb.aio_reqprio, iocb.aio_fildes);
+                       }
+                       if (i)
+                               tprintf("}");
+#else
+                       tprintf("{...}");
+#endif
+               }
+       }
+       return 0;
+}
+
+int
+sys_io_cancel(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp)) {
+#ifdef HAVE_LIBAIO_H
+               struct iocb iocb;
+#endif
+               tprintf("%lu, ", tcp->u_arg[0]);
+#ifdef HAVE_LIBAIO_H
+               if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
+                       tprintf("{%p, %u, %hu, %hu, %d}, ",
+                               iocb.data, iocb.key,
+                               iocb.aio_lio_opcode,
+                               iocb.aio_reqprio, iocb.aio_fildes);
+               } else
+#endif
+                       tprintf("{...}, ");
+       } else {
+               if (tcp->u_rval < 0)
+                       tprintf("{...}");
+               else {
+#ifdef HAVE_LIBAIO_H
+                       struct io_event event;
+                       if (umove(tcp, tcp->u_arg[2], &event) == 0)
+                               tprintf("{%p, %p, %ld, %ld}",
+                                       event.data, event.obj,
+                                       event.res, event.res2);
+                       else 
 #endif
                                tprintf("{...}");
                }
-               tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
+       }
+       return 0;
+}
+
+int
+sys_io_getevents(tcp)
+struct tcb *tcp;
+{
+       if (entering(tcp)) {
+               tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
+                       tcp->u_arg[2]);
+       } else {
+               if (tcp->u_rval == 0) {
+                       tprintf("{}");
+               } else  {
+#ifdef HAVE_LIBAIO_H
+                       struct io_event *events = (void *)tcp->u_arg[3];
+                       long i, nr = tcp->u_rval;
+
+                       for (i = 0; i < nr; i++, events++) {
+                               struct io_event event;
+
+                               if (i == 0)
+                                       tprintf("{");
+                               else
+                                       tprintf(", ");
+
+                               if (umove(tcp, (unsigned long)events, &event) != 0) {
+                                       tprintf("{...}");
+                                       continue;
+                               }
+                               tprintf("{%p, %p, %ld, %ld}", event.data,
+                                       event.obj, event.res, event.res2);
+                       }
+                       tprintf("}, ");
+#else
+                               tprintf("{...}");
+#endif
+               }
+
+               if (tcp->u_arg[4] == 0)
+                       tprintf("NULL");
+               else {
+                       struct timespec to;
+                       if (umove(tcp, tcp->u_arg[4], &to) == 0)
+                               tprintf("{%lu, %lu}", to.tv_sec, to.tv_nsec);
+                       else
+                               tprintf("{...}");
+               }
        }
        return 0;
 }