summaryrefslogtreecommitdiffstats
path: root/usr.bin
diff options
context:
space:
mode:
authorzont <zont@FreeBSD.org>2012-09-16 14:38:01 +0000
committerzont <zont@FreeBSD.org>2012-09-16 14:38:01 +0000
commit07b8304d19dd55a8eaac5abd279a0b195f9a2e0e (patch)
tree4414f2afd3e2d82c1cb68d3c0e47d967f00ff093 /usr.bin
parentbde38da8f25291ce18341692c06e5fece707f914 (diff)
downloadFreeBSD-src-07b8304d19dd55a8eaac5abd279a0b195f9a2e0e.zip
FreeBSD-src-07b8304d19dd55a8eaac5abd279a0b195f9a2e0e.tar.gz
- Make truss thread-aware.
Approved by: kib (mentor) MFC after: 2 weeks
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/truss/amd64-fbsd.c152
-rw-r--r--usr.bin/truss/amd64-fbsd32.c153
-rw-r--r--usr.bin/truss/amd64-linux32.c139
-rw-r--r--usr.bin/truss/i386-fbsd.c146
-rw-r--r--usr.bin/truss/i386-linux.c139
-rw-r--r--usr.bin/truss/ia64-fbsd.c139
-rw-r--r--usr.bin/truss/main.c22
-rw-r--r--usr.bin/truss/mips-fbsd.c158
-rw-r--r--usr.bin/truss/powerpc-fbsd.c146
-rw-r--r--usr.bin/truss/powerpc64-fbsd.c146
-rw-r--r--usr.bin/truss/setup.c6
-rw-r--r--usr.bin/truss/sparc64-fbsd.c158
-rw-r--r--usr.bin/truss/syscalls.c16
-rw-r--r--usr.bin/truss/truss.h5
14 files changed, 804 insertions, 721 deletions
diff --git a/usr.bin/truss/amd64-fbsd.c b/usr.bin/truss/amd64-fbsd.c
index 4ded727..516c4d2 100644
--- a/usr.bin/truss/amd64-fbsd.c
+++ b/usr.bin/truss/amd64-fbsd.c
@@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -77,30 +75,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -115,14 +118,14 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
int i, reg, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -142,57 +145,60 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
break;
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
for (i = 0; i < nargs && reg < 6; i++, reg++) {
switch (reg) {
- case 0: fsc.args[i] = regs.r_rdi; break;
- case 1: fsc.args[i] = regs.r_rsi; break;
- case 2: fsc.args[i] = regs.r_rdx; break;
- case 3: fsc.args[i] = regs.r_rcx; break;
- case 4: fsc.args[i] = regs.r_r8; break;
- case 5: fsc.args[i] = regs.r_r9; break;
+ case 0: fsc->args[i] = regs.r_rdi; break;
+ case 1: fsc->args[i] = regs.r_rsi; break;
+ case 2: fsc->args[i] = regs.r_rdx; break;
+ case 3: fsc->args[i] = regs.r_rcx; break;
+ case 4: fsc->args[i] = regs.r_r8; break;
+ case 5: fsc->args[i] = regs.r_r9; break;
}
}
if (nargs > i) {
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_rsp + sizeof(register_t));
- iorequest.piod_addr = &fsc.args[i];
+ iorequest.piod_addr = &fsc->args[i];
iorequest.piod_len = (nargs - i) * sizeof(register_t);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
}
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -202,19 +208,19 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%lx%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -226,30 +232,29 @@ amd64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -263,16 +268,18 @@ long
amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -285,10 +292,11 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -303,18 +311,18 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -322,9 +330,9 @@ amd64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/amd64-fbsd32.c b/usr.bin/truss/amd64-fbsd32.c
index 5cf9f84..72f4295 100644
--- a/usr.bin/truss/amd64-fbsd32.c
+++ b/usr.bin/truss/amd64-fbsd32.c
@@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "freebsd32_syscalls.h"
static int nsyscalls = sizeof(freebsd32_syscallnames) /
@@ -78,7 +76,7 @@ static int nsyscalls = sizeof(freebsd32_syscallnames) /
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd32_syscall {
+struct freebsd32_syscall {
struct syscall *sc;
const char *name;
int number;
@@ -86,25 +84,29 @@ static struct freebsd32_syscall {
unsigned int *args32;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd32_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd32_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd32_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.args32)
- free(fsc.args32);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ free(fsc->args32);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -119,15 +121,15 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd32_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
unsigned long parm_offset;
int i, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -141,60 +143,63 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_rax;
switch (syscall_num) {
case SYS_syscall:
- syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(int);
break;
case SYS___syscall:
- syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(quad_t);
break;
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : freebsd32_syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args32 = malloc((1 + nargs) * sizeof(unsigned int));
+ fsc->args32 = malloc((1 + nargs) * sizeof(unsigned int));
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset;
- iorequest.piod_addr = fsc.args32;
+ iorequest.piod_addr = fsc->args32;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned int);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
for (i = 0; i < nargs + 1; i++)
- fsc.args[i] = fsc.args32[i];
+ fsc->args[i] = fsc->args32[i];
sc = NULL;
- if (fsc.name)
- sc = get_syscall(fsc.name);
+ if (fsc->name)
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -204,19 +209,19 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -228,30 +233,29 @@ amd64_fbsd32_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "freebsd32_execve") == 0||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "freebsd32_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "freebsd32_execve") == 0) {
+ if (strcmp(fsc->name, "freebsd32_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -265,16 +269,18 @@ long
amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd32_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -287,10 +293,11 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -305,18 +312,18 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "freebsd32_execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "freebsd32_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -324,9 +331,9 @@ amd64_fbsd32_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/amd64-linux32.c b/usr.bin/truss/amd64-linux32.c
index e041b60..2c025a3 100644
--- a/usr.bin/truss/amd64-linux32.c
+++ b/usr.bin/truss/amd64-linux32.c
@@ -59,8 +59,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "linux32_syscalls.h"
static int nsyscalls =
@@ -75,28 +73,34 @@ static int nsyscalls =
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct linux_syscall {
+struct linux_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long args[5];
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct linux_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct linux_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct linux_syscall *fsc)
{
int i;
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -110,31 +114,34 @@ void
amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct reg regs;
+ struct linux_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
int i, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
syscall_num = regs.r_rax;
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : linux32_syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "linux_fork") == 0||
- strcmp(fsc.name, "linux_vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "linux_fork") == 0 ||
+ strcmp(fsc->name, "linux_vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
@@ -148,25 +155,25 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* that have more than five arguments?
*/
- fsc.args[0] = regs.r_rbx;
- fsc.args[1] = regs.r_rcx;
- fsc.args[2] = regs.r_rdx;
- fsc.args[3] = regs.r_rsi;
- fsc.args[4] = regs.r_rdi;
+ fsc->args[0] = regs.r_rbx;
+ fsc->args[1] = regs.r_rcx;
+ fsc->args[2] = regs.r_rdx;
+ fsc->args[3] = regs.r_rsi;
+ fsc->args[4] = regs.r_rdi;
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -176,19 +183,19 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -200,30 +207,29 @@ amd64_linux32_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "linux_execve") == 0) {
+ if (strcmp(fsc->name, "linux_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -246,16 +252,18 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
int syscall_num __unused)
{
struct reg regs;
+ struct linux_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -268,10 +276,11 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -286,12 +295,12 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
@@ -308,13 +317,13 @@ amd64_linux32_syscall_exit(struct trussinfo *trussinfo,
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- errorp ? i : retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ errorp ? i : retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/i386-fbsd.c b/usr.bin/truss/i386-fbsd.c
index cbf2d1e..d146ecd 100644
--- a/usr.bin/truss/i386-fbsd.c
+++ b/usr.bin/truss/i386-fbsd.c
@@ -62,8 +62,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -77,30 +75,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -115,15 +118,15 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
unsigned int parm_offset;
int i, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -137,56 +140,59 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_eax;
switch (syscall_num) {
case SYS_syscall:
- syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(int);
break;
case SYS___syscall:
- syscall_num = ptrace(PT_READ_D, cpid, (caddr_t)parm_offset, 0);
+ syscall_num = ptrace(PT_READ_D, tid, (caddr_t)parm_offset, 0);
parm_offset += sizeof(quad_t);
break;
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset;
- iorequest.piod_addr = fsc.args;
+ iorequest.piod_addr = fsc->args;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned long);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
sc = NULL;
- if (fsc.name)
- sc = get_syscall(fsc.name);
+ if (fsc->name)
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -196,19 +202,19 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -220,30 +226,29 @@ i386_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -257,16 +262,18 @@ long
i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -279,10 +286,11 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -297,18 +305,18 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -316,9 +324,9 @@ i386_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/i386-linux.c b/usr.bin/truss/i386-linux.c
index 6a0c261..84f1451 100644
--- a/usr.bin/truss/i386-linux.c
+++ b/usr.bin/truss/i386-linux.c
@@ -59,8 +59,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "linux_syscalls.h"
static int nsyscalls =
@@ -75,28 +73,34 @@ static int nsyscalls =
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct linux_syscall {
+struct linux_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long args[5];
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct linux_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct linux_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct linux_syscall *fsc)
{
int i;
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -110,31 +114,34 @@ void
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct reg regs;
+ struct linux_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
int i, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
syscall_num = regs.r_eax;
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : linux_syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "linux_fork") == 0 ||
- strcmp(fsc.name, "linux_vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "linux_fork") == 0 ||
+ strcmp(fsc->name, "linux_vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
@@ -148,25 +155,25 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
* that have more than five arguments?
*/
- fsc.args[0] = regs.r_ebx;
- fsc.args[1] = regs.r_ecx;
- fsc.args[2] = regs.r_edx;
- fsc.args[3] = regs.r_esi;
- fsc.args[4] = regs.r_edi;
+ fsc->args[0] = regs.r_ebx;
+ fsc->args[1] = regs.r_ecx;
+ fsc->args[2] = regs.r_edx;
+ fsc->args[3] = regs.r_esi;
+ fsc->args[4] = regs.r_edi;
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -176,19 +183,19 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -200,30 +207,29 @@ i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "linux_execve") == 0) {
+ if (strcmp(fsc->name, "linux_execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -245,16 +251,18 @@ long
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct linux_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -267,10 +275,11 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -285,12 +294,12 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
@@ -307,13 +316,13 @@ i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "linux_execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "linux_execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- errorp ? i : retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ errorp ? i : retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/ia64-fbsd.c b/usr.bin/truss/ia64-fbsd.c
index 951917f..2218fe5 100644
--- a/usr.bin/truss/ia64-fbsd.c
+++ b/usr.bin/truss/ia64-fbsd.c
@@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -76,30 +74,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -113,15 +116,15 @@ void
ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
unsigned long *parm_offset;
+ lwpid_t tid;
int i, syscall_num;
- clear_fsc();
+ tid = trussinfo->curthread->tid;
- cpid = trussinfo->curthread->tid;
-
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -136,39 +139,42 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
if (syscall_num == SYS_syscall || syscall_num == SYS___syscall)
syscall_num = (int)*parm_offset++;
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
- memcpy(fsc.args, parm_offset, nargs * sizeof(long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
+ memcpy(fsc->args, parm_offset, nargs * sizeof(long));
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -178,19 +184,19 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -202,30 +208,29 @@ ia64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -239,16 +244,18 @@ long
ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return (-1);
}
@@ -261,10 +268,11 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -279,27 +287,28 @@ ia64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
+
/*
* It would probably be a good idea to merge the error handling,
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/main.c b/usr.bin/truss/main.c
index cb97293..02c6930 100644
--- a/usr.bin/truss/main.c
+++ b/usr.bin/truss/main.c
@@ -163,6 +163,7 @@ strsig(int sig)
int
main(int ac, char **av)
{
+ struct timespec timediff;
struct sigaction sa;
struct ex_types *funcs;
struct trussinfo *trussinfo;
@@ -170,7 +171,7 @@ main(int ac, char **av)
char *signame;
char **command;
pid_t childpid;
- int c, i, initial_open, status;
+ int c, initial_open, status;
fname = NULL;
initial_open = 1;
@@ -286,18 +287,17 @@ START_TRACE:
clock_gettime(CLOCK_REALTIME, &trussinfo->start_time);
do {
- struct timespec timediff;
waitevent(trussinfo);
- switch (i = trussinfo->pr_why) {
+ switch (trussinfo->pr_why) {
case S_SCE:
funcs->enter_syscall(trussinfo, MAXARGS);
clock_gettime(CLOCK_REALTIME,
- &trussinfo->before);
+ &trussinfo->curthread->before);
break;
case S_SCX:
clock_gettime(CLOCK_REALTIME,
- &trussinfo->after);
+ &trussinfo->curthread->after);
if (trussinfo->curthread->in_fork &&
(trussinfo->flags & FOLLOWFORKS)) {
@@ -326,15 +326,15 @@ START_TRACE:
fprintf(trussinfo->outfile, "%5d: ",
trussinfo->pid);
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
- timespecsubt(&trussinfo->after,
+ timespecsubt(&trussinfo->curthread->after,
&trussinfo->start_time, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec,
timediff.tv_nsec);
}
if (trussinfo->flags & RELATIVETIMESTAMPS) {
- timespecsubt(&trussinfo->after,
- &trussinfo->before, &timediff);
+ timespecsubt(&trussinfo->curthread->after,
+ &trussinfo->curthread->before, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec,
timediff.tv_nsec);
@@ -352,15 +352,15 @@ START_TRACE:
fprintf(trussinfo->outfile, "%5d: ",
trussinfo->pid);
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
- timespecsubt(&trussinfo->after,
+ timespecsubt(&trussinfo->curthread->after,
&trussinfo->start_time, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec,
timediff.tv_nsec);
}
if (trussinfo->flags & RELATIVETIMESTAMPS) {
- timespecsubt(&trussinfo->after,
- &trussinfo->before, &timediff);
+ timespecsubt(&trussinfo->curthread->after,
+ &trussinfo->curthread->before, &timediff);
fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec);
}
diff --git a/usr.bin/truss/mips-fbsd.c b/usr.bin/truss/mips-fbsd.c
index b141f80..6f5be66 100644
--- a/usr.bin/truss/mips-fbsd.c
+++ b/usr.bin/truss/mips-fbsd.c
@@ -66,8 +66,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -81,30 +79,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -119,15 +122,15 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
int i, syscall_num;
int indir; /* indirect system call */
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -139,30 +142,33 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_regs[A0];
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
#if 0 // XXX
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)parm_offset;
- iorequest.piod_addr = fsc.args;
+ iorequest.piod_addr = fsc->args;
iorequest.piod_len = (1 + nargs) * sizeof(unsigned long);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
#else
@@ -192,35 +198,35 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_regs[SP] +
4 * sizeof(uint32_t));
- iorequest.piod_addr = &fsc.args[4];
- iorequest.piod_len = (nargs - 4) * sizeof(fsc.args[0]);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ iorequest.piod_addr = &fsc->args[4];
+ iorequest.piod_len = (nargs - 4) * sizeof(fsc->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
- case 4: fsc.args[3] = regs.r_regs[A3];
- case 3: fsc.args[2] = regs.r_regs[A2];
- case 2: fsc.args[1] = regs.r_regs[A1];
- case 1: fsc.args[0] = regs.r_regs[A0];
+ case 4: fsc->args[3] = regs.r_regs[A3];
+ case 3: fsc->args[2] = regs.r_regs[A2];
+ case 2: fsc->args[1] = regs.r_regs[A1];
+ case 1: fsc->args[0] = regs.r_regs[A0];
case 0: break;
}
if (indir) {
- memmove(&fsc.args[0], &fsc.args[1],
- (nargs - 1) * sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], &fsc->args[1],
+ (nargs - 1) * sizeof(fsc->args[0]));
}
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -230,19 +236,19 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -254,30 +260,29 @@ mips_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -291,16 +296,18 @@ long
mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n");
return (-1);
}
@@ -313,10 +320,11 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -331,18 +339,18 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -350,9 +358,9 @@ mips_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/powerpc-fbsd.c b/usr.bin/truss/powerpc-fbsd.c
index e98b7ed..8cfb9ef 100644
--- a/usr.bin/truss/powerpc-fbsd.c
+++ b/usr.bin/truss/powerpc-fbsd.c
@@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#ifdef __powerpc64__ /* 32-bit compatibility */
#include "freebsd32_syscalls.h"
#define syscallnames freebsd32_syscallnames
@@ -81,30 +79,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -119,18 +122,18 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
void *args;
+ lwpid_t tid;
int i, regargs, syscall_num;
/* Account for a 64-bit argument with corresponding alignment. */
nargs += 2;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -153,51 +156,54 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.fixreg[4];
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
if (nargs > regargs) {
- memmove(&fsc.args[0], args, regargs * sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], args, 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);
+ iorequest.piod_addr = &fsc->args[regargs];
+ iorequest.piod_len = (nargs - regargs) * sizeof(fsc->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
} else
- memmove(&fsc.args[0], args, nargs * sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], args, nargs * sizeof(fsc->args[0]));
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -207,19 +213,19 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -231,30 +237,29 @@ powerpc_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -268,16 +273,18 @@ long
powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n");
return (-1);
}
@@ -290,10 +297,11 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* On 32-bit big-endian, the low word of a 64-bit return is
@@ -316,18 +324,18 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -335,9 +343,9 @@ powerpc_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/powerpc64-fbsd.c b/usr.bin/truss/powerpc64-fbsd.c
index 0eae03f..7147f81 100644
--- a/usr.bin/truss/powerpc64-fbsd.c
+++ b/usr.bin/truss/powerpc64-fbsd.c
@@ -61,8 +61,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -76,30 +74,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -114,15 +117,15 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
void *args;
+ lwpid_t tid;
int i, regargs, syscall_num;
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -141,51 +144,54 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.fixreg[3];
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
if (nargs > regargs) {
- memmove(&fsc.args[0], args, regargs * sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], args, regargs * sizeof(fsc->args[0]));
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.fixreg[1] + 48);
- iorequest.piod_addr = &fsc.args[regargs];
- iorequest.piod_len = (nargs - regargs) * sizeof(fsc.args[0]);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ iorequest.piod_addr = &fsc->args[regargs];
+ iorequest.piod_len = (nargs - regargs) * sizeof(fsc->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
} else
- memmove(&fsc.args[0], args, nargs * sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], args, nargs * sizeof(fsc->args[0]));
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -195,19 +201,19 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -219,30 +225,29 @@ powerpc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -256,16 +261,18 @@ long
powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n");
return (-1);
}
@@ -278,10 +285,11 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -296,18 +304,18 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -315,9 +323,9 @@ powerpc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/setup.c b/usr.bin/truss/setup.c
index c855c33..d6e4300 100644
--- a/usr.bin/truss/setup.c
+++ b/usr.bin/truss/setup.c
@@ -161,12 +161,10 @@ find_thread(struct trussinfo *info, lwpid_t lwpid)
}
}
- np = (struct threadinfo *)malloc(sizeof(struct threadinfo));
+ np = (struct threadinfo *)calloc(1, sizeof(struct threadinfo));
if (np == NULL)
- errx(1, "malloc() failed");
+ err(1, "calloc() failed");
np->tid = lwpid;
- np->in_fork = 0;
- np->in_syscall = 0;
SLIST_INSERT_HEAD(&info->threadlist, np, entries);
info->curthread = np;
}
diff --git a/usr.bin/truss/sparc64-fbsd.c b/usr.bin/truss/sparc64-fbsd.c
index 4aa512d..429fa24 100644
--- a/usr.bin/truss/sparc64-fbsd.c
+++ b/usr.bin/truss/sparc64-fbsd.c
@@ -67,8 +67,6 @@ static const char rcsid[] =
#include "syscall.h"
#include "extern.h"
-static int cpid = -1;
-
#include "syscalls.h"
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
@@ -82,30 +80,35 @@ static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
* 'struct syscall' describes the system call; it may be NULL, however,
* if we don't know about this particular system call yet.
*/
-static struct freebsd_syscall {
+struct freebsd_syscall {
struct syscall *sc;
const char *name;
int number;
unsigned long *args;
int nargs; /* number of arguments -- *not* number of words! */
char **s_args; /* the printable arguments */
-} fsc;
+};
+
+static struct freebsd_syscall *
+alloc_fsc(void)
+{
+
+ return (malloc(sizeof(struct freebsd_syscall)));
+}
/* Clear up and free parts of the fsc structure. */
-static __inline void
-clear_fsc(void)
+static void
+free_fsc(struct freebsd_syscall *fsc)
{
int i;
- if (fsc.args)
- free(fsc.args);
- if (fsc.s_args) {
- for (i = 0; i < fsc.nargs; i++)
- if (fsc.s_args[i])
- free(fsc.s_args[i]);
- free(fsc.s_args);
+ free(fsc->args);
+ if (fsc->s_args) {
+ for (i = 0; i < fsc->nargs; i++)
+ free(fsc->s_args[i]);
+ free(fsc->s_args);
}
- memset(&fsc, 0, sizeof(fsc));
+ free(fsc);
}
/*
@@ -120,15 +123,15 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
{
struct ptrace_io_desc iorequest;
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
int i, syscall_num;
int indir; /* indirect system call */
- clear_fsc();
-
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
return;
}
@@ -145,24 +148,27 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
syscall_num = regs.r_out[0];
}
- fsc.number = syscall_num;
- fsc.name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
+ fsc = alloc_fsc();
+ if (fsc == NULL)
+ return;
+ fsc->number = syscall_num;
+ fsc->name = (syscall_num < 0 || syscall_num >= nsyscalls) ?
NULL : syscallnames[syscall_num];
- if (!fsc.name) {
+ if (!fsc->name) {
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n",
syscall_num);
}
- if (fsc.name && (trussinfo->flags & FOLLOWFORKS) &&
- (strcmp(fsc.name, "fork") == 0 ||
- strcmp(fsc.name, "rfork") == 0 ||
- strcmp(fsc.name, "vfork") == 0))
+ if (fsc->name && (trussinfo->flags & FOLLOWFORKS) &&
+ (strcmp(fsc->name, "fork") == 0 ||
+ strcmp(fsc->name, "rfork") == 0 ||
+ strcmp(fsc->name, "vfork") == 0))
trussinfo->curthread->in_fork = 1;
if (nargs == 0)
return;
- fsc.args = malloc((1 + nargs) * sizeof(unsigned long));
+ fsc->args = malloc((1 + nargs) * sizeof(unsigned long));
switch (nargs) {
default:
/*
@@ -183,38 +189,38 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
iorequest.piod_op = PIOD_READ_D;
iorequest.piod_offs = (void *)(regs.r_out[6] + SPOFF +
offsetof(struct frame, fr_pad[6]));
- iorequest.piod_addr = &fsc.args[6];
- iorequest.piod_len = (nargs - 6) * sizeof(fsc.args[0]);
- ptrace(PT_IO, cpid, (caddr_t)&iorequest, 0);
+ iorequest.piod_addr = &fsc->args[6];
+ iorequest.piod_len = (nargs - 6) * sizeof(fsc->args[0]);
+ ptrace(PT_IO, tid, (caddr_t)&iorequest, 0);
if (iorequest.piod_len == 0)
return;
- case 6: fsc.args[5] = regs.r_out[5];
- case 5: fsc.args[4] = regs.r_out[4];
- case 4: fsc.args[3] = regs.r_out[3];
- case 3: fsc.args[2] = regs.r_out[2];
- case 2: fsc.args[1] = regs.r_out[1];
- case 1: fsc.args[0] = regs.r_out[0];
+ case 6: fsc->args[5] = regs.r_out[5];
+ case 5: fsc->args[4] = regs.r_out[4];
+ case 4: fsc->args[3] = regs.r_out[3];
+ case 3: fsc->args[2] = regs.r_out[2];
+ case 2: fsc->args[1] = regs.r_out[1];
+ case 1: fsc->args[0] = regs.r_out[0];
case 0:
break;
}
if (indir)
- memmove(&fsc.args[0], &fsc.args[1], (nargs - 1) *
- sizeof(fsc.args[0]));
+ memmove(&fsc->args[0], &fsc->args[1], (nargs - 1) *
+ sizeof(fsc->args[0]));
- sc = get_syscall(fsc.name);
+ sc = get_syscall(fsc->name);
if (sc)
- fsc.nargs = sc->nargs;
+ fsc->nargs = sc->nargs;
else {
#if DEBUG
fprintf(trussinfo->outfile, "unknown syscall %s -- setting "
- "args to %d\n", fsc.name, nargs);
+ "args to %d\n", fsc->name, nargs);
#endif
- fsc.nargs = nargs;
+ fsc->nargs = nargs;
}
- fsc.s_args = calloc(1, (1 + fsc.nargs) * sizeof(char *));
- fsc.sc = sc;
+ fsc->s_args = calloc(1, (1 + fsc->nargs) * sizeof(char *));
+ fsc->sc = sc;
/*
* At this point, we set up the system call arguments.
@@ -224,19 +230,19 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
* passed in *and* out, however.
*/
- if (fsc.name) {
+ if (fsc->name) {
#if DEBUG
- fprintf(stderr, "syscall %s(", fsc.name);
+ fprintf(stderr, "syscall %s(", fsc->name);
#endif
- for (i = 0; i < fsc.nargs; i++) {
+ for (i = 0; i < fsc->nargs; i++) {
#if DEBUG
fprintf(stderr, "0x%x%s", sc ?
- fsc.args[sc->args[i].offset] : fsc.args[i],
- i < (fsc.nargs - 1) ? "," : "");
+ fsc->args[sc->args[i].offset] : fsc->args[i],
+ i < (fsc->nargs - 1) ? "," : "");
#endif
if (sc && !(sc->args[i].type & OUT)) {
- fsc.s_args[i] = print_arg(&sc->args[i],
- fsc.args, 0, trussinfo);
+ fsc->s_args[i] = print_arg(&sc->args[i],
+ fsc->args, 0, trussinfo);
}
}
#if DEBUG
@@ -248,30 +254,29 @@ sparc64_syscall_entry(struct trussinfo *trussinfo, int nargs)
fprintf(trussinfo->outfile, "\n");
#endif
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0)) {
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0)) {
/*
* XXX
* This could be done in a more general
* manner but it still wouldn't be very pretty.
*/
- if (strcmp(fsc.name, "execve") == 0) {
+ if (strcmp(fsc->name, "execve") == 0) {
if ((trussinfo->flags & EXECVEARGS) == 0) {
- if (fsc.s_args[1]) {
- free(fsc.s_args[1]);
- fsc.s_args[1] = NULL;
+ if (fsc->s_args[1]) {
+ free(fsc->s_args[1]);
+ fsc->s_args[1] = NULL;
}
}
if ((trussinfo->flags & EXECVEENVS) == 0) {
- if (fsc.s_args[2]) {
- free(fsc.s_args[2]);
- fsc.s_args[2] = NULL;
+ if (fsc->s_args[2]) {
+ free(fsc->s_args[2]);
+ fsc->s_args[2] = NULL;
}
}
}
}
-
- return;
+ trussinfo->curthread->fsc = fsc;
}
/*
@@ -285,16 +290,18 @@ long
sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
{
struct reg regs;
+ struct freebsd_syscall *fsc;
struct syscall *sc;
+ lwpid_t tid;
long retval;
int errorp, i;
- if (fsc.name == NULL)
+ if (trussinfo->curthread->fsc == NULL)
return (-1);
- cpid = trussinfo->curthread->tid;
+ tid = trussinfo->curthread->tid;
- if (ptrace(PT_GETREGS, cpid, (caddr_t)&regs, 0) < 0) {
+ if (ptrace(PT_GETREGS, tid, (caddr_t)&regs, 0) < 0) {
fprintf(trussinfo->outfile, "\n");
return (-1);
}
@@ -307,10 +314,11 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* stand some significant cleaning.
*/
- sc = fsc.sc;
+ fsc = trussinfo->curthread->fsc;
+ sc = fsc->sc;
if (!sc) {
- for (i = 0; i < fsc.nargs; i++)
- asprintf(&fsc.s_args[i], "0x%lx", fsc.args[i]);
+ for (i = 0; i < fsc->nargs; i++)
+ asprintf(&fsc->s_args[i], "0x%lx", fsc->args[i]);
} else {
/*
* Here, we only look for arguments that have OUT masked in --
@@ -325,18 +333,18 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
*/
if (errorp) {
asprintf(&temp, "0x%lx",
- fsc.args[sc->args[i].offset]);
+ fsc->args[sc->args[i].offset]);
} else {
temp = print_arg(&sc->args[i],
- fsc.args, retval, trussinfo);
+ fsc->args, retval, trussinfo);
}
- fsc.s_args[i] = temp;
+ fsc->s_args[i] = temp;
}
}
}
- if (fsc.name != NULL && (strcmp(fsc.name, "execve") == 0 ||
- strcmp(fsc.name, "exit") == 0))
+ if (fsc->name != NULL && (strcmp(fsc->name, "execve") == 0 ||
+ strcmp(fsc->name, "exit") == 0))
trussinfo->curthread->in_syscall = 1;
/*
@@ -344,9 +352,9 @@ sparc64_syscall_exit(struct trussinfo *trussinfo, int syscall_num __unused)
* but that complicates things considerably.
*/
- print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp,
- retval, fsc.sc);
- clear_fsc();
+ print_syscall_ret(trussinfo, fsc->name, fsc->nargs, fsc->s_args, errorp,
+ retval, fsc->sc);
+ free_fsc(fsc);
return (retval);
}
diff --git a/usr.bin/truss/syscalls.c b/usr.bin/truss/syscalls.c
index 4fba0cc..0afd083 100644
--- a/usr.bin/truss/syscalls.c
+++ b/usr.bin/truss/syscalls.c
@@ -1120,20 +1120,21 @@ print_syscall(struct trussinfo *trussinfo, const char *name, int nargs,
if (trussinfo->flags & FOLLOWFORKS)
len += fprintf(trussinfo->outfile, "%5d: ", trussinfo->pid);
- if (name != NULL && (strcmp(name, "execve") == 0||
+ if (name != NULL && (strcmp(name, "execve") == 0 ||
strcmp(name, "exit") == 0)) {
- clock_gettime(CLOCK_REALTIME, &trussinfo->after);
+ clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->after);
}
if (trussinfo->flags & ABSOLUTETIMESTAMPS) {
- timespecsubt(&trussinfo->after, &trussinfo->start_time,
- &timediff);
+ timespecsubt(&trussinfo->curthread->after,
+ &trussinfo->start_time, &timediff);
len += fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec);
}
if (trussinfo->flags & RELATIVETIMESTAMPS) {
- timespecsubt(&trussinfo->after, &trussinfo->before, &timediff);
+ timespecsubt(&trussinfo->curthread->after,
+ &trussinfo->curthread->before, &timediff);
len += fprintf(trussinfo->outfile, "%ld.%09ld ",
(long)timediff.tv_sec, timediff.tv_nsec);
}
@@ -1163,8 +1164,9 @@ print_syscall_ret(struct trussinfo *trussinfo, const char *name, int nargs,
if (trussinfo->flags & COUNTONLY) {
if (!sc)
return;
- clock_gettime(CLOCK_REALTIME, &trussinfo->after);
- timespecsubt(&trussinfo->after, &trussinfo->before, &timediff);
+ clock_gettime(CLOCK_REALTIME, &trussinfo->curthread->after);
+ timespecsubt(&trussinfo->curthread->after,
+ &trussinfo->curthread->before, &timediff);
timespecadd(&sc->time, &timediff, &sc->time);
sc->ncalls++;
if (errorp)
diff --git a/usr.bin/truss/truss.h b/usr.bin/truss/truss.h
index 7dd87f5..dcc86a5 100644
--- a/usr.bin/truss/truss.h
+++ b/usr.bin/truss/truss.h
@@ -41,6 +41,9 @@ struct threadinfo
lwpid_t tid;
int in_syscall;
int in_fork;
+ void *fsc;
+ struct timespec before;
+ struct timespec after;
};
struct trussinfo
@@ -53,8 +56,6 @@ struct trussinfo
FILE *outfile;
struct timespec start_time;
- struct timespec before;
- struct timespec after;
struct threadinfo *curthread;
OpenPOWER on IntegriCloud