test/vfork.c: new file to test vfork traces
test/.cvsignore: new file
defs.h: Up maximum number of traced processed to 64
strace.c: Disable some debugging code from davidm
implement setarg for more architectures
implement change_syscall
diff --git a/ChangeLog b/ChangeLog
index 8249377..f3d1773 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2000-02-19 Wichert Akkerman <wakkerma@debian.org>
+
+ * test/vfork.c: new file to test vfork traces
+ * test/.cvsignore: new file
+ * defs.h: Up maximum number of traced processed to 64
+ * strace.c: Disable some debugging code from davidm
+ * implement setarg for more architectures
+ * implement change_syscall
+
1999-12-27 Morten Welinder <terra@diku.dk>
* syscall.c (lookup_signal, lookup_desc): isdigit requires an
diff --git a/defs.h b/defs.h
index 1f8cb99..822a9f5 100644
--- a/defs.h
+++ b/defs.h
@@ -42,7 +42,7 @@
#define MAX_QUALS 2048 /* maximum number of syscalls, signals, etc. */
#endif
#ifndef MAX_PROCS
-#define MAX_PROCS 32 /* maximum number of processes tracable */
+#define MAX_PROCS 64 /* maximum number of processes tracable */
#endif
#ifndef DEFAULT_STRLEN
#define DEFAULT_STRLEN 32 /* default maximum # of bytes printed in
diff --git a/process.c b/process.c
index 514ef6c..a0045aa 100644
--- a/process.c
+++ b/process.c
@@ -49,11 +49,6 @@
#include <machine/reg.h>
#endif /* SUNOS4 */
-#if HAVE_LINUX_PTRACE_H
-#undef PTRACE_SYSCALL
-#include <linux/ptrace.h>
-#endif
-
#ifdef HAVE_SYS_REG_H
# include <sys/reg.h>
#ifndef PTRACE_PEEKUSR
@@ -62,8 +57,12 @@
#ifndef PTRACE_POKEUSR
# define PTRACE_POKEUSR PTRACE_POKEUSER
#endif
+#elif defined(HAVE_LINUX_PTRACE_H)
+#undef PTRACE_SYSCALL
+#include <linux/ptrace.h>
#endif
+
#ifdef LINUX
#include <asm/posix_types.h>
#undef GETGROUPS_T
@@ -291,21 +290,6 @@
}
int
-change_syscall(tcp, new)
-struct tcb *tcp;
-int new;
-{
-#if defined(I386) && defined(LINUX)
- /* Attempt to make vfork into fork, which we can follow. */
- if (ptrace(PTRACE_POKEUSER, tcp->pid,
- (void *)(ORIG_EAX * 4), new) < 0)
- return -1;
- return 0;
-#endif
- return -1;
-}
-
-int
internal_fork(tcp)
struct tcb *tcp;
{
@@ -387,6 +371,46 @@
}
int
+change_syscall(tcp, new)
+struct tcb *tcp;
+int new;
+{
+#if defined(LINUX)
+#if defined(I386)
+ /* Attempt to make vfork into fork, which we can follow. */
+ if (ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(ORIG_EAX * 4), new) < 0)
+ return -1;
+ return 0;
+#elif defined(POWERPC)
+ if (ptrace(PTRACE_POKEUSER, tcp->pid, (CHAR*)(4*PT_R0), new) < 0)
+ return -1;
+#elif defined(S390)
+ long pc;
+ if (upeek(tcp->pid, PT_PSWADDR,&pc)<0)
+ return -1;
+ if (ptrace(PTRACE_POKETEXT, tcp->pid, (char*)(pc-4), new)<0)
+ return -1;
+ return 0;
+#elif defined(M68K)
+ if (ptrace(PTRACE_POKEUSER, (char*)(4*PT_ORIG_D0), new)<0)
+ return -1;
+ return 0;
+#elif defined(MIPS)
+ if (ptrace(PTRACE_POKEUSER, (char*)(REG_V0), new)<0)
+ return -1;
+ return 0;
+#elif defined(ALPHA)
+ if (ptrace(PTRACE_POKEUSER, (char*)(REG_A3), new)<0)
+ return -1;
+ return 0;
+#else
+#warning Do not know how to handle change_syscall for this architecture
+#endif /* architecture */
+#endif /* LINUX */
+ return -1;
+}
+
+int
setarg(tcp, argnum)
struct tcb *tcp;
int argnum;
@@ -407,14 +431,12 @@
}
#elif defined(I386)
{
- /* TODO: finish this */
- errno=0;
-// ptrace(PTRACE_POKEDATA, tcp->pid, , tcp->u_arg[argnum]);
+ ptrace(PTRACE_POKEUSER, tcp->pid, (char*)(4*argnum), tcp->u_arg[argnum]);
if (errno)
return -1;
}
#else
-# error Sorry, not done yet.
+# warning Sorry, setargs not implemented for this architecture.
#endif
return 0;
}
diff --git a/signal.c b/signal.c
index de6f0d1..49fd1b7 100644
--- a/signal.c
+++ b/signal.c
@@ -43,11 +43,6 @@
#include <sys/ucontext.h>
#endif /* SVR4 */
-#if HAVE_LINUX_PTRACE_H
-#undef PTRACE_SYSCALL
-#include <linux/ptrace.h>
-#endif
-
#ifdef HAVE_SYS_REG_H
# include <sys/reg.h>
#ifndef PTRACE_PEEKUSR
@@ -56,8 +51,12 @@
#ifndef PTRACE_POKEUSR
# define PTRACE_POKEUSR PTRACE_POKEUSER
#endif
+#elif defined(HAVE_LINUX_PTRACE_H)
+#undef PTRACE_SYSCALL
+#include <linux/ptrace.h>
#endif
+
#ifdef LINUX
#ifdef IA64
diff --git a/strace.c b/strace.c
index 223883a..7610432 100644
--- a/strace.c
+++ b/strace.c
@@ -1482,7 +1482,7 @@
/* Look up `pid' in our table. */
if ((tcp = pid2tcb(pid)) == NULL) {
-#if 1 /* XXX davidm */
+#if 0 /* XXX davidm */ /* WTA: disabled again */
struct tcb *tcpchild;
if ((tcpchild = alloctcb(pid)) == NULL) {
diff --git a/stream.c b/stream.c
index 35b3ecc..0cc14a0 100644
--- a/stream.c
+++ b/stream.c
@@ -254,6 +254,8 @@
#endif /* HAVE_PUTPMSG */
+#ifdef HAVE_SYS_POLL_H
+
static struct xlat pollflags[] = {
#ifdef POLLIN
{ POLLIN, "POLLIN" },
@@ -284,7 +286,6 @@
{
struct pollfd *pollp;
-#ifdef HAVE_SYS_POLL_H
if (exiting(tcp)) {
int i;
int nfds = tcp->u_arg[1];
@@ -336,10 +337,18 @@
tprintf("%ld", tcp->u_arg[2]);
free(pollp);
}
-#endif
return 0;
}
+#else /* !HAVE_SYS_POLL_H */
+int
+sys_poll(tcp)
+struct tcb *tcp;
+{
+ return 0;
+}
+#endif
+
#ifndef linux
static struct xlat stream_flush_options[] = {
diff --git a/syscall.c b/syscall.c
index a52677c..9984988 100644
--- a/syscall.c
+++ b/syscall.c
@@ -46,16 +46,14 @@
#include <asm/reg.h>
#endif
-#if HAVE_LINUX_PTRACE_H
-#undef PTRACE_SYSCALL
-#include <linux/ptrace.h>
-#endif
-
#ifdef HAVE_SYS_REG_H
#include <sys/reg.h>
#ifndef PTRACE_PEEKUSR
# define PTRACE_PEEKUSR PTRACE_PEEKUSER
#endif
+#elif defined(HAVE_LINUX_PTRACE_H)
+#undef PTRACE_SYSCALL
+#include <linux/ptrace.h>
#endif
#if defined(LINUX) && defined(IA64)
@@ -1123,7 +1121,7 @@
for (i = 0; i < tcp->u_nargs; i++)
tcp->u_arg[i] = *((®s.r_o0) + i);
}
-#else
+#else /* Other architecture (like i386) (32bits specific) */
{
int i;
tcp->u_nargs = sysent[tcp->scno].nargs;
diff --git a/test/.cvsignore b/test/.cvsignore
new file mode 100644
index 0000000..5c0ba77
--- /dev/null
+++ b/test/.cvsignore
@@ -0,0 +1,4 @@
+fork
+sig
+skodic
+vfork
diff --git a/test/Makefile b/test/Makefile
index ddaa404..9d6a29e 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -2,8 +2,8 @@
# $Id$
#
-all: fork sig skodic
+all: vfork fork sig skodic
clean distclean:
- rm -f fork sig *.o core
+ rm -f vfork fork sig *.o core
diff --git a/test/skodic.c b/test/skodic.c
index 4e65d5d..6528ed8 100644
--- a/test/skodic.c
+++ b/test/skodic.c
@@ -15,7 +15,8 @@
void
main(void)
{
- char *c = 0x94000000;
+ char *c = (char*)0x94000000;
+ int fd;
open( "/tmp/delme", O_RDWR );
mmap( c, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_SHARED, 3, 0 );
*c = 0;
@@ -26,5 +27,6 @@
}
} else
while (1)
- open( c, 0 );
+ if ((fd=open( c, 0 ))!=-1)
+ close(fd);
}
diff --git a/test/vfork.c b/test/vfork.c
new file mode 100644
index 0000000..2c2d603
--- /dev/null
+++ b/test/vfork.c
@@ -0,0 +1,10 @@
+main()
+{
+ if (vfork() == 0)
+ write(1, "child\n", 6);
+ else {
+ wait(0);
+ write(1, "parent\n", 7);
+ }
+ exit(0);
+}
diff --git a/util.c b/util.c
index b69739e..5b0497b 100644
--- a/util.c
+++ b/util.c
@@ -55,10 +55,9 @@
#ifdef HAVE_SYS_REG_H
#include <sys/reg.h>
# define PTRACE_PEEKUSR PTRACE_PEEKUSER
-#endif
-
-#ifdef HAVE_SYS_PTRACE_H
-#include <sys/ptrace.h>
+#elif defined(HAVE_LINUX_PTRACE_H)
+#undef PTRACE_SYSCALL
+#include <linux/ptrace.h>
#endif
#ifdef SUNOS4_KERNEL_ARCH_KLUDGE
@@ -942,8 +941,7 @@
return;
}
tprintf("[%08lx] ", eip);
-#else /* !I386K */
-#ifdef IA64
+#elif defined(IA62)
long ip;
if (upeek(tcp->pid, PT_B0, &ip) < 0) {
@@ -951,8 +949,7 @@
return;
}
tprintf("[%08lx] ", ip);
-#else /* !IA64 */
-#ifdef POWERPC
+#elif defined(POWERPC)
long pc;
if (upeek(tcp->pid, 4*PT_NIP, &pc) < 0) {
@@ -960,8 +957,7 @@
return;
}
tprintf("[%08lx] ", pc);
-#else /* !POWERPC */
-#ifdef M68K
+#elif defined(M68k)
long pc;
if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
@@ -969,8 +965,7 @@
return;
}
tprintf("[%08lx] ", pc);
-#else /* !M68K */
-#ifdef ALPHA
+#elif defined(ALPHA)
long pc;
if (upeek(tcp->pid, REG_PC, &pc) < 0) {
@@ -978,20 +973,14 @@
return;
}
tprintf("[%08lx] ", pc);
-#else /* !ALPHA */
-#ifdef SPARC
+#elif defined(SPARC)
struct regs regs;
if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)®s,0) < 0) {
tprintf("[????????] ");
return;
}
tprintf("[%08lx] ", regs.r_pc);
-#endif /* SPARC */
-#endif /* ALPHA */
-#endif /* !M68K */
-#endif /* !POWERPC */
-#endif /* !IA64 */
-#endif /* !I386 */
+#endif /* !architecture */
#endif /* LINUX */
#ifdef SUNOS4
@@ -1222,21 +1211,15 @@
{
#ifdef LINUX
-#ifdef I386
+#if defined(I386)
long eip;
-#else /* !I386 */
-#ifdef POWERPC
+#elif defined(POWERPC)
long pc;
-#else /* !POWERPC */
-#ifdef M68K
+#elif defined(M68K)
long pc;
-#else /* !M68K */
-#ifdef ALPHA
+#elif defined(ALPHA)
long pc;
-#endif /* ALPHA */
-#endif /* !M68K */
-#endif /* !POWERPC */
-#endif /* !I386 */
+#endif /* architecture */
#ifdef SPARC
/* Again, we borrow the SunOS breakpoint code. */
@@ -1251,8 +1234,7 @@
return -1;
}
tcp->flags &= ~TCB_BPTSET;
-#else /* !SPARC */
-#ifdef IA64
+#elif defined(IA64)
{
unsigned long addr, ipsr;
pid_t pid;
@@ -1292,7 +1274,7 @@
return 0;
}
}
-#else /* !IA64 */
+#else /* !IA64 && ! SPARC */
if (debug)
fprintf(stderr, "[%d] clearing bpt\n", tcp->pid);
@@ -1319,8 +1301,7 @@
eip, tcp->baddr);
return 0;
}
-#else /* !I386 */
-#ifdef POWERPC
+#elif defied(POWERPC)
if (upeek(tcp->pid, 4*PT_NIP, &pc) < 0)
return -1;
if (pc != tcp->baddr) {
@@ -1330,8 +1311,7 @@
pc, tcp->baddr);
return 0;
}
-#else /* !POWERPC */
-#ifdef M68K
+#elif defined(M68K)
if (upeek(tcp->pid, 4*PT_PC, &pc) < 0)
return -1;
if (pc != tcp->baddr) {
@@ -1341,8 +1321,7 @@
pc, tcp->baddr);
return 0;
}
-#else /* !M68K */
-#ifdef ALPHA
+#elif defined(ALPHA)
if (upeek(tcp->pid, REG_PC, &pc) < 0)
return -1;
if (pc != tcp->baddr) {
@@ -1352,12 +1331,8 @@
pc, tcp->baddr);
return 0;
}
-#endif /* ALPHA */
-#endif /* !M68K */
-#endif /* !POWERPC */
-#endif /* !I386 */
-#endif /* !IA64 */
-#endif /* !SPARC */
+#endif /* arch */
+#endif /* !SPARC && !IA64 */
#endif /* LINUX */
#ifdef SUNOS4