Parameterize globals.
PR: bin/25587 (in part) MFC after: 3 weeks
This commit is contained in:
parent
b31d4126e3
commit
ec0bed25ba
@ -60,13 +60,13 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
extern int Procfd;
|
||||
|
||||
extern FILE *outfile;
|
||||
#include "syscalls.h"
|
||||
|
||||
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
@ -113,7 +113,7 @@ clear_fsc() {
|
||||
*/
|
||||
|
||||
void
|
||||
alpha_syscall_entry(int pid, int nargs) {
|
||||
alpha_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { { 0 } };
|
||||
int syscall;
|
||||
@ -122,14 +122,14 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
struct syscall *sc;
|
||||
int indir = 0; /* indirect system call */
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
clear_fsc();
|
||||
@ -152,7 +152,7 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
if (!fsc.name) {
|
||||
fprintf(outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
}
|
||||
|
||||
if (nargs == 0)
|
||||
@ -194,7 +194,7 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
fsc.nargs = sc->nargs;
|
||||
} else {
|
||||
#if DEBUG
|
||||
fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fsc.name, nargs);
|
||||
#endif
|
||||
fsc.nargs = nargs;
|
||||
@ -235,7 +235,7 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
fprintf(outfile, "\n");
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -246,7 +246,7 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
*/
|
||||
|
||||
if (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit")) {
|
||||
print_syscall(outfile, fsc.name, fsc.nargs, fsc.s_args);
|
||||
print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -259,8 +259,8 @@ alpha_syscall_entry(int pid, int nargs) {
|
||||
* the sytem call number instead of, say, an error status).
|
||||
*/
|
||||
|
||||
void
|
||||
alpha_syscall_exit(int pid, int syscall) {
|
||||
int
|
||||
alpha_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -268,19 +268,21 @@ alpha_syscall_exit(int pid, int syscall) {
|
||||
int errorp;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
}
|
||||
retval = regs.r_regs[R_V0];
|
||||
errorp = !!(regs.r_regs[R_A3]);
|
||||
|
||||
@ -323,8 +325,8 @@ alpha_syscall_exit(int pid, int syscall) {
|
||||
* but that complicates things considerably.
|
||||
*/
|
||||
|
||||
print_syscall_ret(outfile, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
clear_fsc();
|
||||
|
||||
return;
|
||||
return (retval);
|
||||
}
|
||||
|
@ -58,13 +58,13 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
extern int Procfd;
|
||||
|
||||
extern FILE *outfile;
|
||||
#include "syscalls.h"
|
||||
|
||||
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
@ -111,7 +111,7 @@ clear_fsc() {
|
||||
*/
|
||||
|
||||
void
|
||||
i386_syscall_entry(int pid, int nargs) {
|
||||
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
@ -119,14 +119,14 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
clear_fsc();
|
||||
@ -157,7 +157,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
if (!fsc.name) {
|
||||
fprintf(outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
}
|
||||
|
||||
if (nargs == 0)
|
||||
@ -173,7 +173,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
fsc.nargs = sc->nargs;
|
||||
} else {
|
||||
#if DEBUG
|
||||
fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fsc.name, nargs);
|
||||
#endif
|
||||
fsc.nargs = nargs;
|
||||
@ -214,7 +214,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
fprintf(outfile, "\n");
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -225,7 +225,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
*/
|
||||
|
||||
if (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit")) {
|
||||
print_syscall(outfile, fsc.name, fsc.nargs, fsc.s_args);
|
||||
print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -238,8 +238,8 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
* the sytem call number instead of, say, an error status).
|
||||
*/
|
||||
|
||||
void
|
||||
i386_syscall_exit(int pid, int syscall) {
|
||||
int
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -247,19 +247,21 @@ i386_syscall_exit(int pid, int syscall) {
|
||||
int errorp;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
||||
@ -302,8 +304,8 @@ i386_syscall_exit(int pid, int syscall) {
|
||||
* but that complicates things considerably.
|
||||
*/
|
||||
|
||||
print_syscall_ret(outfile, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
clear_fsc();
|
||||
|
||||
return;
|
||||
return (retval);
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "extern.h"
|
||||
#include "syscall.h"
|
||||
|
||||
@ -62,7 +63,6 @@ static int fd = -1;
|
||||
static int cpid = -1;
|
||||
extern int Procfd;
|
||||
|
||||
extern FILE *outfile;
|
||||
#include "linux_syscalls.h"
|
||||
|
||||
static int nsyscalls =
|
||||
@ -91,21 +91,21 @@ clear_lsc() {
|
||||
}
|
||||
|
||||
void
|
||||
i386_linux_syscall_entry(int pid, int nargs) {
|
||||
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
clear_lsc();
|
||||
@ -117,7 +117,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
|
||||
if (!lsc.name) {
|
||||
fprintf (outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
|
||||
}
|
||||
|
||||
if (nargs == 0)
|
||||
@ -142,7 +142,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.nargs = sc->nargs;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
lsc.name, nargs);
|
||||
#endif
|
||||
lsc.nargs = nargs;
|
||||
@ -175,7 +175,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
}
|
||||
|
||||
if (!strcmp(lsc.name, "linux_execve") || !strcmp(lsc.name, "exit")) {
|
||||
print_syscall(outfile, lsc.name, lsc.nargs, lsc.s_args);
|
||||
print_syscall(trussinfo, lsc.name, lsc.nargs, lsc.s_args);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -196,8 +196,8 @@ const int bsd_to_linux_errno[] = {
|
||||
-6,
|
||||
};
|
||||
|
||||
void
|
||||
i386_linux_syscall_exit(int pid, int syscall) {
|
||||
int
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -205,20 +205,21 @@ i386_linux_syscall_exit(int pid, int syscall) {
|
||||
int errorp;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
||||
@ -247,8 +248,9 @@ i386_linux_syscall_exit(int pid, int syscall) {
|
||||
if (retval == bsd_to_linux_errno[i])
|
||||
break;
|
||||
}
|
||||
print_syscall_ret(outfile, lsc.name, lsc.nargs, lsc.s_args, errorp,
|
||||
errorp ? i : retval);
|
||||
print_syscall_ret(trussinfo, lsc.name, lsc.nargs, lsc.s_args, errorp,
|
||||
errorp ? i : retval);
|
||||
clear_lsc();
|
||||
return;
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
@ -36,12 +36,12 @@ extern int start_tracing(int, int);
|
||||
extern void restore_proc(int);
|
||||
extern const char *ioctlname(register_t val);
|
||||
#ifdef __alpha__
|
||||
extern void alpha_syscall_entry(int, int);
|
||||
extern void alpha_syscall_exit(int, int);
|
||||
extern void alpha_syscall_entry(struct trussinfo *, int);
|
||||
extern int alpha_syscall_exit(struct trussinfo *, int);
|
||||
#endif
|
||||
#ifdef __i386__
|
||||
extern void i386_syscall_entry(int, int);
|
||||
extern void i386_syscall_exit(int, int);
|
||||
extern void i386_linux_syscall_entry(int, int);
|
||||
extern void i386_linux_syscall_exit(int, int);
|
||||
extern void i386_syscall_entry(struct trussinfo *, int);
|
||||
extern int i386_syscall_exit(struct trussinfo *, int);
|
||||
extern void i386_linux_syscall_entry(struct trussinfo *, int);
|
||||
extern int i386_linux_syscall_exit(struct trussinfo *, int);
|
||||
#endif
|
||||
|
@ -58,13 +58,13 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "syscall.h"
|
||||
|
||||
static int fd = -1;
|
||||
static int cpid = -1;
|
||||
extern int Procfd;
|
||||
|
||||
extern FILE *outfile;
|
||||
#include "syscalls.h"
|
||||
|
||||
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
|
||||
@ -111,7 +111,7 @@ clear_fsc() {
|
||||
*/
|
||||
|
||||
void
|
||||
i386_syscall_entry(int pid, int nargs) {
|
||||
i386_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
@ -119,14 +119,14 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
clear_fsc();
|
||||
@ -157,7 +157,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
fsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : syscallnames[syscall];
|
||||
if (!fsc.name) {
|
||||
fprintf(outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d --\n", syscall);
|
||||
}
|
||||
|
||||
if (nargs == 0)
|
||||
@ -173,7 +173,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
fsc.nargs = sc->nargs;
|
||||
} else {
|
||||
#if DEBUG
|
||||
fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fsc.name, nargs);
|
||||
#endif
|
||||
fsc.nargs = nargs;
|
||||
@ -214,7 +214,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
fprintf(outfile, "\n");
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
#endif
|
||||
|
||||
/*
|
||||
@ -225,7 +225,7 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
*/
|
||||
|
||||
if (!strcmp(fsc.name, "execve") || !strcmp(fsc.name, "exit")) {
|
||||
print_syscall(outfile, fsc.name, fsc.nargs, fsc.s_args);
|
||||
print_syscall(trussinfo, fsc.name, fsc.nargs, fsc.s_args);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -238,8 +238,8 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
* the sytem call number instead of, say, an error status).
|
||||
*/
|
||||
|
||||
void
|
||||
i386_syscall_exit(int pid, int syscall) {
|
||||
int
|
||||
i386_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -247,19 +247,21 @@ i386_syscall_exit(int pid, int syscall) {
|
||||
int errorp;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
||||
@ -302,8 +304,8 @@ i386_syscall_exit(int pid, int syscall) {
|
||||
* but that complicates things considerably.
|
||||
*/
|
||||
|
||||
print_syscall_ret(outfile, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
print_syscall_ret(trussinfo, fsc.name, fsc.nargs, fsc.s_args, errorp, retval);
|
||||
clear_fsc();
|
||||
|
||||
return;
|
||||
return (retval);
|
||||
}
|
||||
|
@ -55,6 +55,7 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "extern.h"
|
||||
#include "syscall.h"
|
||||
|
||||
@ -62,7 +63,6 @@ static int fd = -1;
|
||||
static int cpid = -1;
|
||||
extern int Procfd;
|
||||
|
||||
extern FILE *outfile;
|
||||
#include "linux_syscalls.h"
|
||||
|
||||
static int nsyscalls =
|
||||
@ -91,21 +91,21 @@ clear_lsc() {
|
||||
}
|
||||
|
||||
void
|
||||
i386_linux_syscall_entry(int pid, int nargs) {
|
||||
i386_linux_syscall_entry(struct trussinfo *trussinfo, int nargs) {
|
||||
char buf[32];
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDWR);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
clear_lsc();
|
||||
@ -117,7 +117,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.name =
|
||||
(syscall < 0 || syscall > nsyscalls) ? NULL : linux_syscallnames[syscall];
|
||||
if (!lsc.name) {
|
||||
fprintf (outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
|
||||
fprintf(trussinfo->outfile, "-- UNKNOWN SYSCALL %d\n", syscall);
|
||||
}
|
||||
|
||||
if (nargs == 0)
|
||||
@ -142,7 +142,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.nargs = sc->nargs;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprintf(outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
fprintf(trussinfo->outfile, "unknown syscall %s -- setting args to %d\n",
|
||||
lsc.name, nargs);
|
||||
#endif
|
||||
lsc.nargs = nargs;
|
||||
@ -175,7 +175,7 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
}
|
||||
|
||||
if (!strcmp(lsc.name, "linux_execve") || !strcmp(lsc.name, "exit")) {
|
||||
print_syscall(outfile, lsc.name, lsc.nargs, lsc.s_args);
|
||||
print_syscall(trussinfo, lsc.name, lsc.nargs, lsc.s_args);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -196,8 +196,8 @@ const int bsd_to_linux_errno[] = {
|
||||
-6,
|
||||
};
|
||||
|
||||
void
|
||||
i386_linux_syscall_exit(int pid, int syscall) {
|
||||
int
|
||||
i386_linux_syscall_exit(struct trussinfo *trussinfo, int syscall) {
|
||||
char buf[32];
|
||||
struct reg regs;
|
||||
int retval;
|
||||
@ -205,20 +205,21 @@ i386_linux_syscall_exit(int pid, int syscall) {
|
||||
int errorp;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", pid);
|
||||
if (fd == -1 || trussinfo->pid != cpid) {
|
||||
sprintf(buf, "/proc/%d/regs", trussinfo->pid);
|
||||
fd = open(buf, O_RDONLY);
|
||||
if (fd == -1) {
|
||||
fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
fprintf(trussinfo->outfile, "-- CANNOT READ REGISTERS --\n");
|
||||
return;
|
||||
}
|
||||
cpid = pid;
|
||||
cpid = trussinfo->pid;
|
||||
}
|
||||
|
||||
lseek(fd, 0L, 0);
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs))
|
||||
if (read(fd, ®s, sizeof(regs)) != sizeof(regs)) {
|
||||
fprintf(trussinfo->outfile, "\n");
|
||||
return;
|
||||
|
||||
}
|
||||
retval = regs.r_eax;
|
||||
errorp = !!(regs.r_eflags & PSL_C);
|
||||
|
||||
@ -247,8 +248,9 @@ i386_linux_syscall_exit(int pid, int syscall) {
|
||||
if (retval == bsd_to_linux_errno[i])
|
||||
break;
|
||||
}
|
||||
print_syscall_ret(outfile, lsc.name, lsc.nargs, lsc.s_args, errorp,
|
||||
errorp ? i : retval);
|
||||
print_syscall_ret(trussinfo, lsc.name, lsc.nargs, lsc.s_args, errorp,
|
||||
errorp ? i : retval);
|
||||
clear_lsc();
|
||||
return;
|
||||
|
||||
return (retval);
|
||||
}
|
||||
|
@ -53,16 +53,14 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* These should really be parameterized -- I don't like having globals,
|
||||
* but this is the easiest way, right now, to deal with them.
|
||||
* It's difficult to parameterize this because it must be
|
||||
* accessible in a signal handler.
|
||||
*/
|
||||
|
||||
int pid = 0;
|
||||
int nosigs = 0;
|
||||
FILE *outfile;
|
||||
int Procfd;
|
||||
|
||||
static __inline void
|
||||
@ -80,8 +78,8 @@ usage(void)
|
||||
*/
|
||||
struct ex_types {
|
||||
const char *type;
|
||||
void (*enter_syscall)(int, int);
|
||||
void (*exit_syscall)(int, int);
|
||||
void (*enter_syscall)(struct trussinfo *, int);
|
||||
int (*exit_syscall)(struct trussinfo *, int);
|
||||
} ex_types[] = {
|
||||
#ifdef __alpha__
|
||||
{ "FreeBSD ELF", alpha_syscall_entry, alpha_syscall_exit },
|
||||
@ -101,13 +99,13 @@ struct ex_types {
|
||||
*/
|
||||
|
||||
static struct ex_types *
|
||||
set_etype(void) {
|
||||
set_etype(struct trussinfo *trussinfo) {
|
||||
struct ex_types *funcs;
|
||||
char etype[24];
|
||||
char progt[32];
|
||||
int fd;
|
||||
|
||||
sprintf(etype, "/proc/%d/etype", pid);
|
||||
sprintf(etype, "/proc/%d/etype", trussinfo->pid);
|
||||
if ((fd = open(etype, O_RDONLY)) == -1) {
|
||||
strcpy(progt, "FreeBSD a.out");
|
||||
} else {
|
||||
@ -138,18 +136,25 @@ main(int ac, char **av) {
|
||||
int in_exec = 0;
|
||||
char *fname = NULL;
|
||||
int sigexit = 0;
|
||||
struct trussinfo *trussinfo;
|
||||
|
||||
/* Initialize the trussinfo struct */
|
||||
trussinfo = (struct trussinfo *)malloc(sizeof(struct trussinfo));
|
||||
if (trussinfo == NULL)
|
||||
errx(1, "malloc() failed");
|
||||
bzero(trussinfo, sizeof(struct trussinfo));
|
||||
trussinfo->outfile = stderr;
|
||||
|
||||
outfile = stderr;
|
||||
while ((c = getopt(ac, av, "p:o:S")) != -1) {
|
||||
switch (c) {
|
||||
case 'p': /* specified pid */
|
||||
pid = atoi(optarg);
|
||||
trussinfo->pid = atoi(optarg);
|
||||
break;
|
||||
case 'o': /* Specified output file */
|
||||
fname = optarg;
|
||||
break;
|
||||
case 'S': /* Don't trace signals */
|
||||
nosigs = 1;
|
||||
trussinfo->flags |= NOSIGS;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
@ -157,11 +162,11 @@ main(int ac, char **av) {
|
||||
}
|
||||
|
||||
ac -= optind; av += optind;
|
||||
if ((pid == 0 && ac == 0) || (pid != 0 && ac != 0))
|
||||
if ((trussinfo->pid == 0 && ac == 0) || (trussinfo->pid != 0 && ac != 0))
|
||||
usage();
|
||||
|
||||
if (fname != NULL) { /* Use output file */
|
||||
if ((outfile = fopen(fname, "w")) == NULL)
|
||||
if ((trussinfo->outfile = fopen(fname, "w")) == NULL)
|
||||
errx(1, "cannot open %s", fname);
|
||||
}
|
||||
|
||||
@ -172,9 +177,9 @@ main(int ac, char **av) {
|
||||
* then we restore the event mask on these same signals.
|
||||
*/
|
||||
|
||||
if (pid == 0) { /* Start a command ourselves */
|
||||
if (trussinfo->pid == 0) { /* Start a command ourselves */
|
||||
command = av;
|
||||
pid = setup_and_wait(command);
|
||||
trussinfo->pid = setup_and_wait(command);
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
@ -190,14 +195,15 @@ main(int ac, char **av) {
|
||||
* be woken up, either in exit() or in execve().
|
||||
*/
|
||||
|
||||
Procfd = start_tracing(pid, S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
|
||||
(nosigs ? 0 : S_SIG));
|
||||
Procfd = start_tracing(
|
||||
trussinfo->pid, S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
|
||||
((trussinfo->flags & NOSIGS) ? 0 : S_SIG));
|
||||
if (Procfd == -1)
|
||||
return 0;
|
||||
|
||||
pfs.why = 0;
|
||||
|
||||
funcs = set_etype();
|
||||
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.
|
||||
@ -212,7 +218,7 @@ main(int ac, char **av) {
|
||||
else {
|
||||
switch(i = pfs.why) {
|
||||
case S_SCE:
|
||||
funcs->enter_syscall(pid, pfs.val);
|
||||
funcs->enter_syscall(trussinfo, pfs.val);
|
||||
break;
|
||||
case S_SCX:
|
||||
/*
|
||||
@ -226,32 +232,32 @@ main(int ac, char **av) {
|
||||
in_exec = 0;
|
||||
break;
|
||||
}
|
||||
funcs->exit_syscall(pid, pfs.val);
|
||||
funcs->exit_syscall(trussinfo, pfs.val);
|
||||
break;
|
||||
case S_SIG:
|
||||
fprintf(outfile, "SIGNAL %lu\n", pfs.val);
|
||||
fprintf(trussinfo->outfile, "SIGNAL %lu\n", pfs.val);
|
||||
sigexit = pfs.val;
|
||||
break;
|
||||
case S_EXIT:
|
||||
fprintf (outfile, "process exit, rval = %lu\n", pfs.val);
|
||||
fprintf (trussinfo->outfile, "process exit, rval = %lu\n", pfs.val);
|
||||
break;
|
||||
case S_EXEC:
|
||||
funcs = set_etype();
|
||||
funcs = set_etype(trussinfo);
|
||||
in_exec = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf (outfile, "Process stopped because of: %d\n", i);
|
||||
fprintf (trussinfo->outfile, "Process stopped because of: %d\n", i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ioctl(Procfd, PIOCCONT, val) == -1) {
|
||||
if (kill(pid, 0) == -1 && errno == ESRCH)
|
||||
if (kill(trussinfo->pid, 0) == -1 && errno == ESRCH)
|
||||
break;
|
||||
else
|
||||
warn("PIOCCONT");
|
||||
}
|
||||
} while (pfs.why != S_EXIT);
|
||||
fflush(outfile);
|
||||
fflush(trussinfo->outfile);
|
||||
if (sigexit) {
|
||||
if (sigexit == SIGQUIT)
|
||||
exit(sigexit);
|
||||
|
@ -53,6 +53,7 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "extern.h"
|
||||
|
||||
static int evflags = 0;
|
||||
|
@ -44,5 +44,5 @@ struct syscall {
|
||||
struct syscall *get_syscall(const char*);
|
||||
char *get_string(int, void*, int);
|
||||
char *print_arg(int, struct syscall_args *, unsigned long*);
|
||||
void print_syscall(FILE *, const char *, int, char **);
|
||||
void print_syscall_ret(FILE *, const char *, int, char **, int, int);
|
||||
void print_syscall(struct trussinfo *, const char *, int, char **);
|
||||
void print_syscall_ret(struct trussinfo *, const char *, int, char **, int, int);
|
||||
|
@ -53,6 +53,7 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "truss.h"
|
||||
#include "extern.h"
|
||||
#include "syscall.h"
|
||||
|
||||
@ -353,28 +354,28 @@ print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
|
||||
*/
|
||||
|
||||
void
|
||||
print_syscall(FILE *outfile, const char *name, int nargs, char **s_args) {
|
||||
print_syscall(struct trussinfo *trussinfo, const char *name, int nargs, char **s_args) {
|
||||
int i;
|
||||
int len = 0;
|
||||
len += fprintf(outfile, "%s(", name);
|
||||
len += fprintf(trussinfo->outfile, "%s(", name);
|
||||
for (i = 0; i < nargs; i++) {
|
||||
if (s_args[i])
|
||||
len += fprintf(outfile, "%s", s_args[i]);
|
||||
len += fprintf(trussinfo->outfile, "%s", s_args[i]);
|
||||
else
|
||||
len += fprintf(outfile, "<missing argument>");
|
||||
len += fprintf(outfile, "%s", i < (nargs - 1) ? "," : "");
|
||||
len += fprintf(trussinfo->outfile, "<missing argument>");
|
||||
len += fprintf(trussinfo->outfile, "%s", i < (nargs - 1) ? "," : "");
|
||||
}
|
||||
len += fprintf(outfile, ")");
|
||||
len += fprintf(trussinfo->outfile, ")");
|
||||
for (i = 0; i < 6 - (len / 8); i++)
|
||||
fprintf(outfile, "\t");
|
||||
fprintf(trussinfo->outfile, "\t");
|
||||
}
|
||||
|
||||
void
|
||||
print_syscall_ret(FILE *outfile, const char *name, int nargs, char **s_args, int errorp, int retval) {
|
||||
print_syscall(outfile, name, nargs, s_args);
|
||||
print_syscall_ret(struct trussinfo *trussinfo, const char *name, int nargs, char **s_args, int errorp, int retval) {
|
||||
print_syscall(trussinfo, name, nargs, s_args);
|
||||
if (errorp) {
|
||||
fprintf(outfile, " ERR#%d '%s'\n", retval, strerror(retval));
|
||||
fprintf(trussinfo->outfile, " ERR#%d '%s'\n", retval, strerror(retval));
|
||||
} else {
|
||||
fprintf(outfile, " = %d (0x%x)\n", retval, retval);
|
||||
fprintf(trussinfo->outfile, " = %d (0x%x)\n", retval, retval);
|
||||
}
|
||||
}
|
||||
|
35
usr.bin/truss/truss.h
Normal file
35
usr.bin/truss/truss.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copryight 2001 Jamey Wood
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#define NOSIGS 0x00000008
|
||||
|
||||
struct trussinfo
|
||||
{
|
||||
int pid;
|
||||
int flags;
|
||||
FILE *outfile;
|
||||
};
|
Loading…
Reference in New Issue
Block a user