2004-04-19 19:32:07 +00:00
|
|
|
#include <u.h>
|
|
|
|
|
#include <libc.h>
|
|
|
|
|
#include <bio.h>
|
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <mach.h>
|
|
|
|
|
#define Extern extern
|
|
|
|
|
#include "acid.h"
|
|
|
|
|
#include "y.tab.h"
|
|
|
|
|
|
|
|
|
|
static void install(int);
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
sproc(int xpid)
|
|
|
|
|
{
|
|
|
|
|
Lsym *s;
|
|
|
|
|
int i;
|
2005-02-11 19:44:37 +00:00
|
|
|
Regs *regs;
|
2004-04-19 19:32:07 +00:00
|
|
|
|
|
|
|
|
if(symmap == 0)
|
|
|
|
|
error("no map");
|
|
|
|
|
|
|
|
|
|
if(pid == xpid)
|
|
|
|
|
return;
|
|
|
|
|
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
if(corhdr){
|
2005-02-11 19:44:37 +00:00
|
|
|
regs = coreregs(corhdr, xpid);
|
|
|
|
|
if(regs == nil)
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
error("no such pid in core dump");
|
2005-02-11 19:44:37 +00:00
|
|
|
free(correg);
|
|
|
|
|
correg = regs;
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
}else{
|
|
|
|
|
/* XXX should only change register set here if cormap already mapped */
|
|
|
|
|
if(xpid <= 0)
|
|
|
|
|
error("bad pid");
|
|
|
|
|
unmapproc(cormap);
|
|
|
|
|
unmapfile(corhdr, cormap);
|
|
|
|
|
free(correg);
|
|
|
|
|
correg = nil;
|
2005-02-11 19:44:37 +00:00
|
|
|
pid = -1;
|
|
|
|
|
corpid = -1;
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
|
|
|
|
|
if(mapproc(xpid, cormap, &correg) < 0)
|
|
|
|
|
error("setproc %d: %r", xpid);
|
|
|
|
|
|
|
|
|
|
/* XXX check text file here? */
|
|
|
|
|
|
|
|
|
|
for(i=0; i<cormap->nseg; i++){
|
|
|
|
|
if(cormap->seg[i].file == nil){
|
|
|
|
|
if(strcmp(cormap->seg[i].name, "data") == 0)
|
|
|
|
|
cormap->seg[i].name = "*data";
|
|
|
|
|
if(strcmp(cormap->seg[i].name, "text") == 0)
|
|
|
|
|
cormap->seg[i].name = "*text";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-04-19 19:32:07 +00:00
|
|
|
pid = xpid;
|
2005-02-11 16:44:04 +00:00
|
|
|
corpid = pid;
|
2004-04-19 19:32:07 +00:00
|
|
|
s = look("pid");
|
|
|
|
|
s->v->store.u.ival = pid;
|
|
|
|
|
|
|
|
|
|
install(pid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
nproc(char **argv)
|
|
|
|
|
{
|
2004-04-19 23:03:46 +00:00
|
|
|
int pid, i;
|
2004-04-19 19:32:07 +00:00
|
|
|
|
|
|
|
|
pid = fork();
|
|
|
|
|
switch(pid) {
|
|
|
|
|
case -1:
|
|
|
|
|
error("new: fork %r");
|
|
|
|
|
case 0:
|
|
|
|
|
rfork(RFNAMEG|RFNOTEG);
|
|
|
|
|
if(ctlproc(getpid(), "hang") < 0)
|
|
|
|
|
fatal("new: hang %d: %r", getpid());
|
|
|
|
|
|
|
|
|
|
close(0);
|
|
|
|
|
close(1);
|
|
|
|
|
close(2);
|
|
|
|
|
for(i = 3; i < NFD; i++)
|
|
|
|
|
close(i);
|
|
|
|
|
|
|
|
|
|
open("/dev/tty", OREAD);
|
|
|
|
|
open("/dev/tty", OWRITE);
|
|
|
|
|
open("/dev/tty", OWRITE);
|
2005-11-28 00:43:50 +00:00
|
|
|
execv(argv[0], argv);
|
|
|
|
|
fatal("new: exec %s: %r", argv[0]);
|
2004-04-19 19:32:07 +00:00
|
|
|
default:
|
|
|
|
|
install(pid);
|
2005-11-28 00:39:42 +00:00
|
|
|
msg(pid, "attached");
|
2004-04-19 19:32:07 +00:00
|
|
|
msg(pid, "waitstop");
|
|
|
|
|
notes(pid);
|
|
|
|
|
sproc(pid);
|
|
|
|
|
dostop(pid);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
notes(int pid)
|
|
|
|
|
{
|
|
|
|
|
Lsym *s;
|
|
|
|
|
Value *v;
|
|
|
|
|
int i, n;
|
|
|
|
|
char **notes;
|
|
|
|
|
List *l, **tail;
|
|
|
|
|
|
|
|
|
|
s = look("notes");
|
|
|
|
|
if(s == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
v = s->v;
|
|
|
|
|
n = procnotes(pid, ¬es);
|
|
|
|
|
if(n < 0)
|
|
|
|
|
error("procnotes pid=%d: %r", pid);
|
|
|
|
|
|
|
|
|
|
v->set = 1;
|
|
|
|
|
v->type = TLIST;
|
|
|
|
|
v->store.u.l = 0;
|
|
|
|
|
tail = &v->store.u.l;
|
|
|
|
|
for(i=0; i<n; i++) {
|
|
|
|
|
l = al(TSTRING);
|
|
|
|
|
l->store.u.string = strnode(notes[i]);
|
|
|
|
|
l->store.fmt = 's';
|
|
|
|
|
*tail = l;
|
|
|
|
|
tail = &l->next;
|
|
|
|
|
}
|
|
|
|
|
free(notes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
dostop(int pid)
|
|
|
|
|
{
|
|
|
|
|
Lsym *s;
|
|
|
|
|
Node *np, *p;
|
|
|
|
|
|
|
|
|
|
s = look("stopped");
|
|
|
|
|
if(s && s->proc) {
|
|
|
|
|
np = an(ONAME, ZN, ZN);
|
|
|
|
|
np->sym = s;
|
|
|
|
|
np->store.fmt = 'D';
|
|
|
|
|
np->type = TINT;
|
|
|
|
|
p = con(pid);
|
|
|
|
|
p->store.fmt = 'D';
|
|
|
|
|
np = an(OCALL, np, p);
|
|
|
|
|
execute(np);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
install(int pid)
|
|
|
|
|
{
|
|
|
|
|
Lsym *s;
|
|
|
|
|
List *l;
|
|
|
|
|
int i, new, p;
|
|
|
|
|
|
|
|
|
|
new = -1;
|
|
|
|
|
for(i = 0; i < Maxproc; i++) {
|
|
|
|
|
p = ptab[i].pid;
|
|
|
|
|
if(p == pid)
|
|
|
|
|
return;
|
|
|
|
|
if(p == 0 && new == -1)
|
|
|
|
|
new = i;
|
|
|
|
|
}
|
|
|
|
|
if(new == -1)
|
|
|
|
|
error("no free process slots");
|
|
|
|
|
|
|
|
|
|
ptab[new].pid = pid;
|
|
|
|
|
|
|
|
|
|
s = look("proclist");
|
|
|
|
|
l = al(TINT);
|
|
|
|
|
l->store.fmt = 'D';
|
|
|
|
|
l->store.u.ival = pid;
|
|
|
|
|
l->next = s->v->store.u.l;
|
|
|
|
|
s->v->store.u.l = l;
|
|
|
|
|
s->v->set = 1;
|
|
|
|
|
}
|
|
|
|
|
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
/*
|
2004-05-05 04:22:16 +00:00
|
|
|
static int
|
|
|
|
|
installed(int pid)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for(i=0; i<Maxproc; i++)
|
|
|
|
|
if(ptab[i].pid == pid)
|
|
|
|
|
return 1;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
Working on better handling of multithreading in general
and core dumps in particular. See notes:
new types: register is something that when dereferenced gives you
the registers. the Ureg is no longer mapped at 0.
refconst is something that gives a constant when dereferenced.
new builtin register("AX") creates register values
new builtin refconst(0x123) creates refconst values
new builtin var("foo") is equivalent to the variable foo
(it returns foo but can also be used as the lhs of an assignment).
new acid function getregs() returns a list of the current values of registers.
new acid function setregs() sets the current registers to those values.
note that getregs and setregs operate on register locations, not the
register values themselves.
new acid function resetregs() sets registers to register("AX"), etc.
new acid function clearregs() sets all registers to constant -1.
the default register settings are as in resetregs(), not small numbers.
new acid variables coretext, pids, systype, corefile, cmdline.
new behavior: local variable lookup, stk, etc., use the acid values of registers
(*PC, *SP, and so on), so the thread support code can change the context
completely.
unary + is applicable to more data types and prints more often.
2005-01-23 22:48:19 +00:00
|
|
|
*/
|
2004-05-05 04:22:16 +00:00
|
|
|
|
2004-04-19 19:32:07 +00:00
|
|
|
void
|
|
|
|
|
deinstall(int pid)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
Lsym *s;
|
|
|
|
|
List *f, **d;
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < Maxproc; i++) {
|
|
|
|
|
if(ptab[i].pid == pid) {
|
|
|
|
|
detachproc(pid);
|
|
|
|
|
// close(ptab[i].ctl);
|
|
|
|
|
ptab[i].pid = 0;
|
|
|
|
|
s = look("proclist");
|
|
|
|
|
d = &s->v->store.u.l;
|
|
|
|
|
for(f = *d; f; f = f->next) {
|
|
|
|
|
if(f->store.u.ival == pid) {
|
|
|
|
|
*d = f->next;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
s = look("pid");
|
|
|
|
|
if(s->v->store.u.ival == pid)
|
|
|
|
|
s->v->store.u.ival = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
msg(int pid, char *msg)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
char err[ERRMAX];
|
|
|
|
|
|
|
|
|
|
for(i = 0; i < Maxproc; i++) {
|
|
|
|
|
if(ptab[i].pid == pid) {
|
|
|
|
|
if(ctlproc(pid, msg) < 0){
|
|
|
|
|
errstr(err, sizeof err);
|
|
|
|
|
if(strcmp(err, "process exited") == 0)
|
|
|
|
|
deinstall(pid);
|
|
|
|
|
error("msg: pid=%d %s: %s", pid, msg, err);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
error("msg: pid=%d: not found for %s", pid, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
getstatus(int pid)
|
|
|
|
|
{
|
2005-11-28 00:39:42 +00:00
|
|
|
return "unknown";
|
2004-04-19 19:32:07 +00:00
|
|
|
}
|
|
|
|
|
|