strace improvement patch
Below is a patch to make "strace -f" work (again) for clone()/clone2() system calls. Most of the patch is from Roland's (?) patch shipped with the strace-4.8-8 RPM (strace-4.4-clone-fixes.patch). The only changes I made are:
* defs.h: declare pid2tcb() to avoid pointer-truncation on 64-bit platforms.
* process.c: define internal_clone() if either SYS_clone or SYS_clone2 is defined.
* util.c (arg_setup) [IA64]: Make it work for syscall-stubs that have a non-empty local register partition.
(set_arg0) [IA64]: Fix it so it actually works.
(set_arg1) [IA64]: Ditto.
(setbpt): Treat SYS_clone2 like SYS_clone.
Also, I'd recommend to use gcc-3.2 for compiling strace. I encountered some strange bugs with gcc-2.96, though I did not try to track them down. With gcc-3.2, those bugs went away and strace now seems to work quite nicely (once again, that is). Oh, I only tested on 2.5.xx, though I think it should work fine on 2.4.xx as well.
Is there any reason not to integrate Roland's patch into strace? IMHO, the new approach of using CLONE_PTRACE to trace clone()/fork() is infinitely better than the old code-patching approach.
--david
Index: defs.h
=================================RCS file: /cvsroot/strace/strace/defs.h,v retrieving revision 1.34
defs.h +1 -0
@@ -371,6 +371,7 @@ extern int set_personality P((int personality)); extern char *xlookup P((struct xlat *, int)); extern struct tcb *alloctcb P((int)); +extern struct tcb *pid2tcb P((int pid)); extern void droptcb P((struct tcb *)); extern void set_sortby P((char *));
Index: process.c
=================================RCS file: /cvsroot/strace/strace/process.c,v retrieving revision 1.44
process.c +50 -4
103 lines not on this page · raw message
Index: strace.c
=================================RCS file: /cvsroot/strace/strace/strace.c,v retrieving revision 1.38
strace.c +33 -12
78 lines not on this page · raw message
Index: syscall.c
=================================RCS file: /cvsroot/strace/strace/syscall.c,v retrieving revision 1.43
syscall.c +4 -4
@@ -896,16 +896,16 @@if (upeek (pid,PT_R15 , &scno) <0 ) return -1; } +if (tcp->flags &TCB_WAITEXECVE ) { + tcp->flags &= ~TCB_WAITEXECVE ; +return 0 ; + } }else {/* syscall in progress */ if (upeek (pid,PT_R8 , &r8) <0 )return -1 ;if (upeek (pid,PT_R10 , &r10) <0 )return -1 ; - } -if (tcp->flags &TCB_WAITEXECVE ) { - tcp->flags &= ~TCB_WAITEXECVE ; -return 0 ; }#elif defined (ARM)
Index: util.c
=================================RCS file: /cvsroot/strace/strace/util.c,v retrieving revision 1.31
util.c +191 -3
218 lines not on this page · raw message