PERFORCE change 102783 for review
Howard Su
howardsu at FreeBSD.org
Sun Jul 30 12:06:31 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=102783
Change 102783 by howardsu at su_vm on 2006/07/30 12:05:29
Remove the dependency of procfs. Convert it to use
the new ptrace(2) interface.
Affected files ...
.. //depot/projects/dtrace/src/usr.bin/truss/alpha-fbsd.c#3 edit
.. //depot/projects/dtrace/src/usr.bin/truss/amd64-fbsd.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/extern.h#3 edit
.. //depot/projects/dtrace/src/usr.bin/truss/i386-fbsd.c#5 edit
.. //depot/projects/dtrace/src/usr.bin/truss/i386-linux.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/ia64-fbsd.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/main.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/powerpc-fbsd.c#3 edit
.. //depot/projects/dtrace/src/usr.bin/truss/setup.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/sparc64-fbsd.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/syscall.h#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/syscalls.c#4 edit
.. //depot/projects/dtrace/src/usr.bin/truss/truss.1#3 edit
.. //depot/projects/dtrace/src/usr.bin/truss/truss.h#4 edit
Differences ...
==== //depot/projects/dtrace/src/usr.bin/truss/alpha-fbsd.c#3 (text+ko) ====
@@ -45,8 +45,7 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <machine/reg.h>
@@ -65,7 +64,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -115,30 +113,17 @@
void
alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i;
unsigned int parm_offset;
struct syscall *sc;
int indir = 0; /* indirect system call */
+ struct ptrace_io_desc iorequest;
+ cpid = trussinfo->tid;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
-
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
parm_offset = regs.r_regs[R_SP] + sizeof(int);
/*
@@ -185,8 +170,13 @@
* on the stack, as is normal for other processors.
* The fall-through for all of these is deliberate!!!
*/
- lseek(Procfd, regs.r_regs[R_SP], SEEK_SET);
- read(fd, &fsc.args[6], (nargs - 6) * sizeof(fsc.args[0]));
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)regs.r_regs[R_SP];
+ iorequest.piod_addr = &fsc.args[6];
+ iorequest.piod_len = (nargs - 6) * sizeof(unsigned long);
+ ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0) return;
+ break;
case 6: fsc.args[5] = regs.r_regs[R_A5];
case 5: fsc.args[4] = regs.r_regs[R_A4];
case 4: fsc.args[3] = regs.r_regs[R_A3];
@@ -238,7 +228,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -293,28 +283,15 @@
long
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "\n");
- return (-1);
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
retval = regs.r_regs[R_V0];
errorp = !!(regs.r_regs[R_A3]);
@@ -342,7 +319,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/amd64-fbsd.c#4 (text+ko) ====
@@ -43,9 +43,8 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
#include <sys/syscall.h>
+#include <sys/ptrace.h>
#include <machine/reg.h>
#include <machine/psl.h>
@@ -63,7 +62,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -113,28 +111,15 @@
void
amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i, reg;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->pid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
/*
* FreeBSD has two special kinds of system call redirctions --
@@ -181,9 +166,14 @@
}
}
if (nargs > i) {
- lseek(Procfd, regs.r_rsp + sizeof(register_t), SEEK_SET);
- if (read(Procfd, &fsc.args[i], (nargs-i) * sizeof(register_t)) == -1)
- return;
+ struct ptrace_io_desc iorequest;
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t));
+ iorequest.piod_addr = &fsc.args[i];
+ iorequest.piod_len = (nargs - i) * sizeof(register_t);
+ ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return;
}
sc = get_syscall(fsc.name);
@@ -223,7 +213,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -279,28 +269,15 @@
long
amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->pid;
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
retval = regs.r_rax;
errorp = !!(regs.r_rflags & PSL_C);
@@ -328,7 +305,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/extern.h#3 (text+ko) ====
@@ -32,8 +32,9 @@
*/
extern int setup_and_wait(char **);
-extern int start_tracing(int, int, int, int);
+extern int start_tracing(int);
extern void restore_proc(int);
+extern void waitevent(struct trussinfo *);
extern const char *ioctlname(register_t val);
extern char *strsig(int sig);
#ifdef __alpha__
@@ -63,4 +64,3 @@
extern long sparc64_syscall_exit(struct trussinfo *, int);
#endif
-extern int Procfd;
==== //depot/projects/dtrace/src/usr.bin/truss/i386-fbsd.c#5 (text+ko) ====
@@ -43,9 +43,8 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
#include <sys/syscall.h>
+#include <sys/ptrace.h>
#include <machine/reg.h>
#include <machine/psl.h>
@@ -63,7 +62,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -113,29 +111,16 @@
void
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i;
unsigned int parm_offset;
struct syscall *sc = NULL;
-
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ struct ptrace_io_desc iorequest;
+ cpid = trussinfo->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
parm_offset = regs.r_esp + sizeof(int);
/*
@@ -146,14 +131,12 @@
syscall_num = regs.r_eax;
switch (syscall_num) {
case SYS_syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
- parm_offset += sizeof(int);
+ syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ parm_offset += sizeof(int);
break;
case SYS___syscall:
- lseek(Procfd, parm_offset, SEEK_SET);
- read(Procfd, &syscall_num, sizeof(int));
- parm_offset += sizeof(quad_t);
+ syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ parm_offset += sizeof(quad_t);
break;
}
@@ -171,14 +154,18 @@
{
trussinfo->in_fork = 1;
}
-
+
if (nargs == 0)
return;
fsc.args = malloc((1+nargs) * sizeof(unsigned long));
- lseek(Procfd, parm_offset, SEEK_SET);
- if (read(Procfd, fsc.args, nargs * sizeof(unsigned long)) == -1)
- return;
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)parm_offset;
+ iorequest.piod_addr = fsc.args;
+ iorequest.piod_len = nargs * sizeof(unsigned long);
+ ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0)
+ return;
if (fsc.name)
sc = get_syscall(fsc.name);
@@ -218,7 +205,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -274,28 +261,16 @@
long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->pid;
+
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
retval = regs.r_eax;
errorp = !!(regs.r_eflags & PSL_C);
@@ -323,7 +298,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/i386-linux.c#4 (text+ko) ====
@@ -41,8 +41,7 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <machine/reg.h>
#include <machine/psl.h>
@@ -60,7 +59,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "linux_syscalls.h"
@@ -108,28 +106,16 @@
void
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
syscall_num = regs.r_eax;
fsc.number = syscall_num;
@@ -200,7 +186,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -264,28 +250,15 @@
long
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->pid;
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "\n");
- return (-1);
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
retval = regs.r_eax;
errorp = !!(regs.r_eflags & PSL_C);
@@ -313,7 +286,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/ia64-fbsd.c#4 (text+ko) ====
@@ -43,8 +43,7 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <machine/reg.h>
@@ -62,7 +61,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -112,29 +110,16 @@
void
ia64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
int syscall_num;
int i;
unsigned long *parm_offset;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
parm_offset = ®s.r_scratch.gr16;
/*
@@ -204,7 +189,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -260,28 +245,15 @@
long
ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return (-1);
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
retval = regs.r_scratch.gr8;
errorp = (regs.r_scratch.gr10 != 0) ? 1 : 0;
@@ -309,7 +281,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/main.c#4 (text+ko) ====
@@ -39,11 +39,10 @@
*/
#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
+#include <sys/sysctl.h>
#include <ctype.h>
#include <err.h>
@@ -59,12 +58,7 @@
#include "truss.h"
#include "extern.h"
-/*
- * It's difficult to parameterize this because it must be
- * accessible in a signal handler.
- */
-
-int Procfd;
+#define MAXARGS 5
static void
usage(void)
@@ -119,18 +113,18 @@
set_etype(struct trussinfo *trussinfo)
{
struct ex_types *funcs;
- char etype[24];
char progt[32];
- int fd;
+ int len = sizeof(progt);
+ int mib[4];
+ int error;
- sprintf(etype, "/proc/%d/etype", trussinfo->pid);
- if ((fd = open(etype, O_RDONLY)) == -1) {
- strcpy(progt, "FreeBSD a.out");
- } else {
- int len = read(fd, progt, sizeof(progt));
- progt[len-1] = '\0';
- close(fd);
- }
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_PROC;
+ mib[2] = KERN_PROC_SV_NAME;
+ mib[3] = trussinfo->pid;
+ error = sysctl(mib, 4, progt, &len, NULL, 0);
+ if (error != 0)
+ err(1, "can not sysctl");
for (funcs = ex_types; funcs->type; funcs++)
if (!strcmp(funcs->type, progt))
@@ -167,14 +161,11 @@
int c;
int i;
char **command;
- struct procfs_status pfs;
struct ex_types *funcs;
- int in_exec, sigexit, initial_open;
+ int sigexit, initial_open;
char *fname;
struct trussinfo *trussinfo;
char *signame;
-
- in_exec = 0;
sigexit = 0;
fname = NULL;
initial_open = 1;
@@ -245,6 +236,7 @@
signal(SIGTERM, SIG_IGN);
signal(SIGQUIT, SIG_IGN);
} else {
+ start_tracing(trussinfo->pid);
signal(SIGINT, restore_proc);
signal(SIGTERM, restore_proc);
signal(SIGQUIT, restore_proc);
@@ -255,20 +247,11 @@
* At this point, if we started the process, it is stopped waiting to
* be woken up, either in exit() or in execve().
*/
+START_TRACE:
+ funcs = set_etype(trussinfo);
-START_TRACE:
- Procfd = start_tracing(
- trussinfo->pid, initial_open,
- S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
- ((trussinfo->flags & NOSIGS) ? 0 : S_SIG),
- ((trussinfo->flags & FOLLOWFORKS) ? PF_FORK : 0));
initial_open = 0;
- if (Procfd == -1)
- return (0);
- pfs.why = 0;
-
- funcs = set_etype(trussinfo);
/*
* At this point, it's a simple loop, waiting for the process to
* stop, finding out why, printing out why, and then continuing it.
@@ -278,42 +261,27 @@
clock_gettime(CLOCK_REALTIME, &trussinfo->start_time);
do {
- int val = 0;
- struct timespec timediff;
-
- if (ioctl(Procfd, PIOCWAIT, &pfs) == -1)
- warn("PIOCWAIT top of loop");
- else {
- switch(i = pfs.why) {
+ struct timespec timediff;
+ waitevent(trussinfo);
+ switch(i = trussinfo->pr_why) {
case S_SCE:
- funcs->enter_syscall(trussinfo, pfs.val);
+ funcs->enter_syscall(trussinfo, MAXARGS);
clock_gettime(CLOCK_REALTIME,
&trussinfo->before);
break;
case S_SCX:
clock_gettime(CLOCK_REALTIME,
&trussinfo->after);
- /*
- * This is so we don't get two messages for
- * an exec -- one for the S_EXEC, and one for
- * the syscall exit. It also, conveniently,
- * ensures that the first message printed out
- * isn't the return-from-syscall used to
- * create the process.
- */
- if (in_exec) {
- in_exec = 0;
- break;
- }
if (trussinfo->in_fork &&
- (trussinfo->flags & FOLLOWFORKS)) {
+ (trussinfo->flags & FOLLOWFORKS)
+ ) {
int childpid;
trussinfo->in_fork = 0;
childpid =
funcs->exit_syscall(trussinfo,
- pfs.val);
+ trussinfo->pr_data);
/*
* Fork a new copy of ourself to trace
@@ -326,7 +294,7 @@
}
break;
}
- funcs->exit_syscall(trussinfo, pfs.val);
+ funcs->exit_syscall(trussinfo, MAXARGS);
break;
case S_SIG:
if (trussinfo->flags & FOLLOWFORKS)
@@ -346,12 +314,12 @@
(long)timediff.tv_sec,
timediff.tv_nsec);
}
- signame = strsig(pfs.val);
+ signame = strsig(trussinfo->pr_data);
fprintf(trussinfo->outfile,
- "SIGNAL %lu (%s)\n", pfs.val,
+ "SIGNAL %u (%s)\n", trussinfo->pr_data,
signame == NULL ? "?" : signame);
free(signame);
- sigexit = pfs.val;
+ sigexit = trussinfo->pr_data;
break;
case S_EXIT:
if (trussinfo->flags & FOLLOWFORKS)
@@ -371,25 +339,12 @@
(long)timediff.tv_sec, timediff.tv_nsec);
}
fprintf(trussinfo->outfile,
- "process exit, rval = %lu\n", pfs.val);
+ "process exit, rval = %u\n", trussinfo->pr_data);
break;
- case S_EXEC:
- funcs = set_etype(trussinfo);
- in_exec = 1;
- break;
default:
- fprintf(trussinfo->outfile,
- "Process stopped because of: %d\n", i);
break;
- }
}
- if (ioctl(Procfd, PIOCCONT, val) == -1) {
- if (kill(trussinfo->pid, 0) == -1 && errno == ESRCH)
- break;
- else
- warn("PIOCCONT");
- }
- } while (pfs.why != S_EXIT);
+ } while (trussinfo->pr_why != S_EXIT);
fflush(trussinfo->outfile);
if (sigexit) {
struct rlimit rlp;
==== //depot/projects/dtrace/src/usr.bin/truss/powerpc-fbsd.c#3 (text+ko) ====
@@ -41,8 +41,7 @@
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <machine/reg.h>
@@ -62,7 +61,6 @@
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -112,7 +110,6 @@
void
powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs) {
- char buf[32];
struct reg regs;
void *args;
int syscall_num;
@@ -120,22 +117,10 @@
unsigned int regargs;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDWR);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return;
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
- return;
- }
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
/*
* FreeBSD has two special kinds of system call redirctions --
@@ -177,8 +162,13 @@
if (nargs > regargs) {
memmove(&fsc.args[0], args, regargs * sizeof(fsc.args[0]));
- lseek(Procfd, regs.fixreg[1] + 8, SEEK_SET);
- read(Procfd, &fsc.args[regargs], (nargs - regargs) * sizeof(fsc.args[0]));
+
+ iorequest.piod_op = PIOD_READ_D;
+ iorequest.piod_offs = (void *)(regs.fixreg[1] + 8);
+ iorequest.piod_addr = &fsc.args[regargs];
+ iorequest.piod_len = (nargs - regargs) * sizeof(fsc.args[0]);
+ ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ if (iorequest.piod_len == 0) return;
} else {
memmove(&fsc.args[0], args, nargs * sizeof(fsc.args[0]));
}
@@ -220,7 +210,7 @@
i < (fsc.nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(Procfd, &sc->args[i], fsc.args, 0, trussinfo);
+ fsc.s_args[i] = print_arg(&sc->args[i], fsc.args, 0, trussinfo);
}
}
#if DEBUG
@@ -275,28 +265,15 @@
long
powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
- char buf[32];
struct reg regs;
long retval;
int i;
int errorp;
struct syscall *sc;
- if (fd == -1 || trussinfo->pid != cpid) {
- sprintf(buf, "/proc/%d/regs", trussinfo->pid);
- fd = open(buf, O_RDONLY);
- if (fd == -1) {
- fprintf(trussinfo->outfile, "-- CANNOT OPEN REGISTERS --\n");
- return (-1);
- }
- cpid = trussinfo->pid;
- }
+ cpid = trussinfo->tid;
+ ptrace(PT_GETREGS, cpid, (caddr_t)®s, 0);
- lseek(fd, 0L, 0);
- if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
- fprintf(trussinfo->outfile, "\n");
- return (-1);
- }
retval = regs.fixreg[3];
errorp = !!(regs.cr & 0x10000000);
@@ -332,7 +309,7 @@
if (errorp)
asprintf(&temp, "0x%lx", fsc.args[sc->args[i].offset]);
else
- temp = print_arg(Procfd, &sc->args[i], fsc.args, retval, trussinfo);
+ temp = print_arg(&sc->args[i], fsc.args, retval, trussinfo);
fsc.s_args[i] = temp;
}
}
==== //depot/projects/dtrace/src/usr.bin/truss/setup.c#4 (text+ko) ====
@@ -38,11 +38,13 @@
*/
#include <sys/param.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
#include <sys/wait.h>
+#include <sys/ptrace.h>
+#include <sys/types.h>
+#include <signal.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
@@ -51,11 +53,30 @@
#include <time.h>
#include <unistd.h>
+#include <machine/reg.h>
+
#include "truss.h"
#include "extern.h"
-static int evflags = 0;
+
+static siginfo_t myinfo;
+
+static void handler(int si __unused, siginfo_t *info, void *uap __unused)
+{
+ memcpy(&myinfo, info, sizeof(myinfo));
+}
+static void
+installhandler(void)
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list