changeset 22466:57afe7055486

Truffle/REPL debugger: "call" command can now pass string arguments
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Wed, 18 Nov 2015 18:42:56 -0800
parents ff5c0b5677cd
children 5573f12b94f8
files truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLMessage.java truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/client/REPLRemoteCommand.java truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLHandler.java truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java
diffstat 4 files changed, 37 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLMessage.java	Wed Nov 18 18:42:18 2015 -0800
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLMessage.java	Wed Nov 18 18:42:56 2015 -0800
@@ -56,6 +56,16 @@
     public static final String BREAKPOINT_INFO = "breakpoint-info";
     public static final String BREAKPOINT_STATE = "breakpoint-state";
     public static final String CALL = "call";
+    public static final String ARG0 = "call-argument-0";
+    public static final String ARG1 = "call-argument-1";
+    public static final String ARG2 = "call-argument-2";
+    public static final String ARG3 = "call-argument-3";
+    public static final String ARG4 = "call-argument-4";
+    public static final String ARG5 = "call-argument-5";
+    public static final String ARG6 = "call-argument-6";
+    public static final String ARG7 = "call-argument-7";
+    public static final String ARG8 = "call-argument-8";
+    public static final String ARG9 = "call-argument-9";
     public static final String CALL_NAME = "call-name";
     public static final String CLEAR_BREAK = "clear-breakpoint";
     public static final String CODE = "code";
@@ -119,6 +129,7 @@
     public static final String VALUE = "value";
     public static final String WARNINGS = "warnings";
     public static final String WELCOME_MESSAGE = "welcome-message";
+    public static final String[] ARG_NAMES = new String[]{ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9};
     private final Map<String, String> map;
 
     /**
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/client/REPLRemoteCommand.java	Wed Nov 18 18:42:18 2015 -0800
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/client/REPLRemoteCommand.java	Wed Nov 18 18:42:56 2015 -0800
@@ -26,6 +26,7 @@
 
 import com.oracle.truffle.api.source.Source;
 import com.oracle.truffle.tools.debug.shell.REPLMessage;
+
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
@@ -213,15 +214,20 @@
         public REPLMessage createRequest(REPLClientContext context, String[] args) {
             if (args.length == 1) {
                 context.displayFailReply("name to call not speciified");
-            } else if (args.length > 2) {
-                context.displayFailReply("call arguments not yet supported");
-            } else {
-                final REPLMessage request = new REPLMessage();
-                request.put(REPLMessage.OP, REPLMessage.CALL);
-                request.put(REPLMessage.CALL_NAME, args[1]);
-                return request;
+                return null;
+            }
+            final int maxArgs = REPLMessage.ARG_NAMES.length;
+            if (args.length > maxArgs + 2) {
+                context.displayFailReply("too many call arguments; no more than " + maxArgs + " supported");
+                return null;
             }
-            return null;
+            final REPLMessage request = new REPLMessage();
+            request.put(REPLMessage.OP, REPLMessage.CALL);
+            request.put(REPLMessage.CALL_NAME, args[1]);
+            for (int argIn = 2, argOut = 0; argIn < args.length; argIn++, argOut++) {
+                request.put(REPLMessage.ARG_NAMES[argOut], args[argIn]);
+            }
+            return request;
         }
     };
 
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLHandler.java	Wed Nov 18 18:42:18 2015 -0800
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLHandler.java	Wed Nov 18 18:42:56 2015 -0800
@@ -291,8 +291,17 @@
             if (callName == null) {
                 return finishReplyFailed(reply, "no name specified");
             }
+            final ArrayList<Object> argList = new ArrayList<>();
+            for (int argCount = 0; argCount < REPLMessage.ARG_NAMES.length; argCount++) {
+                final String arg = request.get(REPLMessage.ARG_NAMES[argCount]);
+                if (arg == null) {
+                    break;
+                }
+                argList.add(arg);
+            }
+            final Object[] args = argList.toArray(new Object[0]);
             try {
-                replServer.call(callName);
+                replServer.call(callName, args);
             } catch (QuitException ex) {
                 throw ex;
             } catch (KillException ex) {
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java	Wed Nov 18 18:42:18 2015 -0800
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/server/REPLServer.java	Wed Nov 18 18:42:56 2015 -0800
@@ -518,12 +518,12 @@
         breakpoints.remove(breakpoint);
     }
 
-    void call(String name) throws IOException {
+    void call(String name, Object... args) throws IOException {
         Value symbol = engine.findGlobalSymbol(name);
         if (symbol == null) {
             throw new IOException("symbol \"" + name + "\" not found");
         }
-        symbol.invoke(null);
+        symbol.invoke(null, args);
     }
 
     /**