summaryrefslogtreecommitdiffstats
path: root/usr.bin/truss/amd64-fbsd.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2007-04-10 04:03:34 +0000
committerdelphij <delphij@FreeBSD.org>2007-04-10 04:03:34 +0000
commit70cda62de51a69e83aae7565ff882b9edd048d14 (patch)
tree7ee5d84012b77bdd06777d2992c7aec9f559b5ce /usr.bin/truss/amd64-fbsd.c
parent96664c6737f5b26e562ce2c7fd207087f97ed9a7 (diff)
downloadFreeBSD-src-70cda62de51a69e83aae7565ff882b9edd048d14.zip
FreeBSD-src-70cda62de51a69e83aae7565ff882b9edd048d14.tar.gz
Make use of ptrace(2) instead of procfs in truss(1), eliminating
yet another need of an available /proc/ mount. Tested with: make universe Submitted by: howardsu Reviewed by: alfred
Diffstat (limited to 'usr.bin/truss/amd64-fbsd.c')
-rw-r--r--usr.bin/truss/amd64-fbsd.c49
1 files changed, 17 insertions, 32 deletions
diff --git a/usr.bin/truss/amd64-fbsd.c b/usr.bin/truss/amd64-fbsd.c
index 7c7a82e..dd00f59 100644
--- a/usr.bin/truss/amd64-fbsd.c
+++ b/usr.bin/truss/amd64-fbsd.c
@@ -43,8 +43,7 @@ static const char rcsid[] =
*/
#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/pioctl.h>
+#include <sys/ptrace.h>
#include <sys/syscall.h>
#include <machine/reg.h>
@@ -63,7 +62,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int fd = -1;
static int cpid = -1;
#include "syscalls.h"
@@ -113,25 +111,16 @@ clear_fsc(void) {
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->curthread->tid;
clear_fsc();
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
+ if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0)
+ {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -163,7 +152,7 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|| !strcmp(fsc.name, "rfork")
|| !strcmp(fsc.name, "vfork"))))
{
- trussinfo->in_fork = 1;
+ trussinfo->curthread->in_fork = 1;
}
if (nargs == 0)
@@ -181,8 +170,13 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
}
}
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)
+ 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;
}
@@ -223,7 +217,7 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
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,25 +273,16 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs) {
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->curthread->tid;
- lseek(fd, 0L, 0);
- if (read(fd, &regs, sizeof(regs)) != sizeof(regs)) {
+ if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0)
+ {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -328,7 +313,7 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
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;
}
}
OpenPOWER on IntegriCloud