Ported to FreeBSD (untested)

This commit is contained in:
Pierre Pronchery 2012-11-03 03:17:07 +01:00
parent c680ec5507
commit 8cec231590
10 changed files with 148 additions and 34 deletions

View File

@ -1,9 +1,9 @@
PACKAGE = strace PACKAGE = strace
VERSION = 0.0.0 VERSION = 0.0.0
SUBDIRS = src SUBDIRS = src
RM = rm -f RM ?= rm -f
LN = ln -f LN ?= ln -f
TAR = tar -czvf TAR ?= tar -czvf
all: subdirs all: subdirs
@ -18,20 +18,24 @@ distclean:
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done @for i in $(SUBDIRS); do (cd $$i && $(MAKE) distclean) || exit; done
dist: dist:
$(RM) -r $(PACKAGE)-$(VERSION) $(RM) -r -- $(PACKAGE)-$(VERSION)
$(LN) -s . $(PACKAGE)-$(VERSION) $(LN) -s -- . $(PACKAGE)-$(VERSION)
@$(TAR) $(PACKAGE)-$(VERSION).tar.gz \ @$(TAR) $(PACKAGE)-$(VERSION).tar.gz -- \
$(PACKAGE)-$(VERSION)/src/freebsd.c \
$(PACKAGE)-$(VERSION)/src/linux.c \ $(PACKAGE)-$(VERSION)/src/linux.c \
$(PACKAGE)-$(VERSION)/src/netbsd.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/freebsd.h \
$(PACKAGE)-$(VERSION)/src/linux.h \
$(PACKAGE)-$(VERSION)/src/netbsd.h \
$(PACKAGE)-$(VERSION)/src/project.conf \ $(PACKAGE)-$(VERSION)/src/project.conf \
$(PACKAGE)-$(VERSION)/Makefile \ $(PACKAGE)-$(VERSION)/Makefile \
$(PACKAGE)-$(VERSION)/COPYING \ $(PACKAGE)-$(VERSION)/COPYING \
$(PACKAGE)-$(VERSION)/project.conf $(PACKAGE)-$(VERSION)/project.conf
$(RM) $(PACKAGE)-$(VERSION) $(RM) -- $(PACKAGE)-$(VERSION)
install: all install:
@for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done @for i in $(SUBDIRS); do (cd $$i && $(MAKE) install) || exit; done
uninstall: uninstall:

View File

@ -1,47 +1,51 @@
TARGETS = strace TARGETS = strace
PREFIX = /usr/local PREFIX = /usr/local
DESTDIR = DESTDIR =
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
CC = cc SBINDIR = $(PREFIX)/sbin
CPPFLAGSF= CC ?= cc
CPPFLAGS= CPPFLAGSF?=
CPPFLAGS?=
CFLAGSF = -W CFLAGSF = -W
CFLAGS = -Wall -g -O2 -pedantic CFLAGS = -Wall -g -O2 -pedantic
RM = rm -f RM ?= rm -f
LN = ln -f LN ?= ln -f
MKDIR = mkdir -p MKDIR ?= mkdir -p
INSTALL = install INSTALL ?= install
all: $(TARGETS) 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_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)
freebsd.o: freebsd.c
$(CC) $(strace_CFLAGS) -c freebsd.c
linux.o: linux.c linux.h linux.o: linux.c linux.h
$(CC) $(strace_CFLAGS) -c linux.c $(CC) $(strace_CFLAGS) -c linux.c
netbsd.o: netbsd.c netbsd.h netbsd.o: netbsd.c netbsd.h
$(CC) $(strace_CFLAGS) -c netbsd.c $(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 $(CC) $(strace_CFLAGS) -c strace.c
clean: clean:
$(RM) $(strace_OBJS) $(RM) -- $(strace_OBJS)
distclean: clean distclean: clean
$(RM) $(TARGETS) $(RM) -- $(TARGETS)
install: all install: $(TARGETS)
$(MKDIR) $(DESTDIR)$(BINDIR) $(MKDIR) $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 strace $(DESTDIR)$(BINDIR)/strace $(INSTALL) -m 0755 -- strace $(DESTDIR)$(BINDIR)/strace
uninstall: uninstall:
$(RM) $(DESTDIR)$(BINDIR)/strace $(RM) -- $(DESTDIR)$(BINDIR)/strace
.PHONY: all clean distclean install uninstall .PHONY: all clean distclean install uninstall

49
src/freebsd.c Normal file
View 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
View 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 */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 */ /* 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
@ -16,7 +16,7 @@
#include <stdlib.h> #include <stddef.h>
#include "linux.h" #include "linux.h"

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 */ /* 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

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 */ /* 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
@ -16,7 +16,7 @@
#include <stdlib.h> #include <stddef.h>
#include "netbsd.h" #include "netbsd.h"

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 */ /* 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,6 +20,8 @@
# define STRACE_NETBSD_H # define STRACE_NETBSD_H
# ifdef __NetBSD__ # ifdef __NetBSD__
# include <sys/types.h>
# include <sys/ptrace.h>
# include <sys/syscall.h> # include <sys/syscall.h>
# include <machine/reg.h> # include <machine/reg.h>

View File

@ -1,11 +1,11 @@
targets=strace targets=strace
cflags_force=-W cflags_force=-W
cflags=-Wall -g -O2 -pedantic cflags=-Wall -g -O2 -pedantic
dist=Makefile dist=Makefile,freebsd.h,linux.h,netbsd.h
[strace] [strace]
type=binary type=binary
sources=linux.c,netbsd.c,strace.c sources=freebsd.c,linux.c,netbsd.c,strace.c
install=$(BINDIR) install=$(BINDIR)
[linux.c] [linux.c]
@ -13,3 +13,6 @@ depends=linux.h
[netbsd.c] [netbsd.c]
depends=netbsd.h depends=netbsd.h
[strace.c]
depends=freebsd.h,linux.h,netbsd.h

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 */ /* 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,11 +17,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h>
#include <sys/ptrace.h> #include <sys/ptrace.h>
#include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h> #include <signal.h>
#include "freebsd.h"
#include "linux.h" #include "linux.h"
#include "netbsd.h" #include "netbsd.h"
@ -68,7 +69,7 @@ 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(stracecall) / 4; int size = sizeof(stracecall) / sizeof(*stracecall);
if(!WIFSTOPPED(status)) if(!WIFSTOPPED(status))
return -1; return -1;