changeset 22486:be8a3334434d

Truffle/Debugger: restore signature in SuspendedEvent.eval()
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 08 Dec 2015 11:33:21 -0800
parents 55e2a3f21528
children 66f79c26f897
files truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java
diffstat 3 files changed, 31 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java	Mon Dec 07 22:07:59 2015 -0800
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/Debugger.java	Tue Dec 08 11:33:21 2015 -0800
@@ -39,6 +39,7 @@
 import com.oracle.truffle.api.frame.FrameInstanceVisitor;
 import com.oracle.truffle.api.frame.MaterializedFrame;
 import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
 import com.oracle.truffle.api.impl.Accessor;
 import com.oracle.truffle.api.instrument.Instrumenter;
 import com.oracle.truffle.api.instrument.KillException;
@@ -889,8 +890,21 @@
         debugContext = debugContext.predecessor;
     }
 
-    Object evalInContext(SuspendedEvent ev, String code, Node node, MaterializedFrame frame) throws IOException {
-        return ACCESSOR.evalInContext(vm, ev, code, node, frame);
+    /**
+     * Evaluates a snippet of code in a halted execution context.
+     *
+     * @param ev
+     * @param code
+     * @param frameInstance
+     * @return
+     * @throws IOException
+     */
+    Object evalInContext(SuspendedEvent ev, String code, FrameInstance frameInstance) throws IOException {
+        if (frameInstance == null) {
+            return ACCESSOR.evalInContext(vm, ev, code, debugContext.haltedNode, debugContext.haltedFrame);
+        } else {
+            return ACCESSOR.evalInContext(vm, ev, code, frameInstance.getCallNode(), frameInstance.getFrame(FrameAccess.MATERIALIZE, true).materialize());
+        }
     }
 
     @SuppressWarnings("rawtypes")
--- a/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java	Mon Dec 07 22:07:59 2015 -0800
+++ b/truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/debug/SuspendedEvent.java	Tue Dec 08 11:33:21 2015 -0800
@@ -31,7 +31,6 @@
 
 import com.oracle.truffle.api.CompilerDirectives;
 import com.oracle.truffle.api.frame.FrameInstance;
-import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
 import com.oracle.truffle.api.frame.MaterializedFrame;
 import com.oracle.truffle.api.instrument.StandardSyntaxTag;
 import com.oracle.truffle.api.nodes.Node;
@@ -195,20 +194,12 @@
      * Evaluates given code snippet in the context of currently suspended execution.
      *
      * @param code the snippet to evaluate
-     * @param frameNumber specify a frame from those {@link #getStack() currently on stack} to
-     *            perform the evaluation in context of
+     * @param frame the frame in which to evaluate the code; { means the current frame at the halted
+     *            location.
      * @return the computed value
      * @throws IOException in case an evaluation goes wrong
      */
-    public Object eval(String code, Integer frameNumber) throws IOException {
-        if (frameNumber < 0 || frameNumber >= stack.size()) {
-            throw new IOException("invalid frame number");
-        }
-        if (frameNumber == 0) {
-            return debugger.evalInContext(this, code, haltedNode, haltedFrame);
-        }
-        final FrameInstance instance = stack.get(frameNumber - 1);
-        final MaterializedFrame frame = instance.getFrame(FrameAccess.MATERIALIZE, true).materialize();
-        return debugger.evalInContext(this, code, instance.getCallNode(), frame);
+    public Object eval(String code, FrameInstance frame) throws IOException {
+        return debugger.evalInContext(this, code, frame);
     }
 }
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java	Mon Dec 07 22:07:59 2015 -0800
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java	Tue Dec 08 11:33:21 2015 -0800
@@ -321,16 +321,19 @@
 
         /**
          * Evaluates a code snippet in the context of a selected frame in the currently suspended
-         * execution.
+         * execution, if any; otherwise a top level (new) evaluation.
          *
          * @param code the snippet to evaluate
-         * @param frameNumber index of the stack frame in which to evaluate, {@code null} if the
-         *            topmost frame should be used.
+         * @param frameNumber index of the stack frame in which to evaluate, 0 = current frame where
+         *            halted, null = top level eval
          * @return result of the evaluation
          * @throws IOException if something goes wrong
          */
         Object eval(String code, Integer frameNumber, boolean stepInto) throws IOException {
             if (event == null) {
+                if (frameNumber != null) {
+                    throw new IllegalStateException("Frame number requires a halted execution");
+                }
                 this.steppingInto = stepInto;
                 final String mimeType = defaultMIME(currentLanguage);
                 try {
@@ -339,11 +342,15 @@
                     this.steppingInto = false;
                 }
             } else {
+                if (frameNumber == null) {
+                    throw new IllegalStateException("Eval in halted context requires a frame number");
+                }
                 if (stepInto) {
                     event.prepareStepInto(1);
                 }
                 try {
-                    final Object result = event.eval(code, frameNumber);
+                    FrameInstance frame = frameNumber == 0 ? null : event.getStack().get(frameNumber - 1);
+                    final Object result = event.eval(code, frame);
                     return (result instanceof Value) ? ((Value) result).get() : result;
                 } finally {
                     event.prepareContinue();