commit d7581bb11f3a660fd428d69db767a09fa69a9fd1
parent 89e91d3f4fa10a28e8d0b21edea9ea8eb3d6054c
Author: rminnich@xcpu2 <none@none>
Date: Wed, 17 Mar 2010 09:22:37 -0700
truss changes and my devram too.
Diffstat:
6 files changed, 354 insertions(+), 0 deletions(-)
diff --git a/src/9vx/Makefrag b/src/9vx/Makefrag
@@ -74,6 +74,7 @@ PLAN9_A_OBJS = \
devmnt.o \
devproc.o \
devpipe.o \
+ devram.o \
devroot.o \
devsd.o \
devsrv.o \
diff --git a/src/9vx/a/AUTOGEN b/src/9vx/a/AUTOGEN
@@ -38,6 +38,7 @@ autofiles="
/sys/src/9/port/devmnt.c
/sys/src/9/port/devpipe.c
/sys/src/9/port/devproc.c
+/sys/src/9/port/devram.c
/sys/src/9/port/devroot.c
/sys/src/9/port/devsrv.c
/sys/src/9/port/devtls.c
diff --git a/src/9vx/a/devproc.c b/src/9vx/a/devproc.c
@@ -31,6 +31,7 @@ enum
Qtext,
Qwait,
Qprofile,
+ Qtruss,
};
enum
@@ -84,6 +85,7 @@ Dirtab procdir[] =
"text", {Qtext}, 0, 0000,
"wait", {Qwait}, 0, 0400,
"profile", {Qprofile}, 0, 0400,
+ "truss", {Qtruss}, 0, 0400,
};
static
@@ -397,6 +399,7 @@ procopen(Chan *c, int omode)
case Qwait:
case Qregs:
case Qfpregs:
+ case Qtruss:
nonone(p);
break;
@@ -706,6 +709,12 @@ procread(Chan *c, void *va, long n, vlong off)
memmove(a, &up->genbuf[offset], n);
return n;
+ case Qtruss:
+ if (! p->syscalltrace)
+ return 0;
+ n = readstr(offset, a, n, p->syscalltrace);
+ return n;
+
case Qmem:
if(offset < USTKTOP)
return procctlmemio(p, offset, n, va, 1);
diff --git a/src/9vx/a/portdat.h b/src/9vx/a/portdat.h
@@ -752,6 +752,9 @@ struct Proc
* machine specific MMU
*/
PMMU pmmu;
+ /* syscall trace */
+ char *syscalltrace;
+
};
enum
diff --git a/src/9vx/devtab.c b/src/9vx/devtab.c
@@ -8,6 +8,7 @@
extern Dev consdevtab;
extern Dev rootdevtab;
extern Dev pipedevtab;
+extern Dev ramdevtab;
extern Dev ssldevtab;
extern Dev tlsdevtab;
extern Dev mousedevtab;
@@ -38,6 +39,7 @@ Dev *devtab[] = {
&mousedevtab,
&pipedevtab,
&procdevtab,
+ &ramdevtab,
&srvdevtab,
&ssldevtab,
&tlsdevtab,
diff --git a/src/9vx/trap.c b/src/9vx/trap.c
@@ -178,6 +178,335 @@ dumpregs(Ureg* ureg)
*/
}
+static void
+syscallprint(Ureg *ureg)
+{
+ uint32 *sp = (uint32*)(up->pmmu.uzero + ureg->usp);
+ int syscallno = ureg->ax;
+
+ /* should never happen -- arguably, this should panic. */
+ if (up->syscalltrace)
+ free(up->syscalltrace);
+ switch(syscallno) {
+ case SYSR1:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _ERRSTR:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case BIND:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case CHDIR:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case CLOSE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case DUP:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case ALARM:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case EXEC:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case EXITS:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _FSESSION:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case FAUTH:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _FSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEGBRK:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _MOUNT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case OPEN:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _READ:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case OSEEK:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SLEEP:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _STAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case RFORK:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _WRITE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case PIPE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case CREATE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case FD2PATH:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case BRK_:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case REMOVE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _WSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _FWSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case NOTIFY:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case NOTED:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEGATTACH:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEGDETACH:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEGFREE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEGFLUSH:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case RENDEZVOUS:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case UNMOUNT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case _WAIT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEMACQUIRE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEMRELEASE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case SEEK:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case FVERSION:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case ERRSTR:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case STAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case FSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case WSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case FWSTAT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case MOUNT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case AWAIT:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case PREAD:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ case PWRITE:
+ up->syscalltrace = smprint("%d [%s] %s %#ux %08ux %08ux %08ux %08uxh",
+ up->pid, up->text,
+ sysctab[ureg->ax], sp[0], sp[1], sp[2], sp[3]);
+ break;
+ }
+
+}
+
+static void
+retprint(Ureg *ureg, int syscallno)
+{
+ /* should never happen */
+ if (up->syscalltrace)
+ free(up->syscalltrace);
+ switch(syscallno) {
+ case SYSR1:
+ case _ERRSTR:
+ case BIND:
+ case CHDIR:
+ case CLOSE:
+ case DUP:
+ case ALARM:
+ case EXEC:
+ case EXITS:
+ case _FSESSION:
+ case FAUTH:
+ case _FSTAT:
+ case SEGBRK:
+ case _MOUNT:
+ case OPEN:
+ case _READ:
+ case OSEEK:
+ case SLEEP:
+ case _STAT:
+ case RFORK:
+ case _WRITE:
+ case PIPE:
+ case CREATE:
+ case FD2PATH:
+ case BRK_:
+ case REMOVE:
+ case _WSTAT:
+ case _FWSTAT:
+ case NOTIFY:
+ case NOTED:
+ case SEGATTACH:
+ case SEGDETACH:
+ case SEGFREE:
+ case SEGFLUSH:
+ case RENDEZVOUS:
+ case UNMOUNT:
+ case _WAIT:
+ case SEMACQUIRE:
+ case SEMRELEASE:
+ case SEEK:
+ case FVERSION:
+ case ERRSTR:
+ case STAT:
+ case FSTAT:
+ case WSTAT:
+ case FWSTAT:
+ case MOUNT:
+ case AWAIT:
+ case PREAD:
+ case PWRITE:
+ default:
+ if(ureg->ax == -1)
+ up->syscalltrace = smprint("= %s\n", up->syserrstr);
+ else
+ up->syscalltrace = smprint("= %#ux\n", ureg->ax);
+ }
+
+}
/*
* Handle a system call.
*/
@@ -199,7 +528,11 @@ syscall(Ureg *ureg)
if(up->procctl == Proc_tracesyscall){
up->procctl = Proc_stopme;
+ syscallprint(ureg);
procctl(up);
+ if (up->syscalltrace)
+ free(up->syscalltrace);
+ up->syscalltrace = NULL;
}
scallnr = ureg->ax;
@@ -260,9 +593,14 @@ syscall(Ureg *ureg)
if(up->procctl == Proc_tracesyscall){
up->procctl = Proc_stopme;
+ retprint(ureg, scallnr);
s = splhi();
procctl(up);
splx(s);
+ /* you must have read the string by now. The free above is really not needed */
+ if (up->syscalltrace)
+ free(up->syscalltrace);
+ up->syscalltrace = NULL;
}
up->insyscall = 0;