fix structure arguments. don't map OREG to REG for STASG (match fails)
[unix-history] / usr / src / old / dbx / runtime.c
index 4c37d98..b4fbcc9 100644 (file)
@@ -1,7 +1,7 @@
 
 /* Copyright (c) 1982 Regents of the University of California */
 
 
 /* Copyright (c) 1982 Regents of the University of California */
 
-static char sccsid[] = "@(#)runtime.c 1.6 %G%";
+static char sccsid[] = "@(#)runtime.c 1.10 %G%";
 
 /*
  * Runtime organization dependent routines, mostly dealing with
 
 /*
  * Runtime organization dependent routines, mostly dealing with
@@ -74,44 +74,49 @@ Frame frp;
     struct Frame frame;
     register Integer i, j, mask;
     Address prev_frame, callpc; 
     struct Frame frame;
     register Integer i, j, mask;
     Address prev_frame, callpc; 
-    private Integer ntramp=0;
+    static Integer ntramp = 0;
 
     newfrp = frp;
     prev_frame = frp->save_fp;
 
 
     newfrp = frp;
     prev_frame = frp->save_fp;
 
-/*  The check for interrupt generated frames is taken from adb with only
- *  partial understanding : say you're in sub and on a sigxxx siggsub
- *  gets control and dies; the stack does NOT look like main, sub, sigsub.
+/*
+ *  The check for interrupt generated frames is taken from adb with only
+ *  partial understanding.  If you're in "sub" and on a sigxxx "sigsub"
+ *  gets control, then the stack does NOT look like <main, sub, sigsub>.
  *
  *  As best I can make out it looks like:
  *
  *  As best I can make out it looks like:
- *   main (machine check exception block + sub) sysframe  sigsub.
- *  ie when the sig occurs push an exception block on the user stack
- *  and a frame for the routine in which it occured then push another
- *  frame corresponding to a call from the kernel to sigsub.
+ *
+ *     <main, (machine check exception block + sub), sysframe, sigsub>.
+ *
+ *  When the signal occurs an exception block and a frame for the routine
+ *  in which it occured are pushed on the user stack.  Then another frame
+ *  is pushed corresponding to a call from the kernel to sigsub.
  *
  *  The addr in sub at which the exception occured is not in sub.save_pc
  *
  *  The addr in sub at which the exception occured is not in sub.save_pc
- *  but in the machine check exception block. It can be referenced as
- *  sub.save_reg[11].
+ *  but in the machine check exception block.  It is at the magic address
+ *  fp + 84.
  *
  *  The current approach ignores the sys_frame (what adb reports as sigtramp)
  *
  *  The current approach ignores the sys_frame (what adb reports as sigtramp)
- *  and takes the pc for sub from the exception block. This
- *  allows where to report: main sub sigsub, which seems reasonable
+ *  and takes the pc for sub from the exception block.  This allows the
+ *  "where" command to report <main, sub, sigsub>, which seems reasonable.
  */
  */
-    nextf: dread(&frame, prev_frame , sizeof(struct Frame));
-    if(ntramp == 1 ) callpc = (Address) frame.save_reg[11];
-    else callpc=frame.save_pc;
 
 
+nextf:
+    dread(&frame, prev_frame, sizeof(struct Frame));
+    if (ntramp == 1) {
+       dread(&callpc, prev_frame + 84, sizeof(callpc));
+    } else {
+       callpc = frame.save_pc;
+    }
     if (frame.save_fp == nil) {
        newfrp = nil;
     if (frame.save_fp == nil) {
        newfrp = nil;
-    }
-      else if (callpc > 0x80000000 - 0x200 * UPAGES ) {
+    } else if (callpc > 0x80000000 - 0x200 * UPAGES ) {
         ntramp++;
         prev_frame = frame.save_fp;
         goto nextf;
         ntramp++;
         prev_frame = frame.save_fp;
         goto nextf;
-       }
-      else {
+    } else {
        frame.save_pc = callpc;
        frame.save_pc = callpc;
-        ntramp=0;
+        ntramp = 0;
        mask = ((frame.mask >> 16) & 0x0fff);
        j = 0;
        for (i = 0; i < NSAVEREG; i++) {
        mask = ((frame.mask >> 16) & 0x0fff);
        j = 0;
        for (i = 0; i < NSAVEREG; i++) {
@@ -142,28 +147,33 @@ Symbol f;
     register Frame frp;
     static struct Frame frame;
     Symbol p;
     register Frame frp;
     static struct Frame frame;
     Symbol p;
-    Boolean done;
 
     frp = &frame;
     getcurframe(frp);
 
     frp = &frame;
     getcurframe(frp);
-    if (f != nil) {
-       done = false;
-       do {
-           p = whatblock(frp->save_pc);
-           if (p == f) {
-               done = true;
-           } else if (p == program) {
-               done = true;
-               frp = nil;
-           } else {
-               frp = nextframe(frp);
-               if (frp == nil) {
-                   done = true;
-               }
-           }
-       } while (not done);
+    if (f == nil)
+       return (frp);
+    /*
+     * Starting at the current stack frame,
+     * walk backwards looking for a symbol
+     * match.  Beware of local blocks which
+     * have a back pointer but no stack frame.
+     */
+    p = whatblock(frp->save_pc);
+    while (p != f) {
+       if (p == program) {
+           frp = nil;
+           break;
+       }
+       if (isinline(p)) {
+           p = container(p);
+           continue;
+       }
+       frp = nextframe(frp);
+       if (frp == nil)
+          break;
+       p = whatblock(frp->save_pc);
     }
     }
-    return frp;
+    return (frp);
 }
 
 /*
 }
 
 /*
@@ -354,7 +364,9 @@ Boolean dumpvariables;
        f = whatblock(frp->save_pc);
        do {
            printf("%s", symname(f));
        f = whatblock(frp->save_pc);
        do {
            printf("%s", symname(f));
-           printparams(f, frp);
+           if (not isinline(f)) {
+               printparams(f, frp);
+           }
            line = srcline(frp->save_pc - 1);
            if (line != 0) {
                printf(", line %d", line);
            line = srcline(frp->save_pc - 1);
            if (line != 0) {
                printf(", line %d", line);
@@ -366,9 +378,13 @@ Boolean dumpvariables;
                dumpvars(f, frp);
                putchar('\n');
            }
                dumpvars(f, frp);
                putchar('\n');
            }
-           frp = nextframe(frp);
-           if (frp != nil) {
-               f = whatblock(frp->save_pc);
+           if (isinline(f)) {
+               f = container(f);
+           } else {
+               frp = nextframe(frp);
+               if (frp != nil) {
+                   f = whatblock(frp->save_pc);
+               }
            }
        } while (frp != nil and f != program);
        if (dumpvariables) {
            }
        } while (frp != nil and f != program);
        if (dumpvariables) {