From: Dmitry V. Levin Date: Tue, 16 Feb 2016 00:44:16 +0000 (+0000) Subject: Fix abbreviated output of poll and ppoll decoders X-Git-Tag: v4.12~539 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f612ffc49fbdda0400e0f5e2fe95500f1b0d9ca;p=strace Fix abbreviated output of poll and ppoll decoders * 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. --- diff --git a/poll.c b/poll.c index 9dcaae22..f72c985e 100644 --- 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) diff --git a/tests/ppoll-v.expected b/tests/ppoll-v.expected index d07eac53..5172717c 100644 --- a/tests/ppoll-v.expected +++ b/tests/ppoll-v.expected @@ -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 .* diff --git a/tests/ppoll.expected b/tests/ppoll.expected index e6246fa2..4dfc830d 100644 --- a/tests/ppoll.expected +++ b/tests/ppoll.expected @@ -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 .* diff --git a/tests/ppoll.test b/tests/ppoll.test index 38fec235..5cd6f5d3 100755 --- a/tests/ppoll.test +++ b/tests/ppoll.test @@ -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