various bug fixes

This commit is contained in:
rsc 2004-05-05 04:22:16 +00:00
parent 4f48d1d4f7
commit 2e965b3324
12 changed files with 82 additions and 41 deletions

View file

@ -61,11 +61,6 @@ defn alt(A){
print(altfmt(A), "\n");
}
threadignsrc = {
"plan9/src/libc",
"plan9/src/libthread",
};
defn fnname(a){
local sym, s;
@ -100,7 +95,7 @@ defn threadstkline(T){
pc = frame[2];
pc0 = frame[0];
file = pcfile(pc);
if !regexp("plan9/src/libc/", file)
if !regexp("plan9/src/lib9/", file)
&& !regexp("plan9/src/libthread/", file)
&& match(file, stkignore)==-1 then
stop = 1;
@ -234,7 +229,8 @@ defn lproc(P){
threadstkignore = {
"plan9/src/libthread/",
"plan9/src/libc/(386|arm|alpha|sparc|power|mips)/"
"plan9/src/lib9/",
"plan9/src/lib9/(fmt|utf)/",
};
defn threadstks(P){
complex Proc P;

View file

@ -30,7 +30,7 @@ sproc(int xpid)
correg = nil;
if(mapproc(xpid, cormap, &correg) < 0)
error("setproc %d: %r", pid);
error("setproc %d: %r", xpid);
/* XXX check text file here? */
@ -165,6 +165,17 @@ install(int pid)
s->v->set = 1;
}
static int
installed(int pid)
{
int i;
for(i=0; i<Maxproc; i++)
if(ptab[i].pid == pid)
return 1;
return 0;
}
void
deinstall(int pid)
{

View file

@ -54,7 +54,7 @@ _p9uproc(int inhandler)
while((up = mallocz(sizeof(Uproc), 1)) == nil)
sleep(1000);
//fprint(2, "alloc uproc for pid %d\n", pid);
/* fprint(2, "alloc uproc for pid %d\n", pid); */
up->pid = pid;
lock(&uproclock);
h = pid%PIDHASH;
@ -82,7 +82,7 @@ _p9uprocdie(void)
int pid, i, h;
pid = getpid();
fprint(2, "reap uproc for pid %d\n", pid);
/* fprint(2, "reap uproc for pid %d\n", pid); */
h = pid%PIDHASH;
for(i=0; i<PIDHASH; i++){
up = alluproc[h];

View file

@ -15,15 +15,11 @@ hgethead(HConnect *c, int many)
int n;
hin = &c->hin;
fprint(2, "hgethead top %p - %p\n", hin->pos, hin->stop);
for(;;){
s = (char*)hin->pos;
pp = s;
fprint(2, "hgethead %p - %p\n", pp, hin->stop);
while(p = memchr(pp, '\n', (char*)hin->stop - pp)){
fprint(2, "hgethead %p - %p newline at %p %d\n", pp, hin->stop, p, *pp);
if(!many || p == pp || (p == pp + 1 && *pp == '\r')){
fprint(2, "breaking\n");
pp = p + 1;
break;
}
@ -32,14 +28,13 @@ fprint(2, "breaking\n");
hin->pos = (uchar*)pp;
n = pp - s;
if(c->hstop + n > &c->header[HBufSize])
return 0;
return -1;
memmove(c->hstop, s, n);
c->hstop += n;
*c->hstop = '\0';
fprint(2, "p %p\n", p);
if(p != nil)
return 1;
if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
return 0;
if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
return -1;
}
}

View file

@ -281,7 +281,7 @@ hload(Hio *h, char *buf)
s = strchr(hstates, buf[0]);
if(s == nil)
return 0;
return -1;
h->state = s - hstates;
s = strchr(hxfers, buf[1]);
@ -300,13 +300,13 @@ hload(Hio *h, char *buf)
}
*t++ = c;
if(t >= stop)
return 0;
return -1;
}
*t = '\0';
h->pos = h->start;
h->stop = t;
h->seek = 0;
return 1;
return 0;
}
void

View file

@ -198,7 +198,7 @@ hparseheaders(HConnect *c, int timeout)
memset(&h, 0, sizeof(h));
h.c = c;
alarm(timeout);
if(!hgethead(c, 1))
if(hgethead(c, 1) < 0)
return -1;
alarm(0);
h.hstart = c->hpos;

View file

@ -41,8 +41,8 @@ hparsereq(HConnect *c, int timeout)
* only works for http/1.1 or later.
*/
alarm(timeout);
if(!hgethead(c, 0))
return 0;
if(hgethead(c, 0) < 0)
return -1;
alarm(0);
c->reqtime = time(nil);
c->req.meth = getword(c);

View file

@ -37,6 +37,9 @@ struct PtraceRegs
static int ptracerw(Map*, Seg*, ulong, void*, uint, int);
static int ptraceregrw(Regs*, char*, ulong*, int);
static int attachedpids[1000];
static int nattached;
void
unmapproc(Map *map)
{
@ -55,21 +58,36 @@ unmapproc(Map *map)
int
mapproc(int pid, Map *map, Regs **rp)
{
int i;
Seg s;
PtraceRegs *r;
if(ptrace(PTRACE_ATTACH, pid, 0, 0) < 0)
if(ptrace(PTRACE_PEEKUSER, pid, 0, 0) < 0)
if(nattached==1 && attachedpids[0] == pid)
goto already;
if(nattached)
detachproc(attachedpids[0]);
for(i=0; i<nattached; i++)
if(attachedpids[i]==pid)
goto already;
if(nattached == nelem(attachedpids)){
werrstr("attached to too many processes");
return -1;
}
if(ptrace(PTRACE_ATTACH, pid, 0, 0) < 0){
werrstr("ptrace attach %d: %r", pid);
return -1;
}
if(ctlproc(pid, "waitstop") < 0){
fprint(2, "waitstop: %r");
ptrace(PTRACE_DETACH, pid, 0, 0);
return -1;
}
attachedpids[nattached++] = pid;
already:
memset(&s, 0, sizeof s);
s.base = 0;
s.size = 0xFFFFFFFF;
@ -78,11 +96,15 @@ mapproc(int pid, Map *map, Regs **rp)
s.file = nil;
s.rw = ptracerw;
s.pid = pid;
if(addseg(map, s) < 0)
if(addseg(map, s) < 0){
fprint(2, "addseg: %r\n");
return -1;
}
if((r = mallocz(sizeof(PtraceRegs), 1)) == nil)
if((r = mallocz(sizeof(PtraceRegs), 1)) == nil){
fprint(2, "mallocz: %r\n");
return -1;
}
r->r.rw = ptraceregrw;
r->pid = pid;
*rp = (Regs*)r;
@ -92,6 +114,14 @@ mapproc(int pid, Map *map, Regs **rp)
int
detachproc(int pid)
{
int i;
for(i=0; i<nattached; i++){
if(attachedpids[i] == pid){
attachedpids[i] = attachedpids[--nattached];
break;
}
}
return ptrace(PTRACE_DETACH, pid, 0, 0);
}
@ -367,9 +397,14 @@ ctlproc(int pid, char *msg)
if(isstopped(pid))
return 0;
for(;;){
p = waitpid(pid, &status, WUNTRACED);
if(p <= 0)
p = waitpid(pid, &status, WUNTRACED|__WALL);
if(p <= 0){
if(errno == ECHILD){
if(isstopped(pid))
return 0;
}
return -1;
}
if(WIFEXITED(status) || WIFSTOPPED(status))
return 0;
}

View file

@ -174,7 +174,7 @@ get8(Map *map, ulong addr, u64int *u)
{
u64int v;
if(mrw(map, addr, &v, 4, 1) < 0)
if(mrw(map, addr, &v, 8, 1) < 0)
return -1;
*u = mach->swap8(v);
return 8;

View file

@ -65,6 +65,7 @@ delayednotes(Proc *p, void *v)
}
if(i==NFN){
_threaddebug(DBGNOTE, "Unhandled note %s, proc %p\n", n->s, p);
fprint(2, "unhandled note %s, pid %d\n", n->s, p->pid);
if(v != nil)
noted(NDFLT);
else if(strncmp(n->s, "sys:", 4)==0)

View file

@ -75,6 +75,7 @@ vtrpc(VtConn *z, Packet *p)
while(!r->done){
qunlock(&z->lk);
if((p = vtrecv(z)) == nil){
werrstr("unexpected eof on venti connection");
z->muxer = 0;
return nil;
}

View file

@ -8,29 +8,31 @@ vtsrvhello(VtConn *z)
VtFcall tx, rx;
Packet *p;
if((p = vtrecv(z)) == nil)
return 0;
if((p = vtrecv(z)) == nil){
werrstr("unexpected eof on venti connection");
return -1;
}
if(vtfcallunpack(&tx, p) < 0){
packetfree(p);
return 0;
return -1;
}
packetfree(p);
if(tx.type != VtThello){
vtfcallclear(&tx);
werrstr("bad packet type %d; want Thello %d", tx.type, VtThello);
return 0;
return -1;
}
if(tx.tag != 0){
vtfcallclear(&tx);
werrstr("bad tag in hello");
return 0;
return -1;
}
if(strcmp(tx.version, z->version) != 0){
vtfcallclear(&tx);
werrstr("bad version in hello");
return 0;
return -1;
}
vtfree(z->uid);
z->uid = tx.uid;
@ -42,9 +44,9 @@ vtsrvhello(VtConn *z)
rx.tag = tx.tag;
rx.sid = "anonymous";
if((p = vtfcallpack(&rx)) == nil)
return 0;
return -1;
if(vtsend(z, p) < 0)
return 0;
return -1;
return 1;
return 0;
}