+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
#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
#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
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;
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;
}
#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;
}
#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
/* 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) {
#endif /* HAVE_PUTPMSG */
+#ifdef HAVE_SYS_POLL_H
+
static struct xlat pollflags[] = {
#ifdef POLLIN
{ POLLIN, "POLLIN" },
{
struct pollfd *pollp;
-#ifdef HAVE_SYS_POLL_H
if (exiting(tcp)) {
int i;
int nfds = tcp->u_arg[1];
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[] = {
#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)
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;
--- /dev/null
+fork
+sig
+skodic
+vfork
# $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
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;
}
} else
while (1)
- open( c, 0 );
+ if ((fd=open( c, 0 ))!=-1)
+ close(fd);
}
--- /dev/null
+main()
+{
+ if (vfork() == 0)
+ write(1, "child\n", 6);
+ else {
+ wait(0);
+ write(1, "parent\n", 7);
+ }
+ exit(0);
+}
#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
return;
}
tprintf("[%08lx] ", eip);
-#else /* !I386K */
-#ifdef IA64
+#elif defined(IA62)
long ip;
if (upeek(tcp->pid, PT_B0, &ip) < 0) {
return;
}
tprintf("[%08lx] ", ip);
-#else /* !IA64 */
-#ifdef POWERPC
+#elif defined(POWERPC)
long pc;
if (upeek(tcp->pid, 4*PT_NIP, &pc) < 0) {
return;
}
tprintf("[%08lx] ", pc);
-#else /* !POWERPC */
-#ifdef M68K
+#elif defined(M68k)
long pc;
if (upeek(tcp->pid, 4*PT_PC, &pc) < 0) {
return;
}
tprintf("[%08lx] ", pc);
-#else /* !M68K */
-#ifdef ALPHA
+#elif defined(ALPHA)
long pc;
if (upeek(tcp->pid, REG_PC, &pc) < 0) {
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
{
#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. */
return -1;
}
tcp->flags &= ~TCB_BPTSET;
-#else /* !SPARC */
-#ifdef IA64
+#elif defined(IA64)
{
unsigned long addr, ipsr;
pid_t pid;
return 0;
}
}
-#else /* !IA64 */
+#else /* !IA64 && ! SPARC */
if (debug)
fprintf(stderr, "[%d] clearing bpt\n", tcp->pid);
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) {
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) {
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) {
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