From faf722234dc8af97776f94fdda7e100fb60650a2 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Sat, 19 Feb 2000 23:59:03 +0000 Subject: [PATCH] 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 --- ChangeLog | 9 +++++++ defs.h | 2 +- process.c | 70 ++++++++++++++++++++++++++++++++----------------- signal.c | 9 +++---- strace.c | 2 +- stream.c | 13 +++++++-- syscall.c | 10 +++---- test/.cvsignore | 4 +++ test/Makefile | 4 +-- test/skodic.c | 6 +++-- test/vfork.c | 10 +++++++ util.c | 67 +++++++++++++++------------------------------- 12 files changed, 117 insertions(+), 89 deletions(-) create mode 100644 test/.cvsignore create mode 100644 test/vfork.c diff --git a/ChangeLog b/ChangeLog index 82493773..f3d1773d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2000-02-19 Wichert Akkerman + + * 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 * syscall.c (lookup_signal, lookup_desc): isdigit requires an diff --git a/defs.h b/defs.h index 1f8cb99f..822a9f58 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 514ef6c6..a0045aa7 100644 --- a/process.c +++ b/process.c @@ -49,11 +49,6 @@ #include #endif /* SUNOS4 */ -#if HAVE_LINUX_PTRACE_H -#undef PTRACE_SYSCALL -#include -#endif - #ifdef HAVE_SYS_REG_H # include #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 #endif + #ifdef LINUX #include #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; } diff --git a/signal.c b/signal.c index de6f0d12..49fd1b77 100644 --- a/signal.c +++ b/signal.c @@ -43,11 +43,6 @@ #include #endif /* SVR4 */ -#if HAVE_LINUX_PTRACE_H -#undef PTRACE_SYSCALL -#include -#endif - #ifdef HAVE_SYS_REG_H # include #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 #endif + #ifdef LINUX #ifdef IA64 diff --git a/strace.c b/strace.c index 223883a2..76104322 100644 --- 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) { diff --git a/stream.c b/stream.c index 35b3ecc6..0cc14a03 100644 --- 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[] = { diff --git a/syscall.c b/syscall.c index a52677ca..99849880 100644 --- a/syscall.c +++ b/syscall.c @@ -46,16 +46,14 @@ #include #endif -#if HAVE_LINUX_PTRACE_H -#undef PTRACE_SYSCALL -#include -#endif - #ifdef HAVE_SYS_REG_H #include #ifndef PTRACE_PEEKUSR # define PTRACE_PEEKUSR PTRACE_PEEKUSER #endif +#elif defined(HAVE_LINUX_PTRACE_H) +#undef PTRACE_SYSCALL +#include #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] = *((®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 00000000..5c0ba777 --- /dev/null +++ b/test/.cvsignore @@ -0,0 +1,4 @@ +fork +sig +skodic +vfork diff --git a/test/Makefile b/test/Makefile index ddaa4040..9d6a29e0 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 4e65d5d5..6528ed89 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 @@ 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 index 00000000..2c2d6032 --- /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 b69739e3..5b0497b8 100644 --- a/util.c +++ b/util.c @@ -55,10 +55,9 @@ #ifdef HAVE_SYS_REG_H #include # define PTRACE_PEEKUSR PTRACE_PEEKUSER -#endif - -#ifdef HAVE_SYS_PTRACE_H -#include +#elif defined(HAVE_LINUX_PTRACE_H) +#undef PTRACE_SYSCALL +#include #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 *)®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 @@ 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 -- 2.50.1