diff truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLServer.java @ 22003:5bc7f7b867ab

Making debugger always on for each TruffleVM execution. Introducing EventConsumer to process such debugger events. Requesting each RootNode to be associated with a TruffleLanguage, so debugger can find out proper context for each Node where executions gets suspended.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Sat, 18 Jul 2015 18:03:36 +0200
parents 9c8c0937da41
children dc83cc1f94f2
line wrap: on
line diff
--- a/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLServer.java	Thu Jul 16 19:11:31 2015 +0200
+++ b/truffle/com.oracle.truffle.tools.debug.shell/src/com/oracle/truffle/tools/debug/shell/REPLServer.java	Sat Jul 18 18:03:36 2015 +0200
@@ -24,22 +24,46 @@
  */
 package com.oracle.truffle.tools.debug.shell;
 
+import com.oracle.truffle.api.debug.Breakpoint;
+import java.util.*;
+
 /**
  * The server side of a simple message-based protocol for a possibly remote language
  * Read-Eval-Print-Loop.
  */
-public interface REPLServer {
+public abstract class REPLServer {
 
     /**
      * Starts up a server; status returned in a message.
      */
-    REPLMessage start();
+    public abstract REPLMessage start();
 
     /**
      * Ask the server to handle a request. Return a non-empty array of messages to simulate remote
      * operation where the protocol has possibly multiple messages being returned asynchronously in
      * response to each request.
      */
-    REPLMessage[] receive(REPLMessage request);
+    public abstract REPLMessage[] receive(REPLMessage request);
+
+    private int breakpointCounter;
+    private Map<Breakpoint, Integer> breakpoints = new WeakHashMap<>();
+
+    protected final synchronized void registerBreakpoint(Breakpoint breakpoint) {
+        breakpoints.put(breakpoint, breakpointCounter++);
+    }
+
+    protected final synchronized Breakpoint findBreakpoint(int id) {
+        for (Map.Entry<Breakpoint, Integer> entrySet : breakpoints.entrySet()) {
+            if (id == entrySet.getValue()) {
+                return entrySet.getKey();
+            }
+        }
+        return null;
+    }
+
+    protected final synchronized int getBreakpointID(Breakpoint breakpoint) {
+        final Integer id = breakpoints.get(breakpoint);
+        return id == null ? -1 : id;
+    }
 
 }