1. updated DebugSupport to use one port for two-way communication
2. added a command line debug option to pause the VM on start 3. minor code clean up - replaced tabs with 4 white spaces
This commit is contained in:
@@ -37,9 +37,8 @@ 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.DebugResponse;
|
||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||
import org.luaj.debug.response.DebugResponseSimple;
|
||||
import org.luaj.debug.response.DebugResponseStack;
|
||||
import org.luaj.debug.response.DebugResponseVariables;
|
||||
import org.luaj.vm.CallInfo;
|
||||
import org.luaj.vm.LClosure;
|
||||
@@ -192,7 +191,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||
|
||||
if (DebugUtils.IS_DEBUG)
|
||||
DebugUtils.println("debugHook - executing line: " + line);
|
||||
|
||||
|
||||
int i = currentProto.code[pc];
|
||||
int opCode = LuaState.GET_OPCODE(i);
|
||||
if (isStepping() && opCode == LuaState.OP_RETURN && cc == 0) {
|
||||
@@ -298,7 +297,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||
|
||||
// ------------------ commands coming from the debugger -------------------
|
||||
|
||||
public DebugResponse handleRequest(DebugRequest request) {
|
||||
public void handleRequest(DebugRequest request) {
|
||||
if (this.debugSupport == null) {
|
||||
throw new IllegalStateException(
|
||||
"DebugStackState is not equiped with DebugSupport.");
|
||||
@@ -313,60 +312,59 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
||||
DebugEvent event = new DebugEvent(DebugEventType.started);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
cancelSuspendOnStart();
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.exit == requestType) {
|
||||
stop();
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.suspend == requestType) {
|
||||
suspend();
|
||||
DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.resume == requestType) {
|
||||
resume();
|
||||
DebugEvent event = new DebugEvent(DebugEventType.resumedByClient);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.lineBreakpointSet == requestType) {
|
||||
DebugRequestLineBreakpointToggle setBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
||||
DebugRequestLineBreakpointToggle setBreakpointRequest
|
||||
= (DebugRequestLineBreakpointToggle) request;
|
||||
setBreakpoint(setBreakpointRequest.getSource(),
|
||||
setBreakpointRequest.getLineNumber());
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.lineBreakpointClear == requestType) {
|
||||
DebugRequestLineBreakpointToggle clearBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
||||
DebugRequestLineBreakpointToggle clearBreakpointRequest
|
||||
= (DebugRequestLineBreakpointToggle) request;
|
||||
clearBreakpoint(clearBreakpointRequest.getSource(),
|
||||
clearBreakpointRequest.getLineNumber());
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.callgraph == requestType) {
|
||||
return new DebugResponseCallgraph(getCallgraph());
|
||||
DebugResponseCallgraph callgraph
|
||||
= new DebugResponseCallgraph(getCallgraph());
|
||||
debugSupport.notifyDebugEvent(callgraph);
|
||||
} else if (DebugRequestType.stack == requestType) {
|
||||
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
||||
int index = stackRequest.getIndex();
|
||||
return new DebugResponseVariables(getStack(index));
|
||||
DebugResponseStack stackState
|
||||
= new DebugResponseStack(index, getStack(index));
|
||||
debugSupport.notifyDebugEvent(stackState);
|
||||
} else if (DebugRequestType.global == requestType) {
|
||||
return new DebugResponseVariables(getGlobals());
|
||||
DebugResponseVariables globals
|
||||
= new DebugResponseVariables(getGlobals(), DebugEventType.clientRequestGlobalReply);
|
||||
debugSupport.notifyDebugEvent(globals);
|
||||
} else if (DebugRequestType.stepInto == requestType) {
|
||||
DebugEvent event = new DebugEvent(
|
||||
DebugEventType.resumedOnSteppingInto);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
stepInto();
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.stepOver == requestType) {
|
||||
DebugEvent event = new DebugEvent(
|
||||
DebugEventType.resumedOnSteppingOver);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
stepOver();
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else if (DebugRequestType.stepReturn == requestType) {
|
||||
DebugEvent event = new DebugEvent(
|
||||
DebugEventType.resumedOnSteppingReturn);
|
||||
debugSupport.notifyDebugEvent(event);
|
||||
stepReturn();
|
||||
return DebugResponseSimple.SUCCESS;
|
||||
} else {
|
||||
throw new java.lang.IllegalArgumentException("unkown request type: "
|
||||
+ request.getType());
|
||||
}
|
||||
|
||||
throw new java.lang.IllegalArgumentException("unkown request type: "
|
||||
+ request.getType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,37 +9,28 @@ import org.luaj.debug.event.DebugEvent;
|
||||
import org.luaj.debug.event.DebugEventListener;
|
||||
import org.luaj.debug.request.DebugRequest;
|
||||
import org.luaj.debug.request.DebugRequestListener;
|
||||
import org.luaj.debug.response.DebugResponse;
|
||||
|
||||
/**
|
||||
* DebugSupport provides the network communication support for the debugger and
|
||||
* debugee.
|
||||
*/
|
||||
public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
public abstract class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
protected static final int UNKNOWN = 0;
|
||||
protected static final int RUNNING = 1;
|
||||
protected static final int STOPPED = 2;
|
||||
|
||||
protected DebugLuaState vm;
|
||||
protected int requestPort;
|
||||
protected int eventPort;
|
||||
protected int debugPort;
|
||||
protected Thread requestWatcherThread;
|
||||
protected int state = UNKNOWN;
|
||||
protected DataInputStream requestReader;
|
||||
protected DataOutputStream requestWriter;
|
||||
protected DataOutputStream eventWriter;
|
||||
|
||||
public DebugSupport(int requestPort, int eventPort) {
|
||||
if (requestPort == -1) {
|
||||
public DebugSupport(int debugPort) {
|
||||
if (debugPort == -1) {
|
||||
throw new IllegalArgumentException("requestPort is invalid");
|
||||
}
|
||||
|
||||
if (eventPort == -1) {
|
||||
throw new IllegalArgumentException("eventPort is invalid");
|
||||
}
|
||||
|
||||
this.requestPort = requestPort;
|
||||
this.eventPort = eventPort;
|
||||
this.debugPort = debugPort;
|
||||
}
|
||||
|
||||
public void setDebugStackState(DebugLuaState vm) {
|
||||
@@ -57,14 +48,6 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
if (requestWriter != null) {
|
||||
try {
|
||||
requestWriter.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if (eventWriter != null) {
|
||||
try {
|
||||
eventWriter.close();
|
||||
@@ -81,7 +64,7 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
public synchronized void start() throws IOException {
|
||||
if (this.vm == null) {
|
||||
throw new IllegalStateException(
|
||||
"DebugStackState is not set. Please call setDebugStackState first.");
|
||||
"DebugLuaState is not set. Please call setDebugStackState first.");
|
||||
}
|
||||
|
||||
this.requestWatcherThread = new Thread(new Runnable() {
|
||||
@@ -93,8 +76,7 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
this.requestWatcherThread.start();
|
||||
this.state = RUNNING;
|
||||
|
||||
System.out.println("LuaJ debug server is started on ports: "
|
||||
+ requestPort + ", " + eventPort);
|
||||
System.out.println("LuaJ debug server is listening on port: " + debugPort);
|
||||
}
|
||||
|
||||
protected synchronized int getState() {
|
||||
@@ -107,28 +89,26 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
this.state = STOPPED;
|
||||
}
|
||||
|
||||
public abstract Object getClientConnection();
|
||||
|
||||
protected void loopForRequests() {
|
||||
try {
|
||||
while (getState() != STOPPED) {
|
||||
byte[] data = null;
|
||||
int size = requestReader.readInt();
|
||||
byte[] data = new byte[size];
|
||||
data = new byte[size];
|
||||
requestReader.readFully(data);
|
||||
|
||||
DebugRequest request = (DebugRequest) SerializationHelper
|
||||
.deserialize(data);
|
||||
if (DebugUtils.IS_DEBUG)
|
||||
DebugUtils.println("SERVER receives request: "
|
||||
+ request.toString());
|
||||
|
||||
DebugResponse response = handleRequest(request);
|
||||
data = SerializationHelper.serialize(response);
|
||||
requestWriter.writeInt(data.length);
|
||||
requestWriter.write(data);
|
||||
requestWriter.flush();
|
||||
if (DebugUtils.IS_DEBUG)
|
||||
DebugUtils.println("SERVER sends response: " + response);
|
||||
.deserialize(data);
|
||||
if (DebugUtils.IS_DEBUG) {
|
||||
DebugUtils.println("SERVER receives request: " + request.toString());
|
||||
}
|
||||
|
||||
handleRequest(request);
|
||||
}
|
||||
} catch (EOFException e) {
|
||||
// expected during shutdown
|
||||
// expected. it may occur depending on the timing during the termination
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -184,12 +164,11 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||
*
|
||||
* @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest)
|
||||
*/
|
||||
public DebugResponse handleRequest(DebugRequest request) {
|
||||
public void handleRequest(DebugRequest request) {
|
||||
if (DebugUtils.IS_DEBUG) {
|
||||
DebugUtils.println("handling request: " + request.toString());
|
||||
DebugUtils.println("SERVER handling request: " + request.toString());
|
||||
}
|
||||
|
||||
DebugResponse response = vm.handleRequest(request);
|
||||
return response;
|
||||
vm.handleRequest(request);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ 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.DebugResponseSimple;
|
||||
import org.luaj.debug.response.DebugResponseStack;
|
||||
import org.luaj.debug.response.DebugResponseVariables;
|
||||
|
||||
public class SerializationHelper {
|
||||
@@ -46,21 +46,21 @@ public class SerializationHelper {
|
||||
return object;
|
||||
}
|
||||
|
||||
static final int SERIAL_TYPE_NullableString = 0;
|
||||
static final int SERIAL_TYPE_TableVariable = 1;
|
||||
static final int SERIAL_TYPE_Variable = 2;
|
||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
||||
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
||||
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
||||
static final int SERIAL_TYPE_StackFrame = 6;
|
||||
static final int SERIAL_TYPE_DebugRequestType = 7;
|
||||
static final int SERIAL_TYPE_DebugRequest = 8;
|
||||
static final int SERIAL_TYPE_DebugRequestStack = 9;
|
||||
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 10;
|
||||
static final int SERIAL_TYPE_DebugEventType = 11;
|
||||
static final int SERIAL_TYPE_DebugEvent = 12;
|
||||
static final int SERIAL_TYPE_DebugEventBreakpoint = 13;
|
||||
static final int SERIAL_TYPE_DebugEventError = 14;
|
||||
static final int SERIAL_TYPE_NullableString = 0;
|
||||
static final int SERIAL_TYPE_TableVariable = 1;
|
||||
static final int SERIAL_TYPE_Variable = 2;
|
||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
||||
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
||||
static final int SERIAL_TYPE_DebugResponseStack = 5;
|
||||
static final int SERIAL_TYPE_StackFrame = 6;
|
||||
static final int SERIAL_TYPE_DebugRequestType = 7;
|
||||
static final int SERIAL_TYPE_DebugRequest = 8;
|
||||
static final int SERIAL_TYPE_DebugRequestStack = 9;
|
||||
static final int SERIAL_TYPE_DebugRequestLineBreakpointToggle = 10;
|
||||
static final int SERIAL_TYPE_DebugEventType = 11;
|
||||
static final int SERIAL_TYPE_DebugEvent = 12;
|
||||
static final int SERIAL_TYPE_DebugEventBreakpoint = 13;
|
||||
static final int SERIAL_TYPE_DebugEventError = 14;
|
||||
|
||||
public static void serialize(Serializable object, DataOutputStream dout)
|
||||
throws IOException {
|
||||
@@ -76,9 +76,9 @@ public class SerializationHelper {
|
||||
} else if (object instanceof StackFrame) {
|
||||
dout.writeInt(SERIAL_TYPE_StackFrame);
|
||||
StackFrame.serialize(dout, (StackFrame) object);
|
||||
} else if (object instanceof DebugResponseSimple) {
|
||||
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
||||
DebugResponseSimple.serialize(dout, (DebugResponseSimple) object);
|
||||
} else if (object instanceof DebugResponseStack) {
|
||||
dout.writeInt(SERIAL_TYPE_DebugResponseStack);
|
||||
DebugResponseStack.serialize(dout, (DebugResponseStack) object);
|
||||
} else if (object instanceof DebugResponseVariables) {
|
||||
dout.writeInt(SERIAL_TYPE_DebugResponseVariables);
|
||||
DebugResponseVariables.serialize(dout, (DebugResponseVariables) object);
|
||||
@@ -136,12 +136,12 @@ public class SerializationHelper {
|
||||
case SERIAL_TYPE_StackFrame:
|
||||
object = StackFrame.deserialize(din);
|
||||
break;
|
||||
case SERIAL_TYPE_DebugResponseSimple:
|
||||
object = DebugResponseSimple.deserialize(din);
|
||||
break;
|
||||
case SERIAL_TYPE_DebugResponseCallgraph:
|
||||
object = DebugResponseCallgraph.deserialize(din);
|
||||
break;
|
||||
case SERIAL_TYPE_DebugResponseStack:
|
||||
object = DebugResponseStack.deserialize(din);
|
||||
break;
|
||||
case SERIAL_TYPE_DebugResponseVariables:
|
||||
object = DebugResponseVariables.deserialize(din);
|
||||
break;
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.event;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -29,14 +29,14 @@ import org.luaj.debug.Serializable;
|
||||
import org.luaj.debug.SerializationHelper;
|
||||
|
||||
|
||||
public class DebugEvent implements Serializable {
|
||||
|
||||
public class DebugEvent implements Serializable {
|
||||
|
||||
protected DebugEventType type;
|
||||
|
||||
public DebugEvent(DebugEventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public DebugEventType getType() {
|
||||
return type;
|
||||
}
|
||||
@@ -45,20 +45,23 @@ public class DebugEvent implements Serializable {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.event;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -27,47 +27,52 @@ import java.io.IOException;
|
||||
|
||||
public class DebugEventBreakpoint extends DebugEvent {
|
||||
protected String source;
|
||||
|
||||
protected int lineNumber;
|
||||
|
||||
public DebugEventBreakpoint(String source, int lineNumber) {
|
||||
super(DebugEventType.suspendedOnBreakpoint);
|
||||
if (source == null) {
|
||||
throw new IllegalArgumentException("argument source cannot be null");
|
||||
throw new IllegalArgumentException("argument source cannot be null");
|
||||
}
|
||||
|
||||
|
||||
if (lineNumber <= 0) {
|
||||
throw new IllegalArgumentException("argument lineNumber must be positive integer");
|
||||
throw new IllegalArgumentException(
|
||||
"argument lineNumber must be positive integer");
|
||||
}
|
||||
|
||||
|
||||
this.source = source;
|
||||
this.lineNumber = lineNumber;
|
||||
}
|
||||
|
||||
|
||||
public String getSource() {
|
||||
return this.source;
|
||||
return this.source;
|
||||
}
|
||||
|
||||
|
||||
public int getLineNumber() {
|
||||
return this.lineNumber;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see lua.debug.DebugEvent#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return super.toString() + " source:" + getSource() + " line:" + getLineNumber();
|
||||
return super.toString() + " source:" + getSource() + " line:"
|
||||
+ getLineNumber();
|
||||
}
|
||||
|
||||
public static void serialize(DataOutputStream out, DebugEventBreakpoint object)
|
||||
throws IOException {
|
||||
out.writeUTF(object.getSource());
|
||||
out.writeInt(object.getLineNumber());
|
||||
}
|
||||
|
||||
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||
String source = in.readUTF();
|
||||
int lineNo = in.readInt();
|
||||
|
||||
return new DebugEventBreakpoint(source, lineNo);
|
||||
}
|
||||
public static void serialize(DataOutputStream out,
|
||||
DebugEventBreakpoint object) throws IOException {
|
||||
out.writeUTF(object.getSource());
|
||||
out.writeInt(object.getLineNumber());
|
||||
}
|
||||
|
||||
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||
String source = in.readUTF();
|
||||
int lineNo = in.readInt();
|
||||
|
||||
return new DebugEventBreakpoint(source, lineNo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.luaj.debug.EnumType;
|
||||
|
||||
|
||||
public class DebugEventType extends EnumType {
|
||||
public static DebugEventType started = new DebugEventType("started", 0);
|
||||
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);
|
||||
@@ -43,6 +43,12 @@ public class DebugEventType extends EnumType {
|
||||
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);
|
||||
|
||||
protected static DebugEventType[] ENUMS = new DebugEventType[] {
|
||||
started,
|
||||
@@ -58,7 +64,10 @@ public class DebugEventType extends EnumType {
|
||||
resumedOnSteppingEnd,
|
||||
resumedOnError,
|
||||
error,
|
||||
terminated
|
||||
terminated,
|
||||
clientRequestCallgraphReply,
|
||||
clientRequestStackReply,
|
||||
clientRequestGlobalReply
|
||||
};
|
||||
|
||||
protected DebugEventType(String name, int ordinal) {
|
||||
|
||||
@@ -9,90 +9,63 @@ import javax.microedition.io.SocketConnection;
|
||||
import org.luaj.debug.DebugSupport;
|
||||
import org.luaj.debug.event.DebugEvent;
|
||||
|
||||
|
||||
public class DebugSupportImpl extends DebugSupport {
|
||||
protected ServerSocketConnection requestServerConnection;
|
||||
protected SocketConnection requestSocketConnection;
|
||||
protected ServerSocketConnection serverConnection;
|
||||
protected SocketConnection clientDebugConnection;
|
||||
protected SocketConnection eventSocketConnection;
|
||||
|
||||
protected ServerSocketConnection eventServerConnection;
|
||||
protected SocketConnection eventSocketConnection;
|
||||
|
||||
public DebugSupportImpl(int requestPort,
|
||||
int eventPort) {
|
||||
super(requestPort, eventPort);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see lua.debug.j2se.DebugSupport#start()
|
||||
*/
|
||||
public DebugSupportImpl(int debugPort) {
|
||||
super(debugPort);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see lua.debug.j2se.DebugSupport#start()
|
||||
*/
|
||||
public synchronized void start() throws IOException {
|
||||
System.out.println("Starting the sockets....");
|
||||
// Set up the request socket and request input + output streams
|
||||
this.requestServerConnection
|
||||
= (ServerSocketConnection)Connector.open("socket://:" + this.requestPort);
|
||||
this.requestSocketConnection =
|
||||
(SocketConnection) requestServerConnection.acceptAndOpen();
|
||||
requestSocketConnection.setSocketOption(SocketConnection.DELAY, 0);
|
||||
requestSocketConnection.setSocketOption(SocketConnection.LINGER, 0);
|
||||
requestSocketConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
|
||||
requestSocketConnection.setSocketOption(SocketConnection.RCVBUF, 1024);
|
||||
requestSocketConnection.setSocketOption(SocketConnection.SNDBUF, 1024);
|
||||
this.requestReader = requestSocketConnection.openDataInputStream();
|
||||
this.requestWriter = requestSocketConnection.openDataOutputStream();
|
||||
// Set up the request socket and request input + event output streams
|
||||
this.serverConnection = (ServerSocketConnection) Connector
|
||||
.open("socket://:" + this.debugPort);
|
||||
this.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);
|
||||
this.requestReader = clientDebugConnection.openDataInputStream();
|
||||
this.eventWriter = clientDebugConnection.openDataOutputStream();
|
||||
|
||||
// Set up the event socket and event output stream
|
||||
this.eventServerConnection
|
||||
= (ServerSocketConnection)Connector.open("socket://:" + this.eventPort);
|
||||
this.eventSocketConnection
|
||||
= (SocketConnection) eventServerConnection.acceptAndOpen();
|
||||
eventSocketConnection.setSocketOption(SocketConnection.DELAY, 0);
|
||||
eventSocketConnection.setSocketOption(SocketConnection.LINGER, 0);
|
||||
eventSocketConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
|
||||
eventSocketConnection.setSocketOption(SocketConnection.RCVBUF, 1024);
|
||||
eventSocketConnection.setSocketOption(SocketConnection.SNDBUF, 1024);
|
||||
this.eventWriter = eventSocketConnection.openDataOutputStream();;
|
||||
|
||||
System.out.println("Lua debug server is started on ports: " + requestPort + ", " + eventPort);
|
||||
System.out.println("Lua debug server is started on ports: " + debugPort);
|
||||
super.start();
|
||||
}
|
||||
|
||||
protected void dispose() {
|
||||
super.dispose();
|
||||
|
||||
if (requestSocketConnection != null) {
|
||||
super.dispose();
|
||||
|
||||
if (this.clientDebugConnection != null) {
|
||||
try {
|
||||
requestSocketConnection.close();
|
||||
} catch (IOException e) {}
|
||||
clientDebugConnection.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (requestServerConnection != null) {
|
||||
|
||||
if (this.serverConnection != null) {
|
||||
try {
|
||||
requestServerConnection.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
if (eventSocketConnection != null) {
|
||||
try {
|
||||
eventSocketConnection.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
if (eventServerConnection != null){
|
||||
try {
|
||||
eventServerConnection.close();
|
||||
} catch (IOException e) {}
|
||||
serverConnection.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loopForRequests() {
|
||||
synchronized (requestSocketConnection) {
|
||||
super.loopForRequests();
|
||||
}
|
||||
|
||||
public Object getClientConnection() {
|
||||
return clientDebugConnection;
|
||||
}
|
||||
|
||||
|
||||
protected void sendEvent(DebugEvent event) {
|
||||
synchronized (eventSocketConnection) {
|
||||
super.sendEvent(event);
|
||||
super.sendEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,31 +32,23 @@ import org.luaj.debug.event.DebugEvent;
|
||||
|
||||
|
||||
public class DebugSupportImpl extends DebugSupport {
|
||||
protected ServerSocket requestSocket;
|
||||
protected Socket clientRequestSocket;
|
||||
|
||||
protected ServerSocket eventSocket;
|
||||
protected Socket clientEventSocket;
|
||||
protected ServerSocket serverSocket;
|
||||
protected Socket clientSocket;
|
||||
|
||||
public DebugSupportImpl(int requestPort, int eventPort) {
|
||||
super(requestPort, eventPort);
|
||||
public DebugSupportImpl(int debugPort) {
|
||||
super(debugPort);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see lua.debug.j2se.DebugSupport#start()
|
||||
*/
|
||||
public synchronized void start() throws IOException {
|
||||
this.requestSocket = new ServerSocket(requestPort);
|
||||
this.clientRequestSocket = requestSocket.accept();
|
||||
this.serverSocket = new ServerSocket(debugPort, 1);
|
||||
this.clientSocket = serverSocket.accept();
|
||||
this.requestReader
|
||||
= new DataInputStream(clientRequestSocket.getInputStream());
|
||||
this.requestWriter
|
||||
= new DataOutputStream(clientRequestSocket.getOutputStream());
|
||||
|
||||
this.eventSocket = new ServerSocket(eventPort);
|
||||
this.clientEventSocket = eventSocket.accept();
|
||||
= new DataInputStream(clientSocket.getInputStream());
|
||||
this.eventWriter
|
||||
= new DataOutputStream(clientEventSocket.getOutputStream());
|
||||
= new DataOutputStream(clientSocket.getOutputStream());
|
||||
|
||||
super.start();
|
||||
}
|
||||
@@ -64,35 +56,21 @@ public class DebugSupportImpl extends DebugSupport {
|
||||
protected void dispose() {
|
||||
super.dispose();
|
||||
|
||||
if (clientRequestSocket != null) {
|
||||
if (this.clientSocket != null) {
|
||||
try {
|
||||
clientRequestSocket.close();
|
||||
clientSocket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
if (requestSocket != null) {
|
||||
if (this.serverSocket != null) {
|
||||
try {
|
||||
requestSocket.close();
|
||||
serverSocket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
if (clientEventSocket != null) {
|
||||
try {
|
||||
clientEventSocket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
|
||||
if (eventSocket != null){
|
||||
try {
|
||||
eventSocket.close();
|
||||
} catch (IOException e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void loopForRequests() {
|
||||
synchronized (clientRequestSocket) {
|
||||
super.loopForRequests();
|
||||
}
|
||||
public Object getClientConnection() {
|
||||
return clientSocket;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,8 +91,8 @@ public class DebugSupportImpl extends DebugSupport {
|
||||
* @param event
|
||||
*/
|
||||
protected void sendEvent(DebugEvent event) {
|
||||
synchronized (eventSocket) {
|
||||
super.sendEvent(event);
|
||||
synchronized (clientSocket) {
|
||||
super.sendEvent(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.j2se;
|
||||
|
||||
import java.io.File;
|
||||
@@ -39,7 +39,6 @@ import org.luaj.vm.LValue;
|
||||
import org.luaj.vm.LoadState;
|
||||
import org.luaj.vm.LuaState;
|
||||
|
||||
|
||||
/**
|
||||
* StandardLuaJVM executes a lua program in normal run mode or debug mode.
|
||||
*
|
||||
@@ -47,106 +46,123 @@ import org.luaj.vm.LuaState;
|
||||
* @version: 1.0
|
||||
*/
|
||||
public class StandardLuaJVM {
|
||||
private static final String CMD_LINE_DEBUG_OPTION_SUSPEND_ON_START = "suspendOnStart=";
|
||||
private static final String CMD_LINE_DEBUG_OPTION_PORT = "port=";
|
||||
protected boolean isDebugMode = false;
|
||||
protected int requestPort;
|
||||
protected int eventPort;
|
||||
protected int debugPort = -1;;
|
||||
protected boolean bSuspendOnStart = false;
|
||||
protected String script;
|
||||
protected String[] scriptArgs;
|
||||
protected LuaState state;
|
||||
protected boolean isReady = false;
|
||||
protected boolean isTerminated = false;
|
||||
|
||||
protected boolean isTerminated = false;
|
||||
|
||||
// command line parsing utilities
|
||||
class ParseException extends Exception {
|
||||
private static final long serialVersionUID = -3134938136698856577L;
|
||||
private static final long serialVersionUID = -3134938136698856577L;
|
||||
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void printUsage() {
|
||||
System.out.println("Usage:");
|
||||
System.out.println("\t java StandardLuaJVM [-debug <requestPort> <eventPort>] <script> [<script arguments>]");
|
||||
System.out.println("\t java StandardLuaJVM [-Dport=<port>[,suspendedOnStart=<true|false>]] <script> [<script arguments>]");
|
||||
System.out.println("where [] denotes an optional argument and <> denotes a placeholder.");
|
||||
}
|
||||
|
||||
void parse(String[] args) throws ParseException {
|
||||
if (args == null || args.length < 1) {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
|
||||
if ("-debug".equals(args[0])) {
|
||||
if (args.length < 4) {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
|
||||
this.isDebugMode = true;
|
||||
try {
|
||||
this.requestPort = Integer.parseInt(args[1]);
|
||||
if (this.requestPort <= 0) {
|
||||
throw new ParseException("Invalid request port: it must be greater than zero.");
|
||||
}
|
||||
|
||||
this.eventPort = Integer.parseInt(args[2]);
|
||||
if (this.eventPort <= 0) {
|
||||
throw new ParseException("Invalid event port: it must be greater than zero.");
|
||||
}
|
||||
} catch(NumberFormatException e) {
|
||||
throw new ParseException("Invalid port number: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (this.requestPort == this.eventPort) {
|
||||
throw new ParseException("Invalid ports: request port and event port must be different");
|
||||
void parse(String[] args) throws ParseException {
|
||||
if (args == null || args.length < 1) {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
|
||||
if (args[0] != null && args[0].startsWith("-D")) {
|
||||
if (args.length < 2) {
|
||||
throw new ParseException("Invalid command line arguments.");
|
||||
}
|
||||
|
||||
this.isDebugMode = true;
|
||||
String debugOptions = args[0];
|
||||
debugOptions = debugOptions.substring(2); // remove '-D'
|
||||
String[] options = debugOptions.split(",");
|
||||
for (int i = 0; options != null && i < options.length; i++) {
|
||||
if (options[i].startsWith(CMD_LINE_DEBUG_OPTION_PORT)) {
|
||||
String portString = options[i].substring(CMD_LINE_DEBUG_OPTION_PORT.length());
|
||||
try {
|
||||
this.debugPort = Integer.parseInt(portString);
|
||||
if (this.debugPort <= 0) {
|
||||
throw new ParseException(
|
||||
"Invalid debug port: it must be greater than zero.");
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParseException("Invalid debug port: " + e.getMessage());
|
||||
}
|
||||
} else if (options[i].startsWith(CMD_LINE_DEBUG_OPTION_SUSPEND_ON_START)) {
|
||||
String suspendOnStartStr
|
||||
= options[i].substring(CMD_LINE_DEBUG_OPTION_SUSPEND_ON_START.length());
|
||||
if (!suspendOnStartStr.equalsIgnoreCase("true") &&
|
||||
!suspendOnStartStr.equalsIgnoreCase("false")) {
|
||||
throw new ParseException("invalid debug flag: suspendOnStart");
|
||||
}
|
||||
this.bSuspendOnStart = Boolean.valueOf(suspendOnStartStr).booleanValue();
|
||||
} else {
|
||||
throw new ParseException("Invalid command line argument: " + debugOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.debugPort == -1) {
|
||||
throw new ParseException("Invalid command line: debug port is missing");
|
||||
}
|
||||
|
||||
int tempArgsCount = args.length - 3;
|
||||
int tempArgsCount = args.length - 1;
|
||||
String[] tempArgs = new String[tempArgsCount];
|
||||
System.arraycopy(args, 3, tempArgs, 0, tempArgsCount);
|
||||
System.arraycopy(args, 1, tempArgs, 0, tempArgsCount);
|
||||
parseScriptArgs(tempArgs);
|
||||
} else {
|
||||
parseScriptArgs(args);
|
||||
}
|
||||
} else {
|
||||
parseScriptArgs(args);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseScriptArgs(String[] args)
|
||||
throws org.luaj.debug.j2se.StandardLuaJVM.ParseException {
|
||||
if (args == null || args.length < 1) {
|
||||
throw new ParseException("script is missing.");
|
||||
}
|
||||
|
||||
this.script = args[0];
|
||||
DebugUtils.println("Lua script to run: " + this.script);
|
||||
int scriptArgsLength = args.length - 1;
|
||||
if (scriptArgsLength > 0) {
|
||||
this.scriptArgs = new String[scriptArgsLength];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
this.scriptArgs[i - 1] = args[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parseScriptArgs(String[] args)
|
||||
throws org.luaj.debug.j2se.StandardLuaJVM.ParseException {
|
||||
if (args == null || args.length < 1) {
|
||||
throw new ParseException("script is missing.");
|
||||
}
|
||||
|
||||
this.script = args[0];
|
||||
DebugUtils.println("Lua script to run: " + this.script);
|
||||
int scriptArgsLength = args.length - 1;
|
||||
if (scriptArgsLength > 0) {
|
||||
this.scriptArgs = new String[scriptArgsLength];
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
this.scriptArgs[i - 1] = args[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
// end of command line parsing utilities
|
||||
|
||||
|
||||
boolean isDebug() {
|
||||
return this.isDebugMode;
|
||||
}
|
||||
|
||||
int getRequestPort() {
|
||||
return this.requestPort;
|
||||
|
||||
int getDebugPort() {
|
||||
return this.debugPort;
|
||||
}
|
||||
|
||||
int getEventPort() {
|
||||
return this.eventPort;
|
||||
boolean getSuspendOnStart() {
|
||||
return this.bSuspendOnStart;
|
||||
}
|
||||
|
||||
|
||||
String getScript() {
|
||||
return this.script;
|
||||
}
|
||||
|
||||
|
||||
boolean hasScriptArgs() {
|
||||
return (this.scriptArgs != null && this.scriptArgs.length > 0);
|
||||
}
|
||||
|
||||
|
||||
String[] getScriptArgs() {
|
||||
return this.scriptArgs;
|
||||
}
|
||||
@@ -158,22 +174,21 @@ public class StandardLuaJVM {
|
||||
doRun();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void init(LuaState state) {
|
||||
|
||||
|
||||
// add standard bindings
|
||||
state.installStandardLibs();
|
||||
|
||||
state.installStandardLibs();
|
||||
|
||||
// add LuaJava bindings
|
||||
LuajavaLib.install(state._G);
|
||||
|
||||
// add the compiler
|
||||
LuaC.install();
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected void doRun() throws IOException {
|
||||
|
||||
|
||||
// new lua state
|
||||
state = new LuaState();
|
||||
init(state);
|
||||
@@ -182,22 +197,22 @@ public class StandardLuaJVM {
|
||||
String[] scriptArgs = getScriptArgs();
|
||||
int numOfScriptArgs = (scriptArgs == null) ? 0 : scriptArgs.length;
|
||||
LValue[] vargs = new LValue[numOfScriptArgs];
|
||||
for (int i = 0; i < numOfScriptArgs; i++) {
|
||||
for (int i = 0; i < numOfScriptArgs; i++) {
|
||||
vargs[i] = new LString(getScriptArgs()[i]);
|
||||
}
|
||||
|
||||
|
||||
// load the Lua file
|
||||
DebugUtils.println("loading Lua script '" + getScript() + "'");
|
||||
InputStream is = new FileInputStream(new File(getScript()));
|
||||
LPrototype p = LoadState.undump(state, is, getScript());
|
||||
|
||||
|
||||
// create closure and execute
|
||||
LClosure c = new LClosure(state, p);
|
||||
state.doCall(c, vargs);
|
||||
state.doCall(c, vargs);
|
||||
}
|
||||
|
||||
protected void doDebug() throws IOException {
|
||||
DebugUtils.println("setting up LuaJava and debug stack state...");
|
||||
|
||||
protected void doDebug() throws IOException {
|
||||
DebugUtils.println("setting up LuaJava and debug stack state...");
|
||||
|
||||
// new lua debug state
|
||||
state = new DebugLuaState();
|
||||
@@ -210,29 +225,28 @@ public class StandardLuaJVM {
|
||||
|
||||
// set up debug support if the file is successfully loaded
|
||||
DebugUtils.println("start debugging...");
|
||||
DebugSupport debugSupport
|
||||
= new DebugSupportImpl(getRequestPort(), getEventPort());
|
||||
DebugSupport debugSupport = new DebugSupportImpl(getDebugPort());
|
||||
getDebugState().setSuspendAtStart(getSuspendOnStart());
|
||||
getDebugState().setDebugSupport(debugSupport);
|
||||
getDebugState().setSuspendAtStart(true);
|
||||
|
||||
|
||||
// create closure and execute
|
||||
final LClosure c = new LClosure(p, state._G);
|
||||
String[] args = getScriptArgs();
|
||||
String[] args = getScriptArgs();
|
||||
int numOfScriptArgs = (args != null ? args.length : 0);
|
||||
LValue[] vargs = new LValue[numOfScriptArgs];
|
||||
for (int i = 0; i < numOfScriptArgs; i++) {
|
||||
for (int i = 0; i < numOfScriptArgs; i++) {
|
||||
vargs[i] = new LString(args[i]);
|
||||
}
|
||||
try {
|
||||
getDebugState().doCall(c, vargs);
|
||||
getDebugState().doCall(c, vargs);
|
||||
} catch (VMException e) {
|
||||
System.err.println("VMException: " + e.getMessage());
|
||||
System.err.println("VMException: " + e.getMessage());
|
||||
}
|
||||
getDebugState().stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private DebugLuaState getDebugState() {
|
||||
return (DebugLuaState)state;
|
||||
return (DebugLuaState) state;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,11 +262,11 @@ public class StandardLuaJVM {
|
||||
vm.run();
|
||||
} catch (ParseException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
vm.printUsage();
|
||||
vm.printUsage();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,6 @@
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.request;
|
||||
|
||||
import org.luaj.debug.response.DebugResponse;
|
||||
|
||||
public interface DebugRequestListener {
|
||||
|
||||
@@ -38,5 +37,5 @@ public interface DebugRequestListener {
|
||||
* listing the (variable, value) pairs
|
||||
* step -- single step forward (go to next statement)
|
||||
*/
|
||||
public DebugResponse handleRequest(DebugRequest request);
|
||||
public void handleRequest(DebugRequest request);
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.response;
|
||||
|
||||
import org.luaj.debug.Serializable;
|
||||
|
||||
public interface DebugResponse extends Serializable {}
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.response;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
@@ -26,19 +26,21 @@ import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.luaj.debug.StackFrame;
|
||||
import org.luaj.debug.event.DebugEvent;
|
||||
import org.luaj.debug.event.DebugEventType;
|
||||
|
||||
|
||||
public class DebugResponseCallgraph implements DebugResponse {
|
||||
public class DebugResponseCallgraph extends DebugEvent {
|
||||
protected StackFrame[] stackFrames;
|
||||
|
||||
|
||||
public DebugResponseCallgraph(StackFrame[] callgraph) {
|
||||
if (callgraph == null) {
|
||||
this.stackFrames = new StackFrame[0];
|
||||
} else {
|
||||
this.stackFrames = callgraph;
|
||||
}
|
||||
super(DebugEventType.clientRequestCallgraphReply);
|
||||
if (callgraph == null) {
|
||||
this.stackFrames = new StackFrame[0];
|
||||
} else {
|
||||
this.stackFrames = callgraph;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public StackFrame[] getCallgraph() {
|
||||
return this.stackFrames;
|
||||
}
|
||||
@@ -46,29 +48,29 @@ public class DebugResponseCallgraph implements DebugResponse {
|
||||
public String toString() {
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < stackFrames.length; i++) {
|
||||
StackFrame frame = stackFrames[i];
|
||||
buffer.append(frame.toString());
|
||||
buffer.append("\n");
|
||||
StackFrame frame = stackFrames[i];
|
||||
buffer.append(frame.toString());
|
||||
buffer.append("\n");
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
public static void serialize(DataOutputStream out, DebugResponseCallgraph response)
|
||||
throws IOException {
|
||||
StackFrame[] stackFrames = response.getCallgraph();
|
||||
out.writeInt(stackFrames == null ? 0 : stackFrames.length);
|
||||
for (int i = 0; stackFrames != null && i < stackFrames.length; i++) {
|
||||
StackFrame.serialize(out, stackFrames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugResponseCallgraph deserialize(DataInputStream in) throws IOException {
|
||||
int count = in.readInt();
|
||||
StackFrame[] stackFrames = new StackFrame[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
stackFrames[i] = StackFrame.deserialize(in);
|
||||
}
|
||||
|
||||
return new DebugResponseCallgraph(stackFrames);
|
||||
}
|
||||
public static void serialize(DataOutputStream out,
|
||||
DebugResponseCallgraph response) throws IOException {
|
||||
StackFrame[] stackFrames = response.getCallgraph();
|
||||
out.writeInt(stackFrames == null ? 0 : stackFrames.length);
|
||||
for (int i = 0; stackFrames != null && i < stackFrames.length; i++) {
|
||||
StackFrame.serialize(out, stackFrames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||
int count = in.readInt();
|
||||
StackFrame[] stackFrames = new StackFrame[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
stackFrames[i] = StackFrame.deserialize(in);
|
||||
}
|
||||
|
||||
return new DebugResponseCallgraph(stackFrames);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.response;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class DebugResponseSimple implements DebugResponse {
|
||||
protected boolean isSuccessful;
|
||||
|
||||
public static final DebugResponseSimple SUCCESS = new DebugResponseSimple(true);
|
||||
public static final DebugResponseSimple FAILURE = new DebugResponseSimple(false);
|
||||
|
||||
public DebugResponseSimple(boolean isSuccessful) {
|
||||
this.isSuccessful = isSuccessful;
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
return this.isSuccessful;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
public String toString() {
|
||||
return String.valueOf(isSuccessful);
|
||||
}
|
||||
|
||||
public static void serialize(DataOutputStream out, DebugResponseSimple response)
|
||||
throws IOException {
|
||||
out.writeBoolean(response.isSuccessful());
|
||||
}
|
||||
|
||||
public static DebugResponseSimple deserialize(DataInputStream in)
|
||||
throws IOException {
|
||||
boolean value = in.readBoolean();
|
||||
return value ? SUCCESS : FAILURE;
|
||||
}
|
||||
}
|
||||
47
src/debug/org/luaj/debug/response/DebugResponseStack.java
Normal file
47
src/debug/org/luaj/debug/response/DebugResponseStack.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package org.luaj.debug.response;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
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);
|
||||
this.stackFrameIndex = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return this.stackFrameIndex;
|
||||
}
|
||||
|
||||
public static void serialize(DataOutputStream out,
|
||||
DebugResponseStack response)
|
||||
throws IOException {
|
||||
out.writeInt(response.getIndex());
|
||||
|
||||
Variable[] variables = response.getVariables();
|
||||
out.writeInt(variables == null ? 0 : variables.length);
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
SerializationHelper.serialize(variables[i], out);
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||
int index = in.readInt();
|
||||
|
||||
int count = in.readInt();
|
||||
Variable[] variables = new Variable[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
||||
}
|
||||
|
||||
return new DebugResponseStack(index, variables);
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,14 @@ import java.io.IOException;
|
||||
|
||||
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 implements DebugResponse {
|
||||
public class DebugResponseVariables extends DebugEvent {
|
||||
protected Variable[] variables;
|
||||
|
||||
public DebugResponseVariables(Variable[] variables) {
|
||||
public DebugResponseVariables(Variable[] variables, DebugEventType type) {
|
||||
super(type);
|
||||
if (variables == null) {
|
||||
this.variables = new Variable[0];
|
||||
} else {
|
||||
@@ -57,6 +60,7 @@ public class DebugResponseVariables implements DebugResponse {
|
||||
public static void serialize(DataOutputStream out,
|
||||
DebugResponseVariables response)
|
||||
throws IOException {
|
||||
DebugEventType.serialize(out, response.getType());
|
||||
Variable[] variables = response.getVariables();
|
||||
out.writeInt(variables == null ? 0 : variables.length);
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
@@ -64,13 +68,14 @@ public class DebugResponseVariables implements DebugResponse {
|
||||
}
|
||||
}
|
||||
|
||||
public static DebugResponseVariables deserialize(DataInputStream in)
|
||||
public static DebugEvent deserialize(DataInputStream in)
|
||||
throws IOException {
|
||||
DebugEventType type = DebugEventType.deserialize(in);
|
||||
int count = in.readInt();
|
||||
Variable[] variables = new Variable[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
||||
}
|
||||
return new DebugResponseVariables(variables);
|
||||
return new DebugResponseVariables(variables, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,92 +2,86 @@ package org.luaj.debug;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.debug.event.DebugEventType;
|
||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
||||
import org.luaj.debug.response.DebugResponseSimple;
|
||||
import org.luaj.debug.response.DebugResponseStack;
|
||||
import org.luaj.debug.response.DebugResponseVariables;
|
||||
import org.luaj.vm.Lua;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class DebugResponseTest extends TestCase {
|
||||
public void testDebugResponseSimpleSerialization() {
|
||||
try {
|
||||
DebugResponseSimple responseIn = DebugResponseSimple.SUCCESS;
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseSimple responseOut
|
||||
= (DebugResponseSimple)SerializationHelper.deserialize(data);
|
||||
assertEquals(responseIn, responseOut);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseStackSerialization() {
|
||||
try {
|
||||
doTestDebugResponseStackSerialization(null);
|
||||
|
||||
doTestDebugResponseStackSerialization(new Variable[0]);
|
||||
|
||||
Variable[] variables = new Variable[5];
|
||||
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING, "value1");
|
||||
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
||||
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN, "false");
|
||||
|
||||
TableVariable childTable = new TableVariable(0, "child", Lua.LUA_TTABLE, new String[0], new Object[0]);
|
||||
String[] keys = new String[] {"key1", "key2"};
|
||||
Object[] values = new Object[] {"value1", childTable};
|
||||
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE, keys, values);
|
||||
|
||||
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
|
||||
doTestDebugResponseStackSerialization(variables);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
public void testDebugResponseStackSerialization() {
|
||||
try {
|
||||
doTestDebugResponseStackSerialization(0, null);
|
||||
|
||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
||||
throws IOException {
|
||||
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
||||
byte[] data = SerializationHelper.serialize(stackIn);
|
||||
DebugResponseVariables stackOut
|
||||
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
||||
Variable[] variablesIn = stackIn.getVariables();
|
||||
Variable[] variablesOut = stackOut.getVariables();
|
||||
assertNotNull(variablesIn);
|
||||
assertNotNull(variablesOut);
|
||||
assertEquals(variablesIn.length, variablesOut.length);
|
||||
for (int i = 0; i < variablesIn.length; i++) {
|
||||
assertEquals(variablesIn[i], variablesOut[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseCallgraphSerialization() {
|
||||
try {
|
||||
doTestDebugResponseCallgraphSerialization(null);
|
||||
doTestDebugResponseCallgraphSerialization(new StackFrame[0]);
|
||||
|
||||
StackFrame[] frames = new StackFrame[1];
|
||||
frames[0] = new StackFrame(100, "test.lua");
|
||||
doTestDebugResponseCallgraphSerialization(frames);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseCallgraphSerialization(StackFrame[] frames)
|
||||
throws IOException {
|
||||
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseCallgraph responseOut =
|
||||
(DebugResponseCallgraph) SerializationHelper.deserialize(data);
|
||||
assertNotNull(responseOut);
|
||||
StackFrame[] inFrames = responseIn.getCallgraph();
|
||||
StackFrame[] outFrames = responseOut.getCallgraph();
|
||||
assertNotNull(outFrames);
|
||||
assertEquals(inFrames.length, outFrames.length);
|
||||
for (int i = 0; i < inFrames.length; i++) {
|
||||
assertEquals(inFrames[i], outFrames[i]);
|
||||
}
|
||||
}
|
||||
doTestDebugResponseStackSerialization(1, new Variable[0]);
|
||||
|
||||
Variable[] variables = new Variable[5];
|
||||
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING,
|
||||
"value1");
|
||||
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
||||
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN,
|
||||
"false");
|
||||
|
||||
TableVariable childTable = new TableVariable(0, "child",
|
||||
Lua.LUA_TTABLE, new String[0], new Object[0]);
|
||||
String[] keys = new String[] { "key1", "key2" };
|
||||
Object[] values = new Object[] { "value1", childTable };
|
||||
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE,
|
||||
keys, values);
|
||||
|
||||
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
|
||||
doTestDebugResponseStackSerialization(2, variables);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseStackSerialization(int index, Variable[] variables)
|
||||
throws IOException {
|
||||
DebugResponseStack stackIn = new DebugResponseStack(index, variables);
|
||||
byte[] data = SerializationHelper.serialize(stackIn);
|
||||
DebugResponseStack stackOut = (DebugResponseStack) SerializationHelper
|
||||
.deserialize(data);
|
||||
Variable[] variablesIn = stackIn.getVariables();
|
||||
Variable[] variablesOut = stackOut.getVariables();
|
||||
assertNotNull(variablesIn);
|
||||
assertNotNull(variablesOut);
|
||||
assertEquals(stackIn.getIndex(), stackOut.getIndex());
|
||||
assertEquals(variablesIn.length, variablesOut.length);
|
||||
for (int i = 0; i < variablesIn.length; i++) {
|
||||
assertEquals(variablesIn[i], variablesOut[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDebugResponseCallgraphSerialization() {
|
||||
try {
|
||||
doTestDebugResponseCallgraphSerialization(null);
|
||||
doTestDebugResponseCallgraphSerialization(new StackFrame[0]);
|
||||
|
||||
StackFrame[] frames = new StackFrame[1];
|
||||
frames[0] = new StackFrame(100, "test.lua");
|
||||
doTestDebugResponseCallgraphSerialization(frames);
|
||||
} catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTestDebugResponseCallgraphSerialization(StackFrame[] frames)
|
||||
throws IOException {
|
||||
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
||||
byte[] data = SerializationHelper.serialize(responseIn);
|
||||
DebugResponseCallgraph responseOut = (DebugResponseCallgraph) SerializationHelper
|
||||
.deserialize(data);
|
||||
assertNotNull(responseOut);
|
||||
StackFrame[] inFrames = responseIn.getCallgraph();
|
||||
StackFrame[] outFrames = responseOut.getCallgraph();
|
||||
assertNotNull(outFrames);
|
||||
assertEquals(inFrames.length, outFrames.length);
|
||||
for (int i = 0; i < inFrames.length; i++) {
|
||||
assertEquals(inFrames[i], outFrames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
******************************************************************************/
|
||||
package org.luaj.debug.j2se;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -33,135 +33,172 @@ import junit.framework.TestCase;
|
||||
* Sanity test for StandardLuaJVM.
|
||||
*/
|
||||
public class LuaJVMTest extends TestCase {
|
||||
public void testCommandLineParse() {
|
||||
// null arguments
|
||||
String[] args = null;
|
||||
StandardLuaJVM vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// empty arguments
|
||||
args = new String[] {};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
public void testCommandLineParse() {
|
||||
// null arguments
|
||||
String[] args = null;
|
||||
StandardLuaJVM vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// incomplete arguments
|
||||
args = new String[] { "-debug" };
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// incomplete arguments
|
||||
args = new String[] { "-debug", "1046" };
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// missing script name
|
||||
args = new String[] { "-debug", "1046", "1047"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
// empty arguments
|
||||
args = new String[] {};
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// malformed request port
|
||||
args = new String[] { "-debug", "104x", "1046", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
// incomplete arguments
|
||||
args = new String[] { "-D" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// malformed event port
|
||||
args = new String[] { "-debug", "1046", "104x", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// event port == request port
|
||||
args = new String[] { "-debug", "1046", "1046", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
args = new String[] { "-D1046" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "-debug", "1046", "1047", "dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] {"dummy.lua"};
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {
|
||||
//expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testRun() {
|
||||
String[] tests = new String[] {
|
||||
"autoload",
|
||||
"boolean",
|
||||
"calls",
|
||||
"coercions",
|
||||
"compare",
|
||||
"math",
|
||||
"mathlib",
|
||||
"metatables",
|
||||
"select",
|
||||
"setlist",
|
||||
"swingapp",
|
||||
"test1",
|
||||
"test2",
|
||||
"test3",
|
||||
"test4",
|
||||
"test5",
|
||||
"test6",
|
||||
"test7",
|
||||
"type",
|
||||
"upvalues",
|
||||
//"strlib"
|
||||
};
|
||||
args = new String[] { "-DsuspendOnStart=true" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// invalid debug option format
|
||||
args = new String[] { "-Dport=1044:suspendOnStart=true", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertFalse(1044 == vm.getDebugPort());
|
||||
assertFalse(true == vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
args = new String[] { "-Dport=1044,suspendOnStart=xyz", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertFalse(1044 == vm.getDebugPort());
|
||||
assertFalse(true == vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
//expected
|
||||
}
|
||||
|
||||
// missing script name
|
||||
args = new String[] { "-Dport=1047,suspendOnStart=true"};
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "-Dport=1046,suspendOnStart", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Should never reach this line.");
|
||||
} catch (ParseException e) {}
|
||||
catch (IOException e) {}
|
||||
|
||||
// lua script cannot be found
|
||||
args = new String[] { "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
vm.run();
|
||||
fail("Bad parsing program. Should never reach this line.");
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
} catch (IOException e) {}
|
||||
|
||||
// valid command line
|
||||
args = new String[] { "-Dport=1044,suspendOnStart=true", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-DsuspendOnStart=true,port=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-DsuspendOnStart=TRUE,port=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(true, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
|
||||
args = new String[] { "-Dport=1044", "dummy.lua" };
|
||||
vm = new StandardLuaJVM();
|
||||
try {
|
||||
vm.parse(args);
|
||||
assertEquals(1044, vm.getDebugPort());
|
||||
assertEquals(false, vm.getSuspendOnStart());
|
||||
assertEquals("dummy.lua", vm.getScript());
|
||||
} catch (ParseException e) {
|
||||
fail("Should never reach this line.");
|
||||
}
|
||||
}
|
||||
|
||||
public void testRun() {
|
||||
String[] tests = new String[] { "autoload", "boolean", "calls",
|
||||
"coercions", "compare", "math", "mathlib", "metatables",
|
||||
"select", "setlist", "swingapp", "test1", "test2", "test3",
|
||||
"test4", "test5", "test6", "test7", "type", "upvalues",
|
||||
// "strlib"
|
||||
};
|
||||
|
||||
for (int i = 0; i < tests.length; i++) {
|
||||
String test = tests[i];
|
||||
String test = tests[i];
|
||||
System.out.println("==> running test: " + test + ".lua");
|
||||
doTestRun(test + ".lua");
|
||||
doTestRun(test + ".lua");
|
||||
System.out.println("==> running test: " + test + ".luac");
|
||||
doTestRun(test + ".luac");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void doTestRun(String testName) {
|
||||
String[] args = new String[1];
|
||||
URL filePath = getClass().getResource("/"+ testName);
|
||||
URL filePath = getClass().getResource("/" + testName);
|
||||
if (filePath != null) {
|
||||
args[0] = filePath.getPath();
|
||||
args[0] = filePath.getPath();
|
||||
try {
|
||||
StandardLuaJVM.main(args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail("Test " + testName + " failed due to " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user