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

View file

@ -30,7 +30,7 @@ sproc(int xpid)
correg = nil; correg = nil;
if(mapproc(xpid, cormap, &correg) < 0) if(mapproc(xpid, cormap, &correg) < 0)
error("setproc %d: %r", pid); error("setproc %d: %r", xpid);
/* XXX check text file here? */ /* XXX check text file here? */
@ -165,6 +165,17 @@ install(int pid)
s->v->set = 1; 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 void
deinstall(int pid) deinstall(int pid)
{ {

View file

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

View file

@ -15,15 +15,11 @@ hgethead(HConnect *c, int many)
int n; int n;
hin = &c->hin; hin = &c->hin;
fprint(2, "hgethead top %p - %p\n", hin->pos, hin->stop);
for(;;){ for(;;){
s = (char*)hin->pos; s = (char*)hin->pos;
pp = s; pp = s;
fprint(2, "hgethead %p - %p\n", pp, hin->stop);
while(p = memchr(pp, '\n', (char*)hin->stop - pp)){ 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')){ if(!many || p == pp || (p == pp + 1 && *pp == '\r')){
fprint(2, "breaking\n");
pp = p + 1; pp = p + 1;
break; break;
} }
@ -32,14 +28,13 @@ fprint(2, "breaking\n");
hin->pos = (uchar*)pp; hin->pos = (uchar*)pp;
n = pp - s; n = pp - s;
if(c->hstop + n > &c->header[HBufSize]) if(c->hstop + n > &c->header[HBufSize])
return 0; return -1;
memmove(c->hstop, s, n); memmove(c->hstop, s, n);
c->hstop += n; c->hstop += n;
*c->hstop = '\0'; *c->hstop = '\0';
fprint(2, "p %p\n", p);
if(p != nil) if(p != nil)
return 1;
if(hreadbuf(hin, hin->pos) == nil || hin->state == Hend)
return 0; 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]); s = strchr(hstates, buf[0]);
if(s == nil) if(s == nil)
return 0; return -1;
h->state = s - hstates; h->state = s - hstates;
s = strchr(hxfers, buf[1]); s = strchr(hxfers, buf[1]);
@ -300,13 +300,13 @@ hload(Hio *h, char *buf)
} }
*t++ = c; *t++ = c;
if(t >= stop) if(t >= stop)
return 0; return -1;
} }
*t = '\0'; *t = '\0';
h->pos = h->start; h->pos = h->start;
h->stop = t; h->stop = t;
h->seek = 0; h->seek = 0;
return 1; return 0;
} }
void void

View file

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

View file

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

View file

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

View file

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

View file

@ -65,6 +65,7 @@ delayednotes(Proc *p, void *v)
} }
if(i==NFN){ if(i==NFN){
_threaddebug(DBGNOTE, "Unhandled note %s, proc %p\n", n->s, p); _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) if(v != nil)
noted(NDFLT); noted(NDFLT);
else if(strncmp(n->s, "sys:", 4)==0) else if(strncmp(n->s, "sys:", 4)==0)

View file

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

View file

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