aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acid/builtin.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-23 22:48:19 +0000
committerrsc <devnull@localhost>2005-01-23 22:48:19 +0000
commit4f2ac1b76b04df503944e86c2e7f152c2ff53f0e (patch)
treed90d1387f48337337bd0798f29d6881f67899f80 /src/cmd/acid/builtin.c
parenta5f9ff62b2d70a5b75efe8e4f993aec10f209095 (diff)
downloadplan9port-4f2ac1b76b04df503944e86c2e7f152c2ff53f0e.tar.gz
plan9port-4f2ac1b76b04df503944e86c2e7f152c2ff53f0e.tar.bz2
plan9port-4f2ac1b76b04df503944e86c2e7f152c2ff53f0e.zip
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.
Diffstat (limited to 'src/cmd/acid/builtin.c')
-rw-r--r--src/cmd/acid/builtin.c166
1 files changed, 138 insertions, 28 deletions
diff --git a/src/cmd/acid/builtin.c b/src/cmd/acid/builtin.c
index 490c4521..316c4921 100644
--- a/src/cmd/acid/builtin.c
+++ b/src/cmd/acid/builtin.c
@@ -44,6 +44,9 @@ void regexp(Node*, Node*);
void textfile(Node*, Node*);
void deltextfile(Node*, Node*);
void stringn(Node*, Node*);
+void xregister(Node*, Node*);
+void refconst(Node*, Node*);
+void dolook(Node*, Node*);
typedef struct Btab Btab;
struct Btab
@@ -52,13 +55,12 @@ struct Btab
void (*fn)(Node*, Node*);
} tab[] =
{
+ "access", doaccess,
"atof", cvtatof,
"atoi", cvtatoi,
"deltextfile", deltextfile,
"error", doerror,
"file", getfile,
- "readfile", readfile,
- "access", doaccess,
"filepc", filepc,
"fnbound", funcbound,
"fmt", fmt,
@@ -76,8 +78,11 @@ struct Btab
"print", bprint,
"printto", printto,
"rc", rc,
+ "readfile", readfile,
"reason", reason,
+ "refconst", refconst,
"regexp", regexp,
+ "register", xregister,
"setproc", setproc,
"start", start,
"startstop", startstop,
@@ -87,6 +92,7 @@ struct Btab
"stringn", stringn,
"sysstop", sysstop,
"textfile", textfile,
+ "var", dolook,
"waitstop", waitstop,
0
};
@@ -317,6 +323,65 @@ xkill(Node *r, Node *args)
}
void
+xregister(Node *r, Node *args)
+{
+ Regdesc *rp;
+ Node res;
+
+ if(args == 0)
+ error("register(string): arg count");
+ expr(args, &res);
+ if(res.type != TSTRING)
+ error("register(string): arg type");
+
+ if((rp = regdesc(res.store.u.string->string)) == nil)
+ error("no such register");
+
+ r->op = OCONST;
+ r->type = TREG;
+ r->store.fmt = rp->format;
+ r->store.u.reg = rp->name;
+}
+
+void
+refconst(Node *r, Node *args)
+{
+ Node *n;
+
+ if(args == 0)
+ error("refconst(expr): arg count");
+
+ n = an(OCONST, ZN, ZN);
+ expr(args, n);
+
+ r->op = OCONST;
+ r->type = TCON;
+ r->store.u.con = n;
+}
+
+void
+dolook(Node *r, Node *args)
+{
+ Node res;
+ Lsym *l;
+
+ if(args == 0)
+ error("var(string): arg count");
+ expr(args, &res);
+ if(res.type != TSTRING)
+ error("var(string): arg type");
+
+ r->op = OCONST;
+ if((l = look(res.store.u.string->string)) == nil || l->v->set == 0){
+ r->type = TLIST;
+ r->store.u.l = nil;
+ }else{
+ r->type = l->v->type;
+ r->store = l->v->store;
+ }
+}
+
+void
status(Node *r, Node *args)
{
Node res;
@@ -350,7 +415,7 @@ reason(Node *r, Node *args)
r->op = OCONST;
r->type = TSTRING;
r->store.fmt = 's';
- r->store.u.string = strnode((*mach->exc)(cormap, correg));
+ r->store.u.string = strnode((*mach->exc)(cormap, acidregs));
}
void
@@ -367,7 +432,7 @@ follow(Node *r, Node *args)
if(res.type != TINT)
error("follow(addr): arg type");
- n = (*mach->foll)(cormap, correg, res.store.u.ival, f);
+ n = (*mach->foll)(cormap, acidregs, res.store.u.ival, f);
if (n < 0)
error("follow(addr): %r");
tail = &r->store.u.l;
@@ -953,7 +1018,7 @@ straceregrw(Regs *regs, char *name, ulong *val, int isr)
*val = sregs[i].val;
return 0;
}
- return rget(correg, name, val);
+ return rget(acidregs, name, val);
}
void
@@ -1058,6 +1123,65 @@ patom(char type, Store *res)
int i;
char buf[512];
extern char *typenames[];
+ Node *n;
+
+ switch(type){
+ case TREG:
+ Bprint(bout, "register(\"%s\")", res->u.reg);
+ return;
+ case TCON:
+ Bprint(bout, "refconst(");
+ n = res->u.con;
+ patom(n->type, &n->store);
+ Bprint(bout, ")");
+ return;
+ }
+
+ switch(res->fmt){
+ case 'c':
+ case 'C':
+ case 'r':
+ case 'B':
+ case 'b':
+ case 'X':
+ case 'x':
+ case 'W':
+ case 'D':
+ case 'd':
+ case 'u':
+ case 'U':
+ case 'Z':
+ case 'V':
+ case 'Y':
+ case 'o':
+ case 'O':
+ case 'q':
+ case 'Q':
+ case 'a':
+ case 'A':
+ case 'I':
+ case 'i':
+ if(type != TINT){
+ badtype:
+ Bprint(bout, "*%s\\%c*", typenames[(uchar)type], res->fmt);
+ return;
+ }
+ break;
+
+ case 'f':
+ case 'F':
+ if(type != TFLOAT)
+ goto badtype;
+ break;
+
+ case 's':
+ case 'g':
+ case 'G':
+ case 'R':
+ if(type != TSTRING)
+ goto badtype;
+ break;
+ }
switch(res->fmt) {
case 'c':
@@ -1129,24 +1253,15 @@ patom(char type, Store *res)
break;
case 'f':
case 'F':
- if(type != TFLOAT)
- Bprint(bout, "*%c<%s>*", res->fmt, typenames[(uchar)type]);
- else
- Bprint(bout, "%g", res->u.fval);
+ Bprint(bout, "%g", res->u.fval);
break;
case 's':
case 'g':
case 'G':
- if(type != TSTRING)
- Bprint(bout, "*%c<%s>*", res->fmt, typenames[(uchar)type]);
- else
- Bwrite(bout, res->u.string->string, res->u.string->len);
+ Bwrite(bout, res->u.string->string, res->u.string->len);
break;
case 'R':
- if(type != TSTRING)
- Bprint(bout, "*%c<%s>*", res->fmt, typenames[(uchar)type]);
- else
- Bprint(bout, "%S", (Rune*)res->u.string->string);
+ Bprint(bout, "%S", (Rune*)res->u.string->string);
break;
case 'a':
case 'A':
@@ -1155,14 +1270,10 @@ patom(char type, Store *res)
break;
case 'I':
case 'i':
- if(type != TINT)
- Bprint(bout, "*%c<%s>*", res->fmt, typenames[(uchar)type]);
- else {
- if (symmap == nil || (*mach->das)(symmap, res->u.ival, res->fmt, buf, sizeof(buf)) < 0)
- Bprint(bout, "no instruction");
- else
- Bprint(bout, "%s", buf);
- }
+ if (symmap == nil || (*mach->das)(symmap, res->u.ival, res->fmt, buf, sizeof(buf)) < 0)
+ Bprint(bout, "no instruction");
+ else
+ Bprint(bout, "%s", buf);
break;
}
}
@@ -1406,6 +1517,7 @@ textfile(Node *r, Node *args)
unmapfile(corhdr, cormap);
mapfile(fp, base, cormap, nil);
free(correg);
+ correg = nil;
mapfile(corhdr, 0, cormap, &correg);
}
if(symopen(fp) < 0)
@@ -1476,8 +1588,6 @@ deltextfile(Node *r, Node *args)
error("symbol file %s not open", file);
}
-int xget1(Map *m, ulong addr, u8int *a, int n);
-
void
stringn(Node *r, Node *args)
{
@@ -1507,7 +1617,7 @@ stringn(Node *r, Node *args)
r->type = TSTRING;
for(i=0; i<n; i++){
- ret = xget1(cormap, addr, (uchar*)&buf[i], 1);
+ ret = get1(cormap, addr, (uchar*)&buf[i], 1);
if(ret < 0){
free(buf);
error("indir: %r");