readv/writev io dumping support
Richard Kettlewell
rkettlewell at zeus.com
Thu Jul 5 09:27:04 UTC 2001
"John Hughes" <john at Calva.COM> writes:
> A few minor nits:
>
> >diff -ruN strace-4.3.orig/syscall.c strace-4.3/syscal
>
> >+#ifdef SYS_readv
> >+ case SYS_readv:
> >+#endif
> >+ if (qual_flags[tcp->u_arg[0]] & QUAL_READ)
> >+ dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
> >+ break;
>
> The #endif should be after the break, otherwise you get an extra
> break in the switch for systems without SYS_readv/SYS_writev.
yes
> > #include <fcntl.h>
> >+#include <sys/uio.h>
> > #ifdef SUNOS4
> > #include <machine/reg.h>
>
> Should be conditional on HAVE_SYS_UIO_H, no point testing for
> it if we don't use the test.
>
> >+void
> >+dumpiov(tcp, len, addr)
> >+struct tcb * tcp;
> >+int len;
> >+char * addr;
> >+{
> >+ struct iovec *iov;
>
> The dumpiov stuff should be conditional on HAVE_SYS_UIO_H, or possibly
> HAVE_STRUCT_IOVEC (which we don't have at the moment).
Looking closer, there are more unconditional iovecs in io.c and
strace.c which should also be fixed in this way. And
net.c:printiovec() shares a lot of code with io.c:tprint_iov().
The patch appended below deals with all of the above (including the
effect of my original patch).
> The "addr" argument should be a long (cf dumpstr).
I'm don't find myself entirely convinced by this: by using pointers to
represent addresses in the traced process, strace would avoid problems
on architectures with longer-than-long pointers.
In this particular case it gets turned into an int for umoven(), but
all that means is that that needs fixing too (pointers longer than int
seems an even more likely case that pointers longer than long.)
I haven't touched on these questions in the patch below.
ttfn/rjk
diff -X strace.x -ruN strace-4.3.orig/TODO strace-4.3/TODO
--- strace-4.3.orig/TODO Mon May 1 02:53:59 2000
+++ strace-4.3/TODO Wed Jul 4 17:29:19 2001
@@ -18,7 +18,6 @@
parse long options?
count signals too with -c
treat attach, detach messages like signals
-add readv, writev to I/O dumping
add pread, pwrite to I/O dumping
add system assist for qualifiers on svr4
change printcall to getcaller and fix for linux and svr4
diff -X strace.x -ruN strace-4.3.orig/defs.h strace-4.3/defs.h
--- strace-4.3.orig/defs.h Wed Mar 28 09:05:27 2001
+++ strace-4.3/defs.h Thu Jul 5 10:13:03 2001
@@ -376,6 +376,7 @@
extern int umoven P((struct tcb *, long, int, char *));
extern int umovestr P((struct tcb *, long, int, char *));
extern int upeek P((int, long, long *));
+extern void dumpiov P((struct tcb *, int, char *));
extern void dumpstr P((struct tcb *, long, int));
extern void string_quote P((char *str));
extern void printstr P((struct tcb *, long, int));
@@ -397,6 +398,7 @@
extern void call_summary P((FILE *));
extern void fake_execve P((struct tcb *, char *, char *[], char *[]));
extern void printtv32 P((struct tcb*, long));
+extern void tprint_iov P((struct tcb *, int, char *));
#ifdef LINUX
extern int internal_clone P((struct tcb *));
diff -X strace.x -ruN strace-4.3.orig/io.c strace-4.3/io.c
--- strace-4.3.orig/io.c Thu Mar 8 14:40:06 2001
+++ strace-4.3/io.c Thu Jul 5 10:01:24 2001
@@ -33,7 +33,9 @@
#include "defs.h"
#include <fcntl.h>
+#if HAVE_SYS_UIO_H
#include <sys/uio.h>
+#endif
#ifdef HAVE_LONG_LONG_OFF_T
/*
@@ -72,6 +74,7 @@
return 0;
}
+#if HAVE_SYS_UIO_H
void
tprint_iov(tcp, len, addr)
struct tcb * tcp;
@@ -138,6 +141,7 @@
}
return 0;
}
+#endif
#if defined(SVR4)
diff -X strace.x -ruN strace-4.3.orig/net.c strace-4.3/net.c
--- strace-4.3.orig/net.c Tue Mar 27 17:47:36 2001
+++ strace-4.3/net.c Thu Jul 5 10:20:18 2001
@@ -714,38 +714,6 @@
#if HAVE_SENDMSG
static void
-printiovec(tcp, iovec, len)
-struct tcb *tcp;
-struct iovec *iovec;
-long len;
-{
- struct iovec *iov;
- int i;
-
- iov = (struct iovec *) malloc(len * sizeof *iov);
- if (iov == NULL) {
- fprintf(stderr, "No memory");
- return;
- }
- if (umoven(tcp, (long)iovec,
- len * sizeof *iov, (char *) iov) < 0) {
- tprintf("%#lx", (unsigned long)iovec);
- } else {
- tprintf("[");
- for (i = 0; i < len; i++) {
- if (i)
- tprintf(", ");
- tprintf("{");
- printstr(tcp, (long) iov[i].iov_base,
- iov[i].iov_len);
- tprintf(", %lu}", (unsigned long)iov[i].iov_len);
- }
- tprintf("]");
- }
- free((char *) iov);
-}
-
-static void
printmsghdr(tcp, addr)
struct tcb *tcp;
long addr;
@@ -760,7 +728,7 @@
printsock(tcp, (long)msg.msg_name, msg.msg_namelen);
tprintf(", msg_iov(%lu)=", (unsigned long)msg.msg_iovlen);
- printiovec(tcp, msg.msg_iov, msg.msg_iovlen);
+ tprint_iov(tcp, msg.msg_iovlen, msg.msg_iov);
#ifdef HAVE_MSG_CONTROL
tprintf(", msg_controllen=%lu", (unsigned long)msg.msg_controllen);
Binary files strace-4.3.orig/strace and strace-4.3/strace differ
diff -X strace.x -ruN strace-4.3.orig/strace.c strace-4.3/strace.c
--- strace-4.3.orig/strace.c Wed Mar 28 15:40:14 2001
+++ strace-4.3/strace.c Thu Jul 5 10:00:41 2001
@@ -51,7 +51,9 @@
#ifdef SVR4
#include <sys/stropts.h>
#ifdef HAVE_MP_PROCFS
+#ifdef HAVE_SYS_UIO_H
#include <sys/uio.h>
+#endif
#endif
#endif
diff -X strace.x -ruN strace-4.3.orig/syscall.c strace-4.3/syscall.c
--- strace-4.3.orig/syscall.c Wed Mar 28 21:29:17 2001
+++ strace-4.3/syscall.c Thu Jul 5 10:23:26 2001
@@ -417,6 +417,19 @@
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:
+
+ if (qual_flags[tcp->u_arg[0]] & QUAL_WRITE)
+ dumpiov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
+ break;
+#endif
}
}
diff -X strace.x -ruN strace-4.3.orig/util.c strace-4.3/util.c
--- strace-4.3.orig/util.c Tue Mar 27 13:17:17 2001
+++ strace-4.3/util.c Thu Jul 5 10:19:09 2001
@@ -38,6 +38,9 @@
#include <sys/user.h>
#include <sys/param.h>
#include <fcntl.h>
+#if HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
#ifdef SUNOS4
#include <machine/reg.h>
#include <a.out.h>
@@ -463,6 +466,38 @@
*s = '\0';
tprintf("%s", outstr);
}
+
+#if HAVE_SYS_UIO_H
+void
+dumpiov(tcp, len, addr)
+struct tcb * tcp;
+int len;
+char * addr;
+{
+ struct iovec *iov;
+ int i;
+
+
+ if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
+ fprintf(stderr, "dump: No memory");
+ return;
+ }
+ if (umoven(tcp, (int) addr,
+ len * sizeof *iov, (char *) iov) >= 0) {
+
+ for (i = 0; i < len; i++) {
+ /* include the buffer number to make it easy to
+ * match up the trace with the source */
+ tprintf(" * %lu bytes in buffer %d\n",
+ (unsigned long)iov[i].iov_len, i);
+ dumpstr(tcp, (long) iov[i].iov_base,
+ iov[i].iov_len);
+ }
+ }
+ free((char *) iov);
+
+}
+#endif
void
dumpstr(tcp, addr, len)
More information about the Strace-devel
mailing list