Debugging libthread for acme.
diff --git a/src/cmd/acme/acme.c b/src/cmd/acme/acme.c
index 87924ca..4e047c1 100644
--- a/src/cmd/acme/acme.c
+++ b/src/cmd/acme/acme.c
@@ -63,6 +63,8 @@
 	int ncol;
 	Display *d;
 
+extern int _threaddebuglevel;
+_threaddebuglevel = ~0;
 	rfork(RFENVG|RFNAMEG);
 
 	ncol = -1;
diff --git a/src/libthread/channel.c b/src/libthread/channel.c
index 4f642c8..957a352 100644
--- a/src/libthread/channel.c
+++ b/src/libthread/channel.c
@@ -9,6 +9,16 @@
 int _threadhighnentry;
 int _threadnalt;
 
+static void
+setuserpc(ulong pc)
+{
+	Thread *t;
+
+	t = _threadgetproc()->thread;
+	if(t)
+		t->userpc = pc;
+}
+
 static int
 canexec(Alt *a)
 {
@@ -86,8 +96,8 @@
 	return c;
 }
 
-int
-alt(Alt *alts)
+static int
+_alt(Alt *alts)
 {
 	Alt *a, *xa;
 	Channel *volatile c;
@@ -197,6 +207,13 @@
 	return a - alts;
 }
 
+int
+alt(Alt *alts)
+{
+	setuserpc(getcallerpc(&alts));
+	return _alt(alts);
+}
+
 static int
 runop(int op, Channel *c, void *v, int nb)
 {
@@ -214,7 +231,7 @@
 	a[1].op = CHANEND;
 	if(nb)
 		a[1].op = CHANNOBLK;
-	switch(r=alt(a)){
+	switch(r=_alt(a)){
 	case -1:	/* interrupted */
 		return -1;
 	case 1:	/* nonblocking, didn't accomplish anything */
@@ -232,24 +249,28 @@
 int
 recv(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	return runop(CHANRCV, c, v, 0);
 }
 
 int
 nbrecv(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	return runop(CHANRCV, c, v, 1);
 }
 
 int
 send(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	return runop(CHANSND, c, v, 0);
 }
 
 int
 nbsend(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	return runop(CHANSND, c, v, 1);
 }
 
@@ -266,6 +287,7 @@
 int
 sendul(Channel *c, ulong v)
 {
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(ulong));
 	return send(c, &v);
 }
@@ -275,8 +297,9 @@
 {
 	ulong v;
 
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(ulong));
-	if(recv(c, &v) < 0)
+	if(runop(CHANRCV, c, &v, 0) < 0)
 		return ~0;
 	return v;
 }
@@ -284,8 +307,9 @@
 int
 sendp(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(void*));
-	return send(c, &v);
+	return runop(CHANSND, c, &v, 0);
 }
 
 void*
@@ -293,8 +317,9 @@
 {
 	void *v;
 
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(void*));
-	if(recv(c, &v) < 0)
+	if(runop(CHANRCV, c, &v, 0) < 0)
 		return nil;
 	return v;
 }
@@ -302,8 +327,9 @@
 int
 nbsendul(Channel *c, ulong v)
 {
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(ulong));
-	return nbsend(c, &v);
+	return runop(CHANSND, c, &v, 1);
 }
 
 ulong
@@ -311,8 +337,9 @@
 {
 	ulong v;
 
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(ulong));
-	if(nbrecv(c, &v) == 0)
+	if(runop(CHANRCV, c, &v, 1) == 0)
 		return 0;
 	return v;
 }
@@ -320,8 +347,9 @@
 int
 nbsendp(Channel *c, void *v)
 {
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(void*));
-	return nbsend(c, &v);
+	return runop(CHANSND, c, &v, 1);
 }
 
 void*
@@ -329,8 +357,9 @@
 {
 	void *v;
 
+	setuserpc(getcallerpc(&c));
 	channelsize(c, sizeof(void*));
-	if(nbrecv(c, &v) == 0)
+	if(runop(CHANRCV, c, &v, 1) == 0)
 		return nil;
 	return v;
 }
diff --git a/src/libthread/main.c b/src/libthread/main.c
index 5306147..96d9933 100644
--- a/src/libthread/main.c
+++ b/src/libthread/main.c
@@ -15,6 +15,13 @@
 extern void (*_sysfatal)(char*, va_list);
 
 void
+_threadstatus(int x)
+{
+	USED(x);
+	threadstatus();
+}
+
+void
 _threaddie(int x)
 {
 	extern char *_threadexitsallstatus;
@@ -38,6 +45,7 @@
 
 	signal(SIGTERM, _threaddie);
 	signal(SIGCHLD, _nop);
+	signal(SIGINFO, _threadstatus);
 //	rfork(RFREND);
 
 //_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
diff --git a/src/libthread/sched.c b/src/libthread/sched.c
index 755fc28..250a19a 100644
--- a/src/libthread/sched.c
+++ b/src/libthread/sched.c
@@ -4,7 +4,6 @@
 
 //static Thread	*runthread(Proc*);
 
-#if 0
 static char *_psstate[] = {
 	"Dead",
 	"Running",
@@ -19,7 +18,6 @@
 		return "unknown";
 	return _psstate[s];
 }
-#endif
 
 void
 _schedinit(void *arg)
@@ -271,3 +269,15 @@
 	_sched();
 }
 
+void
+threadstatus(void)
+{
+	Proc *p;
+	Thread *t;
+
+	p = _threadgetproc();
+	for(t=p->threads.head; t; t=t->nextt)
+		fprint(2, "[%3d] %s userpc=%lux\n",
+			t->id, psstate(t->state), t->userpc);
+}
+	
diff --git a/src/libthread/threadimpl.h b/src/libthread/threadimpl.h
index 590342a..e2e92a1 100644
--- a/src/libthread/threadimpl.h
+++ b/src/libthread/threadimpl.h
@@ -96,6 +96,7 @@
 
 	Chanstate	chan;		/* which channel operation is current */
 	Alt		*alt;			/* pointer to current alt structure (debugging) */
+	ulong		userpc;
 
 	void*	udata[NPRIV];	/* User per-thread data pointer */
 };