[SSI] openssi/strace process.c, 1.1.15.1, 1.1.15.2 util.c, 1.1.15.1, 1.1.15.2

Roger Tsang <[email protected]> Tue, 14 Sep 2010 03:12:37 +0000
Newsgroups gmane.linux.cluster.ssic.cvs
Message-ID <[email protected]>
Update of /cvsroot/ssic-linux/openssi/strace
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv19498

Modified Files:
      Tag: CENTOS
	process.c util.c 
Log Message:
Merge from strace-4.5.16-1.el4_8.11.src.rpm


Index: util.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/strace/Attic/util.c,v
retrieving revision 1.1.15.1
retrieving revision 1.1.15.2
diff -u -d -r1.1.15.1 -r1.1.15.2
--- util.c	4 Jul 2010 20:18:15 -0000	1.1.15.1
+++ util.c	14 Sep 2010 03:12:35 -0000	1.1.15.2
@@ -241,6 +241,62 @@
 }
 
 /*
+ * Generic ptrace wrapper which tracks ESRCH errors
+ * by setting tcp->ptrace_errno to ESRCH.
+ *
+ * We assume that ESRCH indicates likely process death (SIGKILL?),
+ * modulo bugs where process somehow ended up not stopped.
+ * Unfortunately kernel uses ESRCH for that case too. Oh well.
+ *
+ * Currently used by upeek() only.
+ * TODO: use this in all other ptrace() calls while decoding.
+ */
+long
+do_ptrace(int request, struct tcb *tcp, void *addr, void *data)
+{
+	long l;
+
+	errno = 0;
+	l = ptrace(request, tcp->pid, addr, data);
+	/* Non-ESRCH errors might be our invalid reg/mem accesses,
+	 * we do not trip on them */
+	if (errno == ESRCH) {
+		tcp->ptrace_errno = ESRCH;
+	}
+	return l;
+}
+
+/*
+ * Used when we want to unblock stopped traced process.
+ * Should be only used with PTRACE_CONT, PTRACE_DETACH and PTRACE_SYSCALL.
+ * Returns 0 on success or if error was ESRCH
+ * (presumably process was killed while we talk to it).
+ * Otherwise prints error message and returns -1.
+ */
+int
+ptrace_restart(int op, struct tcb *tcp, int sig)
+{
+	int err;
+	const char *msg;
+
+	errno = 0;
+	ptrace(op, tcp->pid, (void *) 1, (void *) (long) sig);
+	err = errno;
+	if (!err || err == ESRCH)
+		return 0;
+
+	tcp->ptrace_errno = err;
+	msg = "SYSCALL";
+	if (op == PTRACE_CONT)
+		msg = "CONT";
+	if (op == PTRACE_DETACH)
+		msg = "DETACH";
+	fprintf(stderr, "strace: ptrace(PTRACE_%s,1,%d): %s\n",
+			msg, sig, strerror(err));
+	return -1;
+}
+
+/*
  * Print entry in struct xlat table, if there.
  */
 void
@@ -694,7 +750,7 @@
 				return 0;
 			}
 			/* But if not started, we had a bogus address. */
-			if (addr != 0 && errno != EIO)
+			if (addr != 0 && errno != EIO && errno != ESRCH)
 				perror("ptrace: umoven");
 			return -1;
 		}
@@ -710,7 +766,7 @@
 				/* Ran into 'end of memory' - stupid "printpath" */
 				return 0;
 			}
-			if (addr != 0 && errno != EIO)
+			if (addr != 0 && errno != EIO && errno != ESRCH)
 				perror("ptrace: umoven");
 			return -1;
 		}
@@ -736,7 +792,8 @@
 		errno = 0;
 		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
 		if (errno) {
-			perror("umoven");
+			if (errno != ESRCH)
+				perror("umoven");
 			return -1;
 		}
 		memcpy(laddr, &u.x[n], m = MIN(sizeof(long) - n, len));
@@ -746,7 +803,8 @@
 		errno = 0;
 		u.val = ptrace(PTRACE_PEEKDATA, pid, (char *) addr, 0);
 		if (errno) {
-			perror("umoven");
+			if (errno != ESRCH)
+				perror("umoven");
 			return -1;
 		}
 		memcpy(laddr, u.x, m = MIN(sizeof(long), len));
@@ -760,8 +818,10 @@
 		n = MIN(n, ((addr + PAGSIZ) & PAGMASK) - addr);
 		if (ptrace(PTRACE_READDATA, pid,
 			   (char *) addr, len, laddr) < 0) {
-			perror("umoven: ptrace(PTRACE_READDATA, ...)");
-			abort();
+			if (errno != ESRCH) {
+				perror("umoven: ptrace(PTRACE_READDATA, ...)");
+				abort();
+			}
 			return -1;
 		}
 		len -= n;
@@ -845,7 +905,7 @@
 				/* Ran into 'end of memory' - stupid "printpath" */
 				return 0;
 			}
-			if (addr != 0 && errno != EIO)
+			if (addr != 0 && errno != EIO && errno != ESRCH)
 				perror("umovestr");
 			return -1;
 		}
@@ -864,7 +924,7 @@
 				/* Ran into 'end of memory' - stupid "printpath" */
 				return 0;
 			}
-			if (addr != 0 && errno != EIO)
+			if (addr != 0 && errno != EIO && errno != ESRCH)
 				perror("umovestr");
 			return -1;
 		}
@@ -982,8 +1042,8 @@
 #ifndef USE_PROCFS
 
 int
-upeek(pid, off, res)
-int pid;
+upeek(tcp, off, res)
+struct tcb *tcp;
 long off;
 long *res;
 {
@@ -1014,11 +1074,13 @@
 	}
 #endif /* SUNOS4_KERNEL_ARCH_KLUDGE */
 	errno = 0;
-	val = ptrace(PTRACE_PEEKUSER, pid, (char *) off, 0);
+	val = do_ptrace(PTRACE_PEEKUSER, tcp, (char *) off, 0);
 	if (val == -1 && errno) {
-		char buf[60];
-		sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)",pid,off);
-		perror(buf);
+		if (errno != ESRCH) {
+			char buf[60];
+			sprintf(buf,"upeek: ptrace(PTRACE_PEEKUSER,%d,%lu,0)", tcp->pid, off);
+			perror(buf);
+		}
 		return -1;
 	}
 	*res = val;
@@ -1036,28 +1098,28 @@
 #ifdef LINUX
 	long pc;
 #if defined(I386)
-	if (upeek(tcp->pid, 4*EIP, &pc) < 0)
+	if (upeek(tcp, 4*EIP, &pc) < 0)
 		return -1;
 #elif defined(X86_64)
-	if (upeek(tcp->pid, 8*RIP, &pc) < 0)
+	if (upeek(tcp, 8*RIP, &pc) < 0)
 		return -1;
 #elif defined(IA64)
-	if (upeek(tcp->pid, PT_B0, &pc) < 0)
+	if (upeek(tcp, PT_B0, &pc) < 0)
 		return -1;
 #elif defined(ARM)
-	if (upeek(tcp->pid, 4*15, &pc) < 0)
+	if (upeek(tcp, 4*15, &pc) < 0)
 		return -1;
 #elif defined(POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0)
 		return -1;
 #elif defined(M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
+	if (upeek(tcp, 4*PT_PC, &pc) < 0)
 		return -1;
 #elif defined(ALPHA)
-	if (upeek(tcp->pid, REG_PC, &pc) < 0)
+	if (upeek(tcp, REG_PC, &pc) < 0)
 		return -1;
 #elif defined(MIPS)
- 	if (upeek(tcp->pid, REG_EPC, &pc) < 0)
+ 	if (upeek(tcp, REG_EPC, &pc) < 0)
  		return -1;
 #elif defined(SPARC) || defined(SPARC64)
 	struct regs regs;
@@ -1065,16 +1127,16 @@
 		return -1;
 	pc = regs.r_pc;
 #elif defined(S390) || defined(S390X)
-	if(upeek(tcp->pid,PT_PSWADDR,&pc) < 0)
+	if(upeek(tcp,PT_PSWADDR,&pc) < 0)
 		return -1;
 #elif defined(HPPA)
-	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0)
+	if(upeek(tcp,PT_IAOQ0,&pc) < 0)
 		return -1;
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC ,&pc) < 0)
+       if (upeek(tcp, 4*REG_PC ,&pc) < 0)
                return -1;
 #elif defined(SH64)
-       if (upeek(tcp->pid, REG_PC ,&pc) < 0)
+       if (upeek(tcp, REG_PC ,&pc) < 0)
                return -1;
 #endif
 	return pc;
@@ -1119,7 +1181,7 @@
 #ifdef I386
 	long eip;
 
-	if (upeek(tcp->pid, 4*EIP, &eip) < 0) {
+	if (upeek(tcp, 4*EIP, &eip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1127,7 +1189,7 @@
 
 #elif defined(S390) || defined(S390X)
          long psw;
-         if(upeek(tcp->pid,PT_PSWADDR,&psw) < 0) {
+         if(upeek(tcp,PT_PSWADDR,&psw) < 0) {
                  PRINTBADPC;
                  return;
          }
@@ -1140,7 +1202,7 @@
 #elif defined(X86_64)
 	long rip;
 
-	if (upeek(tcp->pid, 8*RIP, &rip) < 0) {
+	if (upeek(tcp, 8*RIP, &rip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1148,7 +1210,7 @@
 #elif defined(IA64)
 	long ip;
 
-	if (upeek(tcp->pid, PT_B0, &ip) < 0) {
+	if (upeek(tcp, PT_B0, &ip) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1156,7 +1218,7 @@
 #elif defined(POWERPC)
 	long pc;
 
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1164,7 +1226,7 @@
 #elif defined(M68K)
 	long pc;
 
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
+	if (upeek(tcp, 4*PT_PC, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1172,7 +1234,7 @@
 #elif defined(ALPHA)
 	long pc;
 
-	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+	if (upeek(tcp, REG_PC, &pc) < 0) {
 		tprintf ("[????????????????] ");
 		return;
 	}
@@ -1187,7 +1249,7 @@
 #elif defined(HPPA)
 	long pc;
 
-	if(upeek(tcp->pid,PT_IAOQ0,&pc) < 0) {
+	if(upeek(tcp,PT_IAOQ0,&pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1195,7 +1257,7 @@
 #elif defined(MIPS)
 	long pc;
 
-	if (upeek(tcp->pid, REG_EPC, &pc) < 0) {
+	if (upeek(tcp, REG_EPC, &pc) < 0) {
 		tprintf ("[????????] ");
 		return;
 	}
@@ -1203,7 +1265,7 @@
 #elif defined(SH)
        long pc;
 
-       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0) {
+       if (upeek(tcp, 4*REG_PC, &pc) < 0) {
                tprintf ("[????????] ");
                return;
        }
@@ -1211,7 +1273,7 @@
 #elif defined(SH64)
 	long pc;
 
-	if (upeek(tcp->pid, REG_PC, &pc) < 0) {
+	if (upeek(tcp, REG_PC, &pc) < 0) {
 		tprintf ("[????????????????] ");
 		return;
 	}
@@ -1219,7 +1281,7 @@
 #elif defined(ARM)
 	long pc;
 
-	if (upeek(tcp->pid, 4*15, &pc) < 0) {
+	if (upeek(tcp, 4*15, &pc) < 0) {
 		PRINTBADPC;
 		return;
 	}
@@ -1254,10 +1316,15 @@
 
 #if defined LINUX
 
+#include "syscall.h"
+
 #include <sys/syscall.h>
 #ifndef CLONE_PTRACE
 # define CLONE_PTRACE    0x00002000
 #endif
+#ifndef CLONE_VFORK
+# define CLONE_VFORK     0x00004000
+#endif
 #ifndef CLONE_STOPPED
 # define CLONE_STOPPED   0x02000000
 #endif
@@ -1279,9 +1346,9 @@
 	if (ia32)
 		return 0;
 
-	if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) < 0)
+	if (upeek(tcp, PT_AR_BSP, (long *) &bsp) < 0)
 		return -1;
-	if (upeek(tcp->pid, PT_CFM, (long *) &cfm) < 0)
+	if (upeek(tcp, PT_CFM, (long *) &cfm) < 0)
 		return -1;
 
 	sof = (cfm >> 0) & 0x7f;
@@ -1301,7 +1368,7 @@
 	int ret;
 
 	if (ia32)
-		ret = upeek (tcp->pid, PT_R11, valp);
+		ret = upeek (tcp, PT_R11, valp);
 	else
 		ret = umoven (tcp,
 			      (unsigned long) ia64_rse_skip_regs(*state, 0),
@@ -1315,7 +1382,7 @@
 	int ret;
 
 	if (ia32)
-		ret = upeek (tcp->pid, PT_R9, valp);
+		ret = upeek (tcp, PT_R9, valp);
 	else
 		ret = umoven (tcp,
 			      (unsigned long) ia64_rse_skip_regs(*state, 1),
@@ -1356,6 +1423,12 @@
 	return errno ? -1 : 0;
 }
 
+/* ia64 does not return the input arguments from functions (and syscalls)
+   according to ia64 RSE (Register Stack Engine) behavior.  */
+
+# define restore_arg0(tcp, state, val) ((void) (state), 0)
+# define restore_arg1(tcp, state, val) ((void) (state), 0)
+
 #elif defined (SPARC) || defined (SPARC64)
 
 typedef struct regs arg_setup_state;
@@ -1418,9 +1491,9 @@
 # define arg_setup(tcp, state) (0)
 # define arg_finish_change(tcp, state)	0
 # define get_arg0(tcp, cookie, valp) \
-  (upeek ((tcp)->pid, arg0_offset, (valp)))
+  (upeek ((tcp), arg0_offset, (valp)))
 # define get_arg1(tcp, cookie, valp) \
-  (upeek ((tcp)->pid, arg1_offset, (valp)))
+  (upeek ((tcp), arg1_offset, (valp)))
 
 static int
 set_arg0 (struct tcb *tcp, void *cookie, long val)
@@ -1452,6 +1525,7 @@
 setbpt(tcp)
 struct tcb *tcp;
 {
+	static int clone_scno[SUPPORTED_PERSONALITIES] = { SYS_clone };
 	extern int change_syscall(struct tcb *, int);
 	arg_setup_state state;
 
@@ -1460,6 +1534,20 @@
 		return -1;
 	}
 
+	/*
+	 * It's a silly kludge to initialize this with a search at runtime.
+	 * But it's better than maintaining another magic thing in the
+	 * godforsaken tables.
+	 */
+	if (clone_scno[current_personality] == 0) {
+		int i;
+		for (i = 0; i < nsyscalls; ++i)
+			if (sysent[i].sys_func == sys_clone) {
+				clone_scno[current_personality] = i;
+				break;
+			}
+	}
+
 	switch (known_scno(tcp)) {
 #ifdef SYS_vfork
 	case SYS_vfork:
@@ -1471,7 +1559,7 @@
 		if (arg_setup (tcp, &state) < 0
 		    || get_arg0 (tcp, &state, &tcp->inst[0]) < 0
 		    || get_arg1 (tcp, &state, &tcp->inst[1]) < 0
-		    || change_syscall(tcp, SYS_clone) < 0
+		    || change_syscall(tcp, clone_scno[current_personality]) < 0
 		    || set_arg0 (tcp, &state, CLONE_PTRACE|SIGCHLD) < 0
 		    || set_arg1 (tcp, &state, 0) < 0
 		    || arg_finish_change (tcp, &state) < 0)
@@ -1486,12 +1574,17 @@
 #ifdef SYS_clone2
 	case SYS_clone2:
 #endif
-		if ((tcp->u_arg[arg0_index] & CLONE_PTRACE) == 0
-		    && (arg_setup (tcp, &state) < 0
-			|| set_arg0 (tcp, &state,
-				     tcp->u_arg[arg0_index] | CLONE_PTRACE) < 0
-			|| arg_finish_change (tcp, &state) < 0))
-			return -1;
+		/* ia64 calls directly `clone (CLONE_VFORK)' contrary to
+		   x86 SYS_vfork above.  Even on x86 we turn the vfork
+		   semantics into plain fork - each application must not
+		   depend on the vfork specifics according to POSIX.  We
+		   would hang waiting for the parent resume otherwise.  */
+		if ((arg_setup (tcp, &state) < 0
+		    || set_arg0 (tcp, &state,
+				 (tcp->u_arg[arg0_index] | CLONE_PTRACE)
+				 & ~CLONE_VFORK) < 0
+		    || arg_finish_change (tcp, &state) < 0))
+		    return -1;
 		tcp->flags |= TCB_BPTSET;
 		tcp->inst[0] = tcp->u_arg[arg0_index];
 		tcp->inst[1] = tcp->u_arg[arg1_index];
@@ -1515,7 +1608,7 @@
 	    || restore_arg0 (tcp, &state, tcp->inst[0]) < 0
 	    || restore_arg1 (tcp, &state, tcp->inst[1]) < 0
 	    || arg_finish_change (tcp, &state))
-		return -1;
+		if (errno != ESRCH) return -1;
 	tcp->flags &= ~TCB_BPTSET;
 	return 0;
 }
@@ -1583,7 +1676,7 @@
 				tcp->pid);
 			return -1;
 		}
-		if (upeek(tcp->pid, PT_CR_IIP, &tcp->baddr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &tcp->baddr) < 0)
 			return -1;
 		if (debug)
 			fprintf(stderr, "[%d] setting bpt at %lx\n",
@@ -1617,9 +1710,9 @@
 		pid_t pid;
 
 		pid = tcp->pid;
-		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
+		if (upeek(tcp, PT_CR_IPSR, &ipsr) < 0)
 			return -1;
-		if (upeek(pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 		/* store "ri" in low two bits */
 		tcp->baddr = addr | ((ipsr >> 41) & 0x3);
@@ -1678,13 +1771,13 @@
 		return -1;
 	}
 #if defined (I386)
-	if (upeek(tcp->pid, 4*EIP, &tcp->baddr) < 0)
+	if (upeek(tcp, 4*EIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined (X86_64)
-	if (upeek(tcp->pid, 8*RIP, &tcp->baddr) < 0)
+	if (upeek(tcp, 8*RIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined (M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &tcp->baddr) < 0)
+	if (upeek(tcp, 4*PT_PC, &tcp->baddr) < 0)
 	  return -1;
 #elif defined (ALPHA)
 	return -1;
@@ -1693,17 +1786,17 @@
 #elif defined (MIPS)
 	return -1;		/* FIXME: I do not know what i do - Flo */
 #elif defined (POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &tcp->baddr) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &tcp->baddr) < 0)
 		return -1;
 #elif defined(S390) || defined(S390X)
-	if (upeek(tcp->pid,PT_PSWADDR, &tcp->baddr) < 0)
+	if (upeek(tcp,PT_PSWADDR, &tcp->baddr) < 0)
 		return -1;
 #elif defined(HPPA)
-	if (upeek(tcp->pid, PT_IAOQ0, &tcp->baddr) < 0)
+	if (upeek(tcp, PT_IAOQ0, &tcp->baddr) < 0)
 		return -1;
 	tcp->baddr &= ~0x03;
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC, &tcp->baddr) < 0)
+       if (upeek(tcp, 4*REG_PC, &tcp->baddr) < 0)
                return -1;
 #else
 #error unknown architecture
@@ -1829,7 +1922,7 @@
 		}
 		tcp->flags &= ~TCB_BPTSET;
 
-		if (upeek(tcp->pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 		if (addr != tcp->baddr) {
 			/* The breakpoint has not been reached yet.  */
@@ -1845,9 +1938,9 @@
 
 		pid = tcp->pid;
 
-		if (upeek(pid, PT_CR_IPSR, &ipsr) < 0)
+		if (upeek(tcp, PT_CR_IPSR, &ipsr) < 0)
 			return -1;
-		if (upeek(pid, PT_CR_IIP, &addr) < 0)
+		if (upeek(tcp, PT_CR_IIP, &addr) < 0)
 			return -1;
 
 		/* restore original bundle: */
@@ -1895,7 +1988,7 @@
 	tcp->flags &= ~TCB_BPTSET;
 
 #ifdef I386
-	if (upeek(tcp->pid, 4*EIP, &eip) < 0)
+	if (upeek(tcp, 4*EIP, &eip) < 0)
 		return -1;
 	if (eip != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -1906,7 +1999,7 @@
 		return 0;
 	}
 #elif defined(X86_64)
-	if (upeek(tcp->pid, 8*RIP, &eip) < 0)
+	if (upeek(tcp, 8*RIP, &eip) < 0)
 		return -1;
 	if (eip != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -1917,7 +2010,7 @@
 		return 0;
 	}
 #elif defined(POWERPC)
-	if (upeek(tcp->pid, sizeof(unsigned long)*PT_NIP, &pc) < 0)
+	if (upeek(tcp, sizeof(unsigned long)*PT_NIP, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -1927,7 +2020,7 @@
 		return 0;
 	}
 #elif defined(M68K)
-	if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
+	if (upeek(tcp, 4*PT_PC, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -1937,7 +2030,7 @@
 		return 0;
 	}
 #elif defined(ALPHA)
-	if (upeek(tcp->pid, REG_PC, &pc) < 0)
+	if (upeek(tcp, REG_PC, &pc) < 0)
 		return -1;
 	if (pc != tcp->baddr) {
 		/* The breakpoint has not been reached yet.  */
@@ -1947,7 +2040,7 @@
 		return 0;
 	}
 #elif defined(HPPA)
-	if (upeek(tcp->pid, PT_IAOQ0, &iaoq) < 0)
+	if (upeek(tcp, PT_IAOQ0, &iaoq) < 0)
 		return -1;
 	iaoq &= ~0x03;
 	if (iaoq != tcp->baddr && iaoq != tcp->baddr + 4) {
@@ -1965,7 +2058,7 @@
 	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ0, iaoq);
 	ptrace(PTRACE_POKEUSER, tcp->pid, (void *)PT_IAOQ1, iaoq);
 #elif defined(SH)
-       if (upeek(tcp->pid, 4*REG_PC, &pc) < 0)
+       if (upeek(tcp, 4*REG_PC, &pc) < 0)
                return -1;
         if (pc != tcp->baddr) {
                 /* The breakpoint has not been reached yet.  */
@@ -2039,15 +2132,15 @@
 #ifdef SUNOS4
 
 static int
-getex(pid, hdr)
-int pid;
+getex(tcp, hdr)
+struct tcb *tcp;
 struct exec *hdr;
 {
 	int n;
 
 	for (n = 0; n < sizeof *hdr; n += 4) {
 		long res;
-		if (upeek(pid, uoff(u_exdata) + n, &res) < 0)
+		if (upeek(tcp, uoff(u_exdata) + n, &res) < 0)
 			return -1;
 		memcpy(((char *) hdr) + n, &res, 4);
 	}
@@ -2075,7 +2168,7 @@
 	struct link_dynamic_2 ld;
 	char *strtab, *cp;
 
-	if (getex(pid, &hdr) < 0)
+	if (getex(tcp, &hdr) < 0)
 		return -1;
 	if (!hdr.a_dynamic)
 		return -1;

Index: process.c
===================================================================
RCS file: /cvsroot/ssic-linux/openssi/strace/Attic/process.c,v
retrieving revision 1.1.15.1
retrieving revision 1.1.15.2
diff -u -d -r1.1.15.1 -r1.1.15.2
--- process.c	4 Jul 2010 20:18:14 -0000	1.1.15.1
+++ process.c	14 Sep 2010 03:12:34 -0000	1.1.15.2
@@ -731,7 +731,7 @@
 	{
 		unsigned long *bsp, *ap;
 
-		if (upeek(tcp->pid, PT_AR_BSP, (long *) &bsp) , 0)
+		if (upeek(tcp, PT_AR_BSP, (long *) &bsp) , 0)
 			return -1;
 
 		ap = ia64_rse_skip_regs(bsp, argnum);
@@ -773,7 +773,7 @@
 		else {
 			unsigned long *sp;
 
-			if (upeek(tcp->pid, REG_SP, (long *) &sp) , 0)
+			if (upeek(tcp, REG_SP, (long *) &sp) , 0)
 				return -1;
 
 			ptrace(PTRACE_POKEDATA, tcp->pid,
@@ -882,10 +882,11 @@
 				clearbpt(tcpchild);
 
 			tcpchild->flags &= ~(TCB_SUSPENDED|TCB_STARTUP);
-			if (ptrace(PTRACE_SYSCALL, pid, (char *) 1, 0) < 0) {
-				perror("resume: ptrace(PTRACE_SYSCALL, ...)");
+			/* TCB_SUSPENDED tasks are not collected by waitpid
+			 * loop, and left stopped. Restart it:
+			 */
+			if (ptrace_restart(PTRACE_SYSCALL, tcpchild, 0) < 0)
 				return -1;
-			}
 
 			if (!qflag)
 				fprintf(stderr, "\
@@ -953,8 +954,7 @@
 #ifdef SYS_vfork
 	if (known_scno(tcp) == SYS_vfork) {
 		/* Attempt to make vfork into fork, which we can follow. */
-		if (!followvfork ||
-		    change_syscall(tcp, SYS_fork) < 0)
+		if (change_syscall(tcp, SYS_fork) < 0)
 			dont_follow = 1;
 	}
 #endif
@@ -1795,9 +1795,10 @@
 		fixvfork(tcp);
 #endif /* SUNOS4 */
 #if defined LINUX && defined TCB_WAITEXECVE
-	if (exiting(tcp) && syserror(tcp))
-		tcp->flags &= ~TCB_WAITEXECVE;
-	else
+	if (exiting(tcp)) {
+		if (syserror(tcp))
+			tcp->flags &= ~TCB_WAITEXECVE;
+	} else
 		tcp->flags |= TCB_WAITEXECVE;
 #endif /* LINUX && TCB_WAITEXECVE */
 	return 0;


------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev