[PATCH] -e write=trace doesn't dump data after error return

J. Bruce Fields bfields at fieldses.org
Wed Mar 21 21:01:24 UTC 2007


When you provide the commandline option "-e write=fd", strace still
doesn't dump the full write data in the case where the write system call
returns an error.

Of course, the write that fails is sometimes exactly the one I wanted to
see....

So, reorganize the cases in dumpio() so that all the write-like cases
(where the io is input to the system call) are before all the read-like
cases, and only exit early in the second case.

(You could even wonder whether it makes sense to skip dumping in the
read case.  I tend to suspect the likelihood of there being interesting
data in the read buffer is small in that case, and that it's likely to
confuse the reader into thinking that the dumped data was actually
returned from the read.)

diff --git a/syscall.c b/syscall.c
index 06b10e8..781ead0 100644
--- a/syscall.c
+++ b/syscall.c
@@ -505,31 +505,10 @@ static void
 dumpio(tcp)
 struct tcb *tcp;
 {
-	if (syserror(tcp))
-		return;
 	if (tcp->u_arg[0] < 0 || tcp->u_arg[0] >= MAX_QUALS)
 		return;
+
 	switch (known_scno(tcp)) {
-	case SYS_read:
-#ifdef SYS_pread64
-	case SYS_pread64:
-#endif
-#if defined SYS_pread && SYS_pread64 != SYS_pread
-	case SYS_pread:
-#endif
-#ifdef SYS_recv
-	case SYS_recv:
-#elif defined SYS_sub_recv
-	case SYS_sub_recv:
-#endif
-#ifdef SYS_recvfrom
-	case SYS_recvfrom:
-#elif defined SYS_sub_recvfrom
-	case SYS_sub_recvfrom:
-#endif
-		if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
-			dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
-		break;
 	case SYS_write:
 #ifdef SYS_pwrite64
 	case SYS_pwrite64:
@@ -550,12 +529,6 @@ struct tcb *tcp;
 		if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
 			dumpstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
 		break;
-#ifdef SYS_readv
-        case SYS_readv:
-                if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
-                        dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
-                break;
-#endif
 #ifdef SYS_writev
         case SYS_writev:
 
@@ -564,6 +537,39 @@ struct tcb *tcp;
                 break;
 #endif
 	}
+
+	/* Don't bother dumping output if the sycall returned an error */
+	if (syserror(tcp))
+		return;
+
+	switch (known_scno(tcp)) {
+	case SYS_read:
+#ifdef SYS_pread64
+	case SYS_pread64:
+#endif
+#if defined SYS_pread && SYS_pread64 != SYS_pread
+	case SYS_pread:
+#endif
+#ifdef SYS_recv
+	case SYS_recv:
+#elif defined SYS_sub_recv
+	case SYS_sub_recv:
+#endif
+#ifdef SYS_recvfrom
+	case SYS_recvfrom:
+#elif defined SYS_sub_recvfrom
+	case SYS_sub_recvfrom:
+#endif
+		if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
+			dumpstr(tcp, tcp->u_arg[1], tcp->u_rval);
+		break;
+#ifdef SYS_readv
+        case SYS_readv:
+                if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
+                        dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
+                break;
+#endif
+	}
 }
 
 #ifndef FREEBSD




More information about the Strace-devel mailing list