]> granicus.if.org Git - strace/commitdiff
test/vfork.c: new file to test vfork traces
authorWichert Akkerman <wichert@deephackmode.org>
Sat, 19 Feb 2000 23:59:03 +0000 (23:59 +0000)
committerWichert Akkerman <wichert@deephackmode.org>
Sat, 19 Feb 2000 23:59:03 +0000 (23:59 +0000)
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

12 files changed:
ChangeLog
defs.h
process.c
signal.c
strace.c
stream.c
syscall.c
test/.cvsignore [new file with mode: 0644]
test/Makefile
test/skodic.c
test/vfork.c [new file with mode: 0644]
util.c

index 82493773bb6285dc276b8f61d94c9b6f05dc9174..f3d1773d349e5bdf251672d9fae4c4d8a4d68420 100644 (file)
--- 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 1f8cb99f610d7316a3b9db85024c64b5061a03f6..822a9f5810c5e34e0b8f1fed0c37c8249c5e9865 100644 (file)
--- 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
index 514ef6c6abd1b1ae09f9a4680834ba50c9f0246a..a0045aa780d93dc37789801d6645f1a187f009d6 100644 (file)
--- a/process.c
+++ b/process.c
 #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
 #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
@@ -290,21 +289,6 @@ struct tcb *tcp;
        return 0;
 }
 
-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;
@@ -386,6 +370,46 @@ struct tcb *tcp;
        return 0;
 }
 
+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;
@@ -407,14 +431,12 @@ setarg(tcp, argnum)
        }
 #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;
 }
index de6f0d12b14e02b88b221986bc17ec3d3dfe15b5..49fd1b773f66eb3a3757585ab027325c794580d2 100644 (file)
--- a/signal.c
+++ b/signal.c
 #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
 #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
index 223883a20c42b72a8fb864fca072b0fe5df26a6f..761043224c505b5d2cc726ed1d9a6e0084a67b07 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -1482,7 +1482,7 @@ trace()
 
                /* 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) {
index 35b3ecc6d75962a547b7cb42ca23d2591f1641df..0cc14a037be657f2721fa310cef414c15c628528 100644 (file)
--- a/stream.c
+++ b/stream.c
@@ -254,6 +254,8 @@ struct tcb *tcp;
 #endif /* HAVE_PUTPMSG */
 
 
+#ifdef HAVE_SYS_POLL_H
+
 static struct xlat pollflags[] = {
 #ifdef POLLIN
        { POLLIN,       "POLLIN"        },
@@ -284,7 +286,6 @@ struct tcb *tcp;
 {
        struct pollfd *pollp;
 
-#ifdef HAVE_SYS_POLL_H
        if (exiting(tcp)) {
                int i;
                int nfds = tcp->u_arg[1];
@@ -336,10 +337,18 @@ struct tcb *tcp;
                        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[] = {
index a52677ca3beaff3680a951c4937ac8a0b2aba8ea..99849880f48cec17cdb1aaac5dba9670132ded05 100644 (file)
--- a/syscall.c
+++ b/syscall.c
 #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 @@ struct tcb *tcp;
                for (i = 0; i < tcp->u_nargs; i++)
                        tcp->u_arg[i] = *((&regs.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 (file)
index 0000000..5c0ba77
--- /dev/null
@@ -0,0 +1,4 @@
+fork
+sig
+skodic
+vfork
index ddaa4040de6263fcdf60a0400694bc6beb6733d6..9d6a29e0bef3d747f024bfd6d5ba09dd7c998c01 100644 (file)
@@ -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
 
index 4e65d5d56aa52bdbc40a1f46f427835325e2ad60..6528ed895fe161199e8e71a64fa5cd8d353a679f 100644 (file)
@@ -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 @@ main(void)
     }
   } 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 (file)
index 0000000..2c2d603
--- /dev/null
@@ -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 b69739e37fc3dd6747e7889d51188aeec8464ed7..5b0497b8a3dfd55207456a4356783ef2e9d54dc6 100644 (file)
--- a/util.c
+++ b/util.c
 #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 @@ struct tcb *tcp;
                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 @@ struct tcb *tcp;
                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 @@ struct tcb *tcp;
                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 @@ struct tcb *tcp;
                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 @@ struct tcb *tcp;
                return;
        }
        tprintf("[%08lx] ", pc);
-#else /* !ALPHA */
-#ifdef SPARC
+#elif defined(SPARC)
        struct regs regs;
        if (ptrace(PTRACE_GETREGS,tcp->pid,(char *)&regs,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 @@ struct tcb *tcp;
 {
 
 #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 @@ struct tcb *tcp;
                return -1;
        }
        tcp->flags &= ~TCB_BPTSET;
-#else /* !SPARC */
-#ifdef IA64
+#elif defined(IA64)
        {
                unsigned long addr, ipsr;
                pid_t pid;
@@ -1292,7 +1274,7 @@ struct tcb *tcp;
                        return 0;
                }
        }
-#else /* !IA64 */
+#else /* !IA64  && ! SPARC */
 
        if (debug)
                fprintf(stderr, "[%d] clearing bpt\n", tcp->pid);
@@ -1319,8 +1301,7 @@ struct tcb *tcp;
                                        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 @@ struct tcb *tcp;
                                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 @@ struct tcb *tcp;
                                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 @@ struct tcb *tcp;
                                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