usb ioctl() in strace?

Andreas Jellinghaus aj at dungeon.inka.de
Mon Oct 21 01:04:07 UTC 2002


Hi,

what about adding usb ioctl() to strace?
would be very useful for debugging userland usb
applications (those read/write by using ioctl()'s to 
/proc/bus/usb/... files).

I only implemented the control transfer, but the
other two will be straight forward. The important
part is to make a hexdump of the buffer sent/received
available. What strace functions should be used
to do that / when to do that? 

In my patch i do a lot of things that a generic function
could do, and i always dump a hexdump. both is not desireable,
maybe you can tell me how to do it better?

Thanks,

Andreas


diff -udrNP strace-4.4.orig/Makefile.in strace-4.4/Makefile.in
--- strace-4.4.orig/Makefile.in	Fri Feb 16 23:07:01 2001
+++ strace-4.4/Makefile.in	Mon Jul  8 21:26:35 2002
@@ -54,7 +54,7 @@
 OBJ		= strace.o version.o syscall.o util.o desc.o file.o ipc.o \
 			io.o ioctl.o mem.o net.o process.o bjm.o \
 			resource.o signal.o sock.o system.o term.o time.o \
-			proc.o stream.o
+			proc.o stream.o usbdevfs.o
 
 all: strace
 
diff -udrNP strace-4.4.orig/defs.h strace-4.4/defs.h
--- strace-4.4.orig/defs.h	Sat Jul 14 00:07:44 2001
+++ strace-4.4/defs.h	Mon Jul  8 21:10:18 2002
@@ -414,6 +414,7 @@
 extern int sock_ioctl P((struct tcb *, long, long));
 extern int proc_ioctl P((struct tcb *, int, int));
 extern int stream_ioctl P((struct tcb *, int, int));
+extern int usbdevfs_ioctl P((struct tcb *, int, int));
 
 extern void tv_tv P((struct timeval *, int, int));
 extern int tv_nz P((struct timeval *));
diff -udrNP strace-4.4.orig/ioctl.c strace-4.4/ioctl.c
--- strace-4.4.orig/ioctl.c	Sun Aug 19 14:06:50 2001
+++ strace-4.4/ioctl.c	Mon Jul  8 21:27:22 2002
@@ -132,6 +132,10 @@
 	case 'S':
 		return stream_ioctl(tcp, code, arg);
 #endif /* HAVE_SYS_STREAM_H */
+#ifdef LINUX
+	case 'U':
+		return usbdevfs_ioctl(tcp,code,arg);
+#endif /* LINUX */
 	default:
 		break;
 	}
diff -udrNP strace-4.4.orig/usbdevfs.c strace-4.4/usbdevfs.c
--- strace-4.4.orig/usbdevfs.c	Thu Jan  1 01:00:00 1970
+++ strace-4.4/usbdevfs.c	Mon Jul  8 22:38:11 2002
@@ -0,0 +1,74 @@
+/* Decoder for usb device ioctls on linux. 
+ * Handling all Group "U" io controls.
+ *
+ * parts taken from usbdevice_fs.h
+ * Copyright (C) 2000 Thomas Sailer (sailer at ife.ee.ethz.ch)
+ */
+
+#include "config.h"
+
+#ifdef LINUX
+
+#define USBDEVFS_CONTROL 0
+
+#include "defs.h"
+
+struct usbdevfs_ctrltransfer {
+	u_int8_t requesttype;
+	u_int8_t request;
+	u_int8_t value;
+	u_int16_t index;
+	u_int16_t length;
+	u_int32_t timeout;	/* in milliseconds */
+	void *data;
+};
+
+
+int usbdevfs_ioctl(struct tcb *tcp, int code, int arg)
+{
+	struct usbdevfs_ctrltransfer ctrl;
+
+	if (!verbose(tcp))
+		return 0;
+
+	if (((code >> 8) & 255) != 'U')
+		return 0;
+
+	switch (code & 255) {
+	case USBDEVFS_CONTROL:
+		if (umoven(tcp, arg, sizeof(ctrl), (char *) &ctrl))
+			return 0;
+		if (entering(tcp)) {
+			if ((ctrl.requesttype & 0x80) == 0) {
+				tprintf
+				    (", {requesttype=%hhd(write), request=%hhd, value=%hd, index=%hd, length=%hd, timeout=%d}",
+				     ctrl.requesttype, ctrl.request,
+				     ctrl.value, ctrl.index, ctrl.length,
+				     ctrl.timeout);
+				if (ctrl.length > 0) {
+					tprintf("\n");
+					dumpstr(tcp, (long) ctrl.data,
+						ctrl.length);
+				}
+			}
+		} else {
+			if (ctrl.requesttype & 0x80) {
+				tprintf
+				    (", {requesttype=%hhd(read), request=%hhd, value=%hd, index=%hd, length=%hd, timeout=%d}",
+				     ctrl.requesttype, ctrl.request,
+				     ctrl.value, ctrl.index, ctrl.length,
+				     ctrl.timeout);
+				if (ctrl.length > 0) {
+					tprintf("\n");
+					dumpstr(tcp, (long) ctrl.data,
+						ctrl.length);
+				}
+			}
+		}
+
+	default:
+		return 0;
+	}
+}
+
+#endif				/* LINUX */









More information about the Strace-devel mailing list