1. code clean and added documentation for debugging protocol
2. upgrade to version 0.14 since I trimmed the debug message types
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<project default="all">
|
<project default="all">
|
||||||
<property name="version" value="0.13"/>
|
<property name="version" value="0.14"/>
|
||||||
|
|
||||||
<target name="clean">
|
<target name="clean">
|
||||||
<delete dir="build"/>
|
<delete dir="build"/>
|
||||||
|
|||||||
@@ -19,11 +19,4 @@ public interface DebugNetSupport {
|
|||||||
* Disconnect all connected clients.
|
* Disconnect all connected clients.
|
||||||
*/
|
*/
|
||||||
public abstract void disconnect();
|
public abstract void disconnect();
|
||||||
|
|
||||||
/**
|
|
||||||
* Disconnect the client with the given id.
|
|
||||||
* @param id -- client id
|
|
||||||
*/
|
|
||||||
public abstract void disconnect(int id);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,6 @@ import org.luaj.compiler.LexState;
|
|||||||
import org.luaj.debug.event.DebugEventBreakpoint;
|
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||||
import org.luaj.debug.event.DebugEventError;
|
import org.luaj.debug.event.DebugEventError;
|
||||||
import org.luaj.debug.net.DebugNetSupportBase;
|
import org.luaj.debug.net.DebugNetSupportBase;
|
||||||
import org.luaj.debug.request.DebugRequestDisconnect;
|
|
||||||
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||||
import org.luaj.debug.request.DebugRequestListener;
|
import org.luaj.debug.request.DebugRequestListener;
|
||||||
import org.luaj.debug.request.DebugRequestStack;
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
@@ -49,6 +48,110 @@ import org.luaj.vm.LuaState;
|
|||||||
import org.luaj.vm.Platform;
|
import org.luaj.vm.Platform;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <code>DebugLuaState</code> extends <code>LuaState</code> 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 <code>DebugMessage</code>. 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.
|
||||||
|
* <p>
|
||||||
|
* <i>Debugger Requests:</i>
|
||||||
|
* <ul>
|
||||||
|
* <li><code>DebugMessageType.start</code>: The first message for the handshake
|
||||||
|
* between the debugger and the luaj-vm. The VM responds with
|
||||||
|
* <code>DebugMessageType.started</code> immediately. If the VM is paused
|
||||||
|
* on start, it will now resume the execution.
|
||||||
|
* <li><code>DebugMessageType.resume</code>: The debugger instructs the
|
||||||
|
* luaj-vm to resume the execution when the VM is suspended. No reply is needed.
|
||||||
|
* <li><code>DebugMessageType.suspend</code>: The debugger instructs the luaj-vm
|
||||||
|
* to suspend. VM replies with <code>DebugMessageType.suspendedByClient</code>
|
||||||
|
* when it is suspended.
|
||||||
|
* <li><code>DebugMessageType.lineBreakpointSet</code>: 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.
|
||||||
|
* <li><code>DebugMessageType.lineBreakpointClear</code>: 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.
|
||||||
|
* <li><code>DebugMessageType.watchpointSet</code>: The debugger sets a watchpoint
|
||||||
|
* on the given source and line number. Not implemented yet.
|
||||||
|
* <li><code>DebugMessageType.watchpointClear</code>: The debugger clears a
|
||||||
|
* watchpoint at the given source and line number. Not implemented yet.
|
||||||
|
* <li><code>DebugMessageType.callgraph</code>: The debugger requests for the
|
||||||
|
* current call graph. VM replies with the call graph immediately in a debug
|
||||||
|
* message of type <code>DebugMessageType.clientRequestCallgraphReply</code>.
|
||||||
|
* <li><code>DebugMessageType.stack</code>: 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
|
||||||
|
* <code>DebugMessageType.clientRequestStackReply</code>.
|
||||||
|
* <li><code>DebugMessageType.stepInto</code>: The debugger instructs the VM
|
||||||
|
* to begin stepping in stepInto mode. No reply is needed.
|
||||||
|
* <li><code>DebugMessageType.stepOver</code>: The debugger instructs the VM to
|
||||||
|
* begin stepping in stepOver mode. No rely is needed.
|
||||||
|
* <li><code>DebugMessageType.stepReturn</code>: The debugger instructs the VM
|
||||||
|
* to begin stepping in stepReturn mode. No reply is needed.
|
||||||
|
* <li><code>DebugMessageType.global</code>: The debug request the information
|
||||||
|
* about the globals. VM replies with global variables in a debug message of
|
||||||
|
* type <code>DebugMessageType.clientRequestGlobalReply</code>.
|
||||||
|
* <li><code>DebugMessageType.disconnect</code>: The debugger informs the VM
|
||||||
|
* that it is about to disconnect from the VM. VM resets its state and responds
|
||||||
|
* with <code>DebugMessageType.disconnected</code> immediately.
|
||||||
|
* <li><code>DebugMessageType.exit</code>: The debugger instructs the VM to
|
||||||
|
* terminate. VM prepares for termination and responds with
|
||||||
|
* <code>DebugMessageType.terminated</code>.
|
||||||
|
* <li><code>DebugMessageType.reset</code>: 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.
|
||||||
|
* <li><code>DebugMessageType.debugServiceDown</code>: 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.
|
||||||
|
* </ul>
|
||||||
|
* <p>
|
||||||
|
* <i>VM Responses and Events:</i>
|
||||||
|
* <ul>
|
||||||
|
* <li><code>DebugMessageType.clientRequestCallgraphReply</code>: VM replies to
|
||||||
|
* the <code>DebugMessageType.callgraph</code> 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.
|
||||||
|
* <li><code>DebugMessageType.clientRequestStackReply</code>: VM replies
|
||||||
|
* to the <code>DebugMessageType.stack</code> request with the variables visible
|
||||||
|
* on the call stack <code>i</code> where <code>i</code> the call stack index
|
||||||
|
* ranging between 0 and <code>LuaState.calls.length</code>.
|
||||||
|
* <li><code>DebugMessageType.clientRequestGlobalReply</code>: VM replies to the
|
||||||
|
* <code>DebugMessageType.global</code> request with all the globals.
|
||||||
|
* <li><code>DebugMessageType.started</code>: VM replies when a
|
||||||
|
* <code>DebugMessageType.start</code> request is received.
|
||||||
|
* <li><code>DebugMessageType.resumedOnSteppingEnd</code>: VM informs the debugger
|
||||||
|
* that VM is getting out of the stepping mode upon step return because it has
|
||||||
|
* reached the last call stack.
|
||||||
|
* <li><code>DebugMessageType.suspendedByClient</code>: VM sends the event to
|
||||||
|
* respond to a debugger pause action.
|
||||||
|
* <li><code>DebugMessageType.suspendedOnBreakpoint</code>: VM sends the event
|
||||||
|
* when a breakpoint is hit during the execution.
|
||||||
|
* <li><code>DebugMessageType.suspendedOnWatchpoint</code>: Not implemented yet.
|
||||||
|
* VM sends the event when VM is paused to evaluate a watchpoint.
|
||||||
|
* <li><code>DebugMessageType.suspendedOnStepping</code>: 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.
|
||||||
|
* <li><code>DebugMessageType.suspendedOnError</code>: VM sends the event when
|
||||||
|
* an error is raised in VM.
|
||||||
|
* <li><code>DebugMessageType.terminated</code>: VM sends the event when it is
|
||||||
|
* ready to exit.
|
||||||
|
* <li><code>DebugMessageType.disconnected</code>: VM sends the event when it
|
||||||
|
* has de-attached the debugger from the debug session.
|
||||||
|
* <li><code>DebugMessageType.outputRedirect</code>: VM forwards the print
|
||||||
|
* output to the debugger console.
|
||||||
|
* </ul>
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
public class DebugLuaState extends LuaState implements DebugRequestListener {
|
public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||||
private static final boolean TRACE = (null != System.getProperty("TRACE"));
|
private static final boolean TRACE = (null != System.getProperty("TRACE"));
|
||||||
|
|
||||||
@@ -328,10 +431,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
} else if (DebugMessageType.exit == requestType) {
|
} else if (DebugMessageType.exit == requestType) {
|
||||||
stop();
|
stop();
|
||||||
} else if (DebugMessageType.disconnect == requestType) {
|
} else if (DebugMessageType.disconnect == requestType) {
|
||||||
DebugRequestDisconnect disconnectRequest
|
disconnect();
|
||||||
= (DebugRequestDisconnect) request;
|
|
||||||
int connectionId = disconnectRequest.getSessionId();
|
|
||||||
disconnect(connectionId);
|
|
||||||
} else if (DebugMessageType.debugServiceDown == requestType) {
|
} else if (DebugMessageType.debugServiceDown == requestType) {
|
||||||
disconnectFromDebugService();
|
disconnectFromDebugService();
|
||||||
} else if (DebugMessageType.reset == requestType) {
|
} else if (DebugMessageType.reset == requestType) {
|
||||||
@@ -437,7 +537,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect(int connectionId) {
|
public void disconnect() {
|
||||||
if (this.debugSupport == null) {
|
if (this.debugSupport == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"DebugNetSupportBase must be defined.");
|
"DebugNetSupportBase must be defined.");
|
||||||
@@ -446,7 +546,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
reset();
|
reset();
|
||||||
DebugMessage event = new DebugMessage(DebugMessageType.disconnected);
|
DebugMessage event = new DebugMessage(DebugMessageType.disconnected);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
debugSupport.disconnect(connectionId);
|
debugSupport.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnectFromDebugService() {
|
public void disconnectFromDebugService() {
|
||||||
@@ -505,7 +605,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the current call graph (i.e. stack frames from old to new, include
|
* return the current call graph (i.e. stack frames from new to old, include
|
||||||
* information about file, method, etc.)
|
* information about file, method, etc.)
|
||||||
*/
|
*/
|
||||||
public StackFrame[] getCallgraph() {
|
public StackFrame[] getCallgraph() {
|
||||||
@@ -514,11 +614,12 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
if (n < 0 || n >= calls.length)
|
if (n < 0 || n >= calls.length)
|
||||||
return new StackFrame[0];
|
return new StackFrame[0];
|
||||||
|
|
||||||
StackFrame[] frames = new StackFrame[n + 1];
|
int length = n + 1;
|
||||||
for (int i = 0; i <= n; i++) {
|
StackFrame[] frames = new StackFrame[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
CallInfo ci = calls[i];
|
CallInfo ci = calls[i];
|
||||||
String src = getSourceFileName(ci.closure.p.source);
|
String src = getSourceFileName(ci.closure.p.source);
|
||||||
frames[i] = new StackFrame(src, getLineNumber(ci));
|
frames[length - i - 1] = new StackFrame(src, getLineNumber(ci));
|
||||||
}
|
}
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,43 +31,44 @@ public class DebugMessageType extends EnumType {
|
|||||||
public static final DebugMessageType resume = new DebugMessageType("resume", 1);
|
public static final DebugMessageType resume = new DebugMessageType("resume", 1);
|
||||||
public static final DebugMessageType suspend = new DebugMessageType("suspend", 2);
|
public static final DebugMessageType suspend = new DebugMessageType("suspend", 2);
|
||||||
public static final DebugMessageType exit = new DebugMessageType("exit", 3);
|
public static final DebugMessageType exit = new DebugMessageType("exit", 3);
|
||||||
public static final DebugMessageType lineBreakpointSet = new DebugMessageType("lineBreakpointSet", 4);
|
public static final DebugMessageType disconnect = new DebugMessageType("disconnect", 4);
|
||||||
public static final DebugMessageType lineBreakpointClear = new DebugMessageType("lineBreakpointClear", 5);
|
public static final DebugMessageType lineBreakpointSet = new DebugMessageType("lineBreakpointSet", 5);
|
||||||
public static final DebugMessageType watchpointSet = new DebugMessageType("watchpointSet", 6);
|
public static final DebugMessageType lineBreakpointClear = new DebugMessageType("lineBreakpointClear", 6);
|
||||||
public static final DebugMessageType watchpointClear = new DebugMessageType("watchpointClear", 7);
|
public static final DebugMessageType watchpointSet = new DebugMessageType("watchpointSet", 7);
|
||||||
public static final DebugMessageType callgraph = new DebugMessageType("callgraph", 8);
|
public static final DebugMessageType watchpointClear = new DebugMessageType("watchpointClear", 8);
|
||||||
public static final DebugMessageType stack = new DebugMessageType("stack", 9);
|
public static final DebugMessageType callgraph = new DebugMessageType("callgraph", 9);
|
||||||
public static final DebugMessageType stepInto = new DebugMessageType("stepInto", 10);
|
public static final DebugMessageType stack = new DebugMessageType("stack", 10);
|
||||||
public static final DebugMessageType stepOver = new DebugMessageType("stepOver", 11);
|
public static final DebugMessageType stepInto = new DebugMessageType("stepInto", 11);
|
||||||
public static final DebugMessageType stepReturn = new DebugMessageType("stepReturn", 12);
|
public static final DebugMessageType stepOver = new DebugMessageType("stepOver", 12);
|
||||||
public static final DebugMessageType global = new DebugMessageType("global", 13);
|
public static final DebugMessageType stepReturn = new DebugMessageType("stepReturn", 13);
|
||||||
public static final DebugMessageType disconnect = new DebugMessageType("disconnect", 14);
|
public static final DebugMessageType global = new DebugMessageType("global", 14);
|
||||||
public static final DebugMessageType reset = new DebugMessageType("reset", 15);
|
public static final DebugMessageType reset = new DebugMessageType("reset", 15);
|
||||||
public static final DebugMessageType session = new DebugMessageType("session", 16);
|
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
|
// events
|
||||||
public static final DebugMessageType started = new DebugMessageType("started", 17);
|
public static final DebugMessageType started = new DebugMessageType("started", 20);
|
||||||
public static final DebugMessageType suspendedByClient = new DebugMessageType("suspendedByClient", 18);
|
public static final DebugMessageType suspendedByClient = new DebugMessageType("suspendedByClient", 21);
|
||||||
public static final DebugMessageType suspendedOnBreakpoint = new DebugMessageType("suspendedOnBreakpoint", 19);
|
public static final DebugMessageType suspendedOnBreakpoint = new DebugMessageType("suspendedOnBreakpoint", 22);
|
||||||
public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 20);
|
public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 23);
|
||||||
public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 21);
|
public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 24);
|
||||||
public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 22);
|
public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 25);
|
||||||
public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 23);
|
public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 26);
|
||||||
public static final DebugMessageType error = new DebugMessageType("error", 24);
|
public static final DebugMessageType outputRedirect = new DebugMessageType("outputRedirect", 27);
|
||||||
public static final DebugMessageType terminated = new DebugMessageType("terminated", 25);
|
public static final DebugMessageType terminated = new DebugMessageType("terminated", 28);
|
||||||
public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 26);
|
|
||||||
public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 27);
|
|
||||||
public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 28);
|
|
||||||
public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 29);
|
public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 29);
|
||||||
public static final DebugMessageType sessionId = new DebugMessageType("sessionId", 30);
|
|
||||||
public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 31);
|
|
||||||
public static final DebugMessageType outputRedirect = new DebugMessageType("outputRedirect", 32);
|
|
||||||
|
|
||||||
protected static DebugMessageType[] ENUMS = new DebugMessageType[] {
|
protected static DebugMessageType[] ENUMS = new DebugMessageType[] {
|
||||||
|
// requests
|
||||||
start,
|
start,
|
||||||
resume,
|
resume,
|
||||||
suspend,
|
suspend,
|
||||||
exit,
|
exit,
|
||||||
|
disconnect,
|
||||||
lineBreakpointSet,
|
lineBreakpointSet,
|
||||||
lineBreakpointClear,
|
lineBreakpointClear,
|
||||||
watchpointSet,
|
watchpointSet,
|
||||||
@@ -78,25 +79,25 @@ public class DebugMessageType extends EnumType {
|
|||||||
stepOver,
|
stepOver,
|
||||||
stepReturn,
|
stepReturn,
|
||||||
global,
|
global,
|
||||||
disconnect,
|
|
||||||
reset,
|
reset,
|
||||||
session,
|
|
||||||
started,
|
|
||||||
suspendedByClient,
|
|
||||||
suspendedOnBreakpoint,
|
|
||||||
suspendedOnWatchpoint,
|
|
||||||
suspendedOnStepping,
|
|
||||||
suspendedOnError,
|
|
||||||
resumedOnSteppingEnd,
|
|
||||||
error,
|
|
||||||
terminated,
|
|
||||||
clientRequestCallgraphReply,
|
|
||||||
clientRequestStackReply,
|
|
||||||
clientRequestGlobalReply,
|
|
||||||
disconnected,
|
|
||||||
sessionId,
|
|
||||||
debugServiceDown,
|
debugServiceDown,
|
||||||
outputRedirect
|
|
||||||
|
// responses
|
||||||
|
clientRequestCallgraphReply,
|
||||||
|
clientRequestStackReply,
|
||||||
|
clientRequestGlobalReply,
|
||||||
|
|
||||||
|
// events
|
||||||
|
started,
|
||||||
|
suspendedByClient,
|
||||||
|
suspendedOnBreakpoint,
|
||||||
|
suspendedOnWatchpoint,
|
||||||
|
suspendedOnStepping,
|
||||||
|
suspendedOnError,
|
||||||
|
resumedOnSteppingEnd,
|
||||||
|
outputRedirect,
|
||||||
|
terminated,
|
||||||
|
disconnected
|
||||||
};
|
};
|
||||||
|
|
||||||
protected DebugMessageType(String name, int ordinal) {
|
protected DebugMessageType(String name, int ordinal) {
|
||||||
|
|||||||
@@ -9,11 +9,9 @@ import java.io.IOException;
|
|||||||
import org.luaj.debug.event.DebugEventBreakpoint;
|
import org.luaj.debug.event.DebugEventBreakpoint;
|
||||||
import org.luaj.debug.event.DebugEventError;
|
import org.luaj.debug.event.DebugEventError;
|
||||||
import org.luaj.debug.event.DebugEventOutputRedirect;
|
import org.luaj.debug.event.DebugEventOutputRedirect;
|
||||||
import org.luaj.debug.request.DebugRequestDisconnect;
|
|
||||||
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
||||||
import org.luaj.debug.request.DebugRequestStack;
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||||
import org.luaj.debug.response.DebugResponseSession;
|
|
||||||
import org.luaj.debug.response.DebugResponseStack;
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
import org.luaj.debug.response.DebugResponseVariables;
|
import org.luaj.debug.response.DebugResponseVariables;
|
||||||
|
|
||||||
@@ -53,14 +51,12 @@ public class SerializationHelper {
|
|||||||
static final int SERIAL_TYPE_DebugMessage = 5;
|
static final int SERIAL_TYPE_DebugMessage = 5;
|
||||||
static final int SERIAL_TYPE_DebugRequestStack = 6;
|
static final int SERIAL_TYPE_DebugRequestStack = 6;
|
||||||
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 7;
|
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 7;
|
||||||
static final int SERIAL_TYPE_DebugRequestDisconnect = 8;
|
static final int SERIAL_TYPE_DebugEventBreakpoint = 8;
|
||||||
static final int SERIAL_TYPE_DebugEventBreakpoint = 9;
|
static final int SERIAL_TYPE_DebugEventError = 9;
|
||||||
static final int SERIAL_TYPE_DebugEventError = 10;
|
static final int SERIAL_TYPE_DebugResponseCallgraph = 10;
|
||||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 11;
|
static final int SERIAL_TYPE_DebugResponseVariables = 11;
|
||||||
static final int SERIAL_TYPE_DebugResponseVariables = 12;
|
static final int SERIAL_TYPE_DebugResponseStack = 12;
|
||||||
static final int SERIAL_TYPE_DebugResponseStack = 13;
|
static final int SERIAL_TYPE_DebugEventOutputRedirect = 13;
|
||||||
static final int SERIAL_TYPE_DebugResponseSession = 14;
|
|
||||||
static final int SERIAL_TYPE_DebugEventOutputRedirect = 15;
|
|
||||||
|
|
||||||
public static void serialize(Serializable object, DataOutputStream dout)
|
public static void serialize(Serializable object, DataOutputStream dout)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
@@ -86,9 +82,6 @@ public class SerializationHelper {
|
|||||||
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
||||||
DebugRequestLineBreakpointToggle.serialize(dout,
|
DebugRequestLineBreakpointToggle.serialize(dout,
|
||||||
(DebugRequestLineBreakpointToggle) object);
|
(DebugRequestLineBreakpointToggle) object);
|
||||||
} else if (object instanceof DebugRequestDisconnect) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestDisconnect);
|
|
||||||
DebugRequestDisconnect.serialize(dout, (DebugRequestDisconnect) object);
|
|
||||||
} else if (object instanceof DebugEventBreakpoint) {
|
} else if (object instanceof DebugEventBreakpoint) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint);
|
dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint);
|
||||||
DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object);
|
DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object);
|
||||||
@@ -108,9 +101,6 @@ public class SerializationHelper {
|
|||||||
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
||||||
DebugResponseCallgraph.serialize(dout,
|
DebugResponseCallgraph.serialize(dout,
|
||||||
(DebugResponseCallgraph) object);
|
(DebugResponseCallgraph) object);
|
||||||
} else if (object instanceof DebugResponseSession) {
|
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseSession);
|
|
||||||
DebugResponseSession.serialize(dout, (DebugResponseSession) object);
|
|
||||||
} else if (object instanceof DebugMessage) {
|
} else if (object instanceof DebugMessage) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugMessage);
|
dout.writeInt(SERIAL_TYPE_DebugMessage);
|
||||||
DebugMessage.serialize(dout, (DebugMessage) object);
|
DebugMessage.serialize(dout, (DebugMessage) object);
|
||||||
@@ -148,9 +138,6 @@ public class SerializationHelper {
|
|||||||
case SERIAL_TYPE_DebugRequestLineBreakpointToggle:
|
case SERIAL_TYPE_DebugRequestLineBreakpointToggle:
|
||||||
object = DebugRequestLineBreakpointToggle.deserialize(din);
|
object = DebugRequestLineBreakpointToggle.deserialize(din);
|
||||||
break;
|
break;
|
||||||
case SERIAL_TYPE_DebugRequestDisconnect:
|
|
||||||
object = DebugRequestDisconnect.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugEventBreakpoint:
|
case SERIAL_TYPE_DebugEventBreakpoint:
|
||||||
object = DebugEventBreakpoint.deserialize(din);
|
object = DebugEventBreakpoint.deserialize(din);
|
||||||
break;
|
break;
|
||||||
@@ -169,9 +156,6 @@ public class SerializationHelper {
|
|||||||
case SERIAL_TYPE_DebugResponseVariables:
|
case SERIAL_TYPE_DebugResponseVariables:
|
||||||
object = DebugResponseVariables.deserialize(din);
|
object = DebugResponseVariables.deserialize(din);
|
||||||
break;
|
break;
|
||||||
case SERIAL_TYPE_DebugResponseSession:
|
|
||||||
object = DebugResponseSession.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugMessage:
|
case SERIAL_TYPE_DebugMessage:
|
||||||
object = DebugMessage.deserialize(din);
|
object = DebugMessage.deserialize(din);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class DebugEventError extends DebugMessage {
|
|||||||
protected String trace;
|
protected String trace;
|
||||||
|
|
||||||
public DebugEventError(String cause, String trace) {
|
public DebugEventError(String cause, String trace) {
|
||||||
super(DebugMessageType.error);
|
super(DebugMessageType.suspendedOnError);
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,11 +29,6 @@ public abstract class DebugNetSupportBase implements DebugRequestListener, Debug
|
|||||||
*/
|
*/
|
||||||
public abstract void disconnect();
|
public abstract void disconnect();
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.luaj.debug.net.DebugNetSupport#disconnect(int)
|
|
||||||
*/
|
|
||||||
public abstract void disconnect(int id);
|
|
||||||
|
|
||||||
protected DebugLuaState vm;
|
protected DebugLuaState vm;
|
||||||
public void setDebugStackState(DebugLuaState vm) {
|
public void setDebugStackState(DebugLuaState vm) {
|
||||||
this.vm = vm;
|
this.vm = vm;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import org.luaj.debug.DebugMessageType;
|
|||||||
import org.luaj.debug.RedirectOutputStream;
|
import org.luaj.debug.RedirectOutputStream;
|
||||||
import org.luaj.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
import org.luaj.debug.event.DebugEventListener;
|
import org.luaj.debug.event.DebugEventListener;
|
||||||
import org.luaj.debug.response.DebugResponseSession;
|
|
||||||
import org.luaj.lib.BaseLib;
|
import org.luaj.lib.BaseLib;
|
||||||
|
|
||||||
public class ClientConnectionTask implements Runnable, DebugEventListener {
|
public class ClientConnectionTask implements Runnable, DebugEventListener {
|
||||||
@@ -92,7 +91,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
|
|||||||
// discard the current connection.
|
// discard the current connection.
|
||||||
handleRequest(new DebugMessage(DebugMessageType.reset));
|
handleRequest(new DebugMessage(DebugMessageType.reset));
|
||||||
|
|
||||||
debugSupport.disconnect(1);
|
debugSupport.disconnect();
|
||||||
} finally {
|
} finally {
|
||||||
if (redirectOutputStream != null) {
|
if (redirectOutputStream != null) {
|
||||||
try {
|
try {
|
||||||
@@ -134,11 +133,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
|
|||||||
if ( TRACE )
|
if ( TRACE )
|
||||||
System.out.println("SERVER handling request: " + request.toString());
|
System.out.println("SERVER handling request: " + request.toString());
|
||||||
|
|
||||||
if (request.getType() == DebugMessageType.session) {
|
debugSupport.handleRequest(request);
|
||||||
notifyDebugEvent(new DebugResponseSession(1));
|
|
||||||
} else {
|
|
||||||
debugSupport.handleRequest(request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyDebugEvent(DebugMessage event) {
|
public void notifyDebugEvent(DebugMessage event) {
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class DebugSupportImpl extends DebugNetSupportBase {
|
|||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
setState(STOPPED);
|
setState(STOPPED);
|
||||||
disconnect(1);
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
@@ -60,10 +60,6 @@ public class DebugSupportImpl extends DebugNetSupportBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void disconnect(int id) {
|
|
||||||
disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void notifyDebugEvent(DebugMessage event) {
|
public synchronized void notifyDebugEvent(DebugMessage event) {
|
||||||
if (clientTask != null) {
|
if (clientTask != null) {
|
||||||
clientTask.notifyDebugEvent(event);
|
clientTask.notifyDebugEvent(event);
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import org.luaj.debug.DebugMessageType;
|
|||||||
import org.luaj.debug.RedirectOutputStream;
|
import org.luaj.debug.RedirectOutputStream;
|
||||||
import org.luaj.debug.SerializationHelper;
|
import org.luaj.debug.SerializationHelper;
|
||||||
import org.luaj.debug.event.DebugEventListener;
|
import org.luaj.debug.event.DebugEventListener;
|
||||||
import org.luaj.debug.response.DebugResponseSession;
|
|
||||||
import org.luaj.lib.BaseLib;
|
import org.luaj.lib.BaseLib;
|
||||||
|
|
||||||
public class ClientConnectionTask implements Runnable, DebugEventListener {
|
public class ClientConnectionTask implements Runnable, DebugEventListener {
|
||||||
@@ -92,7 +91,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
|
|||||||
// discard the current connection.
|
// discard the current connection.
|
||||||
handleRequest(new DebugMessage(DebugMessageType.reset));
|
handleRequest(new DebugMessage(DebugMessageType.reset));
|
||||||
|
|
||||||
debugSupport.disconnect(getSessionId());
|
debugSupport.disconnect();
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
redirectOutputStream.close();
|
redirectOutputStream.close();
|
||||||
@@ -110,11 +109,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
|
|||||||
System.out.println("SERVER handling request: " + request.toString());
|
System.out.println("SERVER handling request: " + request.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.getType() == DebugMessageType.session) {
|
debugSupport.handleRequest(request);
|
||||||
notifyDebugEvent(new DebugResponseSession(getSessionId()));
|
|
||||||
} else {
|
|
||||||
debugSupport.handleRequest(request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyDebugEvent(DebugMessage event) {
|
public void notifyDebugEvent(DebugMessage event) {
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ public class DebugSupportImpl extends DebugNetSupportBase {
|
|||||||
public synchronized void stop() {
|
public synchronized void stop() {
|
||||||
setState(STOPPED);
|
setState(STOPPED);
|
||||||
if (clientConnectionTask != null) {
|
if (clientConnectionTask != null) {
|
||||||
disconnect(clientConnectionTask.getSessionId());
|
disconnect();
|
||||||
}
|
}
|
||||||
dispose();
|
dispose();
|
||||||
}
|
}
|
||||||
@@ -123,16 +123,8 @@ public class DebugSupportImpl extends DebugNetSupportBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void disconnect() {
|
public synchronized void disconnect() {
|
||||||
disconnect(clientConnectionTask.getSessionId());
|
clientConnectionTask.disconnect();
|
||||||
}
|
clientConnectionTask = null;
|
||||||
|
|
||||||
public synchronized void disconnect(int id) {
|
|
||||||
if (clientConnectionTask.getSessionId() == id) {
|
|
||||||
clientConnectionTask.disconnect();
|
|
||||||
clientConnectionTask = null;
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("Internal Error: mismatching sesion Id");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void acceptClientConnection() throws IOException {
|
public void acceptClientConnection() throws IOException {
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
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 DebugRequestDisconnect extends DebugMessage {
|
|
||||||
protected int sessionId;
|
|
||||||
|
|
||||||
public DebugRequestDisconnect(int connectionId) {
|
|
||||||
super(DebugMessageType.disconnect);
|
|
||||||
this.sessionId = connectionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSessionId() {
|
|
||||||
return this.sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return super.toString() + " sessionId:" + getSessionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out, DebugRequestDisconnect request)
|
|
||||||
throws IOException {
|
|
||||||
out.writeInt(request.getSessionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DebugMessage deserialize(DataInputStream in)
|
|
||||||
throws IOException {
|
|
||||||
int id = in.readInt();
|
|
||||||
|
|
||||||
return new DebugRequestDisconnect(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +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;
|
|
||||||
|
|
||||||
public class DebugResponseSession extends DebugMessage {
|
|
||||||
protected int sessionId;
|
|
||||||
|
|
||||||
public DebugResponseSession(int id) {
|
|
||||||
super(DebugMessageType.session);
|
|
||||||
this.sessionId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSessionId() {
|
|
||||||
return this.sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "SessionId: " + getSessionId();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out,
|
|
||||||
DebugResponseSession response)
|
|
||||||
throws IOException {
|
|
||||||
out.writeInt(response.getSessionId());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static DebugMessage deserialize(DataInputStream in) throws IOException {
|
|
||||||
int id = in.readInt();
|
|
||||||
return new DebugResponseSession(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import java.io.IOException;
|
|||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||||
import org.luaj.debug.response.DebugResponseSession;
|
|
||||||
import org.luaj.debug.response.DebugResponseStack;
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
import org.luaj.vm.Lua;
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
@@ -83,17 +82,4 @@ public class DebugResponseTest extends TestCase {
|
|||||||
assertEquals(inFrames[i], outFrames[i]);
|
assertEquals(inFrames[i], outFrames[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testDebugResponseSession() {
|
|
||||||
try {
|
|
||||||
DebugResponseSession sessionResponse = new DebugResponseSession(100);
|
|
||||||
byte[] data = SerializationHelper.serialize(sessionResponse);
|
|
||||||
DebugResponseSession sessionOut
|
|
||||||
= (DebugResponseSession) SerializationHelper.deserialize(data);
|
|
||||||
assertNotNull(sessionOut);
|
|
||||||
assertEquals(sessionResponse.getSessionId(), sessionOut.getSessionId());
|
|
||||||
} catch (IOException e) {
|
|
||||||
fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public class EnumTypeTest extends TestCase {
|
|||||||
|
|
||||||
public void testDebugEventTypeSerialization() {
|
public void testDebugEventTypeSerialization() {
|
||||||
try {
|
try {
|
||||||
DebugMessageType type = DebugMessageType.error;
|
DebugMessageType type = DebugMessageType.suspendedOnError;
|
||||||
byte[] data = SerializationHelper.serialize(type);
|
byte[] data = SerializationHelper.serialize(type);
|
||||||
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
|
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
|
||||||
.deserialize(data);
|
.deserialize(data);
|
||||||
|
|||||||
Reference in New Issue
Block a user