1. completed j2me debugging support

2. refactored DebugEvents and DebugRequests
This commit is contained in:
Shu Lei
2007-11-29 21:24:07 +00:00
parent c57969bc77
commit fd9b9b51c3
29 changed files with 695 additions and 659 deletions

View File

@@ -1,5 +1,5 @@
<project default="all"> <project default="all">
<property name="version" value="0.9"/> <property name="version" value="0.10"/>
<target name="clean"> <target name="clean">
<delete dir="build"/> <delete dir="build"/>

View File

@@ -26,17 +26,13 @@ import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import org.luaj.compiler.LexState; import org.luaj.compiler.LexState;
import org.luaj.debug.event.DebugEvent;
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.DebugEventType;
import org.luaj.debug.net.DebugSupport; import org.luaj.debug.net.DebugSupport;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestDisconnect; 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;
import org.luaj.debug.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseCallgraph; import org.luaj.debug.response.DebugResponseCallgraph;
import org.luaj.debug.response.DebugResponseStack; import org.luaj.debug.response.DebugResponseStack;
import org.luaj.debug.response.DebugResponseVariables; import org.luaj.debug.response.DebugResponseVariables;
@@ -241,7 +237,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
private void cancelStepping() { private void cancelStepping() {
if (debugSupport != null) { if (debugSupport != null) {
debugSupport.notifyDebugEvent( debugSupport.notifyDebugEvent(
new DebugEvent(DebugEventType.resumedOnSteppingEnd)); new DebugMessage(DebugMessageType.resumedOnSteppingEnd));
} }
stepping = STEP_NONE; stepping = STEP_NONE;
steppingFrame = -1; steppingFrame = -1;
@@ -250,8 +246,8 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
private void suspendOnStepping() { private void suspendOnStepping() {
if (debugSupport != null) { if (debugSupport != null) {
debugSupport.notifyDebugEvent(new DebugEvent( debugSupport.notifyDebugEvent(
DebugEventType.suspendedOnStepping)); new DebugMessage(DebugMessageType.suspendedOnStepping));
} }
suspended = true; suspended = true;
steppingFrame = -1; steppingFrame = -1;
@@ -274,7 +270,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
// ------------------ commands coming from the debugger ------------------- // ------------------ commands coming from the debugger -------------------
public void handleRequest(DebugRequest request) { public void handleRequest(DebugMessage request) {
if (this.debugSupport == null) { if (this.debugSupport == null) {
throw new IllegalStateException( throw new IllegalStateException(
"DebugSupport must be defined."); "DebugSupport must be defined.");
@@ -284,65 +280,67 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
System.out.println("DebugStackState is handling request: " System.out.println("DebugStackState is handling request: "
+ request.toString()); + request.toString());
DebugRequestType requestType = request.getType(); DebugMessageType requestType = request.getType();
if (DebugRequestType.start == requestType) { if (DebugMessageType.start == requestType) {
DebugEvent event = new DebugEvent(DebugEventType.started); DebugMessage event = new DebugMessage(DebugMessageType.started);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
cancelSuspendOnStart(); cancelSuspendOnStart();
} else if (DebugRequestType.exit == requestType) { } else if (DebugMessageType.exit == requestType) {
stop(); stop();
} else if (DebugRequestType.disconnect == requestType) { } else if (DebugMessageType.disconnect == requestType) {
DebugRequestDisconnect disconnectRequest DebugRequestDisconnect disconnectRequest
= (DebugRequestDisconnect) request; = (DebugRequestDisconnect) request;
int connectionId = disconnectRequest.getSessionId(); int connectionId = disconnectRequest.getSessionId();
disconnect(connectionId); disconnect(connectionId);
} else if (DebugRequestType.reset == requestType) { } else if (DebugMessageType.debugServiceDown == requestType) {
disconnectFromDebugService();
} else if (DebugMessageType.reset == requestType) {
reset(); reset();
} else if (DebugRequestType.suspend == requestType) { } else if (DebugMessageType.suspend == requestType) {
suspend(); suspend();
DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient); DebugMessage event = new DebugMessage(DebugMessageType.suspendedByClient);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
} else if (DebugRequestType.resume == requestType) { } else if (DebugMessageType.resume == requestType) {
resume(); resume();
DebugEvent event = new DebugEvent(DebugEventType.resumedByClient); DebugMessage event = new DebugMessage(DebugMessageType.resumedByClient);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
} else if (DebugRequestType.lineBreakpointSet == requestType) { } else if (DebugMessageType.lineBreakpointSet == requestType) {
DebugRequestLineBreakpointToggle setBreakpointRequest DebugRequestLineBreakpointToggle setBreakpointRequest
= (DebugRequestLineBreakpointToggle) request; = (DebugRequestLineBreakpointToggle) request;
setBreakpoint(setBreakpointRequest.getSource(), setBreakpoint(setBreakpointRequest.getSource(),
setBreakpointRequest.getLineNumber()); setBreakpointRequest.getLineNumber());
} else if (DebugRequestType.lineBreakpointClear == requestType) { } else if (DebugMessageType.lineBreakpointClear == requestType) {
DebugRequestLineBreakpointToggle clearBreakpointRequest DebugRequestLineBreakpointToggle clearBreakpointRequest
= (DebugRequestLineBreakpointToggle) request; = (DebugRequestLineBreakpointToggle) request;
clearBreakpoint(clearBreakpointRequest.getSource(), clearBreakpoint(clearBreakpointRequest.getSource(),
clearBreakpointRequest.getLineNumber()); clearBreakpointRequest.getLineNumber());
} else if (DebugRequestType.callgraph == requestType) { } else if (DebugMessageType.callgraph == requestType) {
DebugResponseCallgraph callgraph DebugResponseCallgraph callgraph
= new DebugResponseCallgraph(getCallgraph()); = new DebugResponseCallgraph(getCallgraph());
debugSupport.notifyDebugEvent(callgraph); debugSupport.notifyDebugEvent(callgraph);
} else if (DebugRequestType.stack == requestType) { } else if (DebugMessageType.stack == requestType) {
DebugRequestStack stackRequest = (DebugRequestStack) request; DebugRequestStack stackRequest = (DebugRequestStack) request;
int index = stackRequest.getIndex(); int index = stackRequest.getIndex();
DebugResponseStack stackState DebugResponseStack stackState
= new DebugResponseStack(index, getStack(index)); = new DebugResponseStack(index, getStack(index));
debugSupport.notifyDebugEvent(stackState); debugSupport.notifyDebugEvent(stackState);
} else if (DebugRequestType.global == requestType) { } else if (DebugMessageType.global == requestType) {
DebugResponseVariables globals DebugResponseVariables globals
= new DebugResponseVariables(getGlobals(), DebugEventType.clientRequestGlobalReply); = new DebugResponseVariables(getGlobals(), DebugMessageType.clientRequestGlobalReply);
debugSupport.notifyDebugEvent(globals); debugSupport.notifyDebugEvent(globals);
} else if (DebugRequestType.stepInto == requestType) { } else if (DebugMessageType.stepInto == requestType) {
DebugEvent event = new DebugEvent( DebugMessage event = new DebugMessage(
DebugEventType.resumedOnSteppingInto); DebugMessageType.resumedOnSteppingInto);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
stepInto(); stepInto();
} else if (DebugRequestType.stepOver == requestType) { } else if (DebugMessageType.stepOver == requestType) {
DebugEvent event = new DebugEvent( DebugMessage event = new DebugMessage(
DebugEventType.resumedOnSteppingOver); DebugMessageType.resumedOnSteppingOver);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
stepOver(); stepOver();
} else if (DebugRequestType.stepReturn == requestType) { } else if (DebugMessageType.stepReturn == requestType) {
DebugEvent event = new DebugEvent( DebugMessage event = new DebugMessage(
DebugEventType.resumedOnSteppingReturn); DebugMessageType.resumedOnSteppingReturn);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
stepReturn(); stepReturn();
} else { } else {
@@ -393,16 +391,20 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
* VM execution. * VM execution.
*/ */
public void stop() { public void stop() {
if (this.debugSupport == null) { synchronized (this) {
throw new IllegalStateException( if (exiting) return;
"DebugSupport must be defined.");
}
DebugEvent event = new DebugEvent(DebugEventType.terminated); if (this.debugSupport == null) {
debugSupport.notifyDebugEvent(event); throw new IllegalStateException(
exit(); "DebugSupport must be defined.");
debugSupport.stop(); }
debugSupport = null;
DebugMessage event = new DebugMessage(DebugMessageType.terminated);
debugSupport.notifyDebugEvent(event);
exit();
debugSupport.stop();
debugSupport = null;
}
} }
public void disconnect(int connectionId) { public void disconnect(int connectionId) {
@@ -412,11 +414,21 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
} }
reset(); reset();
DebugEvent event = new DebugEvent(DebugEventType.disconnected); DebugMessage event = new DebugMessage(DebugMessageType.disconnected);
debugSupport.notifyDebugEvent(event); debugSupport.notifyDebugEvent(event);
debugSupport.disconnect(connectionId); debugSupport.disconnect(connectionId);
} }
public void disconnectFromDebugService() {
if (this.debugSupport == null) {
throw new IllegalStateException(
"DebugSupport must be defined.");
}
reset();
debugSupport.disconnect();
}
public void reset() { public void reset() {
synchronized (this) { synchronized (this) {
this.breakpoints.clear(); this.breakpoints.clear();

View File

@@ -0,0 +1,41 @@
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);
}
}

View File

@@ -0,0 +1,123 @@
/*******************************************************************************
* 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 lineBreakpointSet = new DebugMessageType("lineBreakpointSet", 4);
public static final DebugMessageType lineBreakpointClear = new DebugMessageType("lineBreakpointClear", 5);
public static final DebugMessageType watchpointSet = new DebugMessageType("watchpointSet", 6);
public static final DebugMessageType watchpointClear = new DebugMessageType("watchpointClear", 7);
public static final DebugMessageType callgraph = new DebugMessageType("callgraph", 8);
public static final DebugMessageType stack = new DebugMessageType("stack", 9);
public static final DebugMessageType stepInto = new DebugMessageType("stepInto", 10);
public static final DebugMessageType stepOver = new DebugMessageType("stepOver", 11);
public static final DebugMessageType stepReturn = new DebugMessageType("stepReturn", 12);
public static final DebugMessageType global = new DebugMessageType("global", 13);
public static final DebugMessageType disconnect = new DebugMessageType("disconnect", 14);
public static final DebugMessageType reset = new DebugMessageType("reset", 15);
public static final DebugMessageType session = new DebugMessageType("session", 16);
// events
public static final DebugMessageType started = new DebugMessageType("started", 17);
public static final DebugMessageType suspendedByClient = new DebugMessageType("suspendedByClient", 18);
public static final DebugMessageType suspendedOnBreakpoint = new DebugMessageType("suspendedOnBreakpoint", 19);
public static final DebugMessageType suspendedOnWatchpoint = new DebugMessageType("suspendedOnWatchpoint", 20);
public static final DebugMessageType suspendedOnStepping = new DebugMessageType("suspendedOnStepping", 21);
public static final DebugMessageType suspendedOnError = new DebugMessageType("suspendedOnError", 22);
public static final DebugMessageType resumedByClient = new DebugMessageType("resumedByClient", 23);
public static final DebugMessageType resumedOnSteppingInto = new DebugMessageType("resumedOnSteppingInto", 24);
public static final DebugMessageType resumedOnSteppingOver = new DebugMessageType("resumedOnSteppingOver", 25);
public static final DebugMessageType resumedOnSteppingReturn = new DebugMessageType("resumedOnSteppingReturn", 26);
public static final DebugMessageType resumedOnSteppingEnd = new DebugMessageType("resumedOnSteppingEnd", 27);
public static final DebugMessageType resumedOnError = new DebugMessageType("resumedOnError", 28);
public static final DebugMessageType error = new DebugMessageType("error", 29);
public static final DebugMessageType terminated = new DebugMessageType("terminated", 30);
public static final DebugMessageType clientRequestCallgraphReply = new DebugMessageType("clientRequestCallgraphReply", 31);
public static final DebugMessageType clientRequestStackReply = new DebugMessageType("clientRequestStackReply", 32);
public static final DebugMessageType clientRequestGlobalReply = new DebugMessageType("clientRequestGlobalReply", 33);
public static final DebugMessageType disconnected = new DebugMessageType("disconnected", 34);
public static final DebugMessageType sessionId = new DebugMessageType("sessionId", 35);
public static final DebugMessageType debugServiceDown = new DebugMessageType("debugServiceDown", 36);
protected static DebugMessageType[] ENUMS = new DebugMessageType[] {
start,
resume,
suspend,
exit,
lineBreakpointSet,
lineBreakpointClear,
watchpointSet,
watchpointClear,
callgraph,
stack,
stepInto,
stepOver,
stepReturn,
global,
disconnect,
reset,
session,
started,
suspendedByClient,
suspendedOnBreakpoint,
suspendedOnWatchpoint,
suspendedOnStepping,
suspendedOnError,
resumedByClient,
resumedOnSteppingInto,
resumedOnSteppingOver,
resumedOnSteppingReturn,
resumedOnSteppingEnd,
resumedOnError,
error,
terminated,
clientRequestCallgraphReply,
clientRequestStackReply,
clientRequestGlobalReply,
disconnected,
sessionId,
debugServiceDown
};
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];
}
}

View File

@@ -6,15 +6,11 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.event.DebugEvent;
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.DebugEventType;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestDisconnect; 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.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseCallgraph; import org.luaj.debug.response.DebugResponseCallgraph;
import org.luaj.debug.response.DebugResponseSession; import org.luaj.debug.response.DebugResponseSession;
import org.luaj.debug.response.DebugResponseStack; import org.luaj.debug.response.DebugResponseStack;
@@ -52,19 +48,17 @@ public class SerializationHelper {
static final int SERIAL_TYPE_TableVariable = 1; static final int SERIAL_TYPE_TableVariable = 1;
static final int SERIAL_TYPE_Variable = 2; static final int SERIAL_TYPE_Variable = 2;
static final int SERIAL_TYPE_StackFrame = 3; static final int SERIAL_TYPE_StackFrame = 3;
static final int SERIAL_TYPE_DebugRequestType = 4; static final int SERIAL_TYPE_DebugMessageType = 4;
static final int SERIAL_TYPE_DebugRequest = 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_DebugRequestDisconnect = 8;
static final int SERIAL_TYPE_DebugEventType = 9; static final int SERIAL_TYPE_DebugEventBreakpoint = 9;
static final int SERIAL_TYPE_DebugEvent = 10; static final int SERIAL_TYPE_DebugEventError = 10;
static final int SERIAL_TYPE_DebugEventBreakpoint = 11; static final int SERIAL_TYPE_DebugResponseCallgraph = 11;
static final int SERIAL_TYPE_DebugEventError = 12; static final int SERIAL_TYPE_DebugResponseVariables = 12;
static final int SERIAL_TYPE_DebugResponseCallgraph = 13; static final int SERIAL_TYPE_DebugResponseStack = 13;
static final int SERIAL_TYPE_DebugResponseVariables = 14; static final int SERIAL_TYPE_DebugResponseSession = 14;
static final int SERIAL_TYPE_DebugResponseStack = 15;
static final int SERIAL_TYPE_DebugResponseSession = 16;
public static void serialize(Serializable object, DataOutputStream dout) public static void serialize(Serializable object, DataOutputStream dout)
throws IOException { throws IOException {
@@ -80,9 +74,9 @@ public class SerializationHelper {
} else if (object instanceof StackFrame) { } else if (object instanceof StackFrame) {
dout.writeInt(SERIAL_TYPE_StackFrame); dout.writeInt(SERIAL_TYPE_StackFrame);
StackFrame.serialize(dout, (StackFrame) object); StackFrame.serialize(dout, (StackFrame) object);
} else if (object instanceof DebugRequestType) { } else if (object instanceof DebugMessageType) {
dout.writeInt(SERIAL_TYPE_DebugRequestType); dout.writeInt(SERIAL_TYPE_DebugMessageType);
DebugRequestType.serialize(dout, (DebugRequestType) object); DebugMessageType.serialize(dout, (DebugMessageType) object);
} else if (object instanceof DebugRequestStack) { } else if (object instanceof DebugRequestStack) {
dout.writeInt(SERIAL_TYPE_DebugRequestStack); dout.writeInt(SERIAL_TYPE_DebugRequestStack);
DebugRequestStack.serialize(dout, (DebugRequestStack) object); DebugRequestStack.serialize(dout, (DebugRequestStack) object);
@@ -93,12 +87,6 @@ public class SerializationHelper {
} else if (object instanceof DebugRequestDisconnect) { } else if (object instanceof DebugRequestDisconnect) {
dout.writeInt(SERIAL_TYPE_DebugRequestDisconnect); dout.writeInt(SERIAL_TYPE_DebugRequestDisconnect);
DebugRequestDisconnect.serialize(dout, (DebugRequestDisconnect) object); DebugRequestDisconnect.serialize(dout, (DebugRequestDisconnect) object);
} else if (object instanceof DebugRequest) {
dout.writeInt(SERIAL_TYPE_DebugRequest);
DebugRequest.serialize(dout, (DebugRequest) object);
} else if (object instanceof DebugEventType) {
dout.writeInt(SERIAL_TYPE_DebugEventType);
DebugEventType.serialize(dout, (DebugEventType) 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);
@@ -118,9 +106,9 @@ public class SerializationHelper {
} else if (object instanceof DebugResponseSession) { } else if (object instanceof DebugResponseSession) {
dout.writeInt(SERIAL_TYPE_DebugResponseSession); dout.writeInt(SERIAL_TYPE_DebugResponseSession);
DebugResponseSession.serialize(dout, (DebugResponseSession) object); DebugResponseSession.serialize(dout, (DebugResponseSession) object);
} else if (object instanceof DebugEvent) { } else if (object instanceof DebugMessage) {
dout.writeInt(SERIAL_TYPE_DebugEvent); dout.writeInt(SERIAL_TYPE_DebugMessage);
DebugEvent.serialize(dout, (DebugEvent) object); DebugMessage.serialize(dout, (DebugMessage) object);
} else { } else {
// catch the errors: forgot to implement // catch the errors: forgot to implement
// serialization/deserialization // serialization/deserialization
@@ -146,8 +134,8 @@ public class SerializationHelper {
case SERIAL_TYPE_StackFrame: case SERIAL_TYPE_StackFrame:
object = StackFrame.deserialize(din); object = StackFrame.deserialize(din);
break; break;
case SERIAL_TYPE_DebugRequestType: case SERIAL_TYPE_DebugMessageType:
object = DebugRequestType.deserialize(din); object = DebugMessageType.deserialize(din);
break; break;
case SERIAL_TYPE_DebugRequestStack: case SERIAL_TYPE_DebugRequestStack:
object = DebugRequestStack.deserialize(din); object = DebugRequestStack.deserialize(din);
@@ -158,12 +146,6 @@ public class SerializationHelper {
case SERIAL_TYPE_DebugRequestDisconnect: case SERIAL_TYPE_DebugRequestDisconnect:
object = DebugRequestDisconnect.deserialize(din); object = DebugRequestDisconnect.deserialize(din);
break; break;
case SERIAL_TYPE_DebugRequest:
object = DebugRequest.deserialize(din);
break;
case SERIAL_TYPE_DebugEventType:
object = DebugEventType.deserialize(din);
break;
case SERIAL_TYPE_DebugEventBreakpoint: case SERIAL_TYPE_DebugEventBreakpoint:
object = DebugEventBreakpoint.deserialize(din); object = DebugEventBreakpoint.deserialize(din);
break; break;
@@ -182,8 +164,8 @@ public class SerializationHelper {
case SERIAL_TYPE_DebugResponseSession: case SERIAL_TYPE_DebugResponseSession:
object = DebugResponseSession.deserialize(din); object = DebugResponseSession.deserialize(din);
break; break;
case SERIAL_TYPE_DebugEvent: case SERIAL_TYPE_DebugMessage:
object = DebugEvent.deserialize(din); object = DebugMessage.deserialize(din);
break; break;
default: default:
throw new RuntimeException( throw new RuntimeException(

View File

@@ -1,67 +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.Serializable;
import org.luaj.debug.SerializationHelper;
public class DebugEvent implements Serializable {
protected DebugEventType type;
public DebugEvent(DebugEventType type) {
this.type = type;
}
public DebugEventType getType() {
return type;
}
public void setType(DebugEventType type) {
this.type = type;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
return type.toString();
}
public static void serialize(DataOutputStream out, DebugEvent object)
throws IOException {
SerializationHelper.serialize(object.getType(), out);
}
public static DebugEvent deserialize(DataInputStream in) throws IOException {
DebugEventType type = (DebugEventType) SerializationHelper
.deserialize(in);
return new DebugEvent(type);
}
}

View File

@@ -25,13 +25,16 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
public class DebugEventBreakpoint extends DebugEvent { import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
public class DebugEventBreakpoint extends DebugMessage {
protected String source; protected String source;
protected int lineNumber; protected int lineNumber;
public DebugEventBreakpoint(String source, int lineNumber) { public DebugEventBreakpoint(String source, int lineNumber) {
super(DebugEventType.suspendedOnBreakpoint); super(DebugMessageType.suspendedOnBreakpoint);
if (source == null) { if (source == null) {
throw new IllegalArgumentException("argument source cannot be null"); throw new IllegalArgumentException("argument source cannot be null");
} }
@@ -69,7 +72,7 @@ public class DebugEventBreakpoint extends DebugEvent {
out.writeInt(object.getLineNumber()); out.writeInt(object.getLineNumber());
} }
public static DebugEvent deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
String source = in.readUTF(); String source = in.readUTF();
int lineNo = in.readInt(); int lineNo = in.readInt();

View File

@@ -25,12 +25,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
public class DebugEventError extends DebugEvent { import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
public class DebugEventError extends DebugMessage {
protected String cause; protected String cause;
protected String trace; protected String trace;
public DebugEventError(String cause, String trace) { public DebugEventError(String cause, String trace) {
super(DebugEventType.error); super(DebugMessageType.error);
this.cause = cause; this.cause = cause;
this.trace = trace; this.trace = trace;
} }
@@ -58,7 +61,7 @@ public class DebugEventError extends DebugEvent {
out.writeUTF(object.getTrace()); out.writeUTF(object.getTrace());
} }
public static DebugEvent deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
String detail = in.readUTF(); String detail = in.readUTF();
String trace = in.readUTF(); String trace = in.readUTF();
return new DebugEventError(detail, trace); return new DebugEventError(detail, trace);

View File

@@ -21,6 +21,8 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.debug.event; package org.luaj.debug.event;
import org.luaj.debug.DebugMessage;
public interface DebugEventListener { public interface DebugEventListener {
public void notifyDebugEvent(DebugEvent event); public void notifyDebugEvent(DebugMessage event);
} }

View File

@@ -1,91 +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.IOException;
import org.luaj.debug.EnumType;
public class DebugEventType extends EnumType {
public static DebugEventType started = new DebugEventType("started", 0);
public static DebugEventType suspendedByClient = new DebugEventType("suspendedByClient", 1);
public static DebugEventType suspendedOnBreakpoint = new DebugEventType("suspendedOnBreakpoint", 2);
public static DebugEventType suspendedOnWatchpoint = new DebugEventType("suspendedOnWatchpoint", 3);
public static DebugEventType suspendedOnStepping = new DebugEventType("suspendedOnStepping", 4);
public static DebugEventType suspendedOnError = new DebugEventType("suspendedOnError", 5);
public static DebugEventType resumedByClient = new DebugEventType("resumedByClient", 6);
public static DebugEventType resumedOnSteppingInto = new DebugEventType("resumedOnSteppingInto", 7);
public static DebugEventType resumedOnSteppingOver = new DebugEventType("resumedOnSteppingOver", 8);
public static DebugEventType resumedOnSteppingReturn = new DebugEventType("resumedOnSteppingReturn", 9);
public static DebugEventType resumedOnSteppingEnd = new DebugEventType("resumedOnSteppingEnd", 10);
public static DebugEventType resumedOnError = new DebugEventType("resumedOnError", 11);
public static DebugEventType error = new DebugEventType("error", 12);
public static DebugEventType terminated = new DebugEventType("terminated", 13);
public static DebugEventType clientRequestCallgraphReply
= new DebugEventType("clientRequestCallgraphReply", 14);
public static DebugEventType clientRequestStackReply
= new DebugEventType("clientRequestStackReply", 15);
public static DebugEventType clientRequestGlobalReply
= new DebugEventType("clientRequestGlobalReply", 16);
public static DebugEventType disconnected
= new DebugEventType("disconnected", 17);
public static DebugEventType session
= new DebugEventType("session", 17);
protected static DebugEventType[] ENUMS = new DebugEventType[] {
started,
suspendedByClient,
suspendedOnBreakpoint,
suspendedOnWatchpoint,
suspendedOnStepping,
suspendedOnError,
resumedByClient,
resumedOnSteppingInto,
resumedOnSteppingOver,
resumedOnSteppingReturn,
resumedOnSteppingEnd,
resumedOnError,
error,
terminated,
clientRequestCallgraphReply,
clientRequestStackReply,
clientRequestGlobalReply,
disconnected,
session
};
protected DebugEventType(String name, int ordinal) {
super(name, ordinal);
}
public static DebugEventType deserialize(DataInputStream in)
throws IOException {
int ordinal = in.readInt();
if (ordinal < 0 || ordinal >= ENUMS.length) {
throw new RuntimeException("DebugEventType: ordinal is out of the range.");
}
return ENUMS[ordinal];
}
}

View File

@@ -3,16 +3,55 @@ package org.luaj.debug.net;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.DebugLuaState; import org.luaj.debug.DebugLuaState;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.event.DebugEventListener; import org.luaj.debug.event.DebugEventListener;
import org.luaj.debug.request.DebugRequestListener; import org.luaj.debug.request.DebugRequestListener;
/** /**
* DebugSupport provides the network communication support for the debugger and * DebugSupport provides the network communication support between the luaj-vm
* debug clients. * and debug clients.
*/ */
public interface DebugSupport extends DebugRequestListener, DebugEventListener { public abstract class DebugSupport implements DebugRequestListener, DebugEventListener {
public void start() throws IOException;
public void stop(); public abstract void start() throws IOException;
public void setDebugStackState(DebugLuaState vm);
public void disconnect(int id); public abstract void stop();
/**
* Disconnect all connected clients.
*/
public abstract void disconnect();
/**
* Disconnect the client with the given id.
* @param id -- client id
*/
public abstract void disconnect(int id);
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;
}
} }

View File

@@ -0,0 +1,141 @@
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.SerializationHelper;
import org.luaj.debug.event.DebugEventListener;
import org.luaj.debug.response.DebugResponseSession;
public class ClientConnectionTask implements Runnable, DebugEventListener {
private static final boolean TRACE = true; //(null != System.getProperty("TRACE"));
protected String host;
protected int port;
DebugSupportImpl debugSupport;
protected boolean bDisconnected = false;
protected SocketConnection connection;
protected DataInputStream inStream;
protected DataOutputStream outStream;
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);
// 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's time to exit.
} catch (IOException e) {
e.printStackTrace();
// if the connected debugging client aborted abnormally,
// discard the current connection.
handleRequest(new DebugMessage(DebugMessageType.reset));
debugSupport.disconnect(1);
} finally {
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());
if (request.getType() == DebugMessageType.session) {
notifyDebugEvent(new DebugResponseSession(1));
} else {
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();
}
}
}

View File

@@ -2,74 +2,71 @@ package org.luaj.debug.net.j2me;
import java.io.IOException; import java.io.IOException;
import javax.microedition.io.Connector; import org.luaj.debug.DebugMessage;
import javax.microedition.io.ServerSocketConnection;
import javax.microedition.io.SocketConnection;
import org.luaj.debug.DebugLuaState;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.net.DebugSupport; import org.luaj.debug.net.DebugSupport;
import org.luaj.debug.request.DebugRequest;
public class DebugSupportImpl implements DebugSupport { /**
protected ServerSocketConnection serverConnection; * J2ME version of DebugSupport implementation. The vm will connect to a debug
* service hosted on a remote machine and have the debug service relay the
public DebugSupportImpl(int port) throws IOException { * debugging messages between the vm and the debug client.
this.serverConnection */
= (ServerSocketConnection) Connector.open( public class DebugSupportImpl extends DebugSupport {
"socket://:" + port); protected String host;
} protected int port;
ClientConnectionTask clientTask;
public synchronized void acceptClientConnection() Thread main;
throws IOException {
// Set up the request socket and request input + event output streams
SocketConnection clientDebugConnection
= (SocketConnection) serverConnection.acceptAndOpen();
clientDebugConnection.setSocketOption(SocketConnection.DELAY, 0);
clientDebugConnection.setSocketOption(SocketConnection.LINGER, 0);
clientDebugConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
clientDebugConnection.setSocketOption(SocketConnection.RCVBUF, 1024);
clientDebugConnection.setSocketOption(SocketConnection.SNDBUF, 1024);
//TODO....
}
protected void dispose() {
if (this.serverConnection != null) {
try {
serverConnection.close();
serverConnection = null;
} catch (IOException e) {
}
}
}
public void disconnect(int id) {
// TODO Auto-generated method stub
}
public void setDebugStackState(DebugLuaState vm) {
// TODO Auto-generated method stub
public DebugSupportImpl(String host, int port) throws IOException {
this.host = host;
this.port = port;
} }
public void start() throws IOException { public void start() throws IOException {
// TODO Auto-generated method stub 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() { public void stop() {
// TODO Auto-generated method stub setState(STOPPED);
disconnect(1);
} }
public void handleRequest(DebugRequest request) { public void disconnect() {
// TODO Auto-generated method stub clientTask.disconnect();
clientTask = null;
synchronized(main) {
main.notify();
}
} }
public void notifyDebugEvent(DebugEvent event) { public synchronized void disconnect(int id) {
// TODO Auto-generated method stub disconnect();
}
public synchronized void notifyDebugEvent(DebugMessage event) {
if (clientTask != null) {
clientTask.notifyDebugEvent(event);
}
} }
} }

View File

@@ -6,11 +6,10 @@ import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.net.Socket; import java.net.Socket;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper; import org.luaj.debug.SerializationHelper;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventListener; import org.luaj.debug.event.DebugEventListener;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseSession; import org.luaj.debug.response.DebugResponseSession;
public class ClientConnectionTask implements Runnable, DebugEventListener { public class ClientConnectionTask implements Runnable, DebugEventListener {
@@ -23,6 +22,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
protected DataInputStream requestReader; protected DataInputStream requestReader;
protected DataOutputStream eventWriter; protected DataOutputStream eventWriter;
protected DebugSupportImpl debugSupport; protected DebugSupportImpl debugSupport;
protected boolean isDisposed = false;
public ClientConnectionTask(DebugSupportImpl debugSupport, Socket socket) public ClientConnectionTask(DebugSupportImpl debugSupport, Socket socket)
throws IOException { throws IOException {
@@ -67,7 +67,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
data = new byte[size]; data = new byte[size];
requestReader.readFully(data); requestReader.readFully(data);
DebugRequest request = (DebugRequest) SerializationHelper DebugMessage request = (DebugMessage) SerializationHelper
.deserialize(data); .deserialize(data);
if (TRACE) { if (TRACE) {
System.out.println("SERVER receives request: " + request.toString()); System.out.println("SERVER receives request: " + request.toString());
@@ -83,33 +83,30 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
// if the connected debugging client aborted abnormally, // if the connected debugging client aborted abnormally,
// discard the current connection. // discard the current connection.
handleRequest(new DebugRequest(DebugRequestType.reset)); handleRequest(new DebugMessage(DebugMessageType.reset));
debugSupport.disconnect(getSessionId());
} finally { } finally {
dispose(); dispose();
} }
} }
public void handleRequest(DebugRequest request) { public void handleRequest(DebugMessage request) {
if (TRACE) { if (TRACE) {
System.out.println("SERVER handling request: " + request.toString()); System.out.println("SERVER handling request: " + request.toString());
} }
if (request.getType() == DebugRequestType.session) { if (request.getType() == DebugMessageType.session) {
notifyDebugEvent(new DebugResponseSession(getSessionId())); notifyDebugEvent(new DebugResponseSession(getSessionId()));
} else { } else {
debugSupport.handleRequest(request); debugSupport.handleRequest(request);
} }
} }
public void notifyDebugEvent(DebugEvent event) { public void notifyDebugEvent(DebugMessage event) {
if (TRACE) if (TRACE)
System.out.println("SERVER sending event: " + event.toString()); System.out.println("SERVER sending event: " + event.toString());
if (event == null)
System.out.println("notifyDebugEvent: event is null");
if (eventWriter == null)
System.out.println("notifyDebugEvent: eventWriter is null");
try { try {
byte[] data = SerializationHelper.serialize(event); byte[] data = SerializationHelper.serialize(event);
eventWriter.writeInt(data.length); eventWriter.writeInt(data.length);
@@ -120,7 +117,10 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
} }
} }
protected void dispose() { public void dispose() {
if ( this.isDisposed ) return;
this.isDisposed = true;
debugSupport.decrementClientCount(); debugSupport.decrementClientCount();
if (this.requestReader != null) { if (this.requestReader != null) {

View File

@@ -25,21 +25,18 @@ import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import org.luaj.debug.DebugLuaState; import org.luaj.debug.DebugMessage;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.net.DebugSupport; import org.luaj.debug.net.DebugSupport;
import org.luaj.debug.request.DebugRequest;
/**
* J2SE version of DebugSupport. The luaj-vm opens a port accepting the debug
* client connections. The current implementation allows the vm to accept one
* and only one debug client connection at any time.
*/
public class DebugSupportImpl extends DebugSupport {
public class DebugSupportImpl implements DebugSupport {
protected static final int UNKNOWN = 0;
protected static final int RUNNING = 1;
protected static final int STOPPED = 2;
protected int state = UNKNOWN;
protected int numClientConnectionsAllowed; protected int numClientConnectionsAllowed;
protected int numClientConnections = 0; protected int numClientConnections = 0;
protected DebugLuaState vm;
protected ServerSocket serverSocket; protected ServerSocket serverSocket;
protected int debugPort; protected int debugPort;
protected ClientConnectionTask clientConnectionTask; protected ClientConnectionTask clientConnectionTask;
@@ -75,10 +72,6 @@ public class DebugSupportImpl implements DebugSupport {
this.numClientConnectionsAllowed = connections; this.numClientConnectionsAllowed = connections;
} }
public void setDebugStackState(DebugLuaState vm) {
this.vm = vm;
}
public void start() throws IOException { public void start() throws IOException {
if (this.vm == null) { if (this.vm == null) {
throw new IllegalStateException( throw new IllegalStateException(
@@ -111,14 +104,6 @@ public class DebugSupportImpl implements DebugSupport {
return this.numClientConnections; return this.numClientConnections;
} }
protected synchronized void setState(int state) {
this.state = state;
}
protected synchronized boolean isRunning() {
return this.state == RUNNING;
}
public synchronized void stop() { public synchronized void stop() {
setState(STOPPED); setState(STOPPED);
if (clientConnectionTask != null) { if (clientConnectionTask != null) {
@@ -129,22 +114,16 @@ public class DebugSupportImpl implements DebugSupport {
/* /*
* (non-Javadoc) * (non-Javadoc)
* * @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.DebugMessage)
* @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.event.DebugEvent)
*/ */
public void notifyDebugEvent(DebugEvent event) { public void notifyDebugEvent(DebugMessage event) {
if (clientConnectionTask != null) { if (clientConnectionTask != null) {
clientConnectionTask.notifyDebugEvent(event); clientConnectionTask.notifyDebugEvent(event);
} }
} }
/* public synchronized void disconnect() {
* (non-Javadoc) disconnect(clientConnectionTask.getSessionId());
*
* @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest)
*/
public void handleRequest(DebugRequest request) {
vm.handleRequest(request);
} }
public synchronized void disconnect(int id) { public synchronized void disconnect(int id) {
@@ -152,26 +131,34 @@ public class DebugSupportImpl implements DebugSupport {
clientConnectionTask.disconnect(); clientConnectionTask.disconnect();
clientConnectionTask = null; clientConnectionTask = null;
} else { } else {
throw new RuntimeException("Internal Error: mismatching sesion Id: " + id + " current task: " + clientConnectionTask.getSessionId()); throw new RuntimeException("Internal Error: mismatching sesion Id");
} }
} }
public void acceptClientConnection() throws IOException { public void acceptClientConnection() throws IOException {
Socket clientSocket = serverSocket.accept(); try {
int count = getClientCount(); Socket clientSocket = serverSocket.accept();
if (count == numClientConnectionsAllowed) { int count = getClientCount();
clientSocket.close(); if (count == numClientConnectionsAllowed) {
} else { clientSocket.close();
synchronized(this) { } else {
incrementClientCount(); synchronized(this) {
this.clientConnectionTask = new ClientConnectionTask(this, clientSocket); incrementClientCount();
new Thread(clientConnectionTask).start(); this.clientConnectionTask = new ClientConnectionTask(this, clientSocket);
new Thread(clientConnectionTask).start();
}
} }
} finally {
dispose();
} }
} }
protected synchronized void dispose() { protected synchronized void dispose() {
this.clientConnectionTask = null; if (this.clientConnectionTask != null) {
clientConnectionTask.dispose();
clientConnectionTask = null;
}
if (this.serverSocket != null) { if (this.serverSocket != null) {
try { try {
serverSocket.close(); serverSocket.close();

View File

@@ -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.request;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.luaj.debug.Serializable;
import org.luaj.debug.SerializationHelper;
public class DebugRequest implements Serializable {
protected DebugRequestType type;
public DebugRequest(DebugRequestType type) {
this.type = type;
}
public DebugRequestType getType() {
return this.type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return type.toString();
}
public static void serialize(DataOutputStream out, DebugRequest request)
throws IOException {
DebugRequestType type = request.getType();
SerializationHelper.serialize(type, out);
}
public static DebugRequest deserialize(DataInputStream in) throws IOException {
DebugRequestType type = (DebugRequestType) SerializationHelper.deserialize(in);
return new DebugRequest(type);
}
}

View File

@@ -4,11 +4,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
public class DebugRequestDisconnect extends DebugRequest { import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
public class DebugRequestDisconnect extends DebugMessage {
protected int sessionId; protected int sessionId;
public DebugRequestDisconnect(int connectionId) { public DebugRequestDisconnect(int connectionId) {
super(DebugRequestType.disconnect); super(DebugMessageType.disconnect);
this.sessionId = connectionId; this.sessionId = connectionId;
} }
@@ -25,7 +28,7 @@ public class DebugRequestDisconnect extends DebugRequest {
out.writeInt(request.getSessionId()); out.writeInt(request.getSessionId());
} }
public static DebugRequest deserialize(DataInputStream in) public static DebugMessage deserialize(DataInputStream in)
throws IOException { throws IOException {
int id = in.readInt(); int id = in.readInt();

View File

@@ -25,14 +25,16 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper; import org.luaj.debug.SerializationHelper;
public class DebugRequestLineBreakpointToggle extends DebugRequest { public class DebugRequestLineBreakpointToggle extends DebugMessage {
protected String source; protected String source;
protected int lineNumber; protected int lineNumber;
public DebugRequestLineBreakpointToggle(DebugRequestType type, String source, int lineNumber) { public DebugRequestLineBreakpointToggle(DebugMessageType type, String source, int lineNumber) {
super(type); super(type);
if (lineNumber < 0) { if (lineNumber < 0) {
throw new IllegalArgumentException("lineNumber must be equal to greater than zero"); throw new IllegalArgumentException("lineNumber must be equal to greater than zero");
@@ -63,8 +65,8 @@ public class DebugRequestLineBreakpointToggle extends DebugRequest {
out.writeInt(request.getLineNumber()); out.writeInt(request.getLineNumber());
} }
public static DebugRequest deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
DebugRequestType type = (DebugRequestType)SerializationHelper.deserialize(in); DebugMessageType type = (DebugMessageType)SerializationHelper.deserialize(in);
String source = in.readUTF(); String source = in.readUTF();
int lineNo = in.readInt(); int lineNo = in.readInt();

View File

@@ -21,6 +21,8 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.debug.request; package org.luaj.debug.request;
import org.luaj.debug.DebugMessage;
public interface DebugRequestListener { public interface DebugRequestListener {
@@ -37,5 +39,5 @@ public interface DebugRequestListener {
* listing the (variable, value) pairs * listing the (variable, value) pairs
* step -- single step forward (go to next statement) * step -- single step forward (go to next statement)
*/ */
public void handleRequest(DebugRequest request); public void handleRequest(DebugMessage request);
} }

View File

@@ -25,13 +25,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.Serializable; import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
public class DebugRequestStack extends DebugRequest implements Serializable { public class DebugRequestStack extends DebugMessage {
protected int index; protected int index;
public DebugRequestStack(int index) { public DebugRequestStack(int index) {
super(DebugRequestType.stack); super(DebugMessageType.stack);
this.index = index; this.index = index;
} }
@@ -53,7 +54,7 @@ public class DebugRequestStack extends DebugRequest implements Serializable {
out.writeInt(request.getIndex()); out.writeInt(request.getIndex());
} }
public static DebugRequest deserialize(DataInputStream in) public static DebugMessage deserialize(DataInputStream in)
throws IOException { throws IOException {
int index = in.readInt(); int index = in.readInt();

View File

@@ -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.request;
import java.io.DataInputStream;
import java.io.IOException;
import org.luaj.debug.EnumType;
public class DebugRequestType extends EnumType {
public static final DebugRequestType start = new DebugRequestType("start", 0);
public static final DebugRequestType resume = new DebugRequestType("resume", 1);
public static final DebugRequestType suspend = new DebugRequestType("suspend", 2);
public static final DebugRequestType exit = new DebugRequestType("exit", 3);
public static final DebugRequestType lineBreakpointSet = new DebugRequestType("lineBreakpointSet", 4);
public static final DebugRequestType lineBreakpointClear = new DebugRequestType("lineBreakpointClear", 5);
public static final DebugRequestType watchpointSet = new DebugRequestType("watchpointSet", 6);
public static final DebugRequestType watchpointClear = new DebugRequestType("watchpointClear", 7);
public static final DebugRequestType callgraph = new DebugRequestType("callgraph", 8);
public static final DebugRequestType stack = new DebugRequestType("stack", 9);
public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10);
public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11);
public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12);
public static final DebugRequestType global = new DebugRequestType("global", 13);
public static final DebugRequestType disconnect = new DebugRequestType("disconnect", 14);
public static final DebugRequestType reset = new DebugRequestType("reset", 15);
public static final DebugRequestType session = new DebugRequestType("session", 16);
protected static final DebugRequestType[] ENUMS = new DebugRequestType[] {
start,
resume,
suspend,
exit,
lineBreakpointSet,
lineBreakpointClear,
watchpointSet,
watchpointClear,
callgraph,
stack,
stepInto,
stepOver,
stepReturn,
global,
disconnect,
reset,
session
};
public DebugRequestType(String name, int ordinal) {
super(name, ordinal);
}
public static DebugRequestType deserialize(DataInputStream in) throws IOException {
int ordinal = in.readInt();
if (ordinal < 0 || ordinal >= ENUMS.length) {
throw new RuntimeException("DebugRequestType: ordinal is out of the range.");
}
return ENUMS[ordinal];
}
}

View File

@@ -21,13 +21,15 @@
******************************************************************************/ ******************************************************************************/
package org.luaj.debug.request; package org.luaj.debug.request;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.EnumType; import org.luaj.debug.EnumType;
public class DebugRequestWatchpointToggle extends DebugRequest { public class DebugRequestWatchpointToggle extends DebugMessage {
public static class AccessType extends EnumType { public static class AccessType extends EnumType {
private static final long serialVersionUID = 3523086189648091587L; private static final long serialVersionUID = 3523086189648091587L;
public static final AccessType Ignore = new AccessType("Ignore", 0); public static final AccessType Ignore = new AccessType("Ignore", 0);
public static final AccessType Read = new AccessType("Read", 1); public static final AccessType Read = new AccessType("Read", 1);
public static final AccessType Modify = new AccessType("Modify", 2); public static final AccessType Modify = new AccessType("Modify", 2);
public static final AccessType ReadAndModify = new AccessType("ReadAndModify", 3); public static final AccessType ReadAndModify = new AccessType("ReadAndModify", 3);
@@ -44,8 +46,8 @@ public class DebugRequestWatchpointToggle extends DebugRequest {
String variableName, String variableName,
AccessType accessType) { AccessType accessType) {
super(accessType == AccessType.Ignore ? super(accessType == AccessType.Ignore ?
DebugRequestType.watchpointClear : DebugMessageType.watchpointClear :
DebugRequestType.watchpointSet); DebugMessageType.watchpointSet);
this.functionName = functionName; this.functionName = functionName;
this.variableName = variableName; this.variableName = variableName;
} }

View File

@@ -25,15 +25,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.StackFrame; import org.luaj.debug.StackFrame;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventType;
public class DebugResponseCallgraph extends DebugEvent { public class DebugResponseCallgraph extends DebugMessage {
protected StackFrame[] stackFrames; protected StackFrame[] stackFrames;
public DebugResponseCallgraph(StackFrame[] callgraph) { public DebugResponseCallgraph(StackFrame[] callgraph) {
super(DebugEventType.clientRequestCallgraphReply); super(DebugMessageType.clientRequestCallgraphReply);
if (callgraph == null) { if (callgraph == null) {
this.stackFrames = new StackFrame[0]; this.stackFrames = new StackFrame[0];
} else { } else {
@@ -64,7 +64,7 @@ public class DebugResponseCallgraph extends DebugEvent {
} }
} }
public static DebugEvent deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
int count = in.readInt(); int count = in.readInt();
StackFrame[] stackFrames = new StackFrame[count]; StackFrame[] stackFrames = new StackFrame[count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {

View File

@@ -4,14 +4,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.event.DebugEvent; import org.luaj.debug.DebugMessage;
import org.luaj.debug.event.DebugEventType; import org.luaj.debug.DebugMessageType;
public class DebugResponseSession extends DebugEvent { public class DebugResponseSession extends DebugMessage {
protected int sessionId; protected int sessionId;
public DebugResponseSession(int id) { public DebugResponseSession(int id) {
super(DebugEventType.session); super(DebugMessageType.session);
this.sessionId = id; this.sessionId = id;
} }
@@ -29,7 +29,7 @@ public class DebugResponseSession extends DebugEvent {
out.writeInt(response.getSessionId()); out.writeInt(response.getSessionId());
} }
public static DebugEvent deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
int id = in.readInt(); int id = in.readInt();
return new DebugResponseSession(id); return new DebugResponseSession(id);
} }

View File

@@ -4,16 +4,16 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper; import org.luaj.debug.SerializationHelper;
import org.luaj.debug.Variable; import org.luaj.debug.Variable;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventType;
public class DebugResponseStack extends DebugResponseVariables { public class DebugResponseStack extends DebugResponseVariables {
protected int stackFrameIndex; protected int stackFrameIndex;
public DebugResponseStack(int index, Variable[] variables) { public DebugResponseStack(int index, Variable[] variables) {
super(variables, DebugEventType.clientRequestStackReply); super(variables, DebugMessageType.clientRequestStackReply);
this.stackFrameIndex = index; this.stackFrameIndex = index;
} }
@@ -33,7 +33,7 @@ public class DebugResponseStack extends DebugResponseVariables {
} }
} }
public static DebugEvent deserialize(DataInputStream in) throws IOException { public static DebugMessage deserialize(DataInputStream in) throws IOException {
int index = in.readInt(); int index = in.readInt();
int count = in.readInt(); int count = in.readInt();

View File

@@ -25,15 +25,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper; import org.luaj.debug.SerializationHelper;
import org.luaj.debug.Variable; import org.luaj.debug.Variable;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventType;
public class DebugResponseVariables extends DebugEvent { public class DebugResponseVariables extends DebugMessage {
protected Variable[] variables; protected Variable[] variables;
public DebugResponseVariables(Variable[] variables, DebugEventType type) { public DebugResponseVariables(Variable[] variables, DebugMessageType type) {
super(type); super(type);
if (variables == null) { if (variables == null) {
this.variables = new Variable[0]; this.variables = new Variable[0];
@@ -60,7 +60,7 @@ public class DebugResponseVariables extends DebugEvent {
public static void serialize(DataOutputStream out, public static void serialize(DataOutputStream out,
DebugResponseVariables response) DebugResponseVariables response)
throws IOException { throws IOException {
DebugEventType.serialize(out, response.getType()); DebugMessageType.serialize(out, response.getType());
Variable[] variables = response.getVariables(); Variable[] variables = response.getVariables();
out.writeInt(variables == null ? 0 : variables.length); out.writeInt(variables == null ? 0 : variables.length);
for (int i = 0; i < variables.length; i++) { for (int i = 0; i < variables.length; i++) {
@@ -68,9 +68,9 @@ public class DebugResponseVariables extends DebugEvent {
} }
} }
public static DebugEvent deserialize(DataInputStream in) public static DebugMessage deserialize(DataInputStream in)
throws IOException { throws IOException {
DebugEventType type = DebugEventType.deserialize(in); DebugMessageType type = DebugMessageType.deserialize(in);
int count = in.readInt(); int count = in.readInt();
Variable[] variables = new Variable[count]; Variable[] variables = new Variable[count];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {

View File

@@ -2,37 +2,36 @@ package org.luaj.debug;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.SerializationHelper;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventBreakpoint;
import org.luaj.debug.event.DebugEventType;
import junit.framework.TestCase; import junit.framework.TestCase;
public class DebugEventTest extends TestCase { import org.luaj.debug.event.DebugEventBreakpoint;
public void testDebugEventSerialization() {
try {
DebugEvent event = new DebugEvent(DebugEventType.started);
byte[] data = SerializationHelper.serialize(event);
DebugEvent eventOut = (DebugEvent)SerializationHelper.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getType(), eventOut.getType());
} catch (IOException e) {
fail(e.getMessage());
}
}
public void testDebugEventBreakpointSerialization() { public class DebugEventTest extends TestCase {
try { public void testDebugEventSerialization() {
DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua", 100); try {
byte[] data = SerializationHelper.serialize(event); DebugMessage event = new DebugMessage(DebugMessageType.started);
DebugEventBreakpoint eventOut byte[] data = SerializationHelper.serialize(event);
= (DebugEventBreakpoint) SerializationHelper.deserialize(data); DebugMessage eventOut = (DebugMessage) SerializationHelper
assertNotNull(eventOut); .deserialize(data);
assertEquals(event.getSource(), eventOut.getSource()); assertNotNull(eventOut);
assertEquals(event.getLineNumber(), eventOut.getLineNumber()); assertEquals(event.getType(), eventOut.getType());
} catch (IOException e) { } catch (IOException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
public void testDebugEventBreakpointSerialization() {
try {
DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua",
100);
byte[] data = SerializationHelper.serialize(event);
DebugEventBreakpoint eventOut = (DebugEventBreakpoint) SerializationHelper
.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getSource(), eventOut.getSource());
assertEquals(event.getLineNumber(), eventOut.getLineNumber());
} catch (IOException e) {
fail(e.getMessage());
}
}
} }

View File

@@ -2,61 +2,60 @@ package org.luaj.debug;
import java.io.IOException; import java.io.IOException;
import org.luaj.debug.SerializationHelper;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
import org.luaj.debug.request.DebugRequestStack;
import org.luaj.debug.request.DebugRequestType;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
import org.luaj.debug.request.DebugRequestStack;
public class DebugRequestTest extends TestCase { public class DebugRequestTest extends TestCase {
public void testDebugRequestSerialization() { public void testDebugRequestSerialization() {
try { try {
DebugRequest request = new DebugRequest(DebugRequestType.resume); DebugMessage request = new DebugMessage(DebugMessageType.resume);
byte[] data = SerializationHelper.serialize(request); byte[] data = SerializationHelper.serialize(request);
DebugRequest requestOut DebugMessage requestOut = (DebugMessage) SerializationHelper
= (DebugRequest)SerializationHelper.deserialize(data); .deserialize(data);
assertNotNull(requestOut); assertNotNull(requestOut);
assertEquals(request.getType(), requestOut.getType()); assertEquals(request.getType(), requestOut.getType());
} catch (IOException e) { } catch (IOException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
public void testDebugRequestStackSerialization() { public void testDebugRequestStackSerialization() {
try { try {
DebugRequestStack request = new DebugRequestStack(1); DebugRequestStack request = new DebugRequestStack(1);
byte[] data = SerializationHelper.serialize(request); byte[] data = SerializationHelper.serialize(request);
DebugRequestStack requestOut DebugRequestStack requestOut = (DebugRequestStack) SerializationHelper
= (DebugRequestStack) SerializationHelper.deserialize(data); .deserialize(data);
assertNotNull(requestOut); assertNotNull(requestOut);
assertEquals(requestOut.getIndex(), 1); assertEquals(requestOut.getIndex(), 1);
} catch (IOException e) { } catch (IOException e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
public void testDebugRequestLineBreakpointToggleSerialization() { public void testDebugRequestLineBreakpointToggleSerialization() {
try try {
{ doTestDebugRequestLineBreakpointToggleSerialization(
doTestDebugRequestLineBreakpointToggleSerialization(DebugRequestType.lineBreakpointSet, "test.lua", 100); DebugMessageType.lineBreakpointSet, "test.lua", 100);
doTestDebugRequestLineBreakpointToggleSerialization(DebugRequestType.lineBreakpointClear, "test.lua", 50); doTestDebugRequestLineBreakpointToggleSerialization(
} catch (IOException e) { DebugMessageType.lineBreakpointClear, "test.lua", 50);
fail(e.getMessage()); } catch (IOException e) {
} fail(e.getMessage());
} }
}
private void doTestDebugRequestLineBreakpointToggleSerialization( private void doTestDebugRequestLineBreakpointToggleSerialization(
DebugRequestType type, String source, int lineNo) throws IOException { DebugMessageType type, String source, int lineNo)
DebugRequestLineBreakpointToggle request throws IOException {
= new DebugRequestLineBreakpointToggle(DebugRequestType.lineBreakpointSet, "test.lua", 100); DebugRequestLineBreakpointToggle request = new DebugRequestLineBreakpointToggle(
byte[] data = SerializationHelper.serialize(request); DebugMessageType.lineBreakpointSet, "test.lua", 100);
DebugRequestLineBreakpointToggle requestOut = byte[] data = SerializationHelper.serialize(request);
(DebugRequestLineBreakpointToggle) SerializationHelper.deserialize(data); DebugRequestLineBreakpointToggle requestOut = (DebugRequestLineBreakpointToggle) SerializationHelper
assertNotNull(requestOut); .deserialize(data);
assertEquals(request.getType(), requestOut.getType()); assertNotNull(requestOut);
assertEquals(request.getSource(), requestOut.getSource()); assertEquals(request.getType(), requestOut.getType());
assertEquals(request.getLineNumber(), requestOut.getLineNumber()); assertEquals(request.getSource(), requestOut.getSource());
} assertEquals(request.getLineNumber(), requestOut.getLineNumber());
}
} }

View File

@@ -1,33 +1,30 @@
package org.luaj.debug; package org.luaj.debug;
import org.luaj.debug.SerializationHelper;
import org.luaj.debug.event.DebugEventType;
import org.luaj.debug.request.DebugRequestType;
import junit.framework.TestCase; import junit.framework.TestCase;
public class EnumTypeTest extends TestCase { public class EnumTypeTest extends TestCase {
public void testDebugRequestTypeSerialization() { public void testDebugRequestTypeSerialization() {
try { try {
DebugRequestType type = DebugRequestType.lineBreakpointClear; DebugMessageType type = DebugMessageType.lineBreakpointClear;
byte[] data = SerializationHelper.serialize(type); byte[] data = SerializationHelper.serialize(type);
DebugRequestType typeOut DebugMessageType typeOut = (DebugMessageType) SerializationHelper
= (DebugRequestType) SerializationHelper.deserialize(data); .deserialize(data);
assertEquals(type, typeOut); assertEquals(type, typeOut);
} catch (Exception e) { } catch (Exception e) {
fail(e.getMessage()); fail(e.getMessage());
} }
} }
public void testDebugEventTypeSerialization() { public void testDebugEventTypeSerialization() {
try { try {
DebugEventType type = DebugEventType.error; DebugMessageType type = DebugMessageType.error;
byte[] data = SerializationHelper.serialize(type); byte[] data = SerializationHelper.serialize(type);
DebugEventType typeOut = (DebugEventType) SerializationHelper.deserialize(data); DebugMessageType typeOut = (DebugMessageType) SerializationHelper
assertNotNull(typeOut); .deserialize(data);
assertEquals(type, typeOut); assertNotNull(typeOut);
} catch (Exception e) { assertEquals(type, typeOut);
fail(e.getMessage()); } catch (Exception e) {
} fail(e.getMessage());
} }
}
} }