added debugging support and integrated with Eclipse debugger

This commit is contained in:
Shu Lei
2007-10-03 17:39:37 +00:00
parent cd5f278e7b
commit 421eface40
46 changed files with 1586 additions and 2547 deletions

View File

@@ -0,0 +1,30 @@
/*******************************************************************************
* 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 lua.debug;
public class AbortException extends RuntimeException {
private static final long serialVersionUID = 8043724992294286647L;
public AbortException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,50 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.Serializable;
public class DebugEvent implements Serializable {
private static final long serialVersionUID = -6167781055176807311L;
protected DebugEventType type;
public DebugEvent(DebugEventType type) {
this.type = type;
}
public DebugEventType getType() {
return type;
}
public void setType(DebugEventType type) {
this.type = type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return type.toString();
}
}

View File

@@ -0,0 +1,50 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugEventBreakpoint extends DebugEvent {
private static final long serialVersionUID = -7573362646669094458L;
protected String source;
protected int lineNumber;
public DebugEventBreakpoint(String source, int lineNumber) {
super(DebugEventType.suspendedOnBreakpoint);
this.source = source;
this.lineNumber = lineNumber;
}
public String getSource() {
return this.source;
}
public int getLineNumber() {
return this.lineNumber;
}
/* (non-Javadoc)
* @see lua.debug.DebugEvent#toString()
*/
@Override
public String toString() {
return super.toString() + " source:" + getSource() + " line:" + getLineNumber();
}
}

View File

@@ -0,0 +1,44 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugEventError extends DebugEvent {
private static final long serialVersionUID = -7911842790951966147L;
protected String detail;
public DebugEventError(String detail) {
super(DebugEventType.error);
this.detail = detail;
}
public String getDetail() {
return this.detail;
}
/* (non-Javadoc)
* @see lua.debug.DebugEvent#toString()
*/
@Override
public String toString() {
return super.toString() + " detail: " + getDetail();
}
}

View File

@@ -0,0 +1,26 @@
/*******************************************************************************
* 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 lua.debug;
public interface DebugEventListener {
public void notifyDebugEvent(DebugEvent event);
}

View File

@@ -0,0 +1,30 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugEventStepping extends DebugEvent {
private static final long serialVersionUID = 3902898567880012107L;
public DebugEventStepping() {
super(DebugEventType.suspendedOnStepping);
}
}

View File

@@ -0,0 +1,36 @@
/*******************************************************************************
* 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 lua.debug;
public enum DebugEventType {
started,
suspendedByClient,
suspendedOnBreakpoint,
suspendedOnWatchpoint,
suspendedOnStepping,
suspendedOnError,
resumedByClient,
resumedOnStepping,
resumedOnError,
error,
terminated
}

View File

@@ -0,0 +1,45 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.Serializable;
public class DebugRequest implements Serializable {
private static final long serialVersionUID = 2741129244733000595L;
protected DebugRequestType type;
public DebugRequest(DebugRequestType type) {
this.type = type;
}
public DebugRequestType getType() {
return this.type;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return type.toString();
}
}

View File

@@ -0,0 +1,53 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugRequestLineBreakpointToggle extends DebugRequest {
private static final long serialVersionUID = -3954500569399285372L;
protected String source;
protected int lineNumber;
public DebugRequestLineBreakpointToggle(DebugRequestType type, String source, int lineNumber) {
super(type);
if (lineNumber < 0) {
throw new IllegalArgumentException("lineNumber must be equal to greater than zero");
}
this.source = source;
this.lineNumber = lineNumber;
}
public int getLineNumber() {
return this.lineNumber;
}
public String getSource() {
return this.source;
}
/* (non-Javadoc)
* @see lua.debug.DebugRequest#toString()
*/
@Override
public String toString() {
return super.toString() + " Source:" + getSource() + " lineNumber:" + getLineNumber();
}
}

View File

@@ -21,12 +21,6 @@
******************************************************************************/
package lua.debug;
/**
* <code>DebugRequestListener</code> handles debugging requests.
*
* @author: Shu Lei
* @version: 1.0
*/
public interface DebugRequestListener {
/**
@@ -40,10 +34,7 @@ public interface DebugRequestListener {
* old to new, include information about file, method, etc.)
* stack -- return the content of the current stack frame,
* listing the (variable, value) pairs
* step -- single step forward (go to next statement)
* variable N M
* -- return the value of variable M from the stack frame N
* (stack frames are indexed from 0)
* step -- single step forward (go to next statement)
*/
public String handleRequest(String request);
public DebugResponse handleRequest(DebugRequest request);
}

View File

@@ -0,0 +1,44 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugRequestStack extends DebugRequest {
private static final long serialVersionUID = 6270383432060791307L;
protected int index;
public DebugRequestStack(int index) {
super(DebugRequestType.stack);
this.index = index;
}
public int getIndex() {
return this.index;
}
/* (non-Javadoc)
* @see lua.debug.DebugRequest#toString()
*/
@Override
public String toString() {
return super.toString() + " stack frame:" + getIndex();
}
}

View File

@@ -0,0 +1,35 @@
/*******************************************************************************
* 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 lua.debug;
public enum DebugRequestType {
suspend,
resume,
exit,
lineBreakpointSet,
lineBreakpointClear,
watchpointSet,
watchpointClear,
callgraph,
stack,
step
}

View File

@@ -0,0 +1,60 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugRequestWatchpointToggle extends DebugRequest {
private static final long serialVersionUID = -2978341358052851046L;
public enum AccessType {
Ignore,
Read,
Modify,
ReadAndModify
};
protected String functionName;
protected String variableName;
public DebugRequestWatchpointToggle(String functionName,
String variableName,
AccessType accessType) {
super(accessType == AccessType.Ignore ? DebugRequestType.watchpointClear : DebugRequestType.watchpointSet);
this.functionName = functionName;
this.variableName = variableName;
}
public String getFunctionName() {
return this.functionName;
}
public String getVariableName() {
return this.variableName;
}
/* (non-Javadoc)
* @see lua.debug.DebugRequest#toString()
*/
@Override
public String toString() {
return super.toString() + " functionName:" + getFunctionName() + " variableName:" + getVariableName();
}
}

View File

@@ -0,0 +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.
******************************************************************************/
package lua.debug;
public interface DebugResponse {}

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugResponseCallgraph extends DebugResponseSimple {
private static final long serialVersionUID = -7761865402188853413L;
protected StackFrame[] stackFrames;
public DebugResponseCallgraph(StackFrame[] callgraph) {
super(true);
this.stackFrames = callgraph;
}
public StackFrame[] getCallgraph() {
return this.stackFrames;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
if (this.stackFrames != null) {
for (StackFrame frame : stackFrames) {
buffer.append(frame.toString());
buffer.append("\n");
}
}
return buffer.toString();
}
}

View File

@@ -0,0 +1,49 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.Serializable;
public class DebugResponseSimple implements DebugResponse, Serializable {
private static final long serialVersionUID = 7042417813840650230L;
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()
*/
@Override
public String toString() {
return String.valueOf(isSuccessful);
}
}

View File

@@ -0,0 +1,48 @@
/*******************************************************************************
* 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 lua.debug;
public class DebugResponseStack extends DebugResponseSimple {
private static final long serialVersionUID = -2108425321162834731L;
protected Variable[] variables;
public DebugResponseStack(Variable[] variables) {
super(true);
this.variables = variables;
}
public Variable[] getVariables() {
return this.variables;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
for (int i = 0; variables != null && i < variables.length; i++) {
buffer.append("\t" + variables[i].getName() + ":" + variables[i].getIndex() + "\n");
}
return buffer.toString();
}
}

View File

@@ -1,25 +1,75 @@
/*******************************************************************************
* 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 lua.debug;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Set;
import lua.CallInfo;
import lua.StackState;
import lua.addon.compile.LexState;
import lua.io.LocVars;
import lua.io.Proto;
import lua.value.LTable;
import lua.value.LValue;
import lua.value.Type;
public class DebugStackState extends StackState implements DebugRequestListener {
public Map<Integer,Boolean> breakpoints = new HashMap<Integer,Boolean>();
private boolean exiting = false;
private boolean suspended = false;
private boolean stepping = false;
private int lastline = -1;
private static final boolean DEBUG = false;
protected Map<String,Boolean> breakpoints = new HashMap<String,Boolean>();
protected boolean exiting = false;
protected boolean suspended = false;
protected boolean stepping = false;
protected int lastline = -1;
protected List<DebugEventListener> debugEventListeners
= new ArrayList<DebugEventListener>();
public DebugStackState() {
}
public void addDebugEventListener(DebugEventListener listener) {
if (!debugEventListeners.contains(listener)) {
debugEventListeners.add(listener);
}
}
public void removeDebugEventListener(DebugEventListener listener) {
if (debugEventListeners.contains(listener)) {
debugEventListeners.remove(listener);
}
}
protected void notifyDebugEventListeners(DebugEvent event) {
for (DebugEventListener listener : debugEventListeners) {
listener.notifyDebugEvent(event);
}
}
private String getFileLine(int cindex) {
String func = "?";
String line = "?";
@@ -29,119 +79,136 @@ public class DebugStackState extends StackState implements DebugRequestListener
Proto p = call.closure.p;
if ( p != null && p.source != null )
source = p.source.toJavaString();
if ( p.lineinfo != null && p.lineinfo.length > call.pc-1 )
line = String.valueOf( p.lineinfo[call.pc-1] );
if ( p.lineinfo != null && p.lineinfo.length > call.pc )
line = String.valueOf( p.lineinfo[call.pc] );
// TODO: reverse lookup on function name ????
func = call.closure.luaAsString().toJavaString();
}
return source+":"+line+"("+func+")";
}
private String addLineInfo( String message ) {
return getFileLine(cc)+": "+message;
}
private void printLuaTrace(String message) {
System.out.println( "Lua error: "+addLineInfo( message ) );
for ( int cindex=cc-1; cindex>=0; cindex-- )
System.out.println( "\tcalled by "+getFileLine( cindex ) );
}
protected void debugPcallError(Throwable t) {
System.out.println(addLineInfo("(caught in pcall) "+t.getMessage()));
System.out.flush();
}
// override and fill in line number info
public void lua_error(String message) {
throw new RuntimeException( message );
super.lua_error( getFileLine(cc)+": "+message );
}
private void printLuaTrace() {
System.out.println( "Lua location: "+getFileLine(cc) );
for ( int cindex=cc-1; cindex>=0; cindex-- )
System.out.println( "\tin "+getFileLine( cindex ) );
}
// intercept exceptions and fill in line numbers
public void exec() {
try {
super.exec();
} catch ( RuntimeException t ) {
t.printStackTrace();
printLuaTrace(t.getMessage());
} catch (AbortException e) {
// ignored. Client aborts the debugging session.
} catch ( Exception t ) {
t.printStackTrace();
printLuaTrace();
System.out.flush();
throw t;
}
}
// debug hooks
public void debugHooks( int pc ) {
DebugUtils.println("entered debugHook...");
if ( exiting )
throw new java.lang.RuntimeException("exiting");
throw new AbortException("exiting");
// make sure line numbers are current in any stack traces
calls[cc].pc = pc;
synchronized ( this ) {
// anytime the line doesn't change we keep going
int[] li = calls[cc].closure.p.lineinfo;
int line = (li!=null && li.length>pc? li[pc]: -1);
if ( lastline == line )
int line = getLineNumber(calls[cc]);
DebugUtils.println("debugHook - executing line: " + line);
if ( !stepping && lastline == line ) {
return;
}
// save line in case next op is a step
lastline = line;
if ( stepping )
stepping = false;
// check for a break point if we aren't suspended already
if ( ! suspended ) {
if ( breakpoints.containsKey(line) )
suspended = true;
else
return;
if ( stepping ) {
DebugUtils.println("suspended by stepping at pc=" + pc);
notifyDebugEventListeners(new DebugEventStepping());
suspended = true;
} else if ( !suspended ) {
// check for a break point if we aren't suspended already
Proto p = calls[cc].closure.p;
String source = DebugUtils.getSourceFileName(p.source);
if ( breakpoints.containsKey(constructBreakpointKey(source, line))){
DebugUtils.println("hitting breakpoint " + constructBreakpointKey(source, line));
notifyDebugEventListeners(
new DebugEventBreakpoint(source, line));
suspended = true;
} else {
return;
}
}
// wait for a state change
while ( suspended && (!exiting) && (!stepping) ) {
while (suspended && !exiting ) {
try {
this.wait();
DebugUtils.println("resuming execution...");
} catch ( InterruptedException ie ) {
ie.printStackTrace();
}
}
}
}
// ------------------ commands coming from the debugger -------------------
public enum RequestType {
suspend,
resume,
exit,
set,
clear,
callgraph,
stack,
step,
variable,
/**
* Get the current line number
* @param pc program counter
* @return the line number corresponding to the pc
*/
private int getLineNumber(CallInfo ci) {
int[] lineNumbers = ci.closure.p.lineinfo;
int pc = ci.pc;
int line = (lineNumbers != null && lineNumbers.length > pc ? lineNumbers[pc] : -1);
return line;
}
// ------------------ commands coming from the debugger -------------------
public String handleRequest(String request) {
StringTokenizer st = new StringTokenizer( request );
String req = st.nextToken();
RequestType rt = RequestType.valueOf(req);
switch ( rt ) {
case suspend: suspend(); return "true";
case resume: resume(); return "true";
case exit: exit(); return "true";
case set: set( Integer.parseInt(st.nextToken()) ); return "true";
case clear: clear( Integer.parseInt(st.nextToken()) ); return "true";
case callgraph: return callgraph();
case stack: return stack();
case step: step(); return "true";
case variable:
String N = st.nextToken();
String M = st.nextToken();
return variable( Integer.parseInt(N), Integer.parseInt(M) );
}
throw new java.lang.IllegalArgumentException( "unkown request type: "+req );
public DebugResponse handleRequest(DebugRequest request) {
DebugUtils.println("DebugStackState is handling request: " + request.toString());
switch (request.getType()) {
case suspend:
suspend();
return DebugResponseSimple.SUCCESS;
case resume:
resume();
return DebugResponseSimple.SUCCESS;
case exit:
exit();
return DebugResponseSimple.SUCCESS;
case lineBreakpointSet:
DebugRequestLineBreakpointToggle setBreakpointRequest
= (DebugRequestLineBreakpointToggle)request;
setBreakpoint(setBreakpointRequest.getSource(), setBreakpointRequest.getLineNumber());
return DebugResponseSimple.SUCCESS;
case lineBreakpointClear:
DebugRequestLineBreakpointToggle clearBreakpointRequest
= (DebugRequestLineBreakpointToggle)request;
clearBreakpoint(clearBreakpointRequest.getSource(), clearBreakpointRequest.getLineNumber());
return DebugResponseSimple.SUCCESS;
case callgraph:
return new DebugResponseCallgraph(getCallgraph());
case stack:
DebugRequestStack stackRequest = (DebugRequestStack) request;
int index = stackRequest.getIndex();
return new DebugResponseStack(getStack(index));
case step:
step();
return DebugResponseSimple.SUCCESS;
}
throw new java.lang.IllegalArgumentException( "unkown request type: "+request.getType() );
}
/**
@@ -155,13 +222,14 @@ public class DebugStackState extends StackState implements DebugRequestListener
this.notify();
}
}
/**
* resume the execution
*/
public void resume() {
synchronized ( this ) {
suspended = false;
stepping = false;
this.notify();
}
}
@@ -180,18 +248,24 @@ public class DebugStackState extends StackState implements DebugRequestListener
* set breakpoint at line N
* @param N the line to set the breakpoint at
*/
public void set( int N ) {
public void setBreakpoint(String source, int lineNumber) {
DebugUtils.println("adding breakpoint " + constructBreakpointKey(source, lineNumber));
synchronized ( this ) {
breakpoints.put( N, Boolean.TRUE );
breakpoints.put(constructBreakpointKey(source, lineNumber), Boolean.TRUE );
}
}
protected String constructBreakpointKey(String source, int lineNumber) {
return source + ":" + lineNumber;
}
/**
* clear breakpoint at line N
* clear breakpoint at line lineNumber of source source
*/
public void clear( int N ) {
public void clearBreakpoint(String source, int lineNumber) {
DebugUtils.println("removing breakpoint " + constructBreakpointKey(source, lineNumber));
synchronized ( this ) {
breakpoints.remove( N );
breakpoints.remove(constructBreakpointKey(source, lineNumber));
}
}
@@ -199,36 +273,71 @@ public class DebugStackState extends StackState implements DebugRequestListener
* return the current call graph (i.e. stack frames from
* old to new, include information about file, method, etc.)
*/
public String callgraph() {
public StackFrame[] getCallgraph() {
int n = cc;
if ( n < 0 || n >= calls.length )
return "";
StringBuffer sb = new StringBuffer();
for ( int i=0; i<=n; i++ ) {
return new StackFrame[0];
StackFrame[] frames = new StackFrame[n+1];
for ( int i = 0; i <= n; i++ ) {
CallInfo ci = calls[i];
// TODO: fill this out with proper format, names, etc.
sb.append( String.valueOf(ci.closure.p) );
sb.append( "\n" );
frames[i] = new StackFrame(ci, getLineNumber(ci));
}
return sb.toString();
return frames;
}
/**
* return the content of the current stack frame,
* listing the (variable, value) pairs
*/
public String stack() {
CallInfo ci;
if ( cc < 0 || cc >= calls.length || (ci=calls[cc]) == null )
return "<out of scope>";
LocVars[] lv = ci.closure.p.locvars;
int n = (lv != null? lv.length: 0);
StringBuffer sb = new StringBuffer();
for ( int i=0; i<n; i++ ) {
// TODO: figure out format
sb.append( "(" + lv[i].varname + "," + super.stack[ci.base+i] + ")\n" );
}
return sb.toString();
public Variable[] getStack(int index) {
if (index < 0 || index >= calls.length) {
//TODO: this is an error, handle it differently
return new Variable[0];
}
CallInfo callInfo = calls[index];
DebugUtils.println("Stack Frame: " + index + "[" + callInfo.base + "," + callInfo.top + "]");
int top = callInfo.top < callInfo.base ? callInfo.base : callInfo.top;
Proto prototype = callInfo.closure.p;
LocVars[] localVariables = prototype.locvars;
List<Variable> variables = new ArrayList<Variable>();
int localVariableCount = 0;
Set<String> variablesSeen = new HashSet<String>();
for (int i = 0; localVariables != null && i < localVariables.length && i <= top; i++) {
String varName = localVariables[i].varname.toString();
DebugUtils.print("\tVariable: " + varName);
DebugUtils.print("\tValue: " + stack[callInfo.base + i]);
if (!variablesSeen.contains(varName) &&
!LexState.isReservedKeyword(varName)) {
variablesSeen.add(varName);
LValue value = stack[callInfo.base + i];
if (value != null) {
Type type = Type.valueOf(value.luaGetType().toJavaString());
DebugUtils.print("\tType: " + type);
if (type == Type.table) {
DebugUtils.println(" (selected)");
variables.add(
new TableVariable(localVariableCount++,
varName,
type,
(LTable) value));
} else if (type != Type.function &&
type != Type.thread) {
DebugUtils.println(" (selected)");
variables.add(
new Variable(localVariableCount++,
varName,
type,
value.toString()));
} else {
DebugUtils.println("");
}
} else {
DebugUtils.println("");
}
} else {
DebugUtils.println("");
}
}
return (Variable[])variables.toArray(new Variable[0]);
}
@@ -237,19 +346,9 @@ public class DebugStackState extends StackState implements DebugRequestListener
*/
public void step() {
synchronized ( this ) {
suspended = false;
stepping = true;
this.notify();
}
}
/**
* return the value of variable M from the stack frame N
* (stack frames are indexed from 0)
*/
public String variable( int N, int M ) {
CallInfo ci;
if ( M < 0 || M >= calls.length || (ci=calls[M]) == null )
return "<out of scope>";
return String.valueOf( super.stack[ci.base] );
}
}

View File

@@ -21,21 +21,14 @@
******************************************************************************/
package lua.debug;
import java.io.BufferedReader;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
/**
* <code>DebugServer</code> manages the communications between LuaJ VM and
* the debugging client.
*
* @author: Shu Lei
* @version: <version>
*/
public class DebugServer {
public class DebugSupport implements DebugEventListener {
public enum State {
UNKNOWN,
RUNNING,
@@ -50,14 +43,14 @@ public class DebugServer {
protected ServerSocket requestSocket;
protected Socket clientRequestSocket;
protected BufferedReader requestReader;
protected PrintWriter requestWriter;
protected ObjectInputStream requestReader;
protected ObjectOutputStream requestWriter;
protected ServerSocket eventSocket;
protected Socket clientEventSocket;
protected PrintWriter eventWriter;
protected ObjectOutputStream eventWriter;
public DebugServer(DebugRequestListener listener,
public DebugSupport(DebugRequestListener listener,
int requestPort,
int eventPort) {
this.listener = listener;
@@ -65,7 +58,8 @@ public class DebugServer {
this.eventPort = eventPort;
}
protected void destroy() {
protected void releaseServer() {
DebugUtils.println("shutting down the debug server...");
if (requestReader != null) {
try {
requestReader.close();
@@ -73,7 +67,11 @@ public class DebugServer {
}
if (requestWriter != null) {
requestWriter.close();
try {
requestWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (clientRequestSocket != null) {
@@ -89,7 +87,11 @@ public class DebugServer {
}
if (eventWriter != null) {
eventWriter.close();
try {
eventWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (clientEventSocket != null) {
@@ -108,20 +110,22 @@ public class DebugServer {
public synchronized void start() throws IOException {
this.requestSocket = new ServerSocket(requestPort);
this.clientRequestSocket = requestSocket.accept();
this.requestReader = new BufferedReader(
new InputStreamReader(clientRequestSocket.getInputStream()));
this.requestWriter = new PrintWriter(clientRequestSocket.getOutputStream());
this.requestReader
= new ObjectInputStream(clientRequestSocket.getInputStream());
this.requestWriter
= new ObjectOutputStream(clientRequestSocket.getOutputStream());
this.eventSocket = new ServerSocket(eventPort);
this.clientEventSocket = eventSocket.accept();
this.eventWriter = new PrintWriter(clientEventSocket.getOutputStream());
this.eventWriter
= new ObjectOutputStream(clientEventSocket.getOutputStream());
this.requestWatcherThread = new Thread(new Runnable() {
public void run() {
if (getState() != State.STOPPED) {
handleRequest();
} else {
destroy();
releaseServer();
}
}
});
@@ -139,25 +143,39 @@ public class DebugServer {
public void handleRequest() {
synchronized (clientRequestSocket) {
String request = null;
try {
while (getState() != State.STOPPED &&
(request = requestReader.readLine()) != null) {
System.out.println("SERVER receives request: " + request);
String response = listener.handleRequest(request);
requestWriter.write(response);
while (getState() != State.STOPPED) {
DebugRequest request
= (DebugRequest) requestReader.readObject();
DebugUtils.println("SERVER receives request: " + request.toString());
DebugResponse response = listener.handleRequest(request);
requestWriter.writeObject(response);
requestWriter.flush();
DebugUtils.println("SERVER sends response: " + response);
}
if (getState() == State.STOPPED) {
destroy();
cleanup();
}
} catch (EOFException e) {
cleanup();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
/**
*
*/
private void cleanup() {
DebugUtils.println("SERVER terminated...");
releaseServer();
System.exit(0);
}
/**
* This method provides the second communication channel with the debugging
* client. The server can send events via this channel to notify the client
@@ -175,10 +193,22 @@ public class DebugServer {
*
* @param event
*/
public void fireEvent(String event) {
public void fireEvent(DebugEvent event) {
DebugUtils.println("SERVER sending event: " + event.toString());
synchronized (eventSocket) {
eventWriter.println(event);
eventWriter.flush();
try {
eventWriter.writeObject(event);
eventWriter.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/* (non-Javadoc)
* @see lua.debug.DebugEventListener#notifyDebugEvent(lua.debug.DebugEvent)
*/
public void notifyDebugEvent(DebugEvent event) {
fireEvent(event);
}
}

View File

@@ -0,0 +1,54 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.File;
import lua.io.LoadState;
import lua.value.LString;
public class DebugUtils {
public static final boolean IS_DEBUG = false;
public static void println(String message) {
if (IS_DEBUG) {
System.out.println(message);
}
}
public static void print(String message) {
if (IS_DEBUG) {
System.out.print(message);
}
}
public static String getSourceFileName(LString source) {
String sourceStr = source.toJavaString();
sourceStr = LoadState.getSourceName(sourceStr);
if (!LoadState.SOURCE_BINARY_STRING.equals(sourceStr)) {
File sourceFile = new File(sourceStr);
return sourceFile.getName();
} else {
return sourceStr;
}
}
}

View File

@@ -0,0 +1,77 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.Serializable;
import lua.CallInfo;
import lua.io.Proto;
public class StackFrame implements Serializable {
private static final long serialVersionUID = 2102834561519501432L;
protected int lineNumber;
protected String source;
public StackFrame(CallInfo callInfo, int lineNumber) {
Proto prototype = callInfo.closure.p;
this.lineNumber = lineNumber;
this.source = DebugUtils.getSourceFileName(prototype.source);
}
public int getLineNumber() {
return this.lineNumber;
}
public String getSource() {
return this.source;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return getSource() + ":" + getLineNumber();
}
}

View File

@@ -0,0 +1,61 @@
/*******************************************************************************
* 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 lua.debug;
import lua.value.LTable;
import lua.value.LValue;
import lua.value.Type;
public class TableVariable extends Variable {
private static final long serialVersionUID = 1194778378382802700L;
protected String[] keys;
protected Object[] values;
public TableVariable(int index, String name, Type type, LTable table) {
super(index, name, type, null);
int size = table.size();
DebugUtils.println("table size:" + size);
this.keys = new String[size];
this.values = new Object[size];
LValue[] keyValues = table.getKeys();
for (int i = 0; i < size; i++) {
this.keys[i] = keyValues[i].toString();
LValue value = table.get(keyValues[i]);
if (value instanceof LTable) {
this.values[i] = new TableVariable(i, "<table>", Type.table, (LTable)value);
} else {
this.values[i] = value.toString();
}
DebugUtils.println("["+ keys[i] + "," + values[i].toString() + "]");
}
}
public String[] getKeys() {
return this.keys;
}
public Object[] getValues() {
return this.values;
}
}

View File

@@ -0,0 +1,66 @@
/*******************************************************************************
* 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 lua.debug;
import java.io.Serializable;
import lua.value.Type;
public class Variable implements Serializable {
private static final long serialVersionUID = 8194091816623233934L;
protected int index;
protected String name;
protected String value;
protected Type type;
public Variable(int index, String name, Type type, String value) {
this.index = index;
this.name = name;
this.type = type;
this.value = value;
}
public String getName() {
return this.name;
}
public Type getType() {
return this.type;
}
public String getValue() {
return this.value;
}
public int getIndex() {
return this.index;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "index: " + getIndex() + " name:" + getName() + " type: " + getType() + " value:" + getValue();
}
}