Debugging libthread for acme.
This commit is contained in:
parent
315e309098
commit
02a1a5c18b
5 changed files with 62 additions and 12 deletions
|
|
@ -63,6 +63,8 @@ threadmain(int argc, char *argv[])
|
||||||
int ncol;
|
int ncol;
|
||||||
Display *d;
|
Display *d;
|
||||||
|
|
||||||
|
extern int _threaddebuglevel;
|
||||||
|
_threaddebuglevel = ~0;
|
||||||
rfork(RFENVG|RFNAMEG);
|
rfork(RFENVG|RFNAMEG);
|
||||||
|
|
||||||
ncol = -1;
|
ncol = -1;
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,16 @@ static int altexec(Alt*, int);
|
||||||
int _threadhighnentry;
|
int _threadhighnentry;
|
||||||
int _threadnalt;
|
int _threadnalt;
|
||||||
|
|
||||||
|
static void
|
||||||
|
setuserpc(ulong pc)
|
||||||
|
{
|
||||||
|
Thread *t;
|
||||||
|
|
||||||
|
t = _threadgetproc()->thread;
|
||||||
|
if(t)
|
||||||
|
t->userpc = pc;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
canexec(Alt *a)
|
canexec(Alt *a)
|
||||||
{
|
{
|
||||||
|
|
@ -86,8 +96,8 @@ chancreate(int elemsize, int elemcnt)
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
alt(Alt *alts)
|
_alt(Alt *alts)
|
||||||
{
|
{
|
||||||
Alt *a, *xa;
|
Alt *a, *xa;
|
||||||
Channel *volatile c;
|
Channel *volatile c;
|
||||||
|
|
@ -197,6 +207,13 @@ _threadnalt++;
|
||||||
return a - alts;
|
return a - alts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
alt(Alt *alts)
|
||||||
|
{
|
||||||
|
setuserpc(getcallerpc(&alts));
|
||||||
|
return _alt(alts);
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
runop(int op, Channel *c, void *v, int nb)
|
runop(int op, Channel *c, void *v, int nb)
|
||||||
{
|
{
|
||||||
|
|
@ -214,7 +231,7 @@ runop(int op, Channel *c, void *v, int nb)
|
||||||
a[1].op = CHANEND;
|
a[1].op = CHANEND;
|
||||||
if(nb)
|
if(nb)
|
||||||
a[1].op = CHANNOBLK;
|
a[1].op = CHANNOBLK;
|
||||||
switch(r=alt(a)){
|
switch(r=_alt(a)){
|
||||||
case -1: /* interrupted */
|
case -1: /* interrupted */
|
||||||
return -1;
|
return -1;
|
||||||
case 1: /* nonblocking, didn't accomplish anything */
|
case 1: /* nonblocking, didn't accomplish anything */
|
||||||
|
|
@ -232,24 +249,28 @@ runop(int op, Channel *c, void *v, int nb)
|
||||||
int
|
int
|
||||||
recv(Channel *c, void *v)
|
recv(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
return runop(CHANRCV, c, v, 0);
|
return runop(CHANRCV, c, v, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
nbrecv(Channel *c, void *v)
|
nbrecv(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
return runop(CHANRCV, c, v, 1);
|
return runop(CHANRCV, c, v, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
send(Channel *c, void *v)
|
send(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
return runop(CHANSND, c, v, 0);
|
return runop(CHANSND, c, v, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
nbsend(Channel *c, void *v)
|
nbsend(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
return runop(CHANSND, c, v, 1);
|
return runop(CHANSND, c, v, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,6 +287,7 @@ channelsize(Channel *c, int sz)
|
||||||
int
|
int
|
||||||
sendul(Channel *c, ulong v)
|
sendul(Channel *c, ulong v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(ulong));
|
channelsize(c, sizeof(ulong));
|
||||||
return send(c, &v);
|
return send(c, &v);
|
||||||
}
|
}
|
||||||
|
|
@ -275,8 +297,9 @@ recvul(Channel *c)
|
||||||
{
|
{
|
||||||
ulong v;
|
ulong v;
|
||||||
|
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(ulong));
|
channelsize(c, sizeof(ulong));
|
||||||
if(recv(c, &v) < 0)
|
if(runop(CHANRCV, c, &v, 0) < 0)
|
||||||
return ~0;
|
return ~0;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
@ -284,8 +307,9 @@ recvul(Channel *c)
|
||||||
int
|
int
|
||||||
sendp(Channel *c, void *v)
|
sendp(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(void*));
|
channelsize(c, sizeof(void*));
|
||||||
return send(c, &v);
|
return runop(CHANSND, c, &v, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
|
|
@ -293,8 +317,9 @@ recvp(Channel *c)
|
||||||
{
|
{
|
||||||
void *v;
|
void *v;
|
||||||
|
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(void*));
|
channelsize(c, sizeof(void*));
|
||||||
if(recv(c, &v) < 0)
|
if(runop(CHANRCV, c, &v, 0) < 0)
|
||||||
return nil;
|
return nil;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
@ -302,8 +327,9 @@ recvp(Channel *c)
|
||||||
int
|
int
|
||||||
nbsendul(Channel *c, ulong v)
|
nbsendul(Channel *c, ulong v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(ulong));
|
channelsize(c, sizeof(ulong));
|
||||||
return nbsend(c, &v);
|
return runop(CHANSND, c, &v, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ulong
|
ulong
|
||||||
|
|
@ -311,8 +337,9 @@ nbrecvul(Channel *c)
|
||||||
{
|
{
|
||||||
ulong v;
|
ulong v;
|
||||||
|
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(ulong));
|
channelsize(c, sizeof(ulong));
|
||||||
if(nbrecv(c, &v) == 0)
|
if(runop(CHANRCV, c, &v, 1) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
@ -320,8 +347,9 @@ nbrecvul(Channel *c)
|
||||||
int
|
int
|
||||||
nbsendp(Channel *c, void *v)
|
nbsendp(Channel *c, void *v)
|
||||||
{
|
{
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(void*));
|
channelsize(c, sizeof(void*));
|
||||||
return nbsend(c, &v);
|
return runop(CHANSND, c, &v, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void*
|
void*
|
||||||
|
|
@ -329,8 +357,9 @@ nbrecvp(Channel *c)
|
||||||
{
|
{
|
||||||
void *v;
|
void *v;
|
||||||
|
|
||||||
|
setuserpc(getcallerpc(&c));
|
||||||
channelsize(c, sizeof(void*));
|
channelsize(c, sizeof(void*));
|
||||||
if(nbrecv(c, &v) == 0)
|
if(runop(CHANRCV, c, &v, 1) == 0)
|
||||||
return nil;
|
return nil;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,13 @@ int _threadpasserpid;
|
||||||
static void mainlauncher(void*);
|
static void mainlauncher(void*);
|
||||||
extern void (*_sysfatal)(char*, va_list);
|
extern void (*_sysfatal)(char*, va_list);
|
||||||
|
|
||||||
|
void
|
||||||
|
_threadstatus(int x)
|
||||||
|
{
|
||||||
|
USED(x);
|
||||||
|
threadstatus();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_threaddie(int x)
|
_threaddie(int x)
|
||||||
{
|
{
|
||||||
|
|
@ -38,6 +45,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
signal(SIGTERM, _threaddie);
|
signal(SIGTERM, _threaddie);
|
||||||
signal(SIGCHLD, _nop);
|
signal(SIGCHLD, _nop);
|
||||||
|
signal(SIGINFO, _threadstatus);
|
||||||
// rfork(RFREND);
|
// rfork(RFREND);
|
||||||
|
|
||||||
//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
|
//_threaddebuglevel = (DBGSCHED|DBGCHAN|DBGREND)^~0;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
//static Thread *runthread(Proc*);
|
//static Thread *runthread(Proc*);
|
||||||
|
|
||||||
#if 0
|
|
||||||
static char *_psstate[] = {
|
static char *_psstate[] = {
|
||||||
"Dead",
|
"Dead",
|
||||||
"Running",
|
"Running",
|
||||||
|
|
@ -19,7 +18,6 @@ psstate(int s)
|
||||||
return "unknown";
|
return "unknown";
|
||||||
return _psstate[s];
|
return _psstate[s];
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
void
|
||||||
_schedinit(void *arg)
|
_schedinit(void *arg)
|
||||||
|
|
@ -271,3 +269,15 @@ yield(void)
|
||||||
_sched();
|
_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ struct Thread
|
||||||
|
|
||||||
Chanstate chan; /* which channel operation is current */
|
Chanstate chan; /* which channel operation is current */
|
||||||
Alt *alt; /* pointer to current alt structure (debugging) */
|
Alt *alt; /* pointer to current alt structure (debugging) */
|
||||||
|
ulong userpc;
|
||||||
|
|
||||||
void* udata[NPRIV]; /* User per-thread data pointer */
|
void* udata[NPRIV]; /* User per-thread data pointer */
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue