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)
|
$(LN) -s . $(PACKAGE)-$(VERSION)
|
||||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
||||||
$(PACKAGE)-$(VERSION)/src/linux.c \
|
$(PACKAGE)-$(VERSION)/src/linux.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/netbsd.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/strace.c \
|
$(PACKAGE)-$(VERSION)/src/strace.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
|
|
|
@ -15,16 +15,19 @@ INSTALL = install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
strace_OBJS = linux.o strace.o
|
strace_OBJS = linux.o netbsd.o strace.o
|
||||||
strace_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
strace_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
strace_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
strace_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
|
||||||
strace: $(strace_OBJS)
|
strace: $(strace_OBJS)
|
||||||
$(CC) -o strace $(strace_OBJS) $(strace_LDFLAGS)
|
$(CC) -o strace $(strace_OBJS) $(strace_LDFLAGS)
|
||||||
|
|
||||||
linux.o: linux.c
|
linux.o: linux.c linux.h
|
||||||
$(CC) $(strace_CFLAGS) -c linux.c
|
$(CC) $(strace_CFLAGS) -c linux.c
|
||||||
|
|
||||||
|
netbsd.o: netbsd.c netbsd.h
|
||||||
|
$(CC) $(strace_CFLAGS) -c netbsd.c
|
||||||
|
|
||||||
strace.o: strace.c
|
strace.o: strace.c
|
||||||
$(CC) $(strace_CFLAGS) -c strace.c
|
$(CC) $(strace_CFLAGS) -c strace.c
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $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 */
|
/* This file is part of DeforaOS Devel strace */
|
||||||
/* strace is not free software; you can redistribute it and/or modify it under
|
/* 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
|
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||||
|
@ -20,7 +20,9 @@
|
||||||
#include "linux.h"
|
#include "linux.h"
|
||||||
|
|
||||||
|
|
||||||
char const * _syscall[] =
|
#ifdef __linux__
|
||||||
|
/* variables */
|
||||||
|
char const * stracecall[] =
|
||||||
{
|
{
|
||||||
"exit",
|
"exit",
|
||||||
"fork",
|
"fork",
|
||||||
|
@ -43,3 +45,4 @@ char const * _syscall[] =
|
||||||
"lseek",
|
"lseek",
|
||||||
"getpid"
|
"getpid"
|
||||||
};
|
};
|
||||||
|
#endif /* __linux__ */
|
||||||
|
|
15
src/linux.h
15
src/linux.h
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $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 */
|
/* This file is part of DeforaOS Devel strace */
|
||||||
/* strace is not free software; you can redistribute it and/or modify it under
|
/* 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
|
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||||
|
@ -19,10 +19,17 @@
|
||||||
#ifndef STRACE_LINUX_H
|
#ifndef STRACE_LINUX_H
|
||||||
# define STRACE_LINUX_H
|
# define STRACE_LINUX_H
|
||||||
|
|
||||||
# include <linux/user.h>
|
# ifdef __linux__
|
||||||
# include <asm/unistd.h>
|
# 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 */
|
#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]
|
[strace]
|
||||||
type=binary
|
type=binary
|
||||||
sources=linux.c,strace.c
|
sources=linux.c,netbsd.c,strace.c
|
||||||
install=$(BINDIR)
|
install=$(BINDIR)
|
||||||
|
|
||||||
|
[linux.c]
|
||||||
|
depends=linux.h
|
||||||
|
|
||||||
|
[netbsd.c]
|
||||||
|
depends=netbsd.h
|
||||||
|
|
28
src/strace.c
28
src/strace.c
|
@ -1,5 +1,5 @@
|
||||||
/* $Id$ */
|
/* $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 */
|
/* This file is part of DeforaOS Devel strace */
|
||||||
/* strace is not free software; you can redistribute it and/or modify it under
|
/* 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
|
* the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0
|
||||||
|
@ -17,17 +17,18 @@
|
||||||
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/ptrace.h>
|
#include <sys/ptrace.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#ifdef __linux__
|
#include <signal.h>
|
||||||
# include "linux.h"
|
#include "linux.h"
|
||||||
#endif
|
#include "netbsd.h"
|
||||||
|
|
||||||
|
|
||||||
/* strace */
|
/* strace */
|
||||||
static int _strace_parent(pid_t pid);
|
static int _strace_parent(pid_t pid);
|
||||||
|
|
||||||
static int _strace(char * argv[])
|
static int _strace(char * argv[])
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
@ -39,7 +40,7 @@ static int _strace(char * argv[])
|
||||||
}
|
}
|
||||||
if(pid == 0)
|
if(pid == 0)
|
||||||
{
|
{
|
||||||
ptrace(PTRACE_TRACEME);
|
ptrace(PTRACE_TRACEME, -1, NULL, (ptrace_data_t)NULL);
|
||||||
execvp(argv[0], argv);
|
execvp(argv[0], argv);
|
||||||
fprintf(stderr, "%s", "strace: ");
|
fprintf(stderr, "%s", "strace: ");
|
||||||
perror(argv[0]);
|
perror(argv[0]);
|
||||||
|
@ -64,22 +65,23 @@ static int _strace_parent(pid_t pid)
|
||||||
static int _handle(pid_t pid, int status)
|
static int _handle(pid_t pid, int status)
|
||||||
{
|
{
|
||||||
struct user context;
|
struct user context;
|
||||||
int size = sizeof(_syscall) / 4;
|
int size = sizeof(stracecall) / 4;
|
||||||
|
|
||||||
if(!WIFSTOPPED(status))
|
if(!WIFSTOPPED(status))
|
||||||
return -1;
|
return -1;
|
||||||
switch(WSTOPSIG(status))
|
switch(WSTOPSIG(status))
|
||||||
{
|
{
|
||||||
case SIGTRAP:
|
case SIGTRAP:
|
||||||
ptrace(PTRACE_GETREGS, pid, NULL, &context);
|
ptrace(PTRACE_GETREGS, pid, NULL,
|
||||||
|
(ptrace_data_t)&context);
|
||||||
if(size >= context.regs.orig_eax)
|
if(size >= context.regs.orig_eax)
|
||||||
fprintf(stderr, "%s();\n",
|
fprintf(stderr, "%s();\n", stracecall[
|
||||||
_syscall[context.regs.orig_eax - 1]);
|
context.regs.orig_eax - 1]);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%ld\n", context.regs.orig_eax);
|
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);
|
wait(0);
|
||||||
ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
|
ptrace(PTRACE_SYSCALL, pid, NULL, (ptrace_data_t)NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ptrace(PTRACE_CONT, pid, NULL, WSTOPSIG(status));
|
ptrace(PTRACE_CONT, pid, NULL, WSTOPSIG(status));
|
||||||
|
@ -92,7 +94,7 @@ static int _handle(pid_t pid, int status)
|
||||||
/* usage */
|
/* usage */
|
||||||
static int _usage(void)
|
static int _usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "%s", "Usage: strace program [argument...]\n");
|
fputs("Usage: strace program [argument...]\n", stderr);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user