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:
Shu Lei
2007-11-12 22:08:26 +00:00
parent a68fcb6743
commit 7ddfb80116
17 changed files with 696 additions and 738 deletions

View File

@@ -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;
@@ -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,61 +312,60 @@ 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());
}
}
/**
* suspend the execution

View File

@@ -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());
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);
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);
}
}

View File

@@ -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 {
@@ -51,7 +51,7 @@ public class SerializationHelper {
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_DebugResponseStack = 5;
static final int SERIAL_TYPE_StackFrame = 6;
static final int SERIAL_TYPE_DebugRequestType = 7;
static final int SERIAL_TYPE_DebugRequest = 8;
@@ -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;

View File

@@ -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;
@@ -45,7 +45,9 @@ public class DebugEvent implements Serializable {
this.type = type;
}
/* (non-Javadoc)
/*
* (non-Javadoc)
*
* @see java.lang.Object#toString()
*/
public String toString() {
@@ -58,7 +60,8 @@ public class DebugEvent implements Serializable {
}
public static DebugEvent deserialize(DataInputStream in) throws IOException {
DebugEventType type = (DebugEventType) SerializationHelper.deserialize(in);
DebugEventType type = (DebugEventType) SerializationHelper
.deserialize(in);
return new DebugEvent(type);
}
}

View File

@@ -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,6 +27,7 @@ import java.io.IOException;
public class DebugEventBreakpoint extends DebugEvent {
protected String source;
protected int lineNumber;
public DebugEventBreakpoint(String source, int lineNumber) {
@@ -36,7 +37,8 @@ public class DebugEventBreakpoint extends DebugEvent {
}
if (lineNumber <= 0) {
throw new IllegalArgumentException("argument lineNumber must be positive integer");
throw new IllegalArgumentException(
"argument lineNumber must be positive integer");
}
this.source = source;
@@ -51,15 +53,18 @@ public class DebugEventBreakpoint extends DebugEvent {
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 {
public static void serialize(DataOutputStream out,
DebugEventBreakpoint object) throws IOException {
out.writeUTF(object.getSource());
out.writeInt(object.getLineNumber());
}

View File

@@ -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) {

View File

@@ -9,86 +9,59 @@ 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 eventServerConnection;
protected ServerSocketConnection serverConnection;
protected SocketConnection clientDebugConnection;
protected SocketConnection eventSocketConnection;
public DebugSupportImpl(int requestPort,
int eventPort) {
super(requestPort, eventPort);
public DebugSupportImpl(int debugPort) {
super(debugPort);
}
/* (non-Javadoc)
/*
* (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) {
if (this.clientDebugConnection != null) {
try {
requestSocketConnection.close();
} 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) {}
clientDebugConnection.close();
} catch (IOException e) {
}
}
protected void loopForRequests() {
synchronized (requestSocketConnection) {
super.loopForRequests();
if (this.serverConnection != null) {
try {
serverConnection.close();
} catch (IOException e) {
}
}
}
public Object getClientConnection() {
return clientDebugConnection;
}
protected void sendEvent(DebugEvent event) {
synchronized (eventSocketConnection) {

View File

@@ -32,31 +32,23 @@ import org.luaj.debug.event.DebugEvent;
public class DebugSupportImpl extends DebugSupport {
protected ServerSocket requestSocket;
protected Socket clientRequestSocket;
protected ServerSocket serverSocket;
protected Socket clientSocket;
protected ServerSocket eventSocket;
protected Socket clientEventSocket;
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();
} catch (IOException e) {}
}
if (clientEventSocket != null) {
try {
clientEventSocket.close();
} catch (IOException e) {}
}
if (eventSocket != null){
try {
eventSocket.close();
serverSocket.close();
} catch (IOException e) {}
}
}
protected void loopForRequests() {
synchronized (clientRequestSocket) {
super.loopForRequests();
}
public Object getClientConnection() {
return clientSocket;
}
/**
@@ -113,7 +91,7 @@ public class DebugSupportImpl extends DebugSupport {
* @param event
*/
protected void sendEvent(DebugEvent event) {
synchronized (eventSocket) {
synchronized (clientSocket) {
super.sendEvent(event);
}
}

View File

@@ -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,9 +46,11 @@ 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;
@@ -67,7 +68,7 @@ public class StandardLuaJVM {
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.");
}
@@ -76,33 +77,47 @@ public class StandardLuaJVM {
throw new ParseException("Invalid command line arguments.");
}
if ("-debug".equals(args[0])) {
if (args.length < 4) {
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.requestPort = Integer.parseInt(args[1]);
if (this.requestPort <= 0) {
throw new ParseException("Invalid request port: it must be greater than zero.");
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);
}
}
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.debugPort == -1) {
throw new ParseException("Invalid command line: debug port is missing");
}
if (this.requestPort == this.eventPort) {
throw new ParseException("Invalid ports: request port and event port must be different");
}
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);
@@ -125,18 +140,19 @@ public class StandardLuaJVM {
}
}
}
// 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() {
@@ -169,7 +185,6 @@ public class StandardLuaJVM {
// add the compiler
LuaC.install();
}
protected void doRun() throws IOException {
@@ -210,10 +225,9 @@ 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);
@@ -232,7 +246,7 @@ public class StandardLuaJVM {
}
private DebugLuaState getDebugState() {
return (DebugLuaState)state;
return (DebugLuaState) state;
}
/**

View File

@@ -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);
}

View File

@@ -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 {}

View File

@@ -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,12 +26,14 @@ 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) {
super(DebugEventType.clientRequestCallgraphReply);
if (callgraph == null) {
this.stackFrames = new StackFrame[0];
} else {
@@ -53,8 +55,8 @@ public class DebugResponseCallgraph implements DebugResponse {
return buffer.toString();
}
public static void serialize(DataOutputStream out, DebugResponseCallgraph response)
throws IOException {
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++) {
@@ -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();
StackFrame[] stackFrames = new StackFrame[count];
for (int i = 0; i < count; i++) {

View File

@@ -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;
}
}

View 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);
}
}

View File

@@ -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);
}
}

View File

@@ -2,60 +2,54 @@ 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(0, null);
doTestDebugResponseStackSerialization(new Variable[0]);
doTestDebugResponseStackSerialization(1, new Variable[0]);
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[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]);
String[] keys = new String[] {"key1", "key2"};
Object[] values = new Object[] {"value1", childTable};
variables[3] = new TableVariable(2, "variable4", Lua.LUA_TTABLE, keys, values);
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);
doTestDebugResponseStackSerialization(2, variables);
} catch (IOException e) {
fail(e.getMessage());
}
}
private void doTestDebugResponseStackSerialization(Variable[] variables)
private void doTestDebugResponseStackSerialization(int index, Variable[] variables)
throws IOException {
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
DebugResponseStack stackIn = new DebugResponseStack(index, variables);
byte[] data = SerializationHelper.serialize(stackIn);
DebugResponseVariables stackOut
= (DebugResponseVariables) SerializationHelper.deserialize(data);
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]);
@@ -79,8 +73,8 @@ public class DebugResponseTest extends TestCase {
throws IOException {
DebugResponseCallgraph responseIn = new DebugResponseCallgraph(frames);
byte[] data = SerializationHelper.serialize(responseIn);
DebugResponseCallgraph responseOut =
(DebugResponseCallgraph) SerializationHelper.deserialize(data);
DebugResponseCallgraph responseOut = (DebugResponseCallgraph) SerializationHelper
.deserialize(data);
assertNotNull(responseOut);
StackFrame[] inFrames = responseIn.getCallgraph();
StackFrame[] outFrames = responseOut.getCallgraph();

View File

@@ -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;
@@ -44,101 +44,138 @@ public class LuaJVMTest extends TestCase {
// empty arguments
args = new String[] {};
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" };
args = new String[] { "-D" };
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", "1046" };
args = new String[] { "-D1046" };
vm = new StandardLuaJVM();
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"};
args = new String[] { "-DsuspendOnStart=true" };
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"};
// invalid debug option format
args = new String[] { "-Dport=1044:suspendOnStart=true", "dummy.lua" };
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) {}
// 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.");
assertFalse(1044 == vm.getDebugPort());
assertFalse(true == vm.getSuspendOnStart());
assertEquals("dummy.lua", vm.getScript());
} catch (ParseException e) {
fail("Should never reach this line.");
} catch (IOException 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[] {"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 {
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
} 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"
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++) {
@@ -153,7 +190,7 @@ public class LuaJVMTest extends TestCase {
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();
try {