|
|
|
|
@@ -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 lua.debug;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
@@ -53,23 +53,27 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
|
|
|
|
|
// stepping constants and stepping state
|
|
|
|
|
protected static final int STEP_NONE = 0;
|
|
|
|
|
|
|
|
|
|
protected static final int STEP_OVER = 1;
|
|
|
|
|
|
|
|
|
|
protected static final int STEP_INTO = 2;
|
|
|
|
|
|
|
|
|
|
protected static final int STEP_RETURN = 3;
|
|
|
|
|
|
|
|
|
|
protected int stepping = STEP_NONE;
|
|
|
|
|
protected boolean shouldPauseForStepping = false;
|
|
|
|
|
protected int steppingFrame = -1;
|
|
|
|
|
|
|
|
|
|
protected Hashtable breakpoints = new Hashtable();
|
|
|
|
|
protected boolean exiting = false;
|
|
|
|
|
protected boolean suspended = false;
|
|
|
|
|
protected boolean isStarted = false;
|
|
|
|
|
protected int lastline = -1;
|
|
|
|
|
protected String lastSource;
|
|
|
|
|
protected DebugSupport debugSupport;
|
|
|
|
|
protected VMException lastException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DebugStackState() {}
|
|
|
|
|
public DebugStackState() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setDebugSupport(DebugSupport debugSupport) throws IOException {
|
|
|
|
|
if (debugSupport == null) {
|
|
|
|
|
@@ -82,30 +86,31 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void debugAssert(boolean b) {
|
|
|
|
|
if ( ! b )
|
|
|
|
|
error( "assert failure" );
|
|
|
|
|
if (!b)
|
|
|
|
|
error("assert failure");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getFileLine(int cindex) {
|
|
|
|
|
String func = "?";
|
|
|
|
|
String line = "?";
|
|
|
|
|
String source = "?";
|
|
|
|
|
if ( cindex >= 0 ) {
|
|
|
|
|
if (cindex >= 0) {
|
|
|
|
|
CallInfo call = this.calls[cindex];
|
|
|
|
|
Proto p = call.closure.p;
|
|
|
|
|
if ( p != null && p.source != null )
|
|
|
|
|
if (p != null && p.source != null)
|
|
|
|
|
source = p.source.toJavaString();
|
|
|
|
|
if ( p.lineinfo != null && p.lineinfo.length > call.pc )
|
|
|
|
|
line = String.valueOf( p.lineinfo[call.pc] );
|
|
|
|
|
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.toJavaString();
|
|
|
|
|
}
|
|
|
|
|
return source+":"+line+"("+func+")";
|
|
|
|
|
return source + ":" + line + "(" + func + ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// override and fill in line number info
|
|
|
|
|
public void error(String message, int level) {
|
|
|
|
|
super.error( level<=0? message: getFileLine(cc+1-level)+": "+message );
|
|
|
|
|
super.error(level <= 0 ? message : getFileLine(cc + 1 - level) + ": "
|
|
|
|
|
+ message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// use line numbers by default
|
|
|
|
|
@@ -117,80 +122,90 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
public void exec() {
|
|
|
|
|
try {
|
|
|
|
|
super.exec();
|
|
|
|
|
} catch ( AbortException e ) {
|
|
|
|
|
} catch (AbortException e) {
|
|
|
|
|
// ignored. Client aborts the debugging session.
|
|
|
|
|
} catch ( VMException e ) {
|
|
|
|
|
} catch (VMException e) {
|
|
|
|
|
// let VM exceptions be processed
|
|
|
|
|
// the same as the base class to minimize differences
|
|
|
|
|
// between the debug and non-debug behavior
|
|
|
|
|
throw e;
|
|
|
|
|
} catch ( Exception e ) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
lastException = new VMException(e);
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEventError(e.getMessage()));
|
|
|
|
|
suspend();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// debug hooks
|
|
|
|
|
public void debugHooks( int pc ) {
|
|
|
|
|
if ( exiting ) {
|
|
|
|
|
public void debugHooks(int pc) {
|
|
|
|
|
if (exiting) {
|
|
|
|
|
throw new AbortException("aborted by debug client");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("entered debugHook on pc=" + pc + "...");
|
|
|
|
|
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
while (!isStarted) {
|
|
|
|
|
try {
|
|
|
|
|
this.wait();
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallInfo currentCallInfo = calls[cc];
|
|
|
|
|
Proto currentProto = currentCallInfo.closure.p;
|
|
|
|
|
|
|
|
|
|
// if we are not stepping, we keep going if the line doesn't change
|
|
|
|
|
// if we are not stepping, we would keep going if the line doesn't
|
|
|
|
|
// change
|
|
|
|
|
int line = getLineNumber(currentCallInfo);
|
|
|
|
|
String source = DebugUtils.getSourceFileName(currentProto.source);
|
|
|
|
|
if ( !isStepping() && lastline == line && source.equals(lastSource) ) {
|
|
|
|
|
if (!isStepping() && lastline == line && source.equals(lastSource)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("debugHook - executing line: " + line);
|
|
|
|
|
|
|
|
|
|
int i = currentProto.code[pc];
|
|
|
|
|
int opCode = StackState.GET_OPCODE(i);
|
|
|
|
|
if (isStepping() &&
|
|
|
|
|
opCode == StackState.OP_RETURN && cc == 0) {
|
|
|
|
|
if (isStepping() && opCode == StackState.OP_RETURN && cc == 0) {
|
|
|
|
|
cancelStepping();
|
|
|
|
|
} else if (shouldPauseForStepping) {
|
|
|
|
|
shouldPauseForStepping = false;
|
|
|
|
|
suspendOnStepping();
|
|
|
|
|
} else if ( stepping == STEP_INTO ) {
|
|
|
|
|
if (lastline != line){
|
|
|
|
|
} else if (stepping == STEP_INTO) {
|
|
|
|
|
if (lastline != line) {
|
|
|
|
|
suspendOnStepping();
|
|
|
|
|
} else if (opCode == StackState.OP_CALL) {
|
|
|
|
|
shouldPauseForStepping = true;
|
|
|
|
|
}
|
|
|
|
|
} else if (stepping == STEP_OVER) {
|
|
|
|
|
if ((lastline != line && steppingFrame == cc) || (steppingFrame > cc)) {
|
|
|
|
|
if ((lastline != line && steppingFrame == cc)
|
|
|
|
|
|| (steppingFrame > cc)) {
|
|
|
|
|
suspendOnStepping();
|
|
|
|
|
}
|
|
|
|
|
} else if (stepping == STEP_RETURN) {
|
|
|
|
|
if ((opCode == StackState.OP_RETURN && cc == this.steppingFrame) ||
|
|
|
|
|
(opCode == StackState.OP_TAILCALL && cc == this.steppingFrame)){
|
|
|
|
|
if ((opCode == StackState.OP_RETURN && cc == this.steppingFrame)
|
|
|
|
|
|| (opCode == StackState.OP_TAILCALL && cc == this.steppingFrame)) {
|
|
|
|
|
shouldPauseForStepping = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// check for a break point if we aren't suspended already
|
|
|
|
|
if ( !suspended && lastline != line) {
|
|
|
|
|
if (!suspended && lastline != line) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("Source: " + currentProto.source);
|
|
|
|
|
String fileName = DebugUtils.getSourceFileName(source);
|
|
|
|
|
String breakpointKey = constructBreakpointKey(fileName, line);
|
|
|
|
|
if (breakpoints.containsKey(breakpointKey)) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("hitting breakpoint "
|
|
|
|
|
+ constructBreakpointKey(fileName, line));
|
|
|
|
|
|
|
|
|
|
String breakpointKey = constructBreakpointKey(source, line);
|
|
|
|
|
if (breakpoints.containsKey(breakpointKey)){
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("hitting breakpoint " + constructBreakpointKey(source, line));
|
|
|
|
|
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEventBreakpoint(source, line));
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEventBreakpoint(
|
|
|
|
|
fileName, line));
|
|
|
|
|
suspended = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -200,16 +215,16 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
lastSource = source;
|
|
|
|
|
|
|
|
|
|
// wait for a state change
|
|
|
|
|
while (suspended && !exiting ) {
|
|
|
|
|
while (suspended && !exiting) {
|
|
|
|
|
try {
|
|
|
|
|
this.wait();
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("resuming execution...");
|
|
|
|
|
|
|
|
|
|
if (lastException != null) {
|
|
|
|
|
throw lastException;
|
|
|
|
|
}
|
|
|
|
|
} catch ( InterruptedException ie ) {
|
|
|
|
|
} catch (InterruptedException ie) {
|
|
|
|
|
ie.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -221,27 +236,31 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void cancelStepping() {
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEvent(DebugEventType.resumedOnSteppingEnd));
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEvent(
|
|
|
|
|
DebugEventType.resumedOnSteppingEnd));
|
|
|
|
|
stepping = STEP_NONE;
|
|
|
|
|
steppingFrame = -1;
|
|
|
|
|
shouldPauseForStepping = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void suspendOnStepping() {
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEvent(DebugEventType.suspendedOnStepping));
|
|
|
|
|
debugSupport.notifyDebugEvent(new DebugEvent(
|
|
|
|
|
DebugEventType.suspendedOnStepping));
|
|
|
|
|
suspended = true;
|
|
|
|
|
steppingFrame = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
int line = (lineNumbers != null && lineNumbers.length > pc ? lineNumbers[pc]
|
|
|
|
|
: -1);
|
|
|
|
|
return line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -249,16 +268,19 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
|
|
|
|
|
public DebugResponse handleRequest(DebugRequest request) {
|
|
|
|
|
if (this.debugSupport == null) {
|
|
|
|
|
throw new IllegalStateException("DebugStackState is not equiped with DebugSupport.");
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
|
"DebugStackState is not equiped with DebugSupport.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("DebugStackState is handling request: " + request.toString());
|
|
|
|
|
DebugUtils.println("DebugStackState is handling request: "
|
|
|
|
|
+ request.toString());
|
|
|
|
|
|
|
|
|
|
DebugRequestType requestType = request.getType();
|
|
|
|
|
if (DebugRequestType.start == requestType) {
|
|
|
|
|
DebugEvent event = new DebugEvent(DebugEventType.started);
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
setStarted();
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.exit == requestType) {
|
|
|
|
|
stop();
|
|
|
|
|
@@ -274,14 +296,14 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.lineBreakpointSet == requestType) {
|
|
|
|
|
DebugRequestLineBreakpointToggle setBreakpointRequest
|
|
|
|
|
= (DebugRequestLineBreakpointToggle)request;
|
|
|
|
|
setBreakpoint(setBreakpointRequest.getSource(), setBreakpointRequest.getLineNumber());
|
|
|
|
|
DebugRequestLineBreakpointToggle setBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
|
|
|
|
setBreakpoint(setBreakpointRequest.getSource(),
|
|
|
|
|
setBreakpointRequest.getLineNumber());
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.lineBreakpointClear == requestType) {
|
|
|
|
|
DebugRequestLineBreakpointToggle clearBreakpointRequest
|
|
|
|
|
= (DebugRequestLineBreakpointToggle)request;
|
|
|
|
|
clearBreakpoint(clearBreakpointRequest.getSource(), clearBreakpointRequest.getLineNumber());
|
|
|
|
|
DebugRequestLineBreakpointToggle clearBreakpointRequest = (DebugRequestLineBreakpointToggle) request;
|
|
|
|
|
clearBreakpoint(clearBreakpointRequest.getSource(),
|
|
|
|
|
clearBreakpointRequest.getLineNumber());
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.callgraph == requestType) {
|
|
|
|
|
return new DebugResponseCallgraph(getCallgraph());
|
|
|
|
|
@@ -290,30 +312,34 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
int index = stackRequest.getIndex();
|
|
|
|
|
return new DebugResponseStack(getStack(index));
|
|
|
|
|
} else if (DebugRequestType.stepInto == requestType) {
|
|
|
|
|
DebugEvent event = new DebugEvent(DebugEventType.resumedOnSteppingInto);
|
|
|
|
|
DebugEvent event = new DebugEvent(
|
|
|
|
|
DebugEventType.resumedOnSteppingInto);
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
stepInto();
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.stepOver == requestType) {
|
|
|
|
|
DebugEvent event = new DebugEvent(DebugEventType.resumedOnSteppingOver);
|
|
|
|
|
DebugEvent event = new DebugEvent(
|
|
|
|
|
DebugEventType.resumedOnSteppingOver);
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
stepOver();
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
} else if (DebugRequestType.stepReturn == requestType) {
|
|
|
|
|
DebugEvent event = new DebugEvent(DebugEventType.resumedOnSteppingReturn);
|
|
|
|
|
DebugEvent event = new DebugEvent(
|
|
|
|
|
DebugEventType.resumedOnSteppingReturn);
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
stepReturn();
|
|
|
|
|
return DebugResponseSimple.SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
throw new java.lang.IllegalArgumentException( "unkown request type: "+ request.getType());
|
|
|
|
|
throw new java.lang.IllegalArgumentException("unkown request type: "
|
|
|
|
|
+ request.getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* suspend the execution
|
|
|
|
|
*/
|
|
|
|
|
public void suspend() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
suspended = true;
|
|
|
|
|
stepping = STEP_NONE;
|
|
|
|
|
lastline = -1;
|
|
|
|
|
@@ -321,11 +347,18 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void setStarted() {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
isStarted = true;
|
|
|
|
|
this.notify();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* resume the execution
|
|
|
|
|
*/
|
|
|
|
|
public void resume() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
suspended = false;
|
|
|
|
|
stepping = STEP_NONE;
|
|
|
|
|
this.notify();
|
|
|
|
|
@@ -334,14 +367,15 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
|
|
|
|
|
public void stop() {
|
|
|
|
|
if (this.debugSupport == null) {
|
|
|
|
|
throw new IllegalStateException("DebugStackState is not equiped with DebugSupport.");
|
|
|
|
|
throw new IllegalStateException(
|
|
|
|
|
"DebugStackState is not equiped with DebugSupport.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugEvent event = new DebugEvent(DebugEventType.terminated);
|
|
|
|
|
debugSupport.notifyDebugEvent(event);
|
|
|
|
|
|
|
|
|
|
new Timer().schedule(new TimerTask() {
|
|
|
|
|
public void run () {
|
|
|
|
|
public void run() {
|
|
|
|
|
debugSupport.stop();
|
|
|
|
|
debugSupport = null;
|
|
|
|
|
}
|
|
|
|
|
@@ -354,7 +388,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
* terminate the execution
|
|
|
|
|
*/
|
|
|
|
|
public void exit() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
exiting = true;
|
|
|
|
|
this.notify();
|
|
|
|
|
}
|
|
|
|
|
@@ -362,18 +396,18 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* set breakpoint at line N
|
|
|
|
|
* @param N the line to set the breakpoint at
|
|
|
|
|
*
|
|
|
|
|
* @param N
|
|
|
|
|
* the line to set the breakpoint at
|
|
|
|
|
*/
|
|
|
|
|
public void setBreakpoint(String source, int lineNumber) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG) {
|
|
|
|
|
DebugUtils.print("source: " + source + " line:" + lineNumber);
|
|
|
|
|
DebugUtils.println("adding breakpoint " + constructBreakpointKey(source, lineNumber));
|
|
|
|
|
}
|
|
|
|
|
String fileName = DebugUtils.getSourceFileName(source);
|
|
|
|
|
String breakpointKey = constructBreakpointKey(fileName, lineNumber);
|
|
|
|
|
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
String normalizedFileName = DebugUtils.getSourceFileName(source);
|
|
|
|
|
breakpoints.put(constructBreakpointKey(normalizedFileName, lineNumber), Boolean.TRUE );
|
|
|
|
|
}
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("adding breakpoint " + breakpointKey);
|
|
|
|
|
|
|
|
|
|
breakpoints.put(breakpointKey, Boolean.TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected String constructBreakpointKey(String source, int lineNumber) {
|
|
|
|
|
@@ -384,26 +418,27 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
* clear breakpoint at line lineNumber of source source
|
|
|
|
|
*/
|
|
|
|
|
public void clearBreakpoint(String source, int lineNumber) {
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("removing breakpoint " + constructBreakpointKey(source, lineNumber));
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
String normalizedFileName = DebugUtils.getSourceFileName(source);
|
|
|
|
|
breakpoints.remove(constructBreakpointKey(normalizedFileName, lineNumber));
|
|
|
|
|
}
|
|
|
|
|
String fileName = DebugUtils.getSourceFileName(source);
|
|
|
|
|
String breakpointKey = constructBreakpointKey(fileName, lineNumber);
|
|
|
|
|
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("removing breakpoint " + breakpointKey);
|
|
|
|
|
|
|
|
|
|
breakpoints.remove(breakpointKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* return the current call graph (i.e. stack frames from
|
|
|
|
|
* old to new, include information about file, method, etc.)
|
|
|
|
|
* return the current call graph (i.e. stack frames from old to new, include
|
|
|
|
|
* information about file, method, etc.)
|
|
|
|
|
*/
|
|
|
|
|
public StackFrame[] getCallgraph() {
|
|
|
|
|
int n = cc;
|
|
|
|
|
|
|
|
|
|
if ( n < 0 || n >= calls.length )
|
|
|
|
|
if (n < 0 || n >= calls.length)
|
|
|
|
|
return new StackFrame[0];
|
|
|
|
|
|
|
|
|
|
StackFrame[] frames = new StackFrame[n+1];
|
|
|
|
|
for ( int i = 0; i <= n; i++ ) {
|
|
|
|
|
StackFrame[] frames = new StackFrame[n + 1];
|
|
|
|
|
for (int i = 0; i <= n; i++) {
|
|
|
|
|
CallInfo ci = calls[i];
|
|
|
|
|
frames[i] = new StackFrame(ci, getLineNumber(ci));
|
|
|
|
|
}
|
|
|
|
|
@@ -412,77 +447,109 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
|
|
|
|
|
public Variable[] getStack(int index) {
|
|
|
|
|
if (index < 0 || index >= calls.length) {
|
|
|
|
|
//TODO: this is an error, handle it differently
|
|
|
|
|
return new Variable[0];
|
|
|
|
|
throw new RuntimeException("invalid stack index");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CallInfo callInfo = calls[index];
|
|
|
|
|
if(DebugUtils.IS_DEBUG)
|
|
|
|
|
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;
|
|
|
|
|
Vector variables = new Vector();
|
|
|
|
|
int localVariableCount = 0;
|
|
|
|
|
Hashtable variablesSeen = new Hashtable();
|
|
|
|
|
for (int i = 0; localVariables != null && i < localVariables.length && i <= top; i++) {
|
|
|
|
|
String varName = localVariables[i].varname.toString();
|
|
|
|
|
if(DebugUtils.IS_DEBUG) {
|
|
|
|
|
DebugUtils.print("\tVariable: " + varName);
|
|
|
|
|
DebugUtils.print("\tValue: " + stack[callInfo.base + i]);
|
|
|
|
|
}
|
|
|
|
|
if (!variablesSeen.contains(varName) &&
|
|
|
|
|
!LexState.isReservedKeyword(varName)) {
|
|
|
|
|
variablesSeen.put(varName, varName);
|
|
|
|
|
LValue value = stack[callInfo.base + i];
|
|
|
|
|
if (value != null) {
|
|
|
|
|
int type = value.luaGetType();
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.print("\tType: " + Lua.TYPE_NAMES[type]);
|
|
|
|
|
if (type == Lua.LUA_TTABLE) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println(" (selected)");
|
|
|
|
|
variables.addElement(
|
|
|
|
|
new TableVariable(localVariableCount++,
|
|
|
|
|
varName,
|
|
|
|
|
type,
|
|
|
|
|
(LTable) value));
|
|
|
|
|
} else if (type != Lua.LUA_TFUNCTION &&
|
|
|
|
|
type != LUA_TTHREAD) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println(" (selected)");
|
|
|
|
|
variables.addElement(
|
|
|
|
|
new Variable(localVariableCount++,
|
|
|
|
|
varName,
|
|
|
|
|
type,
|
|
|
|
|
value.toString()));
|
|
|
|
|
} else {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("");
|
|
|
|
|
}
|
|
|
|
|
for (int i = index; i >= 0; i--) {
|
|
|
|
|
addVariables(variables, variablesSeen, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Variable[] result = new Variable[variables.size()];
|
|
|
|
|
for (int i = 0; i < variables.size(); i++) {
|
|
|
|
|
result[i] = (Variable) variables.elementAt(i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getVariable(CallInfo callInfo, int index) {
|
|
|
|
|
Proto prototype = callInfo.closure.p;
|
|
|
|
|
int count = -1;
|
|
|
|
|
LocVars[] localVariables = prototype.locvars;
|
|
|
|
|
for (int i = 0; i < localVariables.length; i++) {
|
|
|
|
|
if (callInfo.pc < localVariables[i].startpc ||
|
|
|
|
|
callInfo.pc > localVariables[i].endpc) {
|
|
|
|
|
continue;
|
|
|
|
|
} else {
|
|
|
|
|
count++;
|
|
|
|
|
if (count == index) {
|
|
|
|
|
return localVariables[i].varname.toJavaString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addVariables(Vector variables, Hashtable variablesSeen, int index) {
|
|
|
|
|
CallInfo callInfo = calls[index];
|
|
|
|
|
Proto prototype = callInfo.closure.p;
|
|
|
|
|
int base = callInfo.base;
|
|
|
|
|
int top = callInfo.top < callInfo.base ? callInfo.base+1 : callInfo.top;
|
|
|
|
|
|
|
|
|
|
if (DebugUtils.IS_DEBUG) {
|
|
|
|
|
DebugUtils.println("Stack Frame: " + index + " [" + base + "," + top + "], # of localvars: " + prototype.locvars.length + ", pc=" + callInfo.pc);
|
|
|
|
|
for (int i = 0; i < prototype.locvars.length; i++) {
|
|
|
|
|
DebugUtils.println("localvars[" + i + "]: " + prototype.locvars[i].varname + "(" + prototype.locvars[i].startpc + "," + prototype.locvars[i].endpc + ")");
|
|
|
|
|
}
|
|
|
|
|
for (int i = base; i < top; i++){
|
|
|
|
|
DebugUtils.println("stack[" + i + "]=" + stack[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int selectedVariableCount = 0;
|
|
|
|
|
for (int i = base; i < top; i++) {
|
|
|
|
|
String varName = getVariable(callInfo, i-base);
|
|
|
|
|
if (varName == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(DebugUtils.IS_DEBUG) {
|
|
|
|
|
DebugUtils.print("\tVariable: " + varName);
|
|
|
|
|
DebugUtils.print("\tValue: " + stack[i]);
|
|
|
|
|
}
|
|
|
|
|
if (!variablesSeen.contains(varName) &&
|
|
|
|
|
!LexState.isReservedKeyword(varName)) {
|
|
|
|
|
variablesSeen.put(varName, varName);
|
|
|
|
|
LValue value = stack[i];
|
|
|
|
|
if (value != null) {
|
|
|
|
|
int type = value.luaGetType();
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.print("\tType: " + Lua.TYPE_NAMES[type]);
|
|
|
|
|
if (type == Lua.LUA_TTABLE) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.print(" (selected)");
|
|
|
|
|
variables.addElement(
|
|
|
|
|
new TableVariable(selectedVariableCount++,
|
|
|
|
|
varName,
|
|
|
|
|
type,
|
|
|
|
|
(LTable) value));
|
|
|
|
|
} else if (type == LUA_TTHREAD) {
|
|
|
|
|
// coroutines
|
|
|
|
|
} else if (type != LUA_TFUNCTION) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.print(" (selected)");
|
|
|
|
|
variables.addElement(
|
|
|
|
|
new Variable(selectedVariableCount++,
|
|
|
|
|
varName,
|
|
|
|
|
type,
|
|
|
|
|
value.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* step over to next line
|
|
|
|
|
*/
|
|
|
|
|
public void stepOver() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("stepOver on cc=" + cc + "...");
|
|
|
|
|
|
|
|
|
|
@@ -497,7 +564,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
* step a single statement
|
|
|
|
|
*/
|
|
|
|
|
public void stepInto() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
suspended = false;
|
|
|
|
|
stepping = STEP_INTO;
|
|
|
|
|
this.notify();
|
|
|
|
|
@@ -508,7 +575,7 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|
|
|
|
* return from the method call
|
|
|
|
|
*/
|
|
|
|
|
public void stepReturn() {
|
|
|
|
|
synchronized ( this ) {
|
|
|
|
|
synchronized (this) {
|
|
|
|
|
if (DebugUtils.IS_DEBUG)
|
|
|
|
|
DebugUtils.println("stepReturn on cc=" + cc + "...");
|
|
|
|
|
|
|
|
|
|
|