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">
<property name="version" value="0.9"/>
<property name="version" value="0.10"/>
<target name="clean">
<delete dir="build"/>

View File

@@ -26,17 +26,13 @@ import java.util.Hashtable;
import java.util.Vector;
import org.luaj.compiler.LexState;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventBreakpoint;
import org.luaj.debug.event.DebugEventError;
import org.luaj.debug.event.DebugEventType;
import org.luaj.debug.net.DebugSupport;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestDisconnect;
import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
import org.luaj.debug.request.DebugRequestListener;
import org.luaj.debug.request.DebugRequestStack;
import org.luaj.debug.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseCallgraph;
import org.luaj.debug.response.DebugResponseStack;
import org.luaj.debug.response.DebugResponseVariables;
@@ -241,7 +237,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
private void cancelStepping() {
if (debugSupport != null) {
debugSupport.notifyDebugEvent(
new DebugEvent(DebugEventType.resumedOnSteppingEnd));
new DebugMessage(DebugMessageType.resumedOnSteppingEnd));
}
stepping = STEP_NONE;
steppingFrame = -1;
@@ -250,8 +246,8 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
private void suspendOnStepping() {
if (debugSupport != null) {
debugSupport.notifyDebugEvent(new DebugEvent(
DebugEventType.suspendedOnStepping));
debugSupport.notifyDebugEvent(
new DebugMessage(DebugMessageType.suspendedOnStepping));
}
suspended = true;
steppingFrame = -1;
@@ -274,7 +270,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
// ------------------ commands coming from the debugger -------------------
public void handleRequest(DebugRequest request) {
public void handleRequest(DebugMessage request) {
if (this.debugSupport == null) {
throw new IllegalStateException(
"DebugSupport must be defined.");
@@ -284,65 +280,67 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
System.out.println("DebugStackState is handling request: "
+ request.toString());
DebugRequestType requestType = request.getType();
if (DebugRequestType.start == requestType) {
DebugEvent event = new DebugEvent(DebugEventType.started);
DebugMessageType requestType = request.getType();
if (DebugMessageType.start == requestType) {
DebugMessage event = new DebugMessage(DebugMessageType.started);
debugSupport.notifyDebugEvent(event);
cancelSuspendOnStart();
} else if (DebugRequestType.exit == requestType) {
} else if (DebugMessageType.exit == requestType) {
stop();
} else if (DebugRequestType.disconnect == requestType) {
} else if (DebugMessageType.disconnect == requestType) {
DebugRequestDisconnect disconnectRequest
= (DebugRequestDisconnect) request;
int connectionId = disconnectRequest.getSessionId();
disconnect(connectionId);
} else if (DebugRequestType.reset == requestType) {
} else if (DebugMessageType.debugServiceDown == requestType) {
disconnectFromDebugService();
} else if (DebugMessageType.reset == requestType) {
reset();
} else if (DebugRequestType.suspend == requestType) {
} else if (DebugMessageType.suspend == requestType) {
suspend();
DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient);
DebugMessage event = new DebugMessage(DebugMessageType.suspendedByClient);
debugSupport.notifyDebugEvent(event);
} else if (DebugRequestType.resume == requestType) {
} else if (DebugMessageType.resume == requestType) {
resume();
DebugEvent event = new DebugEvent(DebugEventType.resumedByClient);
DebugMessage event = new DebugMessage(DebugMessageType.resumedByClient);
debugSupport.notifyDebugEvent(event);
} else if (DebugRequestType.lineBreakpointSet == requestType) {
} else if (DebugMessageType.lineBreakpointSet == requestType) {
DebugRequestLineBreakpointToggle setBreakpointRequest
= (DebugRequestLineBreakpointToggle) request;
setBreakpoint(setBreakpointRequest.getSource(),
setBreakpointRequest.getLineNumber());
} else if (DebugRequestType.lineBreakpointClear == requestType) {
} else if (DebugMessageType.lineBreakpointClear == requestType) {
DebugRequestLineBreakpointToggle clearBreakpointRequest
= (DebugRequestLineBreakpointToggle) request;
clearBreakpoint(clearBreakpointRequest.getSource(),
clearBreakpointRequest.getLineNumber());
} else if (DebugRequestType.callgraph == requestType) {
} else if (DebugMessageType.callgraph == requestType) {
DebugResponseCallgraph callgraph
= new DebugResponseCallgraph(getCallgraph());
debugSupport.notifyDebugEvent(callgraph);
} else if (DebugRequestType.stack == requestType) {
} else if (DebugMessageType.stack == requestType) {
DebugRequestStack stackRequest = (DebugRequestStack) request;
int index = stackRequest.getIndex();
DebugResponseStack stackState
= new DebugResponseStack(index, getStack(index));
debugSupport.notifyDebugEvent(stackState);
} else if (DebugRequestType.global == requestType) {
} else if (DebugMessageType.global == requestType) {
DebugResponseVariables globals
= new DebugResponseVariables(getGlobals(), DebugEventType.clientRequestGlobalReply);
= new DebugResponseVariables(getGlobals(), DebugMessageType.clientRequestGlobalReply);
debugSupport.notifyDebugEvent(globals);
} else if (DebugRequestType.stepInto == requestType) {
DebugEvent event = new DebugEvent(
DebugEventType.resumedOnSteppingInto);
} else if (DebugMessageType.stepInto == requestType) {
DebugMessage event = new DebugMessage(
DebugMessageType.resumedOnSteppingInto);
debugSupport.notifyDebugEvent(event);
stepInto();
} else if (DebugRequestType.stepOver == requestType) {
DebugEvent event = new DebugEvent(
DebugEventType.resumedOnSteppingOver);
} else if (DebugMessageType.stepOver == requestType) {
DebugMessage event = new DebugMessage(
DebugMessageType.resumedOnSteppingOver);
debugSupport.notifyDebugEvent(event);
stepOver();
} else if (DebugRequestType.stepReturn == requestType) {
DebugEvent event = new DebugEvent(
DebugEventType.resumedOnSteppingReturn);
} else if (DebugMessageType.stepReturn == requestType) {
DebugMessage event = new DebugMessage(
DebugMessageType.resumedOnSteppingReturn);
debugSupport.notifyDebugEvent(event);
stepReturn();
} else {
@@ -393,17 +391,21 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
* VM execution.
*/
public void stop() {
synchronized (this) {
if (exiting) return;
if (this.debugSupport == null) {
throw new IllegalStateException(
"DebugSupport must be defined.");
}
DebugEvent event = new DebugEvent(DebugEventType.terminated);
DebugMessage event = new DebugMessage(DebugMessageType.terminated);
debugSupport.notifyDebugEvent(event);
exit();
debugSupport.stop();
debugSupport = null;
}
}
public void disconnect(int connectionId) {
if (this.debugSupport == null) {
@@ -412,11 +414,21 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
}
reset();
DebugEvent event = new DebugEvent(DebugEventType.disconnected);
DebugMessage event = new DebugMessage(DebugMessageType.disconnected);
debugSupport.notifyDebugEvent(event);
debugSupport.disconnect(connectionId);
}
public void disconnectFromDebugService() {
if (this.debugSupport == null) {
throw new IllegalStateException(
"DebugSupport must be defined.");
}
reset();
debugSupport.disconnect();
}
public void reset() {
synchronized (this) {
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.IOException;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventBreakpoint;
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.DebugRequestLineBreakpointToggle;
import org.luaj.debug.request.DebugRequestStack;
import org.luaj.debug.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseCallgraph;
import org.luaj.debug.response.DebugResponseSession;
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_Variable = 2;
static final int SERIAL_TYPE_StackFrame = 3;
static final int SERIAL_TYPE_DebugRequestType = 4;
static final int SERIAL_TYPE_DebugRequest = 5;
static final int SERIAL_TYPE_DebugMessageType = 4;
static final int SERIAL_TYPE_DebugMessage = 5;
static final int SERIAL_TYPE_DebugRequestStack = 6;
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 7;
static final int SERIAL_TYPE_DebugRequestDisconnect = 8;
static final int SERIAL_TYPE_DebugEventType = 9;
static final int SERIAL_TYPE_DebugEvent = 10;
static final int SERIAL_TYPE_DebugEventBreakpoint = 11;
static final int SERIAL_TYPE_DebugEventError = 12;
static final int SERIAL_TYPE_DebugResponseCallgraph = 13;
static final int SERIAL_TYPE_DebugResponseVariables = 14;
static final int SERIAL_TYPE_DebugResponseStack = 15;
static final int SERIAL_TYPE_DebugResponseSession = 16;
static final int SERIAL_TYPE_DebugEventBreakpoint = 9;
static final int SERIAL_TYPE_DebugEventError = 10;
static final int SERIAL_TYPE_DebugResponseCallgraph = 11;
static final int SERIAL_TYPE_DebugResponseVariables = 12;
static final int SERIAL_TYPE_DebugResponseStack = 13;
static final int SERIAL_TYPE_DebugResponseSession = 14;
public static void serialize(Serializable object, DataOutputStream dout)
throws IOException {
@@ -80,9 +74,9 @@ public class SerializationHelper {
} else if (object instanceof StackFrame) {
dout.writeInt(SERIAL_TYPE_StackFrame);
StackFrame.serialize(dout, (StackFrame) object);
} else if (object instanceof DebugRequestType) {
dout.writeInt(SERIAL_TYPE_DebugRequestType);
DebugRequestType.serialize(dout, (DebugRequestType) object);
} else if (object instanceof DebugMessageType) {
dout.writeInt(SERIAL_TYPE_DebugMessageType);
DebugMessageType.serialize(dout, (DebugMessageType) object);
} else if (object instanceof DebugRequestStack) {
dout.writeInt(SERIAL_TYPE_DebugRequestStack);
DebugRequestStack.serialize(dout, (DebugRequestStack) object);
@@ -93,12 +87,6 @@ public class SerializationHelper {
} else if (object instanceof DebugRequestDisconnect) {
dout.writeInt(SERIAL_TYPE_DebugRequestDisconnect);
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) {
dout.writeInt(SERIAL_TYPE_DebugEventBreakpoint);
DebugEventBreakpoint.serialize(dout, (DebugEventBreakpoint) object);
@@ -118,9 +106,9 @@ public class SerializationHelper {
} else if (object instanceof DebugResponseSession) {
dout.writeInt(SERIAL_TYPE_DebugResponseSession);
DebugResponseSession.serialize(dout, (DebugResponseSession) object);
} else if (object instanceof DebugEvent) {
dout.writeInt(SERIAL_TYPE_DebugEvent);
DebugEvent.serialize(dout, (DebugEvent) object);
} else if (object instanceof DebugMessage) {
dout.writeInt(SERIAL_TYPE_DebugMessage);
DebugMessage.serialize(dout, (DebugMessage) object);
} else {
// catch the errors: forgot to implement
// serialization/deserialization
@@ -146,8 +134,8 @@ public class SerializationHelper {
case SERIAL_TYPE_StackFrame:
object = StackFrame.deserialize(din);
break;
case SERIAL_TYPE_DebugRequestType:
object = DebugRequestType.deserialize(din);
case SERIAL_TYPE_DebugMessageType:
object = DebugMessageType.deserialize(din);
break;
case SERIAL_TYPE_DebugRequestStack:
object = DebugRequestStack.deserialize(din);
@@ -158,12 +146,6 @@ public class SerializationHelper {
case SERIAL_TYPE_DebugRequestDisconnect:
object = DebugRequestDisconnect.deserialize(din);
break;
case SERIAL_TYPE_DebugRequest:
object = DebugRequest.deserialize(din);
break;
case SERIAL_TYPE_DebugEventType:
object = DebugEventType.deserialize(din);
break;
case SERIAL_TYPE_DebugEventBreakpoint:
object = DebugEventBreakpoint.deserialize(din);
break;
@@ -182,8 +164,8 @@ public class SerializationHelper {
case SERIAL_TYPE_DebugResponseSession:
object = DebugResponseSession.deserialize(din);
break;
case SERIAL_TYPE_DebugEvent:
object = DebugEvent.deserialize(din);
case SERIAL_TYPE_DebugMessage:
object = DebugMessage.deserialize(din);
break;
default:
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.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 int lineNumber;
public DebugEventBreakpoint(String source, int lineNumber) {
super(DebugEventType.suspendedOnBreakpoint);
super(DebugMessageType.suspendedOnBreakpoint);
if (source == null) {
throw new IllegalArgumentException("argument source cannot be null");
}
@@ -69,7 +72,7 @@ public class DebugEventBreakpoint extends DebugEvent {
out.writeInt(object.getLineNumber());
}
public static DebugEvent deserialize(DataInputStream in) throws IOException {
public static DebugMessage deserialize(DataInputStream in) throws IOException {
String source = in.readUTF();
int lineNo = in.readInt();

View File

@@ -25,12 +25,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
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 trace;
public DebugEventError(String cause, String trace) {
super(DebugEventType.error);
super(DebugMessageType.error);
this.cause = cause;
this.trace = trace;
}
@@ -58,7 +61,7 @@ public class DebugEventError extends DebugEvent {
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 trace = in.readUTF();
return new DebugEventError(detail, trace);

View File

@@ -21,6 +21,8 @@
******************************************************************************/
package org.luaj.debug.event;
import org.luaj.debug.DebugMessage;
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 org.luaj.debug.DebugLuaState;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.event.DebugEventListener;
import org.luaj.debug.request.DebugRequestListener;
/**
* DebugSupport provides the network communication support for the debugger and
* debug clients.
* DebugSupport provides the network communication support between the luaj-vm
* and debug clients.
*/
public interface DebugSupport extends DebugRequestListener, DebugEventListener {
public void start() throws IOException;
public void stop();
public void setDebugStackState(DebugLuaState vm);
public void disconnect(int id);
public abstract class DebugSupport implements DebugRequestListener, DebugEventListener {
public abstract void start() throws IOException;
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 javax.microedition.io.Connector;
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.DebugMessage;
import org.luaj.debug.net.DebugSupport;
import org.luaj.debug.request.DebugRequest;
public class DebugSupportImpl implements DebugSupport {
protected ServerSocketConnection serverConnection;
public DebugSupportImpl(int port) throws IOException {
this.serverConnection
= (ServerSocketConnection) Connector.open(
"socket://:" + port);
}
public synchronized void acceptClientConnection()
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
/**
* 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
* debugging messages between the vm and the debug client.
*/
public class DebugSupportImpl extends DebugSupport {
protected String host;
protected int port;
ClientConnectionTask clientTask;
Thread main;
public DebugSupportImpl(String host, int port) throws IOException {
this.host = host;
this.port = port;
}
public void start() throws IOException {
// 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() {
// TODO Auto-generated method stub
setState(STOPPED);
disconnect(1);
}
public void handleRequest(DebugRequest request) {
// TODO Auto-generated method stub
}
public void notifyDebugEvent(DebugEvent event) {
// TODO Auto-generated method stub
public void disconnect() {
clientTask.disconnect();
clientTask = null;
synchronized(main) {
main.notify();
}
}
public synchronized void disconnect(int id) {
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.net.Socket;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventListener;
import org.luaj.debug.request.DebugRequest;
import org.luaj.debug.request.DebugRequestType;
import org.luaj.debug.response.DebugResponseSession;
public class ClientConnectionTask implements Runnable, DebugEventListener {
@@ -23,6 +22,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
protected DataInputStream requestReader;
protected DataOutputStream eventWriter;
protected DebugSupportImpl debugSupport;
protected boolean isDisposed = false;
public ClientConnectionTask(DebugSupportImpl debugSupport, Socket socket)
throws IOException {
@@ -67,7 +67,7 @@ public class ClientConnectionTask implements Runnable, DebugEventListener {
data = new byte[size];
requestReader.readFully(data);
DebugRequest request = (DebugRequest) SerializationHelper
DebugMessage request = (DebugMessage) SerializationHelper
.deserialize(data);
if (TRACE) {
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,
// discard the current connection.
handleRequest(new DebugRequest(DebugRequestType.reset));
handleRequest(new DebugMessage(DebugMessageType.reset));
debugSupport.disconnect(getSessionId());
} finally {
dispose();
}
}
public void handleRequest(DebugRequest request) {
public void handleRequest(DebugMessage request) {
if (TRACE) {
System.out.println("SERVER handling request: " + request.toString());
}
if (request.getType() == DebugRequestType.session) {
if (request.getType() == DebugMessageType.session) {
notifyDebugEvent(new DebugResponseSession(getSessionId()));
} else {
debugSupport.handleRequest(request);
}
}
public void notifyDebugEvent(DebugEvent event) {
public void notifyDebugEvent(DebugMessage event) {
if (TRACE)
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 {
byte[] data = SerializationHelper.serialize(event);
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();
if (this.requestReader != null) {

View File

@@ -25,21 +25,18 @@ import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import org.luaj.debug.DebugLuaState;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.DebugMessage;
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 numClientConnections = 0;
protected DebugLuaState vm;
protected ServerSocket serverSocket;
protected int debugPort;
protected ClientConnectionTask clientConnectionTask;
@@ -75,10 +72,6 @@ public class DebugSupportImpl implements DebugSupport {
this.numClientConnectionsAllowed = connections;
}
public void setDebugStackState(DebugLuaState vm) {
this.vm = vm;
}
public void start() throws IOException {
if (this.vm == null) {
throw new IllegalStateException(
@@ -111,14 +104,6 @@ public class DebugSupportImpl implements DebugSupport {
return this.numClientConnections;
}
protected synchronized void setState(int state) {
this.state = state;
}
protected synchronized boolean isRunning() {
return this.state == RUNNING;
}
public synchronized void stop() {
setState(STOPPED);
if (clientConnectionTask != null) {
@@ -129,22 +114,16 @@ public class DebugSupportImpl implements DebugSupport {
/*
* (non-Javadoc)
*
* @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.event.DebugEvent)
* @see org.luaj.debug.event.DebugEventListener#notifyDebugEvent(org.luaj.debug.DebugMessage)
*/
public void notifyDebugEvent(DebugEvent event) {
public void notifyDebugEvent(DebugMessage event) {
if (clientConnectionTask != null) {
clientConnectionTask.notifyDebugEvent(event);
}
}
/*
* (non-Javadoc)
*
* @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest)
*/
public void handleRequest(DebugRequest request) {
vm.handleRequest(request);
public synchronized void disconnect() {
disconnect(clientConnectionTask.getSessionId());
}
public synchronized void disconnect(int id) {
@@ -152,11 +131,12 @@ public class DebugSupportImpl implements DebugSupport {
clientConnectionTask.disconnect();
clientConnectionTask = null;
} 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 {
try {
Socket clientSocket = serverSocket.accept();
int count = getClientCount();
if (count == numClientConnectionsAllowed) {
@@ -168,10 +148,17 @@ public class DebugSupportImpl implements DebugSupport {
new Thread(clientConnectionTask).start();
}
}
} finally {
dispose();
}
}
protected synchronized void dispose() {
this.clientConnectionTask = null;
if (this.clientConnectionTask != null) {
clientConnectionTask.dispose();
clientConnectionTask = null;
}
if (this.serverSocket != null) {
try {
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.IOException;
public class DebugRequestDisconnect extends DebugRequest {
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
public class DebugRequestDisconnect extends DebugMessage {
protected int sessionId;
public DebugRequestDisconnect(int connectionId) {
super(DebugRequestType.disconnect);
super(DebugMessageType.disconnect);
this.sessionId = connectionId;
}
@@ -25,7 +28,7 @@ public class DebugRequestDisconnect extends DebugRequest {
out.writeInt(request.getSessionId());
}
public static DebugRequest deserialize(DataInputStream in)
public static DebugMessage deserialize(DataInputStream in)
throws IOException {
int id = in.readInt();

View File

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

View File

@@ -21,6 +21,8 @@
******************************************************************************/
package org.luaj.debug.request;
import org.luaj.debug.DebugMessage;
public interface DebugRequestListener {
@@ -37,5 +39,5 @@ public interface DebugRequestListener {
* listing the (variable, value) pairs
* 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.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;
public DebugRequestStack(int index) {
super(DebugRequestType.stack);
super(DebugMessageType.stack);
this.index = index;
}
@@ -53,7 +54,7 @@ public class DebugRequestStack extends DebugRequest implements Serializable {
out.writeInt(request.getIndex());
}
public static DebugRequest deserialize(DataInputStream in)
public static DebugMessage deserialize(DataInputStream in)
throws IOException {
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,9 +21,11 @@
******************************************************************************/
package org.luaj.debug.request;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.EnumType;
public class DebugRequestWatchpointToggle extends DebugRequest {
public class DebugRequestWatchpointToggle extends DebugMessage {
public static class AccessType extends EnumType {
private static final long serialVersionUID = 3523086189648091587L;
@@ -44,8 +46,8 @@ public class DebugRequestWatchpointToggle extends DebugRequest {
String variableName,
AccessType accessType) {
super(accessType == AccessType.Ignore ?
DebugRequestType.watchpointClear :
DebugRequestType.watchpointSet);
DebugMessageType.watchpointClear :
DebugMessageType.watchpointSet);
this.functionName = functionName;
this.variableName = variableName;
}

View File

@@ -25,15 +25,15 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.StackFrame;
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;
public DebugResponseCallgraph(StackFrame[] callgraph) {
super(DebugEventType.clientRequestCallgraphReply);
super(DebugMessageType.clientRequestCallgraphReply);
if (callgraph == null) {
this.stackFrames = new StackFrame[0];
} 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();
StackFrame[] stackFrames = new StackFrame[count];
for (int i = 0; i < count; i++) {

View File

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

View File

@@ -4,16 +4,16 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import org.luaj.debug.DebugMessage;
import org.luaj.debug.DebugMessageType;
import org.luaj.debug.SerializationHelper;
import org.luaj.debug.Variable;
import org.luaj.debug.event.DebugEvent;
import org.luaj.debug.event.DebugEventType;
public class DebugResponseStack extends DebugResponseVariables {
protected int stackFrameIndex;
public DebugResponseStack(int index, Variable[] variables) {
super(variables, DebugEventType.clientRequestStackReply);
super(variables, DebugMessageType.clientRequestStackReply);
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 count = in.readInt();

View File

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

View File

@@ -2,19 +2,17 @@ package org.luaj.debug;
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 org.luaj.debug.event.DebugEventBreakpoint;
public class DebugEventTest extends TestCase {
public void testDebugEventSerialization() {
try {
DebugEvent event = new DebugEvent(DebugEventType.started);
DebugMessage event = new DebugMessage(DebugMessageType.started);
byte[] data = SerializationHelper.serialize(event);
DebugEvent eventOut = (DebugEvent)SerializationHelper.deserialize(data);
DebugMessage eventOut = (DebugMessage) SerializationHelper
.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getType(), eventOut.getType());
} catch (IOException e) {
@@ -24,10 +22,11 @@ public class DebugEventTest extends TestCase {
public void testDebugEventBreakpointSerialization() {
try {
DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua", 100);
DebugEventBreakpoint event = new DebugEventBreakpoint("test.lua",
100);
byte[] data = SerializationHelper.serialize(event);
DebugEventBreakpoint eventOut
= (DebugEventBreakpoint) SerializationHelper.deserialize(data);
DebugEventBreakpoint eventOut = (DebugEventBreakpoint) SerializationHelper
.deserialize(data);
assertNotNull(eventOut);
assertEquals(event.getSource(), eventOut.getSource());
assertEquals(event.getLineNumber(), eventOut.getLineNumber());

View File

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

View File

@@ -1,18 +1,14 @@
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;
public class EnumTypeTest extends TestCase {
public void testDebugRequestTypeSerialization() {
try {
DebugRequestType type = DebugRequestType.lineBreakpointClear;
DebugMessageType type = DebugMessageType.lineBreakpointClear;
byte[] data = SerializationHelper.serialize(type);
DebugRequestType typeOut
= (DebugRequestType) SerializationHelper.deserialize(data);
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
.deserialize(data);
assertEquals(type, typeOut);
} catch (Exception e) {
fail(e.getMessage());
@@ -21,9 +17,10 @@ public class EnumTypeTest extends TestCase {
public void testDebugEventTypeSerialization() {
try {
DebugEventType type = DebugEventType.error;
DebugMessageType type = DebugMessageType.error;
byte[] data = SerializationHelper.serialize(type);
DebugEventType typeOut = (DebugEventType) SerializationHelper.deserialize(data);
DebugMessageType typeOut = (DebugMessageType) SerializationHelper
.deserialize(data);
assertNotNull(typeOut);
assertEquals(type, typeOut);
} catch (Exception e) {