fix structure arguments. don't map OREG to REG for STASG (match fails)
[unix-history] / usr / src / old / dbx / eval.c
index c72c422..6dea109 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 1982 Regents of the University of California */
 
 /* Copyright (c) 1982 Regents of the University of California */
 
-static char sccsid[] = "@(#)eval.c 1.3 %G%";
+static char sccsid[] = "@(#)eval.c 1.10 %G%";
 
 /*
  * Tree evaluation.
 
 /*
  * Tree evaluation.
@@ -24,7 +24,7 @@ static char sccsid[] = "@(#)eval.c 1.3 %G%";
 
 #include "machine.h"
 
 
 #include "machine.h"
 
-#define STACKSIZE 2000
+#define STACKSIZE 20000
 
 typedef Char Stack;
 
 
 typedef Char Stack;
 
@@ -44,6 +44,7 @@ typedef Char Stack;
 
 public Stack stack[STACKSIZE];
 public Stack *sp = &stack[0];
 
 public Stack stack[STACKSIZE];
 public Stack *sp = &stack[0];
+public Boolean useInstLoc = false;
 
 #define chksp() \
 { \
 
 #define chksp() \
 { \
@@ -81,6 +82,9 @@ register Node p;
     File file;
 
     checkref(p);
     File file;
 
     checkref(p);
+    if (debug_flag[2]) {
+       fprintf(stderr," evaluating %s \n",showoperator(p->op));
+    }
     switch (degree(p->op)) {
        case BINARY:
            poparg(1, r1, fr1);
     switch (degree(p->op)) {
        case BINARY:
            poparg(1, r1, fr1);
@@ -158,6 +162,18 @@ register Node p;
                len = size(p->nodetype);
            }
            rpush(addr, len);
                len = size(p->nodetype);
            }
            rpush(addr, len);
+       addr = pop(long);
+        push(long, addr);
+           break;
+
+       /*
+        * Effectively, we want to pop n bytes off for the evaluated subtree
+        * and push len bytes on for the new type of the same tree.
+        */
+       case O_TYPERENAME:
+           n = size(p->value.arg[0]->nodetype);
+           len = size(p->nodetype);
+           sp = sp - n + len;
            break;
 
        case O_COMMA:
            break;
 
        case O_COMMA:
@@ -287,7 +303,7 @@ register Node p;
            break;
 
        case O_CONT:
            break;
 
        case O_CONT:
-           cont();
+           cont(p->value.lcon);
            printnews();
            break;
 
            printnews();
            break;
 
@@ -318,7 +334,14 @@ register Node p;
                printname(stdout, curfunc);
                putchar('\n');
            } else {
                printname(stdout, curfunc);
                putchar('\n');
            } else {
-               curfunc = p->value.arg[0]->value.sym;
+               s = p->value.arg[0]->value.sym;
+               find(f, s->name) where
+                   f->class == FUNC or f->class == PROC
+               endfind(f);
+               if (f == nil) {
+                   error("%s is not a procedure or function", symname(s));
+               }
+               curfunc = f;
                addr = codeloc(curfunc);
                if (addr != NOADDR) {
                    setsource(srcfilename(addr));
                addr = codeloc(curfunc);
                if (addr != NOADDR) {
                    setsource(srcfilename(addr));
@@ -335,7 +358,9 @@ register Node p;
            r0 = pop(long);
            if (p->value.examine.endaddr == nil) {
                n = p->value.examine.count;
            r0 = pop(long);
            if (p->value.examine.endaddr == nil) {
                n = p->value.examine.count;
-               if (streq(p->value.examine.mode, "i")) {
+               if (n == 0) {
+                   printvalue(r0, p->value.examine.mode);
+               } else if (streq(p->value.examine.mode, "i")) {
                    printninst(n, (Address) r0);
                } else {
                    printndata(n, (Address) r0, p->value.examine.mode);
                    printninst(n, (Address) r0);
                } else {
                    printndata(n, (Address) r0, p->value.examine.mode);
@@ -381,6 +406,7 @@ register Node p;
                stepc();
            }
            inst_tracing = b;
                stepc();
            }
            inst_tracing = b;
+           useInstLoc = (Boolean) (not p->value.step.source);
            printnews();
            break;
 
            printnews();
            break;
 
@@ -397,11 +423,19 @@ register Node p;
            break;
 
        case O_WHEREIS:
            break;
 
        case O_WHEREIS:
-           printwhereis(stdout, p->value.arg[0]->value.sym);
+           if (p->value.arg[0]->op == O_SYM) {
+               printwhereis(stdout,p->value.arg[0]->value.sym);
+           } else {
+               printwhereis(stdout,p->value.arg[0]->nodetype);
+           }
            break;
 
        case O_WHICH:
            break;
 
        case O_WHICH:
-           printwhich(stdout, p->value.arg[0]->value.sym);
+           if (p->value.arg[0]->op == O_SYM) {
+               printwhich(stdout,p->value.arg[0]->value.sym);
+           } else {
+               printwhich(stdout,p->value.arg[0]->nodetype);
+           }
            putchar('\n');
            break;
 
            putchar('\n');
            break;
 
@@ -429,6 +463,10 @@ register Node p;
            edit(p->value.scon);
            break;
 
            edit(p->value.scon);
            break;
 
+        case O_DEBUG:
+            debug(p);
+           break;
+
        case O_DUMP:
            dump();
            break;
        case O_DUMP:
            dump();
            break;
@@ -460,17 +498,11 @@ register Node p;
        case O_TRACE:
        case O_TRACEI:
            trace(p);
        case O_TRACE:
        case O_TRACEI:
            trace(p);
-           if (isstdin()) {
-               status();
-           }
            break;
 
        case O_STOP:
        case O_STOPI:
            stop(p);
            break;
 
        case O_STOP:
        case O_STOPI:
            stop(p);
-           if (isstdin()) {
-               status();
-           }
            break;
 
        case O_ADDEVENT:
            break;
 
        case O_ADDEVENT:
@@ -556,6 +588,10 @@ register Node p;
        default:
            panic("eval: bad op %d", p->op);
     }
        default:
            panic("eval: bad op %d", p->op);
     }
+ if(debug_flag[2]) { 
+       fprintf(stderr," evaluated %s \n",showoperator(p->op));
+ }
+           
 }
 
 /*
 }
 
 /*
@@ -671,7 +707,7 @@ Node p;
        b = true;
     } else {
        eval(p);
        b = true;
     } else {
        eval(p);
-       b = pop(Boolean);
+       b = (Boolean) pop(Boolrep);
     }
     return b;
 }
     }
     return b;
 }
@@ -707,7 +743,7 @@ Node p;
     cond = p->value.arg[2];
     if (exp == nil) {
        traceall(p->op, place, cond);
     cond = p->value.arg[2];
     if (exp == nil) {
        traceall(p->op, place, cond);
-    } else if (exp->op == O_QLINE) {
+    } else if (exp->op == O_QLINE or exp->op == O_LCON) {
        traceinst(p->op, exp, cond);
     } else if (place != nil and place->op == O_QLINE) {
        traceat(p->op, exp, place, cond);
        traceinst(p->op, exp, cond);
     } else if (place != nil and place->op == O_QLINE) {
        traceat(p->op, exp, place, cond);
@@ -750,6 +786,9 @@ Node cond;
     }
     action = build(O_TRACEON, (op == O_TRACEI), buildcmdlist(action));
     action->value.trace.event = addevent(event, buildcmdlist(action));
     }
     action = build(O_TRACEON, (op == O_TRACEI), buildcmdlist(action));
     action->value.trace.event = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(action->value.trace.event);
+    }
 }
 
 /*
 }
 
 /*
@@ -761,19 +800,28 @@ Operator op;
 Node exp;
 Node cond;
 {
 Node exp;
 Node cond;
 {
-    Node event;
+    Node event, wh;
     Command action;
     Command action;
+    Event e;
 
 
+    if (exp->op == O_LCON) {
+       wh = build(O_QLINE, build(O_SCON, cursource), exp);
+    } else {
+       wh = exp;
+    }
     if (op == O_TRACEI) {
     if (op == O_TRACEI) {
-       event = build(O_EQ, build(O_SYM, pcsym), exp);
+       event = build(O_EQ, build(O_SYM, pcsym), wh);
     } else {
     } else {
-       event = build(O_EQ, build(O_SYM, linesym), exp);
+       event = build(O_EQ, build(O_SYM, linesym), wh);
     }
     }
-    action = build(O_PRINTSRCPOS, exp);
+    action = build(O_PRINTSRCPOS, wh);
     if (cond) {
        action = build(O_IF, cond, buildcmdlist(action));
     }
     if (cond) {
        action = build(O_IF, cond, buildcmdlist(action));
     }
-    addevent(event, buildcmdlist(action));
+    e = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(e);
+    }
 }
 
 /*
 }
 
 /*
@@ -788,6 +836,7 @@ Node cond;
 {
     Node event;
     Command action;
 {
     Node event;
     Command action;
+    Event e;
 
     if (op == O_TRACEI) {
        event = build(O_EQ, build(O_SYM, pcsym), place);
 
     if (op == O_TRACEI) {
        event = build(O_EQ, build(O_SYM, pcsym), place);
@@ -798,7 +847,10 @@ Node cond;
     if (cond != nil) {
        action = build(O_IF, cond, buildcmdlist(action));
     }
     if (cond != nil) {
        action = build(O_IF, cond, buildcmdlist(action));
     }
-    addevent(event, buildcmdlist(action));
+    e = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(e);
+    }
 }
 
 /*
 }
 
 /*
@@ -828,6 +880,7 @@ Node cond;
     Node event;
     Command action;
     Cmdlist actionlist;
     Node event;
     Command action;
     Cmdlist actionlist;
+    Event e;
 
     action = build(O_PRINTCALL, p);
     actionlist = list_alloc();
 
     action = build(O_PRINTCALL, p);
     actionlist = list_alloc();
@@ -839,7 +892,10 @@ Node cond;
        actionlist = buildcmdlist(build(O_IF, cond, actionlist));
     }
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
        actionlist = buildcmdlist(build(O_IF, cond, actionlist));
     }
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
-    addevent(event, actionlist);
+    e = addevent(event, actionlist);
+    if (isstdin()) {
+       printevent(e);
+    }
 }
 
 /*
 }
 
 /*
@@ -867,6 +923,9 @@ Node cond;
     action = build(O_TRACEON, (op == O_TRACEI), buildcmdlist(action));
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
     action->value.trace.event = addevent(event, buildcmdlist(action));
     action = build(O_TRACEON, (op == O_TRACEI), buildcmdlist(action));
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
     action->value.trace.event = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(action->value.trace.event);
+    }
 }
 
 /*
 }
 
 /*
@@ -876,43 +935,59 @@ Node cond;
 public stop(p)
 Node p;
 {
 public stop(p)
 Node p;
 {
-    Node exp, place, cond;
+    Node exp, place, cond, t;
     Symbol s;
     Command action;
     Symbol s;
     Command action;
+    Event e;
 
     exp = p->value.arg[0];
     place = p->value.arg[1];
     cond = p->value.arg[2];
     if (exp != nil) {
        stopvar(p->op, exp, place, cond);
 
     exp = p->value.arg[0];
     place = p->value.arg[1];
     cond = p->value.arg[2];
     if (exp != nil) {
        stopvar(p->op, exp, place, cond);
-    } else if (cond != nil) {
-       s = (place == nil) ? program : place->value.sym;
-       action = build(O_IF, cond, buildcmdlist(build(O_STOPX)));
-       action = build(O_TRACEON, (p->op == O_STOPI), buildcmdlist(action));
-       cond = build(O_EQ, build(O_SYM, procsym), build(O_SYM, s));
-       action->value.trace.event = addevent(cond, buildcmdlist(action));
-    } else if (place->op == O_SYM) {
-       s = place->value.sym;
-       cond = build(O_EQ, build(O_SYM, procsym), build(O_SYM, s));
-       addevent(cond, buildcmdlist(build(O_STOPX)));
     } else {
     } else {
-       stopinst(p->op, place, cond);
+       action = build(O_STOPX);
+       if (cond != nil) {
+           action = build(O_IF, cond, buildcmdlist(action));
+       }
+       if (place != nil and place->op == O_SYM) {
+           s = place->value.sym;
+           t = build(O_EQ, build(O_SYM, procsym), build(O_SYM, s));
+           if (cond != nil) {
+               action = build(O_TRACEON, (p->op == O_STOPI),
+                   buildcmdlist(action));
+               e = addevent(t, buildcmdlist(action));
+               action->value.trace.event = e;
+           } else {
+               e = addevent(t, buildcmdlist(action));
+           }
+           if (isstdin()) {
+               printevent(e);
+           }
+       } else {
+           stopinst(p->op, place, cond, action);
+       }
     }
 }
 
     }
 }
 
-private stopinst(op, place, cond)
+private stopinst(op, place, cond, action)
 Operator op;
 Node place;
 Node cond;
 Operator op;
 Node place;
 Node cond;
+Command action;
 {
     Node event;
 {
     Node event;
+    Event e;
 
     if (op == O_STOP) {
        event = build(O_EQ, build(O_SYM, linesym), place);
     } else {
        event = build(O_EQ, build(O_SYM, pcsym), place);
     }
 
     if (op == O_STOP) {
        event = build(O_EQ, build(O_SYM, linesym), place);
     } else {
        event = build(O_EQ, build(O_SYM, pcsym), place);
     }
-    addevent(event, buildcmdlist(build(O_STOPX)));
+    e = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(e);
+    }
 }
 
 /*
 }
 
 /*
@@ -930,14 +1005,28 @@ Node cond;
     Node event;
     Command action;
 
     Node event;
     Command action;
 
-    p = (place == nil) ? tcontainer(exp) : place->value.sym;
-    if (p == nil) {
-       p = program;
+    if (place == nil) {
+       if (exp->op == O_LCON) {
+           p = program;
+       } else {
+           p = tcontainer(exp);
+           if (p == nil) {
+               p = program;
+           }
+       }
+    } else {
+       p = place->value.sym;
+    }
+    action = build(O_STOPIFCHANGED, exp);
+    if (cond != nil) {
+       action = build(O_IF, cond, buildcmdlist(action));
     }
     }
-    action = build(O_IF, cond, buildcmdlist(build(O_STOPIFCHANGED, exp)));
     action = build(O_TRACEON, (op == O_STOPI), buildcmdlist(action));
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
     action->value.trace.event = addevent(event, buildcmdlist(action));
     action = build(O_TRACEON, (op == O_STOPI), buildcmdlist(action));
     event = build(O_EQ, build(O_SYM, procsym), build(O_SYM, p));
     action->value.trace.event = addevent(event, buildcmdlist(action));
+    if (isstdin()) {
+       printevent(action->value.trace.event);
+    }
 }
 
 /*
 }
 
 /*
@@ -982,51 +1071,6 @@ Node exp;
     }
 }
 
     }
 }
 
-#define DEF_EDITOR  "vi"
-
-/*
- * Invoke an editor on the given file.  Which editor to use might change
- * installation to installation.  For now, we use "vi".  In any event,
- * the environment variable "EDITOR" overrides any default.
- */
-
-public edit(filename)
-String filename;
-{
-    extern String getenv();
-    String ed, src;
-    File f;
-    Symbol s;
-    Address addr;
-    char buff[10];
-
-    ed = getenv("EDITOR");
-    if (ed == nil) {
-       ed = DEF_EDITOR;
-    }
-    if (filename == nil) {
-       call(ed, stdin, stdout, cursource, nil);
-    } else {
-       f = fopen(filename, "r");
-       if (f == nil) {
-           s = which(identname(filename, true));
-           if (not isblock(s)) {
-               error("can't read \"%s\"", filename);
-           }
-           addr = firstline(s);
-           if (addr == NOADDR) {
-               error("no source for \"%s\"", filename);
-           }
-           src = srcfilename(addr);
-           sprintf(buff, "+%d", srcline(addr));
-           call(ed, stdin, stdout, buff, src, nil);
-       } else {
-           fclose(f);
-           call(ed, stdin, stdout, filename, nil);
-       }
-    }
-}
-
 /*
  * Send some nasty mail to the current support person.
  */
 /*
  * Send some nasty mail to the current support person.
  */
@@ -1035,16 +1079,23 @@ public gripe()
 {
     typedef Operation();
     Operation *old;
 {
     typedef Operation();
     Operation *old;
+    int pid, status;
 
 
-    char *maintainer = "linton@ucbarpa";
+    char *maintainer = "linton@berkeley";
 
     puts("Type control-D to end your message.  Be sure to include");
     puts("your name and the name of the file you are debugging.");
     putchar('\n');
     old = signal(SIGINT, SIG_DFL);
 
     puts("Type control-D to end your message.  Be sure to include");
     puts("your name and the name of the file you are debugging.");
     putchar('\n');
     old = signal(SIGINT, SIG_DFL);
-    call("Mail", stdin, stdout, maintainer, nil);
+    pid = back("Mail", stdin, stdout, "-s", "dbx gripe", maintainer, nil);
+    signal(SIGINT, SIG_IGN);
+    pwait(pid, &status);
     signal(SIGINT, old);
     signal(SIGINT, old);
-    puts("Thank you.");
+    if (status == 0) {
+       puts("Thank you.");
+    } else {
+       puts("\nMail not sent.");
+    }
 }
 
 /*
 }
 
 /*