Ported to FreeBSD (untested)
This commit is contained in:
parent
c680ec5507
commit
8cec231590
20
Makefile
20
Makefile
|
@ -1,9 +1,9 @@
|
|||
PACKAGE = strace
|
||||
VERSION = 0.0.0
|
||||
SUBDIRS = src
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
TAR = tar -czvf
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
TAR ?= tar -czvf
|
||||
|
||||
|
||||
all: subdirs
|
||||
|
@ -18,20 +18,24 @@ distclean:
|
|||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done
|
||||
|
||||
dist:
|
||||
$(RM) -r $(PACKAGE)-$(VERSION)
|
||||
$(LN) -s . $(PACKAGE)-$(VERSION)
|
||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \
|
||||
$(RM) -r -- $(PACKAGE)-$(VERSION)
|
||||
$(LN) -s -- . $(PACKAGE)-$(VERSION)
|
||||
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \
|
||||
$(PACKAGE)-$(VERSION)/src/freebsd.c \
|
||||
$(PACKAGE)-$(VERSION)/src/linux.c \
|
||||
$(PACKAGE)-$(VERSION)/src/netbsd.c \
|
||||
$(PACKAGE)-$(VERSION)/src/strace.c \
|
||||
$(PACKAGE)-$(VERSION)/src/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/src/freebsd.h \
|
||||
$(PACKAGE)-$(VERSION)/src/linux.h \
|
||||
$(PACKAGE)-$(VERSION)/src/netbsd.h \
|
||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||
$(PACKAGE)-$(VERSION)/Makefile \
|
||||
$(PACKAGE)-$(VERSION)/COPYING \
|
||||
$(PACKAGE)-$(VERSION)/project.conf
|
||||
$(RM) $(PACKAGE)-$(VERSION)
|
||||
$(RM) -- $(PACKAGE)-$(VERSION)
|
||||
|
||||
install: all
|
||||
install:
|
||||
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done
|
||||
|
||||
uninstall:
|
||||
|
|
34
src/Makefile
34
src/Makefile
|
@ -1,47 +1,51 @@
|
|||
TARGETS = strace
|
||||
PREFIX = /usr/local
|
||||
DESTDIR =
|
||||
DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
CC = cc
|
||||
CPPFLAGSF=
|
||||
CPPFLAGS=
|
||||
SBINDIR = $(PREFIX)/sbin
|
||||
CC ?= cc
|
||||
CPPFLAGSF?=
|
||||
CPPFLAGS?=
|
||||
CFLAGSF = -W
|
||||
CFLAGS = -Wall -g -O2 -pedantic
|
||||
RM = rm -f
|
||||
LN = ln -f
|
||||
MKDIR = mkdir -p
|
||||
INSTALL = install
|
||||
RM ?= rm -f
|
||||
LN ?= ln -f
|
||||
MKDIR ?= mkdir -p
|
||||
INSTALL ?= install
|
||||
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
strace_OBJS = linux.o netbsd.o strace.o
|
||||
strace_OBJS = freebsd.o 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)
|
||||
|
||||
freebsd.o: freebsd.c
|
||||
$(CC) $(strace_CFLAGS) -c freebsd.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
|
||||
strace.o: strace.c freebsd.h linux.h netbsd.h
|
||||
$(CC) $(strace_CFLAGS) -c strace.c
|
||||
|
||||
clean:
|
||||
$(RM) $(strace_OBJS)
|
||||
$(RM) -- $(strace_OBJS)
|
||||
|
||||
distclean: clean
|
||||
$(RM) $(TARGETS)
|
||||
$(RM) -- $(TARGETS)
|
||||
|
||||
install: all
|
||||
install: $(TARGETS)
|
||||
$(MKDIR) $(DESTDIR)$(BINDIR)
|
||||
$(INSTALL) -m 0755 strace $(DESTDIR)$(BINDIR)/strace
|
||||
$(INSTALL) -m 0755 -- strace $(DESTDIR)$(BINDIR)/strace
|
||||
|
||||
uninstall:
|
||||
$(RM) $(DESTDIR)$(BINDIR)/strace
|
||||
$(RM) -- $(DESTDIR)$(BINDIR)/strace
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
||||
|
|
49
src/freebsd.c
Normal file
49
src/freebsd.c
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 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 <stddef.h>
|
||||
#include "freebsd.h"
|
||||
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
/* variables */
|
||||
char const * stracecall[] =
|
||||
{
|
||||
NULL,
|
||||
"exit",
|
||||
"fork",
|
||||
"read",
|
||||
"write",
|
||||
"open",
|
||||
"close",
|
||||
"wait4",
|
||||
NULL,
|
||||
"link",
|
||||
"unlink",
|
||||
NULL,
|
||||
"chdir",
|
||||
"fchdir",
|
||||
"mknod",
|
||||
"chmod",
|
||||
"chown",
|
||||
"break",
|
||||
NULL,
|
||||
NULL,
|
||||
"getpid"
|
||||
};
|
||||
#endif /* __FreeBSD__ */
|
51
src/freebsd.h
Normal file
51
src/freebsd.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2012 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_FREEBSD_H
|
||||
# define STRACE_FREEBSD_H
|
||||
|
||||
# ifdef __FreeBSD__
|
||||
# include <sys/ptrace.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 orig_eax r_rax
|
||||
# elif defined(__i386__)
|
||||
# define orig_eax r_eax
|
||||
# endif
|
||||
|
||||
|
||||
/* variables */
|
||||
extern char const * stracecall[SYS_getpid + 1];
|
||||
# endif /* __FreeBSD__ */
|
||||
|
||||
#endif /* !STRACE_FREEBSD_H */
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009-2012 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
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include "linux.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009-2012 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
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009-2012 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
|
||||
|
@ -16,7 +16,7 @@
|
|||
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include "netbsd.h"
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009-2012 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,6 +20,8 @@
|
|||
# define STRACE_NETBSD_H
|
||||
|
||||
# ifdef __NetBSD__
|
||||
# include <sys/types.h>
|
||||
# include <sys/ptrace.h>
|
||||
# include <sys/syscall.h>
|
||||
# include <machine/reg.h>
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
targets=strace
|
||||
cflags_force=-W
|
||||
cflags=-Wall -g -O2 -pedantic
|
||||
dist=Makefile
|
||||
dist=Makefile,freebsd.h,linux.h,netbsd.h
|
||||
|
||||
[strace]
|
||||
type=binary
|
||||
sources=linux.c,netbsd.c,strace.c
|
||||
sources=freebsd.c,linux.c,netbsd.c,strace.c
|
||||
install=$(BINDIR)
|
||||
|
||||
[linux.c]
|
||||
|
@ -13,3 +13,6 @@ depends=linux.h
|
|||
|
||||
[netbsd.c]
|
||||
depends=netbsd.h
|
||||
|
||||
[strace.c]
|
||||
depends=freebsd.h,linux.h,netbsd.h
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* $Id$ */
|
||||
/* Copyright (c) 2009 Pierre Pronchery <khorben@defora.org> */
|
||||
/* Copyright (c) 2009-2012 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,11 +17,12 @@
|
|||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include "freebsd.h"
|
||||
#include "linux.h"
|
||||
#include "netbsd.h"
|
||||
|
||||
|
@ -68,7 +69,7 @@ static int _strace_parent(pid_t pid)
|
|||
static int _handle(pid_t pid, int status)
|
||||
{
|
||||
struct user context;
|
||||
int size = sizeof(stracecall) / 4;
|
||||
int size = sizeof(stracecall) / sizeof(*stracecall);
|
||||
|
||||
if(!WIFSTOPPED(status))
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user