diff --git a/.classpath b/.classpath index f8b7ddb4..80b76067 100644 --- a/.classpath +++ b/.classpath @@ -1,7 +1,6 @@ - diff --git a/.cvsignore b/.cvsignore index f0f2c72d..cd047079 100644 --- a/.cvsignore +++ b/.cvsignore @@ -3,3 +3,4 @@ target build luaj*.jar jit +*.ser diff --git a/build-coverage.xml b/build-coverage.xml index 34fdc681..95ff6391 100644 --- a/build-coverage.xml +++ b/build-coverage.xml @@ -43,7 +43,6 @@ - diff --git a/build.xml b/build.xml index ffdf228a..5e9b3218 100644 --- a/build.xml +++ b/build.xml @@ -28,7 +28,6 @@ - diff --git a/src/core/org/luaj/vm/Platform.java b/src/core/org/luaj/vm/Platform.java index 247acf17..3ef1cda9 100644 --- a/src/core/org/luaj/vm/Platform.java +++ b/src/core/org/luaj/vm/Platform.java @@ -21,7 +21,6 @@ ******************************************************************************/ package org.luaj.vm; -import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -37,14 +36,17 @@ import java.io.Reader; */ abstract public class Platform { - public static String DEBUG_CLASS_NAME = "org.luaj.debug.DebugLuaState"; - - public static final String PROPERTY_LUAJ_DEBUG = "Luaj-Debug"; - public static final String PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START = "Luaj-Debug-SuspendAtStart"; - public static final String PROPERTY_LUAJ_DEBUG_HOST = "Luaj-Debug-Host"; - public static final String PROPERTY_LUAJ_DEBUG_PORT = "Luaj-Debug-Port"; - public static final String PROPERTY_LUAJ_DEBUG_CLASS = "Luaj-Debug-Class"; - + /** + * When non-null, name of a Java Class that implements LuaState + * and has a default constructor which will be used to construct + * a new lua state using Platform.newLuaState() + * @see newLuaState + */ + public static String LUA_STATE_CLASS_NAME = null; + + /** + * The singleton Platform instance in use by this JVM + */ private static Platform instance; @@ -73,21 +75,30 @@ abstract public class Platform { } /** - * Creates a new instance of LuaState. If debug properties are present, - * DebugLuaState (a LuaState with debugging capabilities) will be created. + * Creates a new instance of LuaState. * - * @return a new instance of LuaState + * If Platform.LUA_STATE_CLASS_NAME is not null, this method + * will attempt to create an instance using a construction such as + * (LuaState) Class.forName(Platform.LUA_STATE_CLASS_NAME).newInstance() + * + * If Platform.LUA_STATE_CLASS_NAME is null or the specified class cannot + * be instantiated for some reason, a new instance of LuaState + * will be created and used. + * + * In either case, the method LuaState.init() will be invoked, followed by + * Platform.installOptionalProperties(LuaState) on the new instance. + * + * @return a new instance of LuaState initialized via init() and installOptionalProperties() + * + * @see LUA_STATE_CLASS_NAME + * @see LuaState */ public static LuaState newLuaState() { Platform p = Platform.getInstance(); - String isDebugStr = p.getProperty(PROPERTY_LUAJ_DEBUG); - boolean isDebug = (isDebugStr != null && "true".equalsIgnoreCase(isDebugStr)); - LuaState vm = null; - if (isDebug) { + if (LUA_STATE_CLASS_NAME != null) { try { - String c = p.getProperty(PROPERTY_LUAJ_DEBUG_CLASS); - vm = (LuaState) Class.forName(c!=null? c: DEBUG_CLASS_NAME).newInstance(); + vm = (LuaState) Class.forName(LUA_STATE_CLASS_NAME).newInstance(); } catch (Exception e) { System.out.println("Warning: no debug support, " + e); } @@ -133,44 +144,12 @@ abstract public class Platform { */ abstract public String getProperty(String propertyName); - /** - * Returns an platform dependent DebugSupport instance. - * - * @return an platform dependent DebugSupport instance. - */ - abstract public DebugNetSupport getDebugSupport() throws IOException; - /** * Install optional libraries on the LuaState. * @param vm LuaState instance */ abstract protected void installOptionalLibs(LuaState vm); - /** - * Convenience method for the subclasses to figure out the debug host. - * @return the debug host property. If it is not present, null is returned. - */ - protected String getDebugHost() { - String host = getProperty(PROPERTY_LUAJ_DEBUG_HOST); - return host; - } - - /** - * Convenience method for the subclasses to figure out the debug port. - * @return -1 if the port is not found in the platform properties; the port - * as an integer if it is present in the platform properties and valid. - */ - protected int getDebugPort() { - String portStr = getProperty(PROPERTY_LUAJ_DEBUG_PORT); - int port = -1; - if (portStr != null) { - try { - port = Integer.parseInt(portStr); - } catch (NumberFormatException e) {} - } - return port; - } - /** * Compute math.pow() for two numbers using double math when available. * @param lhs LNumber base diff --git a/src/debug/org/luaj/debug/AbortException.java b/src/debug/org/luaj/debug/AbortException.java deleted file mode 100644 index 5cbc9eab..00000000 --- a/src/debug/org/luaj/debug/AbortException.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -/** - * AbortException is thrown by DebugLuaState to abort the VM execution on request - * of the debugger client. - */ -public class AbortException extends RuntimeException { - private static final long serialVersionUID = 8043724992294286647L; - - public AbortException(String msg) { - super(msg); - } -} diff --git a/src/debug/org/luaj/debug/DebugLuaState.java b/src/debug/org/luaj/debug/DebugLuaState.java deleted file mode 100644 index ea472ad7..00000000 --- a/src/debug/org/luaj/debug/DebugLuaState.java +++ /dev/null @@ -1,810 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug; - -import java.io.IOException; -import java.util.Hashtable; -import java.util.Vector; - -import org.luaj.debug.event.DebugEventBreakpoint; -import org.luaj.debug.event.DebugEventError; -import org.luaj.debug.net.DebugNetSupportBase; -import org.luaj.debug.request.DebugRequestLineBreakpointToggle; -import org.luaj.debug.request.DebugRequestListener; -import org.luaj.debug.request.DebugRequestStack; -import org.luaj.debug.response.DebugResponseCallgraph; -import org.luaj.debug.response.DebugResponseStack; -import org.luaj.debug.response.DebugResponseVariables; -import org.luaj.vm.CallInfo; -import org.luaj.vm.DebugNetSupport; -import org.luaj.vm.LClosure; -import org.luaj.vm.LPrototype; -import org.luaj.vm.LString; -import org.luaj.vm.LTable; -import org.luaj.vm.LValue; -import org.luaj.vm.LocVars; -import org.luaj.vm.Lua; -import org.luaj.vm.LuaErrorException; -import org.luaj.vm.LuaState; -import org.luaj.vm.Platform; - - -/** - * DebugLuaState extends LuaState to provide the - * debugging support for luaj-vm. It defines the debugging protocol between a - * debugger, such as LuaJEclipse in Eclipse, and the luaj-vm. The - * debugger and luaj-vm communicates via DebugMessage. The - * debugger sends requests to the luaj-vm and receive responses and events from - * the luaj-vm. For requests that require immediately replies, luaj-vm responds - * synchronously. For events occurs in the luaj-vm, for instance, an exception - * is raised or a breakpoint is hit, luaj-vm informs the debugger when the event - * occurs. - *

- * Debugger Requests: - *

    - *
  • DebugMessageType.start: The first message for the handshake - * between the debugger and the luaj-vm. The VM responds with - * DebugMessageType.started immediately. If the VM is paused - * on start, it will now resume the execution. - *
  • DebugMessageType.resume: The debugger instructs the - * luaj-vm to resume the execution when the VM is suspended. No reply is needed. - *
  • DebugMessageType.suspend: The debugger instructs the luaj-vm - * to suspend. VM replies with DebugMessageType.suspendedByClient - * when it is suspended. - *
  • DebugMessageType.lineBreakpointSet: The debugger informs the - * VM that a breakpoint at the given source and line number is set. No reply - * is needed. For future improvement, VM should check if the breakpoint is - * valid and gives the debugger feedback. - *
  • DebugMessageType.lineBreakpointClear: The debugger informs - * the VM to clear a breakpoint at the given source and line number. No reply - * is needed. For future enhancement, VM should check if the breakpoint is - * valid and gives the debugger feedback. - *
  • DebugMessageType.watchpointSet: The debugger sets a watchpoint - * on the given source and line number. Not implemented yet. - *
  • DebugMessageType.watchpointClear: The debugger clears a - * watchpoint at the given source and line number. Not implemented yet. - *
  • DebugMessageType.callgraph: The debugger requests for the - * current call graph. VM replies with the call graph immediately in a debug - * message of type DebugMessageType.clientRequestCallgraphReply. - *
  • DebugMessageType.stack: The debugger request for the stack - * information for the given stack. VM replies with the variables on the stack - * immediately in a debug message of type - * DebugMessageType.clientRequestStackReply. - *
  • DebugMessageType.stepInto: The debugger instructs the VM - * to begin stepping in stepInto mode. No reply is needed. - *
  • DebugMessageType.stepOver: The debugger instructs the VM to - * begin stepping in stepOver mode. No rely is needed. - *
  • DebugMessageType.stepReturn: The debugger instructs the VM - * to begin stepping in stepReturn mode. No reply is needed. - *
  • DebugMessageType.global: The debug request the information - * about the globals. VM replies with global variables in a debug message of - * type DebugMessageType.clientRequestGlobalReply. - *
  • DebugMessageType.disconnect: The debugger informs the VM - * that it is about to disconnect from the VM. VM resets its state and responds - * with DebugMessageType.disconnected immediately. - *
  • DebugMessageType.exit: The debugger instructs the VM to - * terminate. VM prepares for termination and responds with - * DebugMessageType.terminated. - *
  • DebugMessageType.reset: This is an internal debug message. - * When the communication layer detects that the debugger or the debug service - * exits abnormally, it sends the message to the VM for reset. VM acts upon the - * message and reset its internal state. - *
  • DebugMessageType.debugServiceDown: This message is sent from - * the debug service (on-device remote debugging) when the debug service observed - * that the debugger exits abnormally. Before the debug service restarts the debug - * session, it informs the VM to reset itself. - *
- *

- * VM Responses and Events: - *

    - *
  • DebugMessageType.clientRequestCallgraphReply: VM replies to - * the DebugMessageType.callgraph request with the information - * about the current call graph. A call graph is made of a list of call stacks. - * Call stacks are organized chronically with the most recent call on the top - * of the stack. - *
  • DebugMessageType.clientRequestStackReply: VM replies - * to the DebugMessageType.stack request with the variables visible - * on the call stack i where i the call stack index - * ranging between 0 and LuaState.calls.length. - *
  • DebugMessageType.clientRequestGlobalReply: VM replies to the - * DebugMessageType.global request with all the globals. - *
  • DebugMessageType.started: VM replies when a - * DebugMessageType.start request is received. - *
  • DebugMessageType.resumedOnSteppingEnd: VM informs the debugger - * that VM is getting out of the stepping mode upon step return because it has - * reached the last call stack. - *
  • DebugMessageType.suspendedByClient: VM sends the event to - * respond to a debugger pause action. - *
  • DebugMessageType.suspendedOnBreakpoint: VM sends the event - * when a breakpoint is hit during the execution. - *
  • DebugMessageType.suspendedOnWatchpoint: Not implemented yet. - * VM sends the event when VM is paused to evaluate a watchpoint. - *
  • DebugMessageType.suspendedOnStepping: VM sends the event when - * VM is paused during the stepping. The debugger has instructed the VM to begin - * stepping into, over or return earlier. - *
  • DebugMessageType.suspendedOnError: VM sends the event when - * an error is raised in VM. - *
  • DebugMessageType.terminated: VM sends the event when it is - * ready to exit. - *
  • DebugMessageType.disconnected: VM sends the event when it - * has de-attached the debugger from the debug session. - *
  • DebugMessageType.outputRedirect: VM forwards the print - * output to the debugger console. - *
- *

- */ -public class DebugLuaState extends LuaState implements DebugRequestListener { - private static final boolean TRACE = (null != System.getProperty("TRACE")); - - // stepping constants and stepping state - protected static final int STEP_NONE = 0; - protected static final int STEP_OVER = 1; - protected static final int STEP_INTO = 2; - protected static final int STEP_RETURN = 3; - protected int stepping = STEP_NONE; - protected boolean shouldPauseForStepping = false; - protected int steppingFrame = -1; - - protected Hashtable breakpoints = new Hashtable(); - protected boolean exiting = false; - protected boolean suspended = false; - protected boolean bSuspendOnStart = false; - protected int lastline = -1; - protected String lastSource; - protected DebugNetSupportBase debugSupport; - protected LuaErrorException lastError; - - final String openUpVal = "+"; - final String closedUpVal = "-"; - - /** - * Creates an instance of DebugLuaState. - * - * @deprecated As of version 0.10, replaced by {@link #Platform.newLuaState()} - */ - public DebugLuaState() {} - - /* - * (non-Javadoc) - * @see org.luaj.vm.LuaState#init() - */ - public void init() { - super.init(); - - Platform platform = Platform.getInstance(); - - // set if the vm should be suspended at start - String suspendOnStartStr = platform.getProperty(Platform.PROPERTY_LUAJ_DEBUG_SUSPEND_AT_START); - boolean bSuspendOnStart = (suspendOnStartStr != null && "true".equalsIgnoreCase(suspendOnStartStr)); - setSuspendAtStart(bSuspendOnStart); - - // set up the debug networking support - try { - DebugNetSupport debugSupport = platform.getDebugSupport(); - if (debugSupport != null) - setDebugSupport(debugSupport); - else - System.out.println("Warning: DebugNetSupport is missing. Cannot communicate with a debugging client."); - } catch (IOException e) { - // no debug client can talk to VM, but VM can continue functioning - System.out.println("Warning: cannot communicate with a debugging client due to error: " + e.getMessage()); - } - } - - /* - * (non-Javadoc) - * @see org.luaj.vm.LuaState#shutdown() - */ - public void shutdown() { - stop(); - } - - protected void setDebugSupport(DebugNetSupport debugSupport) - throws IOException { - if (debugSupport == null) { - throw new IllegalArgumentException("DebugNetSupportBase cannot be null"); - } - - this.debugSupport = (DebugNetSupportBase) debugSupport; - this.debugSupport.setDebugStackState(this); - debugSupport.start(); - } - - public void setSuspendAtStart(boolean bSuspendAtStart) { - this.bSuspendOnStart = bSuspendAtStart; - } - - protected void debugAssert(boolean b) { - if (!b) - error("assert failure"); - } - - // use line numbers by default - public void error(String message) { - error(message, 1); - } - - // intercept exceptions and fill in line numbers - public void exec() { - try { - super.exec(); - } catch (AbortException e) { - // ignored. Client aborts the debugging session. - } catch (LuaErrorException e) { - // give debug client a chance to see the error - if (e != lastError) { - lastError = e; - debugErrorHook(e); - } - throw e; - } - } - - private void debugErrorHook(Exception e) { - if (debugSupport != null) { - String msg = getFileLine(cc) + ": " + e.getMessage(); - String trace = getStackTrace(); - debugSupport.notifyDebugEvent(new DebugEventError(msg, trace)); - synchronized (this) { - suspend(); - while (suspended) { - try { - wait(); - } catch (InterruptedException ex) {} - } - } - } - } - - // debug hooks - public void debugHooks(int pc) { - if (TRACE) { - CallInfo ci = calls[cc]; - LClosure cl = ci.closure; - LPrototype p = cl.p; - Print.printState(this, base, top, base+p.maxstacksize, cl, pc); - } - - if (exiting) { - throw new AbortException("aborted by debug client"); - } - -//* - if (TRACE) { - System.out.println("entered debugHook on pc=" + pc + "...Line: " + getFileLine(cc)); - for (int j = 0; j <= cc; j++) { - System.out.println("calls[" + j + "]: base=" + calls[j].base + ", top=" + calls[j].top + " , pc=" + calls[j].pc); - dumpStack(j); - } - } -//*/ - synchronized (this) { - while (bSuspendOnStart) { - try { - this.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - - CallInfo currentCallInfo = calls[cc]; - LPrototype currentProto = currentCallInfo.closure.p; - - // if we are not stepping, we would keep going if the line doesn't - // change - int line = getLineNumber(currentCallInfo); - String source = getSourceFileName(currentProto.source); - if (!isStepping() && lastline == line && source.equals(lastSource)) { - return; - } - - if (TRACE) - System.out.println("debugHook - executing line: " + line); - - int i = currentProto.code[pc]; - int opCode = LuaState.GET_OPCODE(i); - if (isStepping() && opCode == LuaState.OP_RETURN && cc == 0) { - cancelStepping(); - } else if (shouldPauseForStepping) { - shouldPauseForStepping = false; - suspendOnStepping(); - } else if (stepping == STEP_INTO) { - if (lastline != line) { - suspendOnStepping(); - } else if (opCode == LuaState.OP_CALL) { - shouldPauseForStepping = true; - } - } else if (stepping == STEP_OVER) { - if ((steppingFrame == cc && lastline != line)|| - (steppingFrame > cc)) { - suspendOnStepping(); - } - } else if (stepping == STEP_RETURN) { - if ((opCode == LuaState.OP_RETURN && cc == this.steppingFrame) || - (opCode == LuaState.OP_TAILCALL && cc == this.steppingFrame)) { - shouldPauseForStepping = true; - } - } - - // check for a break point if we aren't suspended already - if (!suspended && lastline != line) { - if (TRACE) - System.out.println("Source: " + currentProto.source); - String fileName = getSourceFileName(source); - String breakpointKey = constructBreakpointKey(fileName, line); - if (breakpoints.containsKey(breakpointKey)) { - if (TRACE) - System.out.println("hitting breakpoint " - + constructBreakpointKey(fileName, line)); - if (debugSupport != null) { - debugSupport.notifyDebugEvent( - new DebugEventBreakpoint(fileName, line)); - } - suspended = true; - } - } - - // save line in case next op is a step - lastline = line; - lastSource = source; - - // wait for a state change - while (suspended && !exiting) { - try { - this.wait(); - } catch (InterruptedException ie) { - ie.printStackTrace(); - } - } - } - } - - private boolean isStepping() { - return stepping != STEP_NONE; - } - - private void cancelStepping() { - if (debugSupport != null) { - debugSupport.notifyDebugEvent( - new DebugMessage(DebugMessageType.resumedOnSteppingEnd)); - } - stepping = STEP_NONE; - steppingFrame = -1; - shouldPauseForStepping = false; - } - - private void suspendOnStepping() { - if (debugSupport != null) { - debugSupport.notifyDebugEvent( - new DebugMessage(DebugMessageType.suspendedOnStepping)); - } - suspended = true; - steppingFrame = -1; - } - - /** - * Get the current line number - * - * @param pc program counter - * @return the line number corresponding to the pc - */ - private int getLineNumber(CallInfo ci) { - int[] lineNumbers = ci.closure.p.lineinfo; - int pc = getCurrentPc(ci); - int line = (lineNumbers != null && lineNumbers.length > pc ? - lineNumbers[pc] : - -1); - return line; - } - - // ------------------ commands coming from the debugger ------------------- - - public void handleRequest(DebugMessage request) { - if (this.debugSupport == null) { - throw new IllegalStateException( - "DebugNetSupportBase must be defined."); - } - - if (TRACE) - System.out.println("DebugStackState is handling request: " - + request.toString()); - - DebugMessageType requestType = request.getType(); - if (DebugMessageType.start == requestType) { - DebugMessage event = new DebugMessage(DebugMessageType.started); - debugSupport.notifyDebugEvent(event); - cancelSuspendOnStart(); - } else if (DebugMessageType.exit == requestType) { - stop(); - } else if (DebugMessageType.disconnect == requestType) { - disconnect(); - } else if (DebugMessageType.debugServiceDown == requestType) { - disconnectFromDebugService(); - } else if (DebugMessageType.reset == requestType) { - reset(); - } else if (DebugMessageType.suspend == requestType) { - suspend(); - DebugMessage event = new DebugMessage(DebugMessageType.suspendedByClient); - debugSupport.notifyDebugEvent(event); - } else if (DebugMessageType.resume == requestType) { - resume(); - } else if (DebugMessageType.lineBreakpointSet == requestType) { - DebugRequestLineBreakpointToggle setBreakpointRequest - = (DebugRequestLineBreakpointToggle) request; - setBreakpoint(setBreakpointRequest.getSource(), - setBreakpointRequest.getLineNumber()); - } else if (DebugMessageType.lineBreakpointClear == requestType) { - DebugRequestLineBreakpointToggle clearBreakpointRequest - = (DebugRequestLineBreakpointToggle) request; - clearBreakpoint(clearBreakpointRequest.getSource(), - clearBreakpointRequest.getLineNumber()); - } else if (DebugMessageType.callgraph == requestType) { - DebugResponseCallgraph callgraph - = new DebugResponseCallgraph(getCallgraph()); - debugSupport.notifyDebugEvent(callgraph); - } else if (DebugMessageType.stack == requestType) { - DebugRequestStack stackRequest = (DebugRequestStack) request; - int index = stackRequest.getIndex(); - DebugResponseStack stackState - = new DebugResponseStack(index, getStack(index)); - debugSupport.notifyDebugEvent(stackState); - } else if (DebugMessageType.global == requestType) { - DebugResponseVariables globals - = new DebugResponseVariables(getGlobals(), DebugMessageType.clientRequestGlobalReply); - debugSupport.notifyDebugEvent(globals); - } else if (DebugMessageType.stepInto == requestType) { - stepInto(); - } else if (DebugMessageType.stepOver == requestType) { - stepOver(); - } else if (DebugMessageType.stepReturn == requestType) { - stepReturn(); - } else { - throw new java.lang.IllegalArgumentException("unkown request type: " - + request.getType()); - } - } - - /** - * suspend the execution - */ - public synchronized void suspend() { - suspended = true; - stepping = STEP_NONE; - lastline = -1; - this.notify(); - } - - /** - * If the VM is suspended on start, this method resumes the execution. - */ - protected synchronized void cancelSuspendOnStart() { - if (bSuspendOnStart) { - bSuspendOnStart = false; - this.notify(); - } - } - - /** - * resume the execution - */ - public synchronized void resume() { - this.suspended = false; - this.stepping = STEP_NONE; - this.shouldPauseForStepping = false; - this.steppingFrame = -1; - this.notify(); - } - - /** - * Stops the debugging communication with the debug client and terminate the - * VM execution. - */ - public synchronized void stop() { - if (exiting) return; - - if (this.debugSupport != null) { - DebugMessage event = new DebugMessage(DebugMessageType.terminated); - debugSupport.notifyDebugEvent(event); - } - - exit(); - - if (this.debugSupport != null) { - debugSupport.stop(); - debugSupport = null; - } - } - - public void disconnect() { - if (this.debugSupport == null) { - throw new IllegalStateException( - "DebugNetSupportBase must be defined."); - } - - reset(); - DebugMessage event = new DebugMessage(DebugMessageType.disconnected); - debugSupport.notifyDebugEvent(event); - debugSupport.disconnect(); - } - - public void disconnectFromDebugService() { - if (this.debugSupport == null) { - throw new IllegalStateException( - "DebugNetSupportBase must be defined."); - } - - reset(); - debugSupport.disconnect(); - } - - public synchronized void reset() { - this.breakpoints.clear(); - if (this.suspended) { - resume(); - } - } - - /** - * terminate the execution - */ - public synchronized void exit() { - exiting = true; - this.notify(); - } - - /** - * set breakpoint at line N - * - * @param N -- the line to set the breakpoint at - */ - public void setBreakpoint(String source, int lineNumber) { - String fileName = getSourceFileName(source); - String breakpointKey = constructBreakpointKey(fileName, lineNumber); - - breakpoints.put(breakpointKey, Boolean.TRUE); - } - - protected String constructBreakpointKey(String source, int lineNumber) { - return source + ":" + lineNumber; - } - - /** - * clear breakpoint at line lineNumber of source source - */ - public void clearBreakpoint(String source, int lineNumber) { - String fileName = getSourceFileName(source); - String breakpointKey = constructBreakpointKey(fileName, lineNumber); - - breakpoints.remove(breakpointKey); - } - - /** - * return the current call graph (i.e. stack frames from new to old, include - * information about file, method, etc.) - */ - public StackFrame[] getCallgraph() { - int n = cc; - - if (n < 0 || n >= calls.length) - return new StackFrame[0]; - - int length = n + 1; - StackFrame[] frames = new StackFrame[length]; - for (int i = 0; i < length; i++) { - CallInfo ci = calls[i]; - String src = getSourceFileName(ci.closure.p.source); - frames[length - i - 1] = new StackFrame(src, getLineNumber(ci)); - } - return frames; - } - - /** - * Returns the visible local variables on a stack frame. - * @param index The stack frame index - * @return the visible local variables on the given stack frame. - */ - public Variable[] getStack(int index) { - if (index < 0 || index > cc) { - throw new RuntimeException("invalid stack index"); - } - - - CallInfo callInfo = calls[index]; - LClosure closure = callInfo.closure; - LPrototype prototype = closure.p; - LocVars[] localVariables = prototype.locvars; - - Vector variables = new Vector(); - - int pc = getCurrentPc(callInfo); - - // add upvalues - for ( int i=0; ii? String.valueOf(ups[i]): "?"); - LValue value = closure.upVals[i].getValue(); - addVariable( variables, upstate+name, value ); - } - } - - // add locals - for (int i = 0; i < localVariables.length; i++) { - if (isActiveVariable(pc, localVariables[i])) { - String name = localVariables[i].varname.toJavaString(); - LValue value = stack[callInfo.base+i]; - addVariable(variables, name, value); - } - } - - - // convert to array - Variable[] result = new Variable[variables.size()]; - variables.copyInto(result); - - return result; - } - - /** - * Check if the current LPrototype is lexically defined in the caller scope. - * @param p -- current LPrototype - * @param ci -- caller info - * @return true if the current LPrototype is lexically defined in the - * caller scope; false, otherwise. - */ - protected boolean isInScope(LPrototype p, CallInfo ci) { - LPrototype[] enclosingProtos = ci.closure.p.p; - boolean bFound = false; - for (int i = 0; enclosingProtos!= null && i < enclosingProtos.length; i++) { - if (enclosingProtos[i] == p) { - bFound = true; - break; - } - } - - return bFound; - } - - /** - * Returns the visible globals to the current VM. - * @return the visible globals. - */ - public Variable[] getGlobals() { - Vector variables = new Vector(); - variables.addElement( - new TableVariable(0, - "*Globals*", - Lua.LUA_TTABLE, - (LTable) _G)); - - Variable[] result = new Variable[variables.size()]; - for (int i = 0; i < variables.size(); i++) { - result[i] = (Variable) variables.elementAt(i); - } - - return result; - } - - /** - * Debugging Utility. Dumps the variables for a given call frame. - * @param index Index of the call frame - */ - private void dumpStack(int index) { - if (index < 0 || index > cc) return; - - CallInfo callInfo = calls[index]; - LPrototype prototype = callInfo.closure.p; - LocVars[] localVariables = prototype.locvars; - System.out.println("Stack Frame: " + index + " [" + base + "," + top + "]," + - " # of localvars: " + localVariables.length + ", pc=" + callInfo.pc + - " # upvals: " + prototype.nups ); - - int pc = getCurrentPc(callInfo); - for (int i = 0; i < localVariables.length; i++) { - if (!isActiveVariable(pc, localVariables[i])) { - continue; - } else { - System.out.println("localvars["+i+"]=" + localVariables[i].varname.toJavaString()); - } - } - - int base = callInfo.base; - int top = callInfo.top < callInfo.base ? callInfo.base+1 : callInfo.top; - for (int i = base; i < top; i++){ - System.out.println("stack[" + i + "]=" + stack[i]); - } - } - - /** - * Check if a variable is in scope. - * @param pc -- Current program counter. - * @param localVariable -- A local variable. - * @return true if the variable is active under the given program counter; - * false, otherwise. - */ - private boolean isActiveVariable(int pc, LocVars localVariable) { - return pc >= localVariable.startpc && pc <= localVariable.endpc; - } - - /** - * Adds an active variable for the given call frame to the list of variables. - * @param variables -- the list of active variables. - * @param varName -- the name of the variable - * @param index -- the value of the variable - */ - private void addVariable(Vector variables, String varName, LValue value) { - - int selectedVariableCount = variables.size(); - if (TRACE) { - System.out.print("\tVariable: " + varName); - System.out.print("\tValue: " + value); - System.out.print("\tN: "+selectedVariableCount); - } - - if (value != null) { - int type = value.luaGetType(); - if (TRACE) - System.out.print("\tType: " + value.luaGetTypeName()); - if (type == Lua.LUA_TTABLE) { - variables.addElement(new TableVariable( selectedVariableCount, varName, type, (LTable) value)); - } else if (type == LUA_TSTRING) { - variables.addElement(new Variable(selectedVariableCount, varName, type, "'"+value.toString()+"'")); - } else { - variables.addElement(new Variable(selectedVariableCount, varName, type, value.toString())); - } - } - - if (TRACE) - System.out.print(""); - } - - - /** - * step over to next line - */ - public synchronized void stepOver() { - suspended = false; - stepping = STEP_OVER; - steppingFrame = cc; - this.notify(); - } - - /** - * step to the next statement - */ - public synchronized void stepInto() { - suspended = false; - stepping = STEP_INTO; - this.notify(); - } - - /** - * return from the current method call - */ - public synchronized void stepReturn() { - suspended = false; - stepping = STEP_RETURN; - steppingFrame = cc; - this.notify(); - } -} diff --git a/src/debug/org/luaj/debug/DebugMessage.java b/src/debug/org/luaj/debug/DebugMessage.java deleted file mode 100644 index c69e2524..00000000 --- a/src/debug/org/luaj/debug/DebugMessage.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class DebugMessage implements Serializable { - protected DebugMessageType type; - - public DebugMessage(DebugMessageType type) { - this.type = type; - } - - public DebugMessageType getType() { - return type; - } - - public void setType(DebugMessageType type) { - this.type = type; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - return type.toString(); - } - - public static void serialize(DataOutputStream out, DebugMessage object) - throws IOException { - SerializationHelper.serialize(object.getType(), out); - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - DebugMessageType type = (DebugMessageType) SerializationHelper - .deserialize(in); - return new DebugMessage(type); - } -} diff --git a/src/debug/org/luaj/debug/DebugMessageType.java b/src/debug/org/luaj/debug/DebugMessageType.java deleted file mode 100644 index f445937e..00000000 --- a/src/debug/org/luaj/debug/DebugMessageType.java +++ /dev/null @@ -1,116 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.IOException; - - -public class DebugMessageType extends EnumType { - // requests - public static final DebugMessageType start = new DebugMessageType("start", 0); - public static final DebugMessageType resume = new DebugMessageType("resume", 1); - public static final DebugMessageType suspend = new DebugMessageType("suspend", 2); - public static final DebugMessageType exit = new DebugMessageType("exit", 3); - public static final DebugMessageType disconnect = new DebugMessageType("disconnect", 4); - public static final DebugMessageType lineBreakpointSet = new DebugMessageType("lineBreakpointSet", 5); - public static final DebugMessageType lineBreakpointClear = new DebugMessageType("lineBreakpointClear", 6); - public static final DebugMessageType watchpointSet = new DebugMessageType("watchpointSet", 7); - public static final DebugMessageType watchpointClear = new DebugMessageType("watchpointClear", 8); - public static final DebugMessageType callgraph = new DebugMessageType("callgraph", 9); - public static final DebugMessageType stack = new DebugMessageType("stack", 10); - public static final DebugMessageType stepInto = new DebugMessageType("stepInto", 11); - public static final DebugMessageType stepOver = new DebugMessageType("stepOver", 12); - public static final DebugMessageType stepReturn = new DebugMessageType("stepReturn", 13); - public static final DebugMessageType global = new DebugMessageType("global", 14); - public static final DebugMessageType reset = new DebugMessageType("reset", 15); - public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 16); - - // responses - public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 17); - public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 18); - public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 19); - - // events - public static final DebugMessageType started = new DebugMessageType("started", 20); - public static final DebugMessageType suspendedByClient = new DebugMessageType("suspendedByClient", 21); - public static final DebugMessageType suspendedOnBreakpoint = new DebugMessageType("suspendedOnBreakpoint", 22); - public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 23); - public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 24); - public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 25); - public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 26); - public static final DebugMessageType outputRedirect = new DebugMessageType("outputRedirect", 27); - public static final DebugMessageType terminated = new DebugMessageType("terminated", 28); - public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 29); - - protected static DebugMessageType[] ENUMS = new DebugMessageType[] { - // requests - start, - resume, - suspend, - exit, - disconnect, - lineBreakpointSet, - lineBreakpointClear, - watchpointSet, - watchpointClear, - callgraph, - stack, - stepInto, - stepOver, - stepReturn, - global, - reset, - debugServiceDown, - - // responses - clientRequestCallgraphReply, - clientRequestStackReply, - clientRequestGlobalReply, - - // events - started, - suspendedByClient, - suspendedOnBreakpoint, - suspendedOnWatchpoint, - suspendedOnStepping, - suspendedOnError, - resumedOnSteppingEnd, - outputRedirect, - terminated, - disconnected - }; - - protected DebugMessageType(String name, int ordinal) { - super(name, ordinal); - } - - public static DebugMessageType deserialize(DataInputStream in) - throws IOException { - int ordinal = in.readInt(); - if (ordinal < 0 || ordinal >= ENUMS.length) { - throw new RuntimeException( - "DebugMessageType: ordinal is out of the range."); - } - return ENUMS[ordinal]; - } -} diff --git a/src/debug/org/luaj/debug/EnumType.java b/src/debug/org/luaj/debug/EnumType.java deleted file mode 100644 index ec6f2f5c..00000000 --- a/src/debug/org/luaj/debug/EnumType.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -import java.io.DataOutputStream; -import java.io.IOException; - - -public abstract class EnumType implements Serializable { - protected String name; - protected int ordinal; - - public EnumType(String name, int ordinal) { - this.name = name; - this.ordinal = ordinal; - } - - public String toString() { - return this.name; - } - - public final boolean equals(Object other) { - return (this == other); - } - - public final int hashCode() { - return System.identityHashCode(this); - } - - public final String name() { - return this.name; - } - - public final int ordinal() { - return this.ordinal; - } - - public static void serialize(DataOutputStream out, EnumType enumType) throws IOException { - out.writeInt(enumType.ordinal()); - } -} diff --git a/src/debug/org/luaj/debug/NullableString.java b/src/debug/org/luaj/debug/NullableString.java deleted file mode 100644 index 81c4778d..00000000 --- a/src/debug/org/luaj/debug/NullableString.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class NullableString implements Serializable { - protected String string; - - public NullableString(String someString) { - this.string = someString; - } - - public String getNullableString() { - return (this.string == null) ? "[NULL]" : this.string; - } - - public String getRawString() { - return (this.string.equals("[NULL]")) ? null : this.string; - } - - public static void serialize(DataOutputStream out, NullableString string) - throws IOException { - out.writeUTF(string.getNullableString()); - } - - public static NullableString deserialize(DataInputStream in) - throws IOException { - String string = in.readUTF(); - return new NullableString(string); - } -} diff --git a/src/debug/org/luaj/debug/RedirectOutputStream.java b/src/debug/org/luaj/debug/RedirectOutputStream.java deleted file mode 100644 index 7f104ab5..00000000 --- a/src/debug/org/luaj/debug/RedirectOutputStream.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.luaj.debug; - -import java.io.IOException; -import java.io.OutputStream; - -import org.luaj.debug.event.DebugEventListener; -import org.luaj.debug.event.DebugEventOutputRedirect; - -public class RedirectOutputStream extends OutputStream { - - protected DebugEventListener listener; - protected int count; - protected byte[] buffer; - - public RedirectOutputStream(DebugEventListener listener) { - this(listener, 1024); - } - - public RedirectOutputStream(DebugEventListener listener, int count) { - this.listener = listener; - this.count = 0; - this.buffer = new byte[count]; - } - - public void close() throws IOException { - flushBuffer(); - } - - public synchronized void flush() throws IOException { - flushBuffer(); - } - - public void write(byte[] b, int off, int len) throws IOException { - super.write(b, off, len); - flushBuffer(); - } - - public void write(byte[] b) throws IOException { - super.write(b); - flushBuffer(); - } - - public synchronized void write(int b) throws IOException { - if (count >= buffer.length) { - flushBuffer(); - } - buffer[count++] = (byte)b; - } - - protected synchronized void flushBuffer(){ - if (count > 0) { - String msg = new String(buffer, 0, this.count); - listener.notifyDebugEvent(new DebugEventOutputRedirect(msg)); - count = 0; - } - } -} diff --git a/src/debug/org/luaj/debug/Serializable.java b/src/debug/org/luaj/debug/Serializable.java deleted file mode 100644 index 629b485d..00000000 --- a/src/debug/org/luaj/debug/Serializable.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - - - -public interface Serializable { } diff --git a/src/debug/org/luaj/debug/SerializationHelper.java b/src/debug/org/luaj/debug/SerializationHelper.java deleted file mode 100644 index a6aa4ef4..00000000 --- a/src/debug/org/luaj/debug/SerializationHelper.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.luaj.debug; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.event.DebugEventBreakpoint; -import org.luaj.debug.event.DebugEventError; -import org.luaj.debug.event.DebugEventOutputRedirect; -import org.luaj.debug.request.DebugRequestLineBreakpointToggle; -import org.luaj.debug.request.DebugRequestStack; -import org.luaj.debug.response.DebugResponseCallgraph; -import org.luaj.debug.response.DebugResponseStack; -import org.luaj.debug.response.DebugResponseVariables; - -public class SerializationHelper { - - public static byte[] serialize(Serializable object) throws IOException { - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - DataOutputStream dout = new DataOutputStream(bout); - - serialize(object, dout); - - byte[] data = bout.toByteArray(); - - bout.close(); - dout.close(); - - return data; - } - - public static Serializable deserialize(byte[] data) throws IOException { - ByteArrayInputStream bin = new ByteArrayInputStream(data); - DataInputStream din = new DataInputStream(bin); - - Serializable object = deserialize(din); - - bin.close(); - din.close(); - - return object; - } - - static final int SERIAL_TYPE_NullableString = 0; - static final int SERIAL_TYPE_TableVariable = 1; - static final int SERIAL_TYPE_Variable = 2; - static final int SERIAL_TYPE_StackFrame = 3; - static final int SERIAL_TYPE_DebugMessageType = 4; - static final int SERIAL_TYPE_DebugMessage = 5; - static final int SERIAL_TYPE_DebugRequestStack = 6; - static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 7; - static final int SERIAL_TYPE_DebugEventBreakpoint = 8; - static final int SERIAL_TYPE_DebugEventError = 9; - static final int SERIAL_TYPE_DebugResponseCallgraph = 10; - static final int SERIAL_TYPE_DebugResponseVariables = 11; - static final int SERIAL_TYPE_DebugResponseStack = 12; - static final int SERIAL_TYPE_DebugEventOutputRedirect = 13; - - public static void serialize(Serializable object, DataOutputStream dout) - throws IOException { - if (object instanceof NullableString) { - dout.writeInt(SERIAL_TYPE_NullableString); - NullableString.serialize(dout, (NullableString) object); - } else if (object instanceof TableVariable) { - dout.writeInt(SERIAL_TYPE_TableVariable); - TableVariable.serialize(dout, (TableVariable) object); - } else if (object instanceof Variable) { - dout.writeInt(SERIAL_TYPE_Variable); - Variable.serialize(dout, (Variable) object); - } else if (object instanceof StackFrame) { - dout.writeInt(SERIAL_TYPE_StackFrame); - StackFrame.serialize(dout, (StackFrame) object); - } else if (object instanceof DebugMessageType) { - dout.writeInt(SERIAL_TYPE_DebugMessageType); - DebugMessageType.serialize(dout, (DebugMessageType) object); - } else if (object instanceof DebugRequestStack) { - dout.writeInt(SERIAL_TYPE_DebugRequestStack); - DebugRequestStack.serialize(dout, (DebugRequestStack) object); - } else if (object instanceof DebugRequestLineBreakpointToggle) { - dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle); - DebugRequestLineBreakpointToggle.serialize(dout, - (DebugRequestLineBreakpointToggle) object); - } else if (object instanceof DebugEventBreakpoint) { - dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint); - DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object); - } else if (object instanceof DebugEventError) { - dout.writeInt(SERIAL_TYPE_DebugEventError); - DebugEventError.serialize(dout, (DebugEventError) object); - } else if (object instanceof DebugEventOutputRedirect) { - dout.writeInt(SERIAL_TYPE_DebugEventOutputRedirect); - DebugEventOutputRedirect.serialize(dout, (DebugEventOutputRedirect) object); - } else if (object instanceof DebugResponseStack) { - dout.writeInt(SERIAL_TYPE_DebugResponseStack); - DebugResponseStack.serialize(dout, (DebugResponseStack) object); - } else if (object instanceof DebugResponseVariables) { - dout.writeInt(SERIAL_TYPE_DebugResponseVariables); - DebugResponseVariables.serialize(dout, (DebugResponseVariables) object); - } else if (object instanceof DebugResponseCallgraph) { - dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph); - DebugResponseCallgraph.serialize(dout, - (DebugResponseCallgraph) object); - } else if (object instanceof DebugMessage) { - dout.writeInt(SERIAL_TYPE_DebugMessage); - DebugMessage.serialize(dout, (DebugMessage) object); - } else { - // catch the errors: forgot to implement - // serialization/deserialization - throw new RuntimeException( - "serialization operation is not supported"); - } - } - - public static Serializable deserialize(DataInputStream din) - throws IOException { - Serializable object = null; - int type = din.readInt(); - switch (type) { - case SERIAL_TYPE_NullableString: - object = NullableString.deserialize(din); - break; - case SERIAL_TYPE_TableVariable: - object = TableVariable.deserialize(din); - break; - case SERIAL_TYPE_Variable: - object = Variable.deserialize(din); - break; - case SERIAL_TYPE_StackFrame: - object = StackFrame.deserialize(din); - break; - case SERIAL_TYPE_DebugMessageType: - object = DebugMessageType.deserialize(din); - break; - case SERIAL_TYPE_DebugRequestStack: - object = DebugRequestStack.deserialize(din); - break; - case SERIAL_TYPE_DebugRequestLineBreakpointToggle: - object = DebugRequestLineBreakpointToggle.deserialize(din); - break; - case SERIAL_TYPE_DebugEventBreakpoint: - object = DebugEventBreakpoint.deserialize(din); - break; - case SERIAL_TYPE_DebugEventError: - object = DebugEventError.deserialize(din); - break; - case SERIAL_TYPE_DebugEventOutputRedirect: - object = DebugEventOutputRedirect.deserialize(din); - break; - case SERIAL_TYPE_DebugResponseCallgraph: - object = DebugResponseCallgraph.deserialize(din); - break; - case SERIAL_TYPE_DebugResponseStack: - object = DebugResponseStack.deserialize(din); - break; - case SERIAL_TYPE_DebugResponseVariables: - object = DebugResponseVariables.deserialize(din); - break; - case SERIAL_TYPE_DebugMessage: - object = DebugMessage.deserialize(din); - break; - default: - throw new RuntimeException( - "deserialization operation is not supported: " + type); - } - - return object; - } -} diff --git a/src/debug/org/luaj/debug/StackFrame.java b/src/debug/org/luaj/debug/StackFrame.java deleted file mode 100644 index a478113f..00000000 --- a/src/debug/org/luaj/debug/StackFrame.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -public class StackFrame implements Serializable { - protected int lineNumber; - - protected String source; - - public StackFrame(String source, int lineNumber) { - this.lineNumber = lineNumber; - this.source = source; - } - - public int getLineNumber() { - return this.lineNumber; - } - - public String getSource() { - return this.source; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - return getSource() + ":" + getLineNumber(); - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + lineNumber; - result = prime * result + ((source == null) ? 0 : source.hashCode()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final StackFrame other = (StackFrame) obj; - if (lineNumber != other.lineNumber) - return false; - if (source == null) { - if (other.source != null) - return false; - } else if (!source.equals(other.source)) - return false; - return true; - } - - public static void serialize(DataOutputStream out, StackFrame stackFrame) - throws IOException { - out.writeInt(stackFrame.getLineNumber()); - out.writeUTF(stackFrame.getSource()); - } - - public static StackFrame deserialize(DataInputStream in) throws IOException { - int lineNumber = in.readInt(); - String source = in.readUTF(); - return new StackFrame(source, lineNumber); - } -} diff --git a/src/debug/org/luaj/debug/TableVariable.java b/src/debug/org/luaj/debug/TableVariable.java deleted file mode 100644 index 21e5f9dd..00000000 --- a/src/debug/org/luaj/debug/TableVariable.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Vector; - -import org.luaj.vm.LTable; -import org.luaj.vm.LValue; -import org.luaj.vm.Lua; - - -public class TableVariable extends Variable { - protected String[] keys; - protected Object[] values; - - public TableVariable(int index, String name, int type, LTable table) { - super(index, name, type, null); - - int size = table.size(); - Vector keyList = new Vector(); - Vector valueList = new Vector(); - LValue[] keyValues = table.getKeys(); - for (int i = 0; i < size; i++) { - - LValue value = table.get(keyValues[i]); - if (value == table) { - continue; - } - - keyList.addElement(keyValues[i].toString()); - if (value instanceof LTable) { - valueList.addElement(new TableVariable(i, "[" + keyValues[i].toString() + "]", Lua.LUA_TTABLE, (LTable)value)); - } else { - valueList.addElement(value.toString()); - } - } - - this.keys = new String[keyList.size()]; - for (int i = 0; i < keyList.size(); i++) { - this.keys[i] = (String)keyList.elementAt(i); - } - - this.values = new Object[valueList.size()]; - for (int i = 0; i < valueList.size(); i++) { - this.values[i] = valueList.elementAt(i); - } - - if (this.keys.length != this.values.length) { - throw new RuntimeException("Internal Error: key.length must equal to values.length"); - } - } - - public TableVariable(int index, String name, int type, String[] keys, Object[] values) { - super(index, name, type, null); - this.keys = keys; - this.values = values; - } - - public String[] getKeys() { - return this.keys == null ? new String[0] : this.keys; - } - - public Object[] getValues() { - return this.values == null ? new Object[0] : this.values; - } - - public static void serialize(DataOutputStream out, TableVariable variable) throws IOException { - out.writeInt(variable.getIndex()); - out.writeUTF(variable.getName()); - out.writeInt(variable.getType()); - - String[] keys = variable.getKeys(); - out.writeInt(keys.length); - for (int i = 0; keys != null && i < keys.length; i++) { - SerializationHelper.serialize(new NullableString(keys[i]), out); - } - - Object[] values = variable.getValues(); - for (int i = 0; values != null && i < values.length; i++) { - if (values[i] instanceof String) { - SerializationHelper.serialize(new NullableString((String)values[i]), out); - } else if (values[i] instanceof TableVariable) { - SerializationHelper.serialize((TableVariable)values[i], out); - } else { - throw new RuntimeException("Internal Error: values array should only contain String and TableVariable"); - } - } - } - - public static Variable deserialize(DataInputStream in) throws IOException { - int index = in.readInt(); - String name = in.readUTF(); - int type = in.readInt(); - - String[] keys = null; - Object[] values = null; - int count = in.readInt(); - keys = new String[count]; - for (int i = 0; i < count; i++) { - keys[i] = ((NullableString) SerializationHelper.deserialize(in)).getRawString(); - } - - values = new Object[count]; - for (int i = 0; i < count; i++) { - int serialType = in.readInt(); - if (serialType == SerializationHelper.SERIAL_TYPE_NullableString) { - values[i] = NullableString.deserialize(in).getRawString(); - } else if (serialType == SerializationHelper.SERIAL_TYPE_TableVariable) { - values[i] = TableVariable.deserialize(in); - } - } - - TableVariable variable = new TableVariable(index, name, type, keys, values); - return variable; - } -} diff --git a/src/debug/org/luaj/debug/Variable.java b/src/debug/org/luaj/debug/Variable.java deleted file mode 100644 index 151e658a..00000000 --- a/src/debug/org/luaj/debug/Variable.java +++ /dev/null @@ -1,124 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.vm.Lua; - - -public class Variable implements Serializable { - protected int index; - protected String name; - protected String value; - protected int type; - - public Variable(int index, String name, int type, String value) { - if (name == null) { - throw new IllegalArgumentException("argument name is null"); - } - - if (type < Lua.LUA_TNIL || type > Lua.LUA_TTHREAD) { - throw new IllegalArgumentException("invalid LValue type: " + type); - } - - this.index = index; - this.name = name; - this.type = type; - this.value = value; - } - - public String getName() { - return this.name; - } - - public int getType() { - return this.type; - } - - public String getValue() { - return this.value; - } - - public int getIndex() { - return this.index; - } - - public String toString() { - return "index: " + getIndex() + " name:" + getName() + " type: " + Lua.TYPE_NAMES[getType()] + " value:" + getValue(); - } - - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + type; - result = prime * result + ((value == null) ? 0 : value.hashCode()); - return result; - } - - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - final Variable other = (Variable) obj; - if (index != other.index) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (type != other.type) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equals(other.value)) - return false; - return true; - } - - public static void serialize(DataOutputStream out, Variable variable) - throws IOException { - out.writeInt(variable.getIndex()); - out.writeUTF(variable.getName()); - out.writeInt(variable.getType()); - SerializationHelper.serialize(new NullableString(variable.getValue()), out); - } - - public static Variable deserialize(DataInputStream in) throws IOException { - int index = in.readInt(); - String name = in.readUTF(); - int type = in.readInt(); - NullableString value = (NullableString)SerializationHelper.deserialize(in); - - Variable variable = new Variable(index, name, type, value.getRawString()); - return variable; - } -} diff --git a/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java b/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java deleted file mode 100644 index ff412dfa..00000000 --- a/src/debug/org/luaj/debug/event/DebugEventBreakpoint.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.event; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; - -public class DebugEventBreakpoint extends DebugMessage { - protected String source; - - protected int lineNumber; - - public DebugEventBreakpoint(String source, int lineNumber) { - super(DebugMessageType.suspendedOnBreakpoint); - if (source == null) { - throw new IllegalArgumentException("argument source cannot be null"); - } - - if (lineNumber <= 0) { - throw new IllegalArgumentException( - "argument lineNumber must be positive integer"); - } - - this.source = source; - this.lineNumber = lineNumber; - } - - public String getSource() { - return this.source; - } - - public int getLineNumber() { - return this.lineNumber; - } - - /* - * (non-Javadoc) - * - * @see lua.debug.DebugEvent#toString() - */ - public String toString() { - return super.toString() + " source:" + getSource() + " line:" - + getLineNumber(); - } - - public static void serialize(DataOutputStream out, - DebugEventBreakpoint object) throws IOException { - out.writeUTF(object.getSource()); - out.writeInt(object.getLineNumber()); - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - String source = in.readUTF(); - int lineNo = in.readInt(); - - return new DebugEventBreakpoint(source, lineNo); - } -} diff --git a/src/debug/org/luaj/debug/event/DebugEventError.java b/src/debug/org/luaj/debug/event/DebugEventError.java deleted file mode 100644 index 0a7b6386..00000000 --- a/src/debug/org/luaj/debug/event/DebugEventError.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.event; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; - -public class DebugEventError extends DebugMessage { - protected String cause; - protected String trace; - - public DebugEventError(String cause, String trace) { - super(DebugMessageType.suspendedOnError); - this.cause = cause; - this.trace = trace; - } - - public String getCause() { - return this.cause; - } - - public String getTrace() { - return this.trace; - } - - /* - * (non-Javadoc) - * - * @see lua.debug.DebugEvent#toString() - */ - public String toString() { - return super.toString() + "[cause: " + getCause() + ", trace: " + trace + "]"; - } - - public static void serialize(DataOutputStream out, DebugEventError object) - throws IOException { - out.writeUTF(object.getCause()); - out.writeUTF(object.getTrace()); - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - String detail = in.readUTF(); - String trace = in.readUTF(); - return new DebugEventError(detail, trace); - } -} diff --git a/src/debug/org/luaj/debug/event/DebugEventListener.java b/src/debug/org/luaj/debug/event/DebugEventListener.java deleted file mode 100644 index 5d7023a3..00000000 --- a/src/debug/org/luaj/debug/event/DebugEventListener.java +++ /dev/null @@ -1,28 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.event; - -import org.luaj.debug.DebugMessage; - -public interface DebugEventListener { - public void notifyDebugEvent(DebugMessage event); -} diff --git a/src/debug/org/luaj/debug/event/DebugEventOutputRedirect.java b/src/debug/org/luaj/debug/event/DebugEventOutputRedirect.java deleted file mode 100644 index 5a18557c..00000000 --- a/src/debug/org/luaj/debug/event/DebugEventOutputRedirect.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.luaj.debug.event; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; - -public class DebugEventOutputRedirect extends DebugMessage { - protected String data; - - public DebugEventOutputRedirect(String data) { - super(DebugMessageType.outputRedirect); - this.data = data; - } - - public String getOutput() { - return this.data; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - public String toString() { - return type.toString() + ": " + this.data; - } - - public static void serialize(DataOutputStream out, DebugEventOutputRedirect event) - throws IOException { - out.writeUTF(event.getOutput()); - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - String data = in.readUTF(); - return new DebugEventOutputRedirect(data); - } -} diff --git a/src/debug/org/luaj/debug/net/DebugNetSupportBase.java b/src/debug/org/luaj/debug/net/DebugNetSupportBase.java deleted file mode 100644 index fd6d3265..00000000 --- a/src/debug/org/luaj/debug/net/DebugNetSupportBase.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.luaj.debug.net; - -import java.io.IOException; - -import org.luaj.debug.DebugLuaState; -import org.luaj.debug.DebugMessage; -import org.luaj.debug.event.DebugEventListener; -import org.luaj.debug.request.DebugRequestListener; -import org.luaj.vm.DebugNetSupport; - -/** - * DebugNetSupportBase provides the network communication support between the luaj-vm - * and debug clients. - */ -public abstract class DebugNetSupportBase implements DebugRequestListener, DebugEventListener, DebugNetSupport { - - /* (non-Javadoc) - * @see org.luaj.debug.net.DebugNetSupport#start() - */ - public abstract void start() throws IOException; - - /* (non-Javadoc) - * @see org.luaj.debug.net.DebugNetSupport#stop() - */ - public abstract void stop(); - - /* (non-Javadoc) - * @see org.luaj.debug.net.DebugNetSupport#disconnect() - */ - public abstract void disconnect(); - - protected DebugLuaState vm; - public void setDebugStackState(DebugLuaState vm) { - this.vm = vm; - } - - /* - * (non-Javadoc) - * - * @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest) - */ - public void handleRequest(DebugMessage request) { - vm.handleRequest(request); - } - - protected static final int UNKNOWN = 0; - protected static final int RUNNING = 1; - protected static final int STOPPED = 2; - - protected int state = UNKNOWN; - protected synchronized void setState(int state) { - this.state = state; - } - - protected synchronized boolean isRunning() { - return this.state == RUNNING; - } -} \ No newline at end of file diff --git a/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java b/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java deleted file mode 100644 index c89eae29..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequestLineBreakpointToggle.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.request; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.SerializationHelper; - - -public class DebugRequestLineBreakpointToggle extends DebugMessage { - protected String source; - protected int lineNumber; - - public DebugRequestLineBreakpointToggle(DebugMessageType type, String source, int lineNumber) { - super(type); - if (lineNumber < 0) { - throw new IllegalArgumentException("lineNumber must be equal to greater than zero"); - } - this.source = source; - this.lineNumber = lineNumber; - } - - public int getLineNumber() { - return this.lineNumber; - } - - public String getSource() { - return this.source; - } - - /* (non-Javadoc) - * @see lua.debug.DebugRequest#toString() - */ - public String toString() { - return super.toString() + " Source:" + getSource() + " lineNumber:" + getLineNumber(); - } - - public static void serialize(DataOutputStream out, DebugRequestLineBreakpointToggle request) - throws IOException { - SerializationHelper.serialize(request.getType(), out); - out.writeUTF(request.getSource()); - out.writeInt(request.getLineNumber()); - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - DebugMessageType type = (DebugMessageType)SerializationHelper.deserialize(in); - String source = in.readUTF(); - int lineNo = in.readInt(); - - return new DebugRequestLineBreakpointToggle(type, source, lineNo); - } -} diff --git a/src/debug/org/luaj/debug/request/DebugRequestListener.java b/src/debug/org/luaj/debug/request/DebugRequestListener.java deleted file mode 100644 index 098d545d..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequestListener.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.request; - -import org.luaj.debug.DebugMessage; - - -public interface DebugRequestListener { - - /** - * Debugging client can send the following requests to the server: - * suspend -- suspend the execution and listen for debug requests - * resume -- resume the execution - * exit -- terminate the execution - * set N -- set breakpoint at line N - * clear N -- clear breakpoint at line N - * callgraph -- return the current call graph (i.e. stack frames from - * old to new, include information about file, method, etc.) - * stack -- return the content of the current stack frame, - * listing the (variable, value) pairs - * step -- single step forward (go to next statement) - */ - public void handleRequest(DebugMessage request); -} diff --git a/src/debug/org/luaj/debug/request/DebugRequestStack.java b/src/debug/org/luaj/debug/request/DebugRequestStack.java deleted file mode 100644 index e07aa96a..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequestStack.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.request; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; - -public class DebugRequestStack extends DebugMessage { - protected int index; - - public DebugRequestStack(int index) { - super(DebugMessageType.stack); - this.index = index; - } - - public int getIndex() { - return this.index; - } - - /* - * (non-Javadoc) - * - * @see lua.debug.DebugRequest#toString() - */ - public String toString() { - return super.toString() + " stack frame:" + getIndex(); - } - - public static void serialize(DataOutputStream out, DebugRequestStack request) - throws IOException { - out.writeInt(request.getIndex()); - } - - public static DebugMessage deserialize(DataInputStream in) - throws IOException { - int index = in.readInt(); - - return new DebugRequestStack(index); - } -} diff --git a/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java b/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java deleted file mode 100644 index 8d1c455c..00000000 --- a/src/debug/org/luaj/debug/request/DebugRequestWatchpointToggle.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.request; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.EnumType; - -public class DebugRequestWatchpointToggle extends DebugMessage { - public static class AccessType extends EnumType { - private static final long serialVersionUID = 3523086189648091587L; - - public static final AccessType Ignore = new AccessType("Ignore", 0); - public static final AccessType Read = new AccessType("Read", 1); - public static final AccessType Modify = new AccessType("Modify", 2); - public static final AccessType ReadAndModify = new AccessType("ReadAndModify", 3); - - protected AccessType(String name, int ordinal) { - super(name, ordinal); - } - }; - - protected String functionName; - protected String variableName; - - public DebugRequestWatchpointToggle(String functionName, - String variableName, - AccessType accessType) { - super(accessType == AccessType.Ignore ? - DebugMessageType.watchpointClear : - DebugMessageType.watchpointSet); - this.functionName = functionName; - this.variableName = variableName; - } - - public String getFunctionName() { - return this.functionName; - } - - public String getVariableName() { - return this.variableName; - } - - /* (non-Javadoc) - * @see lua.debug.DebugRequest#toString() - */ - public String toString() { - return super.toString() + " functionName:" + getFunctionName() + " variableName:" + getVariableName(); - } - - // TODO: add the serialization stuff -} diff --git a/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java b/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java deleted file mode 100644 index 5a7240d8..00000000 --- a/src/debug/org/luaj/debug/response/DebugResponseCallgraph.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.response; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.StackFrame; - -public class DebugResponseCallgraph extends DebugMessage { - protected StackFrame[] stackFrames; - - public DebugResponseCallgraph(StackFrame[] callgraph) { - super(DebugMessageType.clientRequestCallgraphReply); - if (callgraph == null) { - this.stackFrames = new StackFrame[0]; - } else { - this.stackFrames = callgraph; - } - } - - public StackFrame[] getCallgraph() { - return this.stackFrames; - } - - public String toString() { - StringBuffer buffer = new StringBuffer("callgraph: "); - for (int i = 0; i < stackFrames.length; i++) { - StackFrame frame = stackFrames[i]; - buffer.append(frame.toString()); - buffer.append("\n"); - } - return buffer.toString(); - } - - public static void serialize(DataOutputStream out, - DebugResponseCallgraph response) throws IOException { - StackFrame[] stackFrames = response.getCallgraph(); - out.writeInt(stackFrames == null ? 0 : stackFrames.length); - for (int i = 0; stackFrames != null && i < stackFrames.length; i++) { - StackFrame.serialize(out, stackFrames[i]); - } - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - int count = in.readInt(); - StackFrame[] stackFrames = new StackFrame[count]; - for (int i = 0; i < count; i++) { - stackFrames[i] = StackFrame.deserialize(in); - } - - return new DebugResponseCallgraph(stackFrames); - } -} diff --git a/src/debug/org/luaj/debug/response/DebugResponseStack.java b/src/debug/org/luaj/debug/response/DebugResponseStack.java deleted file mode 100644 index cfddfa39..00000000 --- a/src/debug/org/luaj/debug/response/DebugResponseStack.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.luaj.debug.response; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.Variable; - -public class DebugResponseStack extends DebugResponseVariables { - protected int stackFrameIndex; - - public DebugResponseStack(int index, Variable[] variables) { - super(variables, DebugMessageType.clientRequestStackReply); - this.stackFrameIndex = index; - } - - public int getIndex() { - return this.stackFrameIndex; - } - - public static void serialize(DataOutputStream out, - DebugResponseStack response) - throws IOException { - out.writeInt(response.getIndex()); - - Variable[] variables = response.getVariables(); - out.writeInt(variables == null ? 0 : variables.length); - for (int i = 0; i < variables.length; i++) { - SerializationHelper.serialize(variables[i], out); - } - } - - public static DebugMessage deserialize(DataInputStream in) throws IOException { - int index = in.readInt(); - - int count = in.readInt(); - Variable[] variables = new Variable[count]; - for (int i = 0; i < count; i++) { - variables[i] = (Variable) SerializationHelper.deserialize(in); - } - - return new DebugResponseStack(index, variables); - } -} diff --git a/src/debug/org/luaj/debug/response/DebugResponseVariables.java b/src/debug/org/luaj/debug/response/DebugResponseVariables.java deleted file mode 100644 index ec23c5b0..00000000 --- a/src/debug/org/luaj/debug/response/DebugResponseVariables.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* -* Copyright (c) 2007 LuaJ. All rights reserved. -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -******************************************************************************/ -package org.luaj.debug.response; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.Variable; - -public class DebugResponseVariables extends DebugMessage { - protected Variable[] variables; - - public DebugResponseVariables(Variable[] variables, DebugMessageType type) { - super(type); - if (variables == null) { - this.variables = new Variable[0]; - } else { - this.variables = variables; - } - } - - public Variable[] getVariables() { - return this.variables; - } - - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ - public String toString() { - StringBuffer buffer = new StringBuffer(getType().toString() + ":"); - for (int i = 0; variables != null && i < variables.length; i++) { - buffer.append("\t" + variables[i].getName() + ":" + variables[i].getIndex() + "\n"); - } - return buffer.toString(); - } - - public static void serialize(DataOutputStream out, - DebugResponseVariables response) - throws IOException { - DebugMessageType.serialize(out, response.getType()); - Variable[] variables = response.getVariables(); - out.writeInt(variables == null ? 0 : variables.length); - for (int i = 0; i < variables.length; i++) { - SerializationHelper.serialize(variables[i], out); - } - } - - public static DebugMessage deserialize(DataInputStream in) - throws IOException { - DebugMessageType type = DebugMessageType.deserialize(in); - int count = in.readInt(); - Variable[] variables = new Variable[count]; - for (int i = 0; i < count; i++) { - variables[i] = (Variable) SerializationHelper.deserialize(in); - } - return new DebugResponseVariables(variables, type); - } -} diff --git a/src/j2me/org/luaj/debug/net/j2me/ClientConnectionTask.java b/src/j2me/org/luaj/debug/net/j2me/ClientConnectionTask.java deleted file mode 100644 index ac6c1bd7..00000000 --- a/src/j2me/org/luaj/debug/net/j2me/ClientConnectionTask.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.luaj.debug.net.j2me; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.EOFException; -import java.io.IOException; - -import javax.microedition.io.Connector; -import javax.microedition.io.SocketConnection; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.DebugMessageType; -import org.luaj.debug.RedirectOutputStream; -import org.luaj.debug.SerializationHelper; -import org.luaj.debug.event.DebugEventListener; -import org.luaj.lib.BaseLib; - -public class ClientConnectionTask implements Runnable, DebugEventListener { - private static final boolean TRACE = true; //(null != System.getProperty("TRACE")); - - protected String host; - protected int port; - protected DebugSupportImpl debugSupport; - protected boolean bDisconnected = false; - - protected SocketConnection connection; - protected DataInputStream inStream; - protected DataOutputStream outStream; - - protected RedirectOutputStream redirectOutputStream; - - public ClientConnectionTask(String host, int port, DebugSupportImpl debugSupport) { - this.host = host; - this.port = port; - this.debugSupport = debugSupport; - } - - public synchronized void disconnect () { - this.bDisconnected = true; - if (this.inStream != null) { - try { - inStream.close(); - } catch (IOException e) {} - } - } - - public boolean isDisconnected() { - return this.bDisconnected; - } - - public void run() { - try { - if ( TRACE ) - System.out.println("LuaJ debug server connecting to " + host + ":" + port); - - // create connection - this.connection = (SocketConnection) - Connector.open("socket://" + host + ":" + port); - this.inStream = connection.openDataInputStream(); - this.outStream = connection.openDataOutputStream(); - - if ( TRACE ) - System.out.println("LuaJ debug server connected to " + host + ":" + port); - - // to redirect the print to the debug client console - this.redirectOutputStream = new RedirectOutputStream(this); - BaseLib.redirectOutput( redirectOutputStream ); - - // loop for incoming requests - while ( !isDisconnected() ) { - byte[] data = null; - int size = inStream.readInt(); - data = new byte[size]; - inStream.readFully(data); - - DebugMessage request = (DebugMessage) SerializationHelper - .deserialize(data); - if ( TRACE ) - System.out.println("SERVER receives request: " + request.toString()); - - handleRequest(request); - } - } catch (EOFException e) { - // client has terminated the connection - // it may be time to exit. - handleRequest(new DebugMessage(DebugMessageType.reset)); - } catch (IOException e) { - e.printStackTrace(); - - // if the connected debugging client aborted abnormally, - // discard the current connection. - handleRequest(new DebugMessage(DebugMessageType.reset)); - - debugSupport.disconnect(); - } finally { - if (redirectOutputStream != null) { - try { - redirectOutputStream.close(); - } catch (IOException ignore) {} - - // restore the print output - BaseLib.restoreStandardOutput(); - } - - dispose(); - } - } - - protected void dispose() { - if (this.inStream != null) { - try { - inStream.close(); - inStream = null; - } catch (IOException e) {} - } - - if (this.outStream != null) { - try { - outStream.close(); - outStream = null; - } catch (IOException e) {} - } - - if (this.connection != null) { - try { - connection.close(); - connection = null; - } catch (IOException e) {} - } - } - - public void handleRequest(DebugMessage request) { - if ( TRACE ) - System.out.println("SERVER handling request: " + request.toString()); - - debugSupport.handleRequest(request); - } - - public void notifyDebugEvent(DebugMessage event) { - if (outStream == null) return; - - if ( TRACE ) - System.out.println("SERVER sending event: " + event.toString()); - - try { - byte[] data = SerializationHelper.serialize(event); - outStream.writeInt(data.length); - outStream.write(data); - outStream.flush(); - } catch (IOException e) { - e.printStackTrace(); - } - } -} diff --git a/src/j2me/org/luaj/debug/net/j2me/DebugSupportImpl.java b/src/j2me/org/luaj/debug/net/j2me/DebugSupportImpl.java deleted file mode 100644 index 066be4e6..00000000 --- a/src/j2me/org/luaj/debug/net/j2me/DebugSupportImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.luaj.debug.net.j2me; - -import java.io.IOException; - -import org.luaj.debug.DebugMessage; -import org.luaj.debug.net.DebugNetSupportBase; - -/** - * J2ME version of DebugNetSupportBase implementation. The vm will connect to a debug - * service hosted on a remote machine and have the debug service relay the - * debugging messages between the vm and the debug client. - */ -public class DebugSupportImpl extends DebugNetSupportBase { - protected String host; - protected int port; - ClientConnectionTask clientTask; - Thread main; - - public DebugSupportImpl(String host, int port) throws IOException { - this.host = host; - this.port = port; - } - - public void start() throws IOException { - setState(RUNNING); - main = new Thread(new Runnable() { - public void run() { - while ( isRunning() ) { - synchronized (DebugSupportImpl.this) { - if ( clientTask == null ) { - clientTask = new ClientConnectionTask(host, port, DebugSupportImpl.this); - new Thread(clientTask).start(); - } - } - - synchronized(main) { - try { - main.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - } - }); - main.start(); - } - - - public void stop() { - setState(STOPPED); - disconnect(); - } - - public void disconnect() { - clientTask.disconnect(); - clientTask = null; - synchronized(main) { - main.notify(); - } - } - - public synchronized void notifyDebugEvent(DebugMessage event) { - if (clientTask != null) { - clientTask.notifyDebugEvent(event); - } - } -} diff --git a/src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java b/src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java index 2a9b54e7..c84d3f25 100644 --- a/src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java +++ b/src/j2me/org/luaj/platform/J2meMidp10Cldc10Platform.java @@ -1,18 +1,12 @@ package org.luaj.platform; -import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import javax.microedition.midlet.MIDlet; -import org.luaj.debug.net.j2me.DebugSupportImpl; -import org.luaj.lib.MathLib; -import org.luaj.vm.DebugNetSupport; -import org.luaj.vm.LDouble; import org.luaj.vm.LNumber; -import org.luaj.vm.LuaErrorException; import org.luaj.vm.LuaState; import org.luaj.vm.Platform; @@ -37,13 +31,6 @@ public class J2meMidp10Cldc10Platform extends Platform { InputStream is = this.getClass().getResourceAsStream(fileName); return is; } - - public DebugNetSupport getDebugSupport() throws IOException { - String host = getDebugHost(); - int port = getDebugPort(); - return new DebugSupportImpl(host, port); - } - public String getProperty(String key) { return midlet.getAppProperty(key); } diff --git a/src/j2se/org/luaj/debug/j2se/StandardLuaJVM.java b/src/j2se/org/luaj/debug/j2se/StandardLuaJVM.java deleted file mode 100644 index 5fb108c8..00000000 --- a/src/j2se/org/luaj/debug/j2se/StandardLuaJVM.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 LuaJ. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - ******************************************************************************/ -package org.luaj.debug.j2se; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.luaj.compiler.LuaC; -import org.luaj.debug.DebugLuaState; -import org.luaj.lib.PackageLib; -import org.luaj.platform.J2sePlatform; -import org.luaj.vm.LClosure; -import org.luaj.vm.LPrototype; -import org.luaj.vm.LString; -import org.luaj.vm.LValue; -import org.luaj.vm.LoadState; -import org.luaj.vm.LuaErrorException; -import org.luaj.vm.LuaState; -import org.luaj.vm.Platform; - -/** - * StandardLuaJVM executes a lua program in normal run mode or debug mode. - * - * @author: Shu Lei - * @version: 1.0 - */ -public class StandardLuaJVM { - private static final String CMD_LINE_DEBUG_OPTION_SUSPEND_ON_START = "suspendOnStart="; - private static final String CMD_LINE_DEBUG_OPTION_PORT = "port="; - protected boolean isDebugMode = false; - protected int debugPort = -1;; - protected boolean bSuspendOnStart = false; - protected String script; - protected String[] scriptArgs; - protected LuaState state; - protected boolean isReady = false; - protected boolean isTerminated = false; - - // command line parsing utilities - class ParseException extends Exception { - private static final long serialVersionUID = -3134938136698856577L; - - public ParseException(String message) { - super(message); - } - } - - protected void printUsage() { - System.out.println("Usage:"); - System.out.println("\t java StandardLuaJVM [-Dport=[,suspendedOnStart=]] [-L]