Now also compiles on NetBSD (although untested)
This commit is contained in:
parent
6dc80d5fd5
commit
2900d1904b
1
Makefile
1
Makefile
|
@ -22,6 +22,7 @@ dist:
|
|||
$(LN) -s . $(PACKAGE)-$(VERSION)
|
||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(PACKAGE)-$(VERSION)/src/linux.c \
|
||||
$(PACKAGE)-$(VERSION)/src/netbsd.c \
|
||||
$(PACKAGE)-$(VERSION)/src/strace.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
|
|
|
@ -15,16 +15,19 @@ INSTALL = install
|
|||
|
||||
all: $(TARGETS)
|
||||
|
||||
strace_OBJS = linux.o strace.o
|
||||
strace_OBJS = linux.o netbsd.o strace.o
|
||||
strace_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||
strace_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||
|
||||
strace: $(strace_OBJS)
|
||||
$(CC) -o strace $(strace_OBJS) $(strace_LDFLAGS)
|
||||
|
||||
linux.o: linux.c
|
||||
linux.o: linux.c linux.h
|
||||
$(CC) $(strace_CFLAGS) -c linux.c
|
||||
|
||||
netbsd.o: netbsd.c netbsd.h
|
||||
$(CC) $(strace_CFLAGS) -c netbsd.c
|
||||
|
||||
strace.o: strace.c
|
||||
$(CC) $(strace_CFLAGS) -c strace.c
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2007 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Devel strace */
|
||||
/* strace is not free software; you can redistribute it and/or modify it under
|
||||
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||
|
@ -20,7 +20,9 @@
|
|||
#include "linux.h"
|
||||
|
||||
|
||||
char const * _syscall[] =
|
||||
#ifdef __linux__
|
||||
/* variables */
|
||||
char const * stracecall[] =
|
||||
{
|
||||
"exit",
|
||||
"fork",
|
||||
|
@ -43,3 +45,4 @@ char const * _syscall[] =
|
|||
"lseek",
|
||||
"getpid"
|
||||
};
|
||||
#endif /* __linux__ */
|
||||
|
|
11
src/linux.h
11
src/linux.h
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2007 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Devel strace */
|
||||
/* strace is not free software; you can redistribute it and/or modify it under
|
||||
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||
|
@ -19,10 +19,17 @@
|
|||
#ifndef STRACE_LINUX_H
|
||||
# define STRACE_LINUX_H
|
||||
|
||||
# ifdef __linux__
|
||||
# include <linux/user.h>
|
||||
# include <asm/unistd.h>
|
||||
|
||||
|
||||
extern char * syscall[__NR_getpid];
|
||||
/* types */
|
||||
typedef void * ptrace_data_t;
|
||||
|
||||
|
||||
/* variables */
|
||||
extern char * stracecall[__NR_getpid];
|
||||
# endif /* __linux__ */
|
||||
|
||||
#endif /* !STRACE_LINUX_H */
|
||||
|
|
49
src/netbsd.c
Normal file
49
src/netbsd.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Devel strace */
|
||||
/* strace is not free software; you can redistribute it and/or modify it under
|
||||
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||
* Unported as published by the Creative Commons organization.
|
||||
*
|
||||
* strace is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the Creative Commons Attribution-NonCommercial-
|
||||
* ShareAlike 3.0 Unported license for more details.
|
||||
*
|
||||
* You should have received a copy of the Creative Commons Attribution-
|
||||
* NonCommercial-ShareAlike 3.0 along with strace; if not, browse to
|
||||
* http://creativecommons.org/licenses/by-nc-sa/3.0/ */
|
||||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "netbsd.h"
|
||||
|
||||
|
||||
#ifdef __NetBSD__
|
||||
/* variables */
|
||||
char const * stracecall[] =
|
||||
{
|
||||
NULL,
|
||||
"exit",
|
||||
"fork",
|
||||
"read",
|
||||
"write",
|
||||
"open",
|
||||
"close",
|
||||
"wait4",
|
||||
"oldcreat",
|
||||
"link",
|
||||
"unlink",
|
||||
"oldexecv",
|
||||
"chdir",
|
||||
"fchdir",
|
||||
"mknod",
|
||||
"chmod",
|
||||
"chown",
|
||||
"break",
|
||||
NULL,
|
||||
"oldlseek",
|
||||
"getpid"
|
||||
};
|
||||
#endif /* __NetBSD__ */
|
53
src/netbsd.h
Normal file
53
src/netbsd.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Devel strace */
|
||||
/* strace is not free software; you can redistribute it and/or modify it under
|
||||
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||
* Unported as published by the Creative Commons organization.
|
||||
*
|
||||
* strace is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
* A PARTICULAR PURPOSE. See the Creative Commons Attribution-NonCommercial-
|
||||
* ShareAlike 3.0 Unported license for more details.
|
||||
*
|
||||
* You should have received a copy of the Creative Commons Attribution-
|
||||
* NonCommercial-ShareAlike 3.0 along with strace; if not, browse to
|
||||
* http://creativecommons.org/licenses/by-nc-sa/3.0/ */
|
||||
|
||||
|
||||
|
||||
#ifndef STRACE_NETBSD_H
|
||||
# define STRACE_NETBSD_H
|
||||
|
||||
# ifdef __NetBSD__
|
||||
# include <sys/syscall.h>
|
||||
# include <machine/reg.h>
|
||||
|
||||
|
||||
/* types */
|
||||
typedef long ptrace_data_t; /* XXX really is int */
|
||||
struct user
|
||||
{
|
||||
struct reg regs;
|
||||
};
|
||||
|
||||
|
||||
/* constants */
|
||||
# define PTRACE_CONT PT_CONTINUE
|
||||
# define PTRACE_GETREGS PT_GETREGS
|
||||
# define PTRACE_SYSCALL PT_SYSCALL
|
||||
# define PTRACE_TRACEME PT_TRACE_ME
|
||||
|
||||
# if defined(__amd64__)
|
||||
# define _REG32_EAX 11 /* XXX or #define _KERNEL */
|
||||
# define orig_eax regs[_REG32_EAX]
|
||||
# elif defined(__i386__)
|
||||
# define orig_eax r_eax
|
||||
# endif
|
||||
|
||||
|
||||
/* variables */
|
||||
extern char const * stracecall[SYS_getpid + 1];
|
||||
# endif /* __NetBSD__ */
|
||||
|
||||
#endif /* !STRACE_NETBSD_H */
|
|
@ -5,5 +5,11 @@ dist=Makefile
|
|||
|
||||
[strace]
|
||||
type=binary
|
||||
sources=linux.c,strace.c
|
||||
sources=linux.c,netbsd.c,strace.c
|
||||
install=$(BINDIR)
|
||||
|
||||
[linux.c]
|
||||
depends=linux.h
|
||||
|
||||
[netbsd.c]
|
||||
depends=netbsd.h
|
||||
|
|
26
src/strace.c
26
src/strace.c
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2007 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* This file is part of DeforaOS Devel strace */
|
||||
/* strace is not free software; you can redistribute it and/or modify it under
|
||||
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||
|
@ -17,17 +17,18 @@
|
|||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __linux__
|
||||
#include <signal.h>
|
||||
#include "linux.h"
|
||||
#endif
|
||||
#include "netbsd.h"
|
||||
|
||||
|
||||
/* strace */
|
||||
static int _strace_parent(pid_t pid);
|
||||
|
||||
static int _strace(char * argv[])
|
||||
{
|
||||
pid_t pid;
|
||||
|
@ -39,7 +40,7 @@ static int _strace(char * argv[])
|
|||
}
|
||||
if(pid == 0)
|
||||
{
|
||||
ptrace(PTRACE_TRACEME);
|
||||
ptrace(PTRACE_TRACEME, -1, NULL, (ptrace_data_t)NULL);
|
||||
execvp(argv[0], argv);
|
||||
fprintf(stderr, "%s", "strace: ");
|
||||
perror(argv[0]);
|
||||
|
@ -64,22 +65,23 @@ static int _strace_parent(pid_t pid)
|
|||
static int _handle(pid_t pid, int status)
|
||||
{
|
||||
struct user context;
|
||||
int size = sizeof(_syscall) / 4;
|
||||
int size = sizeof(stracecall) / 4;
|
||||
|
||||
if(!WIFSTOPPED(status))
|
||||
return -1;
|
||||
switch(WSTOPSIG(status))
|
||||
{
|
||||
case SIGTRAP:
|
||||
ptrace(PTRACE_GETREGS, pid, NULL, &context);
|
||||
ptrace(PTRACE_GETREGS, pid, NULL,
|
||||
(ptrace_data_t)&context);
|
||||
if(size >= context.regs.orig_eax)
|
||||
fprintf(stderr, "%s();\n",
|
||||
_syscall[context.regs.orig_eax - 1]);
|
||||
fprintf(stderr, "%s();\n", stracecall[
|
||||
context.regs.orig_eax - 1]);
|
||||
else
|
||||
fprintf(stderr, "%ld\n", context.regs.orig_eax);
|
||||
ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
|
||||
ptrace(PTRACE_SYSCALL, pid, NULL, (ptrace_data_t)NULL);
|
||||
wait(0);
|
||||
ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
|
||||
ptrace(PTRACE_SYSCALL, pid, NULL, (ptrace_data_t)NULL);
|
||||
break;
|
||||
default:
|
||||
ptrace(PTRACE_CONT, pid, NULL, WSTOPSIG(status));
|
||||
|
@ -92,7 +94,7 @@ static int _handle(pid_t pid, int status)
|
|||
/* usage */
|
||||
static int _usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s", "Usage: strace program [argument...]\n");
|
||||
fputs("Usage: strace program [argument...]\n", stderr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user