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.DebugRequestListener;
|
||||||
import org.luaj.debug.request.DebugRequestStack;
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
import org.luaj.debug.request.DebugRequestType;
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
import org.luaj.debug.response.DebugResponse;
|
|
||||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
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.debug.response.DebugResponseVariables;
|
||||||
import org.luaj.vm.CallInfo;
|
import org.luaj.vm.CallInfo;
|
||||||
import org.luaj.vm.LClosure;
|
import org.luaj.vm.LClosure;
|
||||||
@@ -298,7 +297,7 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
|
|
||||||
// ------------------ commands coming from the debugger -------------------
|
// ------------------ commands coming from the debugger -------------------
|
||||||
|
|
||||||
public DebugResponse handleRequest(DebugRequest request) {
|
public void handleRequest(DebugRequest request) {
|
||||||
if (this.debugSupport == null) {
|
if (this.debugSupport == null) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"DebugStackState is not equiped with DebugSupport.");
|
"DebugStackState is not equiped with DebugSupport.");
|
||||||
@@ -313,61 +312,60 @@ public class DebugLuaState extends LuaState implements DebugRequestListener {
|
|||||||
DebugEvent event = new DebugEvent(DebugEventType.started);
|
DebugEvent event = new DebugEvent(DebugEventType.started);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
cancelSuspendOnStart();
|
cancelSuspendOnStart();
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.exit == requestType) {
|
} else if (DebugRequestType.exit == requestType) {
|
||||||
stop();
|
stop();
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.suspend == requestType) {
|
} else if (DebugRequestType.suspend == requestType) {
|
||||||
suspend();
|
suspend();
|
||||||
DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient);
|
DebugEvent event = new DebugEvent(DebugEventType.suspendedByClient);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.resume == requestType) {
|
} else if (DebugRequestType.resume == requestType) {
|
||||||
resume();
|
resume();
|
||||||
DebugEvent event = new DebugEvent(DebugEventType.resumedByClient);
|
DebugEvent event = new DebugEvent(DebugEventType.resumedByClient);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.lineBreakpointSet == requestType) {
|
} else if (DebugRequestType.lineBreakpointSet == requestType) {
|
||||||
DebugRequestLineBreakpointToggle setBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
DebugRequestLineBreakpointToggle setBreakpointRequest
|
||||||
|
= (DebugRequestLineBreakpointToggle) request;
|
||||||
setBreakpoint(setBreakpointRequest.getSource(),
|
setBreakpoint(setBreakpointRequest.getSource(),
|
||||||
setBreakpointRequest.getLineNumber());
|
setBreakpointRequest.getLineNumber());
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.lineBreakpointClear == requestType) {
|
} else if (DebugRequestType.lineBreakpointClear == requestType) {
|
||||||
DebugRequestLineBreakpointToggle clearBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
DebugRequestLineBreakpointToggle clearBreakpointRequest
|
||||||
|
= (DebugRequestLineBreakpointToggle) request;
|
||||||
clearBreakpoint(clearBreakpointRequest.getSource(),
|
clearBreakpoint(clearBreakpointRequest.getSource(),
|
||||||
clearBreakpointRequest.getLineNumber());
|
clearBreakpointRequest.getLineNumber());
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.callgraph == requestType) {
|
} else if (DebugRequestType.callgraph == requestType) {
|
||||||
return new DebugResponseCallgraph(getCallgraph());
|
DebugResponseCallgraph callgraph
|
||||||
|
= new DebugResponseCallgraph(getCallgraph());
|
||||||
|
debugSupport.notifyDebugEvent(callgraph);
|
||||||
} else if (DebugRequestType.stack == requestType) {
|
} else if (DebugRequestType.stack == requestType) {
|
||||||
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
||||||
int index = stackRequest.getIndex();
|
int index = stackRequest.getIndex();
|
||||||
return new DebugResponseVariables(getStack(index));
|
DebugResponseStack stackState
|
||||||
|
= new DebugResponseStack(index, getStack(index));
|
||||||
|
debugSupport.notifyDebugEvent(stackState);
|
||||||
} else if (DebugRequestType.global == requestType) {
|
} else if (DebugRequestType.global == requestType) {
|
||||||
return new DebugResponseVariables(getGlobals());
|
DebugResponseVariables globals
|
||||||
|
= new DebugResponseVariables(getGlobals(), DebugEventType.clientRequestGlobalReply);
|
||||||
|
debugSupport.notifyDebugEvent(globals);
|
||||||
} else if (DebugRequestType.stepInto == requestType) {
|
} else if (DebugRequestType.stepInto == requestType) {
|
||||||
DebugEvent event = new DebugEvent(
|
DebugEvent event = new DebugEvent(
|
||||||
DebugEventType.resumedOnSteppingInto);
|
DebugEventType.resumedOnSteppingInto);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
stepInto();
|
stepInto();
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.stepOver == requestType) {
|
} else if (DebugRequestType.stepOver == requestType) {
|
||||||
DebugEvent event = new DebugEvent(
|
DebugEvent event = new DebugEvent(
|
||||||
DebugEventType.resumedOnSteppingOver);
|
DebugEventType.resumedOnSteppingOver);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
stepOver();
|
stepOver();
|
||||||
return DebugResponseSimple.SUCCESS;
|
|
||||||
} else if (DebugRequestType.stepReturn == requestType) {
|
} else if (DebugRequestType.stepReturn == requestType) {
|
||||||
DebugEvent event = new DebugEvent(
|
DebugEvent event = new DebugEvent(
|
||||||
DebugEventType.resumedOnSteppingReturn);
|
DebugEventType.resumedOnSteppingReturn);
|
||||||
debugSupport.notifyDebugEvent(event);
|
debugSupport.notifyDebugEvent(event);
|
||||||
stepReturn();
|
stepReturn();
|
||||||
return DebugResponseSimple.SUCCESS;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
throw new java.lang.IllegalArgumentException("unkown request type: "
|
throw new java.lang.IllegalArgumentException("unkown request type: "
|
||||||
+ request.getType());
|
+ request.getType());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* suspend the execution
|
* suspend the execution
|
||||||
|
|||||||
@@ -9,37 +9,28 @@ import org.luaj.debug.event.DebugEvent;
|
|||||||
import org.luaj.debug.event.DebugEventListener;
|
import org.luaj.debug.event.DebugEventListener;
|
||||||
import org.luaj.debug.request.DebugRequest;
|
import org.luaj.debug.request.DebugRequest;
|
||||||
import org.luaj.debug.request.DebugRequestListener;
|
import org.luaj.debug.request.DebugRequestListener;
|
||||||
import org.luaj.debug.response.DebugResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DebugSupport provides the network communication support for the debugger and
|
* DebugSupport provides the network communication support for the debugger and
|
||||||
* debugee.
|
* debugee.
|
||||||
*/
|
*/
|
||||||
public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
public abstract class DebugSupport implements DebugRequestListener, DebugEventListener {
|
||||||
protected static final int UNKNOWN = 0;
|
protected static final int UNKNOWN = 0;
|
||||||
protected static final int RUNNING = 1;
|
protected static final int RUNNING = 1;
|
||||||
protected static final int STOPPED = 2;
|
protected static final int STOPPED = 2;
|
||||||
|
|
||||||
protected DebugLuaState vm;
|
protected DebugLuaState vm;
|
||||||
protected int requestPort;
|
protected int debugPort;
|
||||||
protected int eventPort;
|
|
||||||
protected Thread requestWatcherThread;
|
protected Thread requestWatcherThread;
|
||||||
protected int state = UNKNOWN;
|
protected int state = UNKNOWN;
|
||||||
protected DataInputStream requestReader;
|
protected DataInputStream requestReader;
|
||||||
protected DataOutputStream requestWriter;
|
|
||||||
protected DataOutputStream eventWriter;
|
protected DataOutputStream eventWriter;
|
||||||
|
|
||||||
public DebugSupport(int requestPort, int eventPort) {
|
public DebugSupport(int debugPort) {
|
||||||
if (requestPort == -1) {
|
if (debugPort == -1) {
|
||||||
throw new IllegalArgumentException("requestPort is invalid");
|
throw new IllegalArgumentException("requestPort is invalid");
|
||||||
}
|
}
|
||||||
|
this.debugPort = debugPort;
|
||||||
if (eventPort == -1) {
|
|
||||||
throw new IllegalArgumentException("eventPort is invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.requestPort = requestPort;
|
|
||||||
this.eventPort = eventPort;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDebugStackState(DebugLuaState vm) {
|
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) {
|
if (eventWriter != null) {
|
||||||
try {
|
try {
|
||||||
eventWriter.close();
|
eventWriter.close();
|
||||||
@@ -81,7 +64,7 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
|||||||
public synchronized void start() throws IOException {
|
public synchronized void start() throws IOException {
|
||||||
if (this.vm == null) {
|
if (this.vm == null) {
|
||||||
throw new IllegalStateException(
|
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() {
|
this.requestWatcherThread = new Thread(new Runnable() {
|
||||||
@@ -93,8 +76,7 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
|||||||
this.requestWatcherThread.start();
|
this.requestWatcherThread.start();
|
||||||
this.state = RUNNING;
|
this.state = RUNNING;
|
||||||
|
|
||||||
System.out.println("LuaJ debug server is started on ports: "
|
System.out.println("LuaJ debug server is listening on port: " + debugPort);
|
||||||
+ requestPort + ", " + eventPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected synchronized int getState() {
|
protected synchronized int getState() {
|
||||||
@@ -107,28 +89,26 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
|||||||
this.state = STOPPED;
|
this.state = STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract Object getClientConnection();
|
||||||
|
|
||||||
protected void loopForRequests() {
|
protected void loopForRequests() {
|
||||||
try {
|
try {
|
||||||
while (getState() != STOPPED) {
|
while (getState() != STOPPED) {
|
||||||
|
byte[] data = null;
|
||||||
int size = requestReader.readInt();
|
int size = requestReader.readInt();
|
||||||
byte[] data = new byte[size];
|
data = new byte[size];
|
||||||
requestReader.readFully(data);
|
requestReader.readFully(data);
|
||||||
|
|
||||||
DebugRequest request = (DebugRequest) SerializationHelper
|
DebugRequest request = (DebugRequest) SerializationHelper
|
||||||
.deserialize(data);
|
.deserialize(data);
|
||||||
if (DebugUtils.IS_DEBUG)
|
if (DebugUtils.IS_DEBUG) {
|
||||||
DebugUtils.println("SERVER receives request: "
|
DebugUtils.println("SERVER receives request: " + request.toString());
|
||||||
+ request.toString());
|
}
|
||||||
|
|
||||||
DebugResponse response = handleRequest(request);
|
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);
|
|
||||||
}
|
}
|
||||||
} catch (EOFException e) {
|
} catch (EOFException e) {
|
||||||
// expected during shutdown
|
// expected. it may occur depending on the timing during the termination
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -184,12 +164,11 @@ public class DebugSupport implements DebugRequestListener, DebugEventListener {
|
|||||||
*
|
*
|
||||||
* @see org.luaj.debug.request.DebugRequestListener#handleRequest(org.luaj.debug.request.DebugRequest)
|
* @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) {
|
if (DebugUtils.IS_DEBUG) {
|
||||||
DebugUtils.println("handling request: " + request.toString());
|
DebugUtils.println("SERVER handling request: " + request.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
DebugResponse response = vm.handleRequest(request);
|
vm.handleRequest(request);
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ import org.luaj.debug.request.DebugRequestLineBreakpointToggle;
|
|||||||
import org.luaj.debug.request.DebugRequestStack;
|
import org.luaj.debug.request.DebugRequestStack;
|
||||||
import org.luaj.debug.request.DebugRequestType;
|
import org.luaj.debug.request.DebugRequestType;
|
||||||
import org.luaj.debug.response.DebugResponseCallgraph;
|
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.debug.response.DebugResponseVariables;
|
||||||
|
|
||||||
public class SerializationHelper {
|
public class SerializationHelper {
|
||||||
@@ -51,7 +51,7 @@ public class SerializationHelper {
|
|||||||
static final int SERIAL_TYPE_Variable = 2;
|
static final int SERIAL_TYPE_Variable = 2;
|
||||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
||||||
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
||||||
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
static final int SERIAL_TYPE_DebugResponseStack = 5;
|
||||||
static final int SERIAL_TYPE_StackFrame = 6;
|
static final int SERIAL_TYPE_StackFrame = 6;
|
||||||
static final int SERIAL_TYPE_DebugRequestType = 7;
|
static final int SERIAL_TYPE_DebugRequestType = 7;
|
||||||
static final int SERIAL_TYPE_DebugRequest = 8;
|
static final int SERIAL_TYPE_DebugRequest = 8;
|
||||||
@@ -76,9 +76,9 @@ public class SerializationHelper {
|
|||||||
} else if (object instanceof StackFrame) {
|
} else if (object instanceof StackFrame) {
|
||||||
dout.writeInt(SERIAL_TYPE_StackFrame);
|
dout.writeInt(SERIAL_TYPE_StackFrame);
|
||||||
StackFrame.serialize(dout, (StackFrame) object);
|
StackFrame.serialize(dout, (StackFrame) object);
|
||||||
} else if (object instanceof DebugResponseSimple) {
|
} else if (object instanceof DebugResponseStack) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
dout.writeInt(SERIAL_TYPE_DebugResponseStack);
|
||||||
DebugResponseSimple.serialize(dout, (DebugResponseSimple) object);
|
DebugResponseStack.serialize(dout, (DebugResponseStack) object);
|
||||||
} else if (object instanceof DebugResponseVariables) {
|
} else if (object instanceof DebugResponseVariables) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseVariables);
|
dout.writeInt(SERIAL_TYPE_DebugResponseVariables);
|
||||||
DebugResponseVariables.serialize(dout, (DebugResponseVariables) object);
|
DebugResponseVariables.serialize(dout, (DebugResponseVariables) object);
|
||||||
@@ -136,12 +136,12 @@ public class SerializationHelper {
|
|||||||
case SERIAL_TYPE_StackFrame:
|
case SERIAL_TYPE_StackFrame:
|
||||||
object = StackFrame.deserialize(din);
|
object = StackFrame.deserialize(din);
|
||||||
break;
|
break;
|
||||||
case SERIAL_TYPE_DebugResponseSimple:
|
|
||||||
object = DebugResponseSimple.deserialize(din);
|
|
||||||
break;
|
|
||||||
case SERIAL_TYPE_DebugResponseCallgraph:
|
case SERIAL_TYPE_DebugResponseCallgraph:
|
||||||
object = DebugResponseCallgraph.deserialize(din);
|
object = DebugResponseCallgraph.deserialize(din);
|
||||||
break;
|
break;
|
||||||
|
case SERIAL_TYPE_DebugResponseStack:
|
||||||
|
object = DebugResponseStack.deserialize(din);
|
||||||
|
break;
|
||||||
case SERIAL_TYPE_DebugResponseVariables:
|
case SERIAL_TYPE_DebugResponseVariables:
|
||||||
object = DebugResponseVariables.deserialize(din);
|
object = DebugResponseVariables.deserialize(din);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@@ -45,7 +45,9 @@ public class DebugEvent implements Serializable {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see java.lang.Object#toString()
|
* @see java.lang.Object#toString()
|
||||||
*/
|
*/
|
||||||
public String toString() {
|
public String toString() {
|
||||||
@@ -58,7 +60,8 @@ public class DebugEvent implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||||
DebugEventType type = (DebugEventType) SerializationHelper.deserialize(in);
|
DebugEventType type = (DebugEventType) SerializationHelper
|
||||||
|
.deserialize(in);
|
||||||
return new DebugEvent(type);
|
return new DebugEvent(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.event;
|
package org.luaj.debug.event;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@@ -27,6 +27,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
public class DebugEventBreakpoint extends DebugEvent {
|
public class DebugEventBreakpoint extends DebugEvent {
|
||||||
protected String source;
|
protected String source;
|
||||||
|
|
||||||
protected int lineNumber;
|
protected int lineNumber;
|
||||||
|
|
||||||
public DebugEventBreakpoint(String source, int lineNumber) {
|
public DebugEventBreakpoint(String source, int lineNumber) {
|
||||||
@@ -36,7 +37,8 @@ public class DebugEventBreakpoint extends DebugEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lineNumber <= 0) {
|
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.source = source;
|
||||||
@@ -51,15 +53,18 @@ public class DebugEventBreakpoint extends DebugEvent {
|
|||||||
return this.lineNumber;
|
return this.lineNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see lua.debug.DebugEvent#toString()
|
* @see lua.debug.DebugEvent#toString()
|
||||||
*/
|
*/
|
||||||
public String 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)
|
public static void serialize(DataOutputStream out,
|
||||||
throws IOException {
|
DebugEventBreakpoint object) throws IOException {
|
||||||
out.writeUTF(object.getSource());
|
out.writeUTF(object.getSource());
|
||||||
out.writeInt(object.getLineNumber());
|
out.writeInt(object.getLineNumber());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ public class DebugEventType extends EnumType {
|
|||||||
public static DebugEventType resumedOnError = new DebugEventType("resumedOnError", 11);
|
public static DebugEventType resumedOnError = new DebugEventType("resumedOnError", 11);
|
||||||
public static DebugEventType error = new DebugEventType("error", 12);
|
public static DebugEventType error = new DebugEventType("error", 12);
|
||||||
public static DebugEventType terminated = new DebugEventType("terminated", 13);
|
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[] {
|
protected static DebugEventType[] ENUMS = new DebugEventType[] {
|
||||||
started,
|
started,
|
||||||
@@ -58,7 +64,10 @@ public class DebugEventType extends EnumType {
|
|||||||
resumedOnSteppingEnd,
|
resumedOnSteppingEnd,
|
||||||
resumedOnError,
|
resumedOnError,
|
||||||
error,
|
error,
|
||||||
terminated
|
terminated,
|
||||||
|
clientRequestCallgraphReply,
|
||||||
|
clientRequestStackReply,
|
||||||
|
clientRequestGlobalReply
|
||||||
};
|
};
|
||||||
|
|
||||||
protected DebugEventType(String name, int ordinal) {
|
protected DebugEventType(String name, int ordinal) {
|
||||||
|
|||||||
@@ -9,86 +9,59 @@ import javax.microedition.io.SocketConnection;
|
|||||||
import org.luaj.debug.DebugSupport;
|
import org.luaj.debug.DebugSupport;
|
||||||
import org.luaj.debug.event.DebugEvent;
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
|
||||||
|
|
||||||
public class DebugSupportImpl extends DebugSupport {
|
public class DebugSupportImpl extends DebugSupport {
|
||||||
protected ServerSocketConnection requestServerConnection;
|
protected ServerSocketConnection serverConnection;
|
||||||
protected SocketConnection requestSocketConnection;
|
protected SocketConnection clientDebugConnection;
|
||||||
|
|
||||||
protected ServerSocketConnection eventServerConnection;
|
|
||||||
protected SocketConnection eventSocketConnection;
|
protected SocketConnection eventSocketConnection;
|
||||||
|
|
||||||
public DebugSupportImpl(int requestPort,
|
public DebugSupportImpl(int debugPort) {
|
||||||
int eventPort) {
|
super(debugPort);
|
||||||
super(requestPort, eventPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see lua.debug.j2se.DebugSupport#start()
|
* @see lua.debug.j2se.DebugSupport#start()
|
||||||
*/
|
*/
|
||||||
public synchronized void start() throws IOException {
|
public synchronized void start() throws IOException {
|
||||||
System.out.println("Starting the sockets....");
|
// Set up the request socket and request input + event output streams
|
||||||
// Set up the request socket and request input + output streams
|
this.serverConnection = (ServerSocketConnection) Connector
|
||||||
this.requestServerConnection
|
.open("socket://:" + this.debugPort);
|
||||||
= (ServerSocketConnection)Connector.open("socket://:" + this.requestPort);
|
this.clientDebugConnection = (SocketConnection) serverConnection
|
||||||
this.requestSocketConnection =
|
.acceptAndOpen();
|
||||||
(SocketConnection) requestServerConnection.acceptAndOpen();
|
clientDebugConnection.setSocketOption(SocketConnection.DELAY, 0);
|
||||||
requestSocketConnection.setSocketOption(SocketConnection.DELAY, 0);
|
clientDebugConnection.setSocketOption(SocketConnection.LINGER, 0);
|
||||||
requestSocketConnection.setSocketOption(SocketConnection.LINGER, 0);
|
clientDebugConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
|
||||||
requestSocketConnection.setSocketOption(SocketConnection.KEEPALIVE, 1);
|
clientDebugConnection.setSocketOption(SocketConnection.RCVBUF, 1024);
|
||||||
requestSocketConnection.setSocketOption(SocketConnection.RCVBUF, 1024);
|
clientDebugConnection.setSocketOption(SocketConnection.SNDBUF, 1024);
|
||||||
requestSocketConnection.setSocketOption(SocketConnection.SNDBUF, 1024);
|
this.requestReader = clientDebugConnection.openDataInputStream();
|
||||||
this.requestReader = requestSocketConnection.openDataInputStream();
|
this.eventWriter = clientDebugConnection.openDataOutputStream();
|
||||||
this.requestWriter = requestSocketConnection.openDataOutputStream();
|
|
||||||
|
|
||||||
// Set up the event socket and event output stream
|
System.out.println("Lua debug server is started on ports: " + debugPort);
|
||||||
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);
|
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void dispose() {
|
protected void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
if (requestSocketConnection != null) {
|
if (this.clientDebugConnection != null) {
|
||||||
try {
|
try {
|
||||||
requestSocketConnection.close();
|
clientDebugConnection.close();
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {
|
||||||
}
|
|
||||||
|
|
||||||
if (requestServerConnection != 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) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loopForRequests() {
|
if (this.serverConnection != null) {
|
||||||
synchronized (requestSocketConnection) {
|
try {
|
||||||
super.loopForRequests();
|
serverConnection.close();
|
||||||
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getClientConnection() {
|
||||||
|
return clientDebugConnection;
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendEvent(DebugEvent event) {
|
protected void sendEvent(DebugEvent event) {
|
||||||
synchronized (eventSocketConnection) {
|
synchronized (eventSocketConnection) {
|
||||||
|
|||||||
@@ -32,31 +32,23 @@ import org.luaj.debug.event.DebugEvent;
|
|||||||
|
|
||||||
|
|
||||||
public class DebugSupportImpl extends DebugSupport {
|
public class DebugSupportImpl extends DebugSupport {
|
||||||
protected ServerSocket requestSocket;
|
protected ServerSocket serverSocket;
|
||||||
protected Socket clientRequestSocket;
|
protected Socket clientSocket;
|
||||||
|
|
||||||
protected ServerSocket eventSocket;
|
public DebugSupportImpl(int debugPort) {
|
||||||
protected Socket clientEventSocket;
|
super(debugPort);
|
||||||
|
|
||||||
public DebugSupportImpl(int requestPort, int eventPort) {
|
|
||||||
super(requestPort, eventPort);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see lua.debug.j2se.DebugSupport#start()
|
* @see lua.debug.j2se.DebugSupport#start()
|
||||||
*/
|
*/
|
||||||
public synchronized void start() throws IOException {
|
public synchronized void start() throws IOException {
|
||||||
this.requestSocket = new ServerSocket(requestPort);
|
this.serverSocket = new ServerSocket(debugPort, 1);
|
||||||
this.clientRequestSocket = requestSocket.accept();
|
this.clientSocket = serverSocket.accept();
|
||||||
this.requestReader
|
this.requestReader
|
||||||
= new DataInputStream(clientRequestSocket.getInputStream());
|
= new DataInputStream(clientSocket.getInputStream());
|
||||||
this.requestWriter
|
|
||||||
= new DataOutputStream(clientRequestSocket.getOutputStream());
|
|
||||||
|
|
||||||
this.eventSocket = new ServerSocket(eventPort);
|
|
||||||
this.clientEventSocket = eventSocket.accept();
|
|
||||||
this.eventWriter
|
this.eventWriter
|
||||||
= new DataOutputStream(clientEventSocket.getOutputStream());
|
= new DataOutputStream(clientSocket.getOutputStream());
|
||||||
|
|
||||||
super.start();
|
super.start();
|
||||||
}
|
}
|
||||||
@@ -64,35 +56,21 @@ public class DebugSupportImpl extends DebugSupport {
|
|||||||
protected void dispose() {
|
protected void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
if (clientRequestSocket != null) {
|
if (this.clientSocket != null) {
|
||||||
try {
|
try {
|
||||||
clientRequestSocket.close();
|
clientSocket.close();
|
||||||
} catch (IOException e) {}
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestSocket != null) {
|
if (this.serverSocket != null) {
|
||||||
try {
|
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) {}
|
} catch (IOException e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void loopForRequests() {
|
public Object getClientConnection() {
|
||||||
synchronized (clientRequestSocket) {
|
return clientSocket;
|
||||||
super.loopForRequests();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +91,7 @@ public class DebugSupportImpl extends DebugSupport {
|
|||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
protected void sendEvent(DebugEvent event) {
|
protected void sendEvent(DebugEvent event) {
|
||||||
synchronized (eventSocket) {
|
synchronized (clientSocket) {
|
||||||
super.sendEvent(event);
|
super.sendEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -39,7 +39,6 @@ import org.luaj.vm.LValue;
|
|||||||
import org.luaj.vm.LoadState;
|
import org.luaj.vm.LoadState;
|
||||||
import org.luaj.vm.LuaState;
|
import org.luaj.vm.LuaState;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StandardLuaJVM executes a lua program in normal run mode or debug mode.
|
* StandardLuaJVM executes a lua program in normal run mode or debug mode.
|
||||||
*
|
*
|
||||||
@@ -47,9 +46,11 @@ import org.luaj.vm.LuaState;
|
|||||||
* @version: 1.0
|
* @version: 1.0
|
||||||
*/
|
*/
|
||||||
public class StandardLuaJVM {
|
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 boolean isDebugMode = false;
|
||||||
protected int requestPort;
|
protected int debugPort = -1;;
|
||||||
protected int eventPort;
|
protected boolean bSuspendOnStart = false;
|
||||||
protected String script;
|
protected String script;
|
||||||
protected String[] scriptArgs;
|
protected String[] scriptArgs;
|
||||||
protected LuaState state;
|
protected LuaState state;
|
||||||
@@ -67,7 +68,7 @@ public class StandardLuaJVM {
|
|||||||
|
|
||||||
protected void printUsage() {
|
protected void printUsage() {
|
||||||
System.out.println("Usage:");
|
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.");
|
System.out.println("where [] denotes an optional argument and <> denotes a placeholder.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,33 +77,47 @@ public class StandardLuaJVM {
|
|||||||
throw new ParseException("Invalid command line arguments.");
|
throw new ParseException("Invalid command line arguments.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("-debug".equals(args[0])) {
|
if (args[0] != null && args[0].startsWith("-D")) {
|
||||||
if (args.length < 4) {
|
if (args.length < 2) {
|
||||||
throw new ParseException("Invalid command line arguments.");
|
throw new ParseException("Invalid command line arguments.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isDebugMode = true;
|
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 {
|
try {
|
||||||
this.requestPort = Integer.parseInt(args[1]);
|
this.debugPort = Integer.parseInt(portString);
|
||||||
if (this.requestPort <= 0) {
|
if (this.debugPort <= 0) {
|
||||||
throw new ParseException("Invalid request port: it must be greater than zero.");
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.eventPort = Integer.parseInt(args[2]);
|
if (this.debugPort == -1) {
|
||||||
if (this.eventPort <= 0) {
|
throw new ParseException("Invalid command line: debug port is missing");
|
||||||
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) {
|
int tempArgsCount = args.length - 1;
|
||||||
throw new ParseException("Invalid ports: request port and event port must be different");
|
|
||||||
}
|
|
||||||
|
|
||||||
int tempArgsCount = args.length - 3;
|
|
||||||
String[] tempArgs = new String[tempArgsCount];
|
String[] tempArgs = new String[tempArgsCount];
|
||||||
System.arraycopy(args, 3, tempArgs, 0, tempArgsCount);
|
System.arraycopy(args, 1, tempArgs, 0, tempArgsCount);
|
||||||
parseScriptArgs(tempArgs);
|
parseScriptArgs(tempArgs);
|
||||||
} else {
|
} else {
|
||||||
parseScriptArgs(args);
|
parseScriptArgs(args);
|
||||||
@@ -125,18 +140,19 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// end of command line parsing utilities
|
// end of command line parsing utilities
|
||||||
|
|
||||||
boolean isDebug() {
|
boolean isDebug() {
|
||||||
return this.isDebugMode;
|
return this.isDebugMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getRequestPort() {
|
int getDebugPort() {
|
||||||
return this.requestPort;
|
return this.debugPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getEventPort() {
|
boolean getSuspendOnStart() {
|
||||||
return this.eventPort;
|
return this.bSuspendOnStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
String getScript() {
|
String getScript() {
|
||||||
@@ -169,7 +185,6 @@ public class StandardLuaJVM {
|
|||||||
|
|
||||||
// add the compiler
|
// add the compiler
|
||||||
LuaC.install();
|
LuaC.install();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doRun() throws IOException {
|
protected void doRun() throws IOException {
|
||||||
@@ -210,10 +225,9 @@ public class StandardLuaJVM {
|
|||||||
|
|
||||||
// set up debug support if the file is successfully loaded
|
// set up debug support if the file is successfully loaded
|
||||||
DebugUtils.println("start debugging...");
|
DebugUtils.println("start debugging...");
|
||||||
DebugSupport debugSupport
|
DebugSupport debugSupport = new DebugSupportImpl(getDebugPort());
|
||||||
= new DebugSupportImpl(getRequestPort(), getEventPort());
|
getDebugState().setSuspendAtStart(getSuspendOnStart());
|
||||||
getDebugState().setDebugSupport(debugSupport);
|
getDebugState().setDebugSupport(debugSupport);
|
||||||
getDebugState().setSuspendAtStart(true);
|
|
||||||
|
|
||||||
// create closure and execute
|
// create closure and execute
|
||||||
final LClosure c = new LClosure(p, state._G);
|
final LClosure c = new LClosure(p, state._G);
|
||||||
@@ -232,7 +246,7 @@ public class StandardLuaJVM {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private DebugLuaState getDebugState() {
|
private DebugLuaState getDebugState() {
|
||||||
return (DebugLuaState)state;
|
return (DebugLuaState) state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -21,7 +21,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.request;
|
package org.luaj.debug.request;
|
||||||
|
|
||||||
import org.luaj.debug.response.DebugResponse;
|
|
||||||
|
|
||||||
public interface DebugRequestListener {
|
public interface DebugRequestListener {
|
||||||
|
|
||||||
@@ -38,5 +37,5 @@ public interface DebugRequestListener {
|
|||||||
* listing the (variable, value) pairs
|
* listing the (variable, value) pairs
|
||||||
* step -- single step forward (go to next statement)
|
* step -- single step forward (go to next statement)
|
||||||
*/
|
*/
|
||||||
public 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.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.response;
|
package org.luaj.debug.response;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
@@ -26,12 +26,14 @@ import java.io.DataOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.luaj.debug.StackFrame;
|
import org.luaj.debug.StackFrame;
|
||||||
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
import org.luaj.debug.event.DebugEventType;
|
||||||
|
|
||||||
|
public class DebugResponseCallgraph extends DebugEvent {
|
||||||
public class DebugResponseCallgraph implements DebugResponse {
|
|
||||||
protected StackFrame[] stackFrames;
|
protected StackFrame[] stackFrames;
|
||||||
|
|
||||||
public DebugResponseCallgraph(StackFrame[] callgraph) {
|
public DebugResponseCallgraph(StackFrame[] callgraph) {
|
||||||
|
super(DebugEventType.clientRequestCallgraphReply);
|
||||||
if (callgraph == null) {
|
if (callgraph == null) {
|
||||||
this.stackFrames = new StackFrame[0];
|
this.stackFrames = new StackFrame[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -53,8 +55,8 @@ public class DebugResponseCallgraph implements DebugResponse {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out, DebugResponseCallgraph response)
|
public static void serialize(DataOutputStream out,
|
||||||
throws IOException {
|
DebugResponseCallgraph response) throws IOException {
|
||||||
StackFrame[] stackFrames = response.getCallgraph();
|
StackFrame[] stackFrames = response.getCallgraph();
|
||||||
out.writeInt(stackFrames == null ? 0 : stackFrames.length);
|
out.writeInt(stackFrames == null ? 0 : stackFrames.length);
|
||||||
for (int i = 0; stackFrames != null && i < stackFrames.length; i++) {
|
for (int i = 0; stackFrames != null && i < stackFrames.length; i++) {
|
||||||
@@ -62,7 +64,7 @@ public class DebugResponseCallgraph implements DebugResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugResponseCallgraph deserialize(DataInputStream in) throws IOException {
|
public static DebugEvent deserialize(DataInputStream in) throws IOException {
|
||||||
int count = in.readInt();
|
int count = in.readInt();
|
||||||
StackFrame[] stackFrames = new StackFrame[count];
|
StackFrame[] stackFrames = new StackFrame[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
|
|||||||
@@ -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.SerializationHelper;
|
||||||
import org.luaj.debug.Variable;
|
import org.luaj.debug.Variable;
|
||||||
|
import org.luaj.debug.event.DebugEvent;
|
||||||
|
import org.luaj.debug.event.DebugEventType;
|
||||||
|
|
||||||
public class DebugResponseVariables implements DebugResponse {
|
public class DebugResponseVariables extends DebugEvent {
|
||||||
protected Variable[] variables;
|
protected Variable[] variables;
|
||||||
|
|
||||||
public DebugResponseVariables(Variable[] variables) {
|
public DebugResponseVariables(Variable[] variables, DebugEventType type) {
|
||||||
|
super(type);
|
||||||
if (variables == null) {
|
if (variables == null) {
|
||||||
this.variables = new Variable[0];
|
this.variables = new Variable[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -57,6 +60,7 @@ public class DebugResponseVariables implements DebugResponse {
|
|||||||
public static void serialize(DataOutputStream out,
|
public static void serialize(DataOutputStream out,
|
||||||
DebugResponseVariables response)
|
DebugResponseVariables response)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
DebugEventType.serialize(out, response.getType());
|
||||||
Variable[] variables = response.getVariables();
|
Variable[] variables = response.getVariables();
|
||||||
out.writeInt(variables == null ? 0 : variables.length);
|
out.writeInt(variables == null ? 0 : variables.length);
|
||||||
for (int i = 0; i < variables.length; i++) {
|
for (int i = 0; i < variables.length; i++) {
|
||||||
@@ -64,13 +68,14 @@ public class DebugResponseVariables implements DebugResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugResponseVariables deserialize(DataInputStream in)
|
public static DebugEvent deserialize(DataInputStream in)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
DebugEventType type = DebugEventType.deserialize(in);
|
||||||
int count = in.readInt();
|
int count = in.readInt();
|
||||||
Variable[] variables = new Variable[count];
|
Variable[] variables = new Variable[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
||||||
}
|
}
|
||||||
return new DebugResponseVariables(variables);
|
return new DebugResponseVariables(variables, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,60 +2,54 @@ package org.luaj.debug;
|
|||||||
|
|
||||||
import java.io.IOException;
|
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.DebugResponseCallgraph;
|
||||||
import org.luaj.debug.response.DebugResponseSimple;
|
import org.luaj.debug.response.DebugResponseStack;
|
||||||
import org.luaj.debug.response.DebugResponseVariables;
|
import org.luaj.debug.response.DebugResponseVariables;
|
||||||
import org.luaj.vm.Lua;
|
import org.luaj.vm.Lua;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
public class DebugResponseTest extends 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() {
|
public void testDebugResponseStackSerialization() {
|
||||||
try {
|
try {
|
||||||
doTestDebugResponseStackSerialization(null);
|
doTestDebugResponseStackSerialization(0, null);
|
||||||
|
|
||||||
doTestDebugResponseStackSerialization(new Variable[0]);
|
doTestDebugResponseStackSerialization(1, new Variable[0]);
|
||||||
|
|
||||||
Variable[] variables = new Variable[5];
|
Variable[] variables = new Variable[5];
|
||||||
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING, "value1");
|
variables[0] = new Variable(0, "variable1", Lua.LUA_TSTRING,
|
||||||
|
"value1");
|
||||||
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
variables[1] = new Variable(1, "variable2", Lua.LUA_TNIL, "nil");
|
||||||
variables[2] = new Variable(2, "variable3", Lua.LUA_TBOOLEAN, "false");
|
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]);
|
TableVariable childTable = new TableVariable(0, "child",
|
||||||
String[] keys = new String[] {"key1", "key2"};
|
Lua.LUA_TTABLE, new String[0], new Object[0]);
|
||||||
Object[] values = new Object[] {"value1", childTable};
|
String[] keys = new String[] { "key1", "key2" };
|
||||||
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE, keys, values);
|
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");
|
variables[4] = new Variable(2, "variable3", Lua.LUA_TNUMBER, "10");
|
||||||
doTestDebugResponseStackSerialization(variables);
|
doTestDebugResponseStackSerialization(2, variables);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
fail(e.getMessage());
|
fail(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
private void doTestDebugResponseStackSerialization(int index, Variable[] variables)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
DebugResponseStack stackIn = new DebugResponseStack(index, variables);
|
||||||
byte[] data = SerializationHelper.serialize(stackIn);
|
byte[] data = SerializationHelper.serialize(stackIn);
|
||||||
DebugResponseVariables stackOut
|
DebugResponseStack stackOut = (DebugResponseStack) SerializationHelper
|
||||||
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
.deserialize(data);
|
||||||
Variable[] variablesIn = stackIn.getVariables();
|
Variable[] variablesIn = stackIn.getVariables();
|
||||||
Variable[] variablesOut = stackOut.getVariables();
|
Variable[] variablesOut = stackOut.getVariables();
|
||||||
assertNotNull(variablesIn);
|
assertNotNull(variablesIn);
|
||||||
assertNotNull(variablesOut);
|
assertNotNull(variablesOut);
|
||||||
|
assertEquals(stackIn.getIndex(), stackOut.getIndex());
|
||||||
assertEquals(variablesIn.length, variablesOut.length);
|
assertEquals(variablesIn.length, variablesOut.length);
|
||||||
for (int i = 0; i < variablesIn.length; i++) {
|
for (int i = 0; i < variablesIn.length; i++) {
|
||||||
assertEquals(variablesIn[i], variablesOut[i]);
|
assertEquals(variablesIn[i], variablesOut[i]);
|
||||||
@@ -79,8 +73,8 @@ public class DebugResponseTest extends TestCase {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
|
||||||
byte[] data = SerializationHelper.serialize(responseIn);
|
byte[] data = SerializationHelper.serialize(responseIn);
|
||||||
DebugResponseCallgraph responseOut =
|
DebugResponseCallgraph responseOut = (DebugResponseCallgraph) SerializationHelper
|
||||||
(DebugResponseCallgraph) SerializationHelper.deserialize(data);
|
.deserialize(data);
|
||||||
assertNotNull(responseOut);
|
assertNotNull(responseOut);
|
||||||
StackFrame[] inFrames = responseIn.getCallgraph();
|
StackFrame[] inFrames = responseIn.getCallgraph();
|
||||||
StackFrame[] outFrames = responseOut.getCallgraph();
|
StackFrame[] outFrames = responseOut.getCallgraph();
|
||||||
|
|||||||
@@ -1,24 +1,24 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2007 LuaJ. All rights reserved.
|
* Copyright (c) 2007 LuaJ. All rights reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* 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
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.luaj.debug.j2se;
|
package org.luaj.debug.j2se;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -44,101 +44,138 @@ public class LuaJVMTest extends TestCase {
|
|||||||
|
|
||||||
// empty arguments
|
// empty arguments
|
||||||
args = new String[] {};
|
args = new String[] {};
|
||||||
|
vm = new StandardLuaJVM();
|
||||||
try {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
fail("Bad parsing program. Should never reach this line.");
|
||||||
} catch (ParseException e) {}
|
} catch (ParseException e) {}
|
||||||
|
|
||||||
// incomplete arguments
|
// incomplete arguments
|
||||||
args = new String[] { "-debug" };
|
args = new String[] { "-D" };
|
||||||
|
vm = new StandardLuaJVM();
|
||||||
try {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
fail("Bad parsing program. Should never reach this line.");
|
||||||
} catch (ParseException e) {}
|
} catch (ParseException e) {}
|
||||||
|
|
||||||
// incomplete arguments
|
args = new String[] { "-D1046" };
|
||||||
args = new String[] { "-debug", "1046" };
|
vm = new StandardLuaJVM();
|
||||||
try {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
fail("Bad parsing program. Should never reach this line.");
|
||||||
} catch (ParseException e) {}
|
} catch (ParseException e) {}
|
||||||
|
|
||||||
// missing script name
|
args = new String[] { "-DsuspendOnStart=true" };
|
||||||
args = new String[] { "-debug", "1046", "1047"};
|
vm = new StandardLuaJVM();
|
||||||
try {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
fail("Bad parsing program. Should never reach this line.");
|
||||||
} catch (ParseException e) {}
|
} catch (ParseException e) {}
|
||||||
|
|
||||||
// malformed request port
|
// invalid debug option format
|
||||||
args = new String[] { "-debug", "104x", "1046", "dummy.lua"};
|
args = new String[] { "-Dport=1044:suspendOnStart=true", "dummy.lua" };
|
||||||
|
vm = new StandardLuaJVM();
|
||||||
try {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
assertFalse(1044 == vm.getDebugPort());
|
||||||
} catch (ParseException e) {}
|
assertFalse(true == vm.getSuspendOnStart());
|
||||||
|
assertEquals("dummy.lua", vm.getScript());
|
||||||
// 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) {}
|
|
||||||
|
|
||||||
// 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) {
|
} catch (ParseException e) {
|
||||||
fail("Should never reach this line.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
//expected
|
//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
|
// lua script cannot be found
|
||||||
args = new String[] {"dummy.lua"};
|
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 {
|
try {
|
||||||
vm.parse(args);
|
vm.parse(args);
|
||||||
vm.run();
|
vm.run();
|
||||||
fail("Bad parsing program. Should never reach this line.");
|
fail("Bad parsing program. Should never reach this line.");
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
fail("Should never reach this line.");
|
fail("Should never reach this line.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {}
|
||||||
//expected
|
|
||||||
|
// 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() {
|
public void testRun() {
|
||||||
String[] tests = new String[] {
|
String[] tests = new String[] { "autoload", "boolean", "calls",
|
||||||
"autoload",
|
"coercions", "compare", "math", "mathlib", "metatables",
|
||||||
"boolean",
|
"select", "setlist", "swingapp", "test1", "test2", "test3",
|
||||||
"calls",
|
"test4", "test5", "test6", "test7", "type", "upvalues",
|
||||||
"coercions",
|
// "strlib"
|
||||||
"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++) {
|
for (int i = 0; i < tests.length; i++) {
|
||||||
@@ -153,7 +190,7 @@ public class LuaJVMTest extends TestCase {
|
|||||||
|
|
||||||
protected void doTestRun(String testName) {
|
protected void doTestRun(String testName) {
|
||||||
String[] args = new String[1];
|
String[] args = new String[1];
|
||||||
URL filePath = getClass().getResource("/"+ testName);
|
URL filePath = getClass().getResource("/" + testName);
|
||||||
if (filePath != null) {
|
if (filePath != null) {
|
||||||
args[0] = filePath.getPath();
|
args[0] = filePath.getPath();
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user