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
This commit is contained in:
Wichert Akkerman 2000-02-19 23:59:03 +00:00
parent 2ee6e45f36
commit faf722234d
12 changed files with 117 additions and 89 deletions

View File

@ -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

2
defs.h
View File

@ -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

View File

@ -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
@ -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;
}

View File

@ -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

View File

@ -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) {

View File

@ -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[] = {

View File

@ -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 @@ 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;

4
test/.cvsignore Normal file
View File

@ -0,0 +1,4 @@
fork
sig
skodic
vfork

View 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

View 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);
}

10
test/vfork.c Normal file
View File

@ -0,0 +1,10 @@
main()
{
if (vfork() == 0)
write(1, "child\n", 6);
else {
wait(0);
write(1, "parent\n", 7);
}
exit(0);
}

67
util.c
View File

@ -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 @@ 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