]> granicus.if.org Git - strace/commitdiff
Fix abbreviated output of poll and ppoll decoders
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 16 Feb 2016 00:44:16 +0000 (00:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 16 Feb 2016 01:35:36 +0000 (01:35 +0000)
* poll.c (decode_poll_entering, decode_poll_exiting): Fix corner cases
of abbreviated output.
* tests/ppoll-v.expected: Update.
* tests/ppoll.expected: Update.
* tests/ppoll.test: Update.

poll.c
tests/ppoll-v.expected
tests/ppoll.expected
tests/ppoll.test

diff --git a/poll.c b/poll.c
index 9dcaae22491b3cc14f81c84a926a75a395735d57..f72c985e2ab0dac9f994137188b1aa68a9b32ab9 100644 (file)
--- a/poll.c
+++ b/poll.c
@@ -51,7 +51,8 @@ decode_poll_entering(struct tcb *tcp)
        const unsigned long size = sizeof(fds) * nfds;
        const unsigned long start = tcp->u_arg[0];
        const unsigned long end = start + size;
-       unsigned long cur, abbrev_end;
+       const unsigned long max_printed =
+               abbrev(tcp) ? max_strlen : (unsigned int) -1;
 
        if (!verbose(tcp) || !start || !nfds ||
            size / sizeof(fds) != nfds || end < start) {
@@ -60,32 +61,31 @@ decode_poll_entering(struct tcb *tcp)
                return 0;
        }
 
-       if (abbrev(tcp)) {
-               abbrev_end = start + max_strlen * sizeof(fds);
-               if (abbrev_end < start)
-                       abbrev_end = end;
-       } else {
-               abbrev_end = end;
-       }
-
-       if (start >= abbrev_end || umove(tcp, start, &fds) < 0) {
+       if (umove(tcp, start, &fds) < 0) {
                printaddr(start);
                tprintf(", %u, ", nfds);
                return 0;
        }
 
        tprints("[");
-       print_pollfd(tcp, &fds);
-       for (cur = start + sizeof(fds); cur < end; cur += sizeof(fds)) {
-               tprints(", ");
-               if (cur >= abbrev_end) {
-                       tprints("...");
-                       break;
-               }
-               if (umove_or_printaddr(tcp, cur, &fds))
-                       break;
+       if (max_printed) {
+               unsigned long printed = 1;
+               unsigned long cur = start + sizeof(fds);
+
                print_pollfd(tcp, &fds);
+               for (; cur < end; ++printed, cur += sizeof(fds)) {
+                       tprints(", ");
+                       if (printed >= max_printed) {
+                               tprints("...");
+                               break;
+                       }
+                       if (umove_or_printaddr(tcp, cur, &fds))
+                               break;
+                       print_pollfd(tcp, &fds);
 
+               }
+       } else {
+               tprints("...");
        }
        tprintf("], %u, ", nfds);
 
@@ -100,7 +100,9 @@ decode_poll_exiting(struct tcb *tcp, const long pts)
        const unsigned long size = sizeof(fds) * nfds;
        const unsigned long start = tcp->u_arg[0];
        const unsigned long end = start + size;
-       unsigned long cur, abbrev_end;
+       const unsigned long max_printed =
+               abbrev(tcp) ? max_strlen : (unsigned int) -1;
+       unsigned long printed, cur;
 
        static char outstr[1024];
        char *outptr;
@@ -116,17 +118,10 @@ decode_poll_exiting(struct tcb *tcp, const long pts)
        if (!verbose(tcp) || !start || !nfds ||
            size / sizeof(fds) != nfds || end < start)
                return 0;
-       if (abbrev(tcp)) {
-               abbrev_end = start + max_strlen * sizeof(fds);
-               if (abbrev_end < start)
-                       abbrev_end = end;
-       } else {
-               abbrev_end = end;
-       }
 
        outptr = outstr;
 
-       for (cur = start; cur < end; cur += sizeof(fds)) {
+       for (printed = 0, cur = start; cur < end; cur += sizeof(fds)) {
                if (umove(tcp, cur, &fds) < 0) {
                        if (outptr == outstr)
                                *outptr++ = '[';
@@ -141,7 +136,7 @@ decode_poll_exiting(struct tcb *tcp, const long pts)
                        *outptr++ = '[';
                else
                        outptr = stpcpy(outptr, ", ");
-               if (cur >= abbrev_end) {
+               if (printed >= max_printed) {
                        outptr = stpcpy(outptr, "...");
                        break;
                }
@@ -160,6 +155,7 @@ decode_poll_exiting(struct tcb *tcp, const long pts)
                outptr = stpcpy(outptr, fdstr);
                outptr = stpcpy(outptr, flagstr);
                *outptr++ = '}';
+               ++printed;
        }
 
        if (outptr != outstr)
index d07eac539e60708f53e7d45baca92836a1b5896f..5172717c8e1a5c23c2da2c8265689742b6551140 100644 (file)
@@ -1,3 +1,3 @@
-ppoll\(\[\{fd=0, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=1, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}, \{fd=3, events=POLLIN\|POLLPRI\}, \{fd=4, events=POLLOUT\}\], 4, \{42, 999999999\}, \[(USR2 CHLD|CHLD USR2)\], (4|8|16)\) += 2 \(\[\{fd=1, revents=POLLOUT(\|POLLWRNORM)?\}, \{fd=4, revents=POLLOUT\}\], left \{42, 9[0-9]{8}\}\)
-ppoll\(\[\{fd=1, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=0, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}\], 2, \{0, 999\}, ~\[HUP KILL STOP[^]]*\], (4|8|16)\) += 0 \(Timeout\)
-ppoll\(NULL, 42, NULL, NULL, (4|8|16)\) += -1 EFAULT .*
+ppoll\(\[\{fd=0, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=1, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}, \{fd=3, events=POLLIN\|POLLPRI\}, \{fd=4, events=POLLOUT\}\], 4, \{42, 999999999\}, \[(USR2 CHLD|CHLD USR2)\], (4|8|16)\) = 2 \(\[\{fd=1, revents=POLLOUT(\|POLLWRNORM)?\}, \{fd=4, revents=POLLOUT\}\], left \{42, 9[0-9]{8}\}\)
+ppoll\(\[\{fd=1, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=0, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}\], 2, \{0, 999\}, ~\[HUP KILL STOP[^]]*\], (4|8|16)\) = 0 \(Timeout\)
+ppoll\(NULL, 42, NULL, NULL, (4|8|16)\) = -1 EFAULT .*
index e6246fa2f831e9f74b6d6f947387fb74ca158f2e..4dfc830d00089c5961bf1b11f73916a7ca27ad89 100644 (file)
@@ -1,3 +1,3 @@
-ppoll\(\[\{fd=0, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=1, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}, \.\.\.\], 4, \{42, 999999999\}, \[(USR2 CHLD|CHLD USR2)\], (4|8|16)\) += 2 \(\[\{fd=1, revents=POLLOUT(\|POLLWRNORM)?\}, \.\.\.\], left \{42, 9[0-9]{8}\}\)
-ppoll\(\[\{fd=1, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=0, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}\], 2, \{0, 999\}, ~\[HUP KILL STOP[^]]*\], (4|8|16)\) += 0 \(Timeout\)
-ppoll\(NULL, 42, NULL, NULL, (4|8|16)\) += -1 EFAULT .*
+ppoll\(\[\{fd=0, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=1, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}, \.\.\.\], 4, \{42, 999999999\}, \[(USR2 CHLD|CHLD USR2)\], (4|8|16)\) = 2 \(\[\{fd=1, revents=POLLOUT(\|POLLWRNORM)?\}, \{fd=4, revents=POLLOUT\}\], left \{42, 9[0-9]{8}\}\)
+ppoll\(\[\{fd=1, events=POLLIN\|POLLPRI\|POLLRDNORM\|POLLRDBAND\}, \{fd=0, events=POLLOUT(\|POLLWRNORM)?\|POLLWRBAND\}\], 2, \{0, 999\}, ~\[HUP KILL STOP[^]]*\], (4|8|16)\) = 0 \(Timeout\)
+ppoll\(NULL, 42, NULL, NULL, (4|8|16)\) = -1 EFAULT .*
index 38fec2359c7bba2e61439b2619b5b9eac1ac581d..5cd6f5d387330640e0d1f47608c66926ad569cc9 100755 (executable)
@@ -5,9 +5,9 @@
 . "${srcdir=.}/init.sh"
 
 run_prog
-run_strace -s2 -e ppoll $args
+run_strace -a30 -s2 -e ppoll $args
 match_grep
-run_strace -v -s2 -e ppoll $args
+run_strace -a30 -v -s2 -e ppoll $args
 match_grep "$LOG" "$srcdir/${ME_%.test}-v.expected"
 
 exit 0