/* * functions for running the debugged process */ #include "defs.h" #include "fns.h" extern char lastc, peekc; int child; int msgfd = -1; int notefd = -1; int pcspid = -1; int pcsactive = 0; void setpcs(void) { char buf[128]; if(pid && pid != pcspid){ if(msgfd >= 0){ close(msgfd); msgfd = -1; } if(notefd >= 0){ close(notefd); notefd = -1; } pcspid = -1; sprint(buf, "/proc/%d/ctl", pid); msgfd = open(buf, OWRITE); if(msgfd < 0) error("can't open control file"); sprint(buf, "/proc/%d/note", pid); notefd = open(buf, ORDWR); if(notefd < 0) error("can't open note file"); pcspid = pid; } } void msgpcs(char *msg) { char err[ERRLEN]; setpcs(); if(write(msgfd, msg, strlen(msg)) < 0 && !ending){ errstr(err); if(strcmp(err, "interrupted") != 0) endpcs(); errors("can't write control file", err); } } /* * empty the note buffer and toss pending breakpoint notes */ void unloadnote(void) { char err[ERRLEN]; setpcs(); for(; nnote') { *p++ = lastc; rdc(); } while (lastc != EOR && lastc != SPC && lastc != TB) { *p++ = lastc; readchar(); } if (lastc == SPC || lastc == TB) rdc(); *p++ = 0; if (*thisarg == '<') { close(0); if (open(&thisarg[1], OREAD) < 0) { print("%s: cannot open\n", &thisarg[1]); _exits(0); } } else if (*thisarg == '>') { close(1); if (create(&thisarg[1], OWRITE, 0666) < 0) { print("%s: cannot create\n", &thisarg[1]); _exits(0); } } else *ap++ = thisarg; } *ap = 0; exec(symfil, argl); perror(symfil); } char procname[100]; void startpcs(void) { if ((pid = fork()) == 0) { pid = getpid(); msgpcs("hang"); doexec(); exits(0); } if (pid == -1) error("can't fork"); child++; sprint(procname, "/proc/%d/mem", pid); corfil = procname; if ((fcor = open(corfil, ORDWR|OCEXEC)) < 0) { dprint("cannot open %s\n", corfil); error(0); } msgpcs("waitstop"); bpwait(); if (adrflg) rput(rname("PC"), adrval); while (rdc() != EOR) ; reread(); } void runstep(ulong loc, int keepnote) { int nfoll; ulong foll[3]; BKPT bkpt[3]; int i; if(machdata->foll == 0){ dprint("stepping unimplemented; assuming not a branch\n"); nfoll = 1; foll[0] = loc+mach->pcquant; }else nfoll = machdata->foll(loc, foll); memset(bkpt, 0, sizeof bkpt); for(i=0; ibpfix) loc = (*machdata->bpfix)(bp->loc); else loc = bp->loc; if(install){ if (get1(cormap, loc, SEGANY, bp->save, machdata->bpsize)) put1(cormap, loc, SEGANY, machdata->bpinst, machdata->bpsize); }else put1(cormap, loc, SEGANY, bp->save, machdata->bpsize); if(errflg){ errstr(err); sprint(buf, "can't set breakpoint at %lux: %s", bp->loc, err); print(buf); read(0, buf, 100); } }