Bug 487684 - Store the last trace PC to pass into the decompiler. r=igor
authorBlake Kaplan <mrbkap@gmail.com>
Sat, 18 Apr 2009 14:21:01 -0400
changeset 24906 ff2552207e39e4bc3fe3110d79fce961c3834fc3
parent 24905 49234f4a69fb2cfeeea88c3d0c04d3cabca80771
child 24907 4948d39190a927d3a819c9432273c97e7f1c950d
push id1267
push userrsayre@mozilla.com
push dateSun, 19 Apr 2009 02:47:24 +0000
reviewersigor
bugs487684
milestone1.9.1b4pre
Bug 487684 - Store the last trace PC to pass into the decompiler. r=igor
js/src/js.cpp
js/src/jscntxt.cpp
js/src/jscntxt.h
js/src/jsinterp.cpp
--- a/js/src/js.cpp
+++ b/js/src/js.cpp
@@ -1842,17 +1842,17 @@ Tracing(JSContext *cx, JSObject *obj, ui
         break;
       }
       default:
           goto bad_argument;
     }
     if (cx->tracefp && cx->tracefp != stderr)
       fclose((FILE *)cx->tracefp);
     cx->tracefp = file;
-    cx->tracePrevOp = JSOP_LIMIT;
+    cx->tracePrevPc = NULL;
     return JS_TRUE;
 
  bad_argument:
     JSString *str = JS_ValueToString(cx, argv[0]);
     if (!str)
         return JS_FALSE;
     JS_ReportError(cx, "tracing: illegal argument %s",
                    JS_GetStringBytes(str));
--- a/js/src/jscntxt.cpp
+++ b/js/src/jscntxt.cpp
@@ -1602,17 +1602,17 @@ js_ReportValueErrorFlags(JSContext *cx, 
     ok = JS_ReportErrorFlagsAndNumber(cx, flags, js_GetErrorMessage,
                                       NULL, errorNumber, bytes, arg1, arg2);
     JS_free(cx, bytes);
     return ok;
 }
 
 #if defined DEBUG && defined XP_UNIX
 /* For gdb usage. */
-void js_traceon(JSContext *cx)  { cx->tracefp = stderr; cx->tracePrevOp = JSOP_LIMIT; }
+void js_traceon(JSContext *cx)  { cx->tracefp = stderr; cx->tracePrevPc = NULL; }
 void js_traceoff(JSContext *cx) { cx->tracefp = NULL; }
 #endif
 
 JSErrorFormatString js_ErrorFormatString[JSErr_Limit] = {
 #define MSG_DEF(name, number, count, exception, format) \
     { format, count, exception } ,
 #include "js.msg"
 #undef MSG_DEF
--- a/js/src/jscntxt.h
+++ b/js/src/jscntxt.h
@@ -927,17 +927,17 @@ struct JSContext {
 
     /* Argument formatter support for JS_{Convert,Push}Arguments{,VA}. */
     JSArgumentFormatMap *argumentFormatMap;
 
     /* Last message string and trace file for debugging. */
     char                *lastMessage;
 #ifdef DEBUG
     void                *tracefp;
-    JSOp                tracePrevOp;
+    jsbytecode          *tracePrevPc;
 #endif
 
     /* Per-context optional error reporter. */
     JSErrorReporter     errorReporter;
 
     /* Branch callback. */
     JSOperationCallback operationCallback;
 
--- a/js/src/jsinterp.cpp
+++ b/js/src/jsinterp.cpp
@@ -2099,19 +2099,20 @@ js_TraceOpcode(JSContext *cx)
     JS_ASSERT(tracefp);
     fp = cx->fp;
     regs = fp->regs;
 
     /*
      * Operations in prologues don't produce interesting values, and
      * js_DecompileValueGenerator isn't set up to handle them anyway.
      */
-    if (cx->tracePrevOp != JSOP_LIMIT && regs->pc >= fp->script->main) {
-        ndefs = js_GetStackDefs(cx, &js_CodeSpec[cx->tracePrevOp],
-                                cx->tracePrevOp, fp->script, regs->pc);
+    if (cx->tracePrevPc && regs->pc >= fp->script->main) {
+        JSOp tracePrevOp = JSOp(*cx->tracePrevPc);
+        ndefs = js_GetStackDefs(cx, &js_CodeSpec[tracePrevOp], tracePrevOp,
+                                fp->script, cx->tracePrevPc);
 
         /*
          * If there aren't that many elements on the stack, then 
          * we have probably entered a new frame, and printing output
          * would just be misleading.
          */
         if (ndefs != 0 &&
             ndefs < regs->sp - fp->slots) {
@@ -2154,17 +2155,17 @@ js_TraceOpcode(JSContext *cx)
                 fprintf(tracefp, "%s %s",
                         (n == -nuses) ? "  inputs:" : ",",
                         bytes);
                 JS_free(cx, bytes);
             }
         }
         fprintf(tracefp, " @ %u\n", (uintN) (regs->sp - StackBase(fp)));
     }
-    cx->tracePrevOp = op;
+    cx->tracePrevPc = regs->pc;
 
     /* It's nice to have complete traces when debugging a crash.  */
     fflush(tracefp);
 }
 
 #endif /* DEBUG */
 
 #ifdef JS_OPMETER
@@ -7284,16 +7285,20 @@ js_Interpret(JSContext *cx)
      * returns true.
      *
      * When a trap handler returns JSTRAP_RETURN, we jump here with ok set to
      * true bypassing any finally blocks.
      */
     ok &= js_UnwindScope(cx, fp, 0, ok || cx->throwing);
     JS_ASSERT(regs.sp == StackBase(fp));
 
+#ifdef DEBUG
+    cx->tracePrevPc = NULL;
+#endif
+
     if (inlineCallCount)
         goto inline_return;
 
   exit:
     /*
      * At this point we are inevitably leaving an interpreted function or a
      * top-level script, and returning to one of:
      * (a) an "out of line" call made through js_Invoke;