1. renamed DebugResponseStack to DebugResponseVariables
2. added getGlobal to DebugStackState for supporting the Globals view 3. converted tabs to 4 whitespaces in some files
This commit is contained in:
@@ -43,7 +43,7 @@ import lua.debug.request.DebugRequestType;
|
|||||||
import lua.debug.response.DebugResponse;
|
import lua.debug.response.DebugResponse;
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
import lua.debug.response.DebugResponseCallgraph;
|
||||||
import lua.debug.response.DebugResponseSimple;
|
import lua.debug.response.DebugResponseSimple;
|
||||||
import lua.debug.response.DebugResponseStack;
|
import lua.debug.response.DebugResponseVariables;
|
||||||
import lua.io.LocVars;
|
import lua.io.LocVars;
|
||||||
import lua.io.Proto;
|
import lua.io.Proto;
|
||||||
import lua.value.LTable;
|
import lua.value.LTable;
|
||||||
@@ -328,7 +328,9 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
} else if (DebugRequestType.stack == requestType) {
|
} else if (DebugRequestType.stack == requestType) {
|
||||||
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
DebugRequestStack stackRequest = (DebugRequestStack) request;
|
||||||
int index = stackRequest.getIndex();
|
int index = stackRequest.getIndex();
|
||||||
return new DebugResponseStack(getStack(index));
|
return new DebugResponseVariables(getStack(index));
|
||||||
|
} else if (DebugRequestType.global == requestType) {
|
||||||
|
return new DebugResponseVariables(getGlobals());
|
||||||
} else if (DebugRequestType.stepInto == requestType) {
|
} else if (DebugRequestType.stepInto == requestType) {
|
||||||
DebugEvent event = new DebugEvent(
|
DebugEvent event = new DebugEvent(
|
||||||
DebugEventType.resumedOnSteppingInto);
|
DebugEventType.resumedOnSteppingInto);
|
||||||
@@ -485,6 +487,26 @@ public class DebugStackState extends StackState implements DebugRequestListener
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the visible globals to the current VM.
|
||||||
|
* @return the visible globals.
|
||||||
|
*/
|
||||||
|
public Variable[] getGlobals() {
|
||||||
|
Vector variables = new Vector();
|
||||||
|
variables.addElement(
|
||||||
|
new TableVariable(0,
|
||||||
|
"*Globals*",
|
||||||
|
Lua.LUA_TTABLE,
|
||||||
|
(LTable) _G));
|
||||||
|
|
||||||
|
Variable[] result = new Variable[variables.size()];
|
||||||
|
for (int i = 0; i < variables.size(); i++) {
|
||||||
|
result[i] = (Variable) variables.elementAt(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private void dumpStack(int index) {
|
private void dumpStack(int index) {
|
||||||
CallInfo callInfo = calls[index];
|
CallInfo callInfo = calls[index];
|
||||||
LocVars[] localVariables = callInfo.closure.p.locvars;
|
LocVars[] localVariables = callInfo.closure.p.locvars;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import lua.debug.request.DebugRequestStack;
|
|||||||
import lua.debug.request.DebugRequestType;
|
import lua.debug.request.DebugRequestType;
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
import lua.debug.response.DebugResponseCallgraph;
|
||||||
import lua.debug.response.DebugResponseSimple;
|
import lua.debug.response.DebugResponseSimple;
|
||||||
import lua.debug.response.DebugResponseStack;
|
import lua.debug.response.DebugResponseVariables;
|
||||||
|
|
||||||
public class SerializationHelper {
|
public class SerializationHelper {
|
||||||
|
|
||||||
@@ -46,12 +46,11 @@ public class SerializationHelper {
|
|||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static final int SERIAL_TYPE_NullableString = 0;
|
static final int SERIAL_TYPE_NullableString = 0;
|
||||||
static final int SERIAL_TYPE_TableVariable = 1;
|
static final int SERIAL_TYPE_TableVariable = 1;
|
||||||
static final int SERIAL_TYPE_Variable = 2;
|
static final int SERIAL_TYPE_Variable = 2;
|
||||||
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
static final int SERIAL_TYPE_DebugResponseCallgraph = 3;
|
||||||
static final int SERIAL_TYPE_DebugResponseStack = 4;
|
static final int SERIAL_TYPE_DebugResponseVariables = 4;
|
||||||
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
static final int SERIAL_TYPE_DebugResponseSimple = 5;
|
||||||
static final int SERIAL_TYPE_StackFrame = 6;
|
static final int SERIAL_TYPE_StackFrame = 6;
|
||||||
static final int SERIAL_TYPE_DebugRequestType = 7;
|
static final int SERIAL_TYPE_DebugRequestType = 7;
|
||||||
@@ -80,12 +79,13 @@ public class SerializationHelper {
|
|||||||
} else if (object instanceof DebugResponseSimple) {
|
} else if (object instanceof DebugResponseSimple) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
dout.writeInt(SERIAL_TYPE_DebugResponseSimple);
|
||||||
DebugResponseSimple.serialize(dout, (DebugResponseSimple) object);
|
DebugResponseSimple.serialize(dout, (DebugResponseSimple) object);
|
||||||
} else if (object instanceof DebugResponseStack) {
|
} else if (object instanceof DebugResponseVariables) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseStack);
|
dout.writeInt(SERIAL_TYPE_DebugResponseVariables);
|
||||||
DebugResponseStack.serialize(dout, (DebugResponseStack)object);
|
DebugResponseVariables.serialize(dout, (DebugResponseVariables) object);
|
||||||
} else if (object instanceof DebugResponseCallgraph) {
|
} else if (object instanceof DebugResponseCallgraph) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
dout.writeInt(SERIAL_TYPE_DebugResponseCallgraph);
|
||||||
DebugResponseCallgraph.serialize(dout, (DebugResponseCallgraph)object);
|
DebugResponseCallgraph.serialize(dout,
|
||||||
|
(DebugResponseCallgraph) object);
|
||||||
} else if (object instanceof DebugRequestType) {
|
} else if (object instanceof DebugRequestType) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestType);
|
dout.writeInt(SERIAL_TYPE_DebugRequestType);
|
||||||
DebugRequestType.serialize(dout, (DebugRequestType) object);
|
DebugRequestType.serialize(dout, (DebugRequestType) object);
|
||||||
@@ -94,7 +94,8 @@ public class SerializationHelper {
|
|||||||
DebugRequestStack.serialize(dout, (DebugRequestStack) object);
|
DebugRequestStack.serialize(dout, (DebugRequestStack) object);
|
||||||
} else if (object instanceof DebugRequestLineBreakpointToggle) {
|
} else if (object instanceof DebugRequestLineBreakpointToggle) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
dout.writeInt(SERIAL_TYPE_DebugRequestLineBreakpointToggle);
|
||||||
DebugRequestLineBreakpointToggle.serialize(dout, (DebugRequestLineBreakpointToggle)object);
|
DebugRequestLineBreakpointToggle.serialize(dout,
|
||||||
|
(DebugRequestLineBreakpointToggle) object);
|
||||||
} else if (object instanceof DebugRequest) {
|
} else if (object instanceof DebugRequest) {
|
||||||
dout.writeInt(SERIAL_TYPE_DebugRequest);
|
dout.writeInt(SERIAL_TYPE_DebugRequest);
|
||||||
DebugRequest.serialize(dout, (DebugRequest) object);
|
DebugRequest.serialize(dout, (DebugRequest) object);
|
||||||
@@ -111,8 +112,10 @@ public class SerializationHelper {
|
|||||||
dout.writeInt(SERIAL_TYPE_DebugEvent);
|
dout.writeInt(SERIAL_TYPE_DebugEvent);
|
||||||
DebugEvent.serialize(dout, (DebugEvent) object);
|
DebugEvent.serialize(dout, (DebugEvent) object);
|
||||||
} else {
|
} else {
|
||||||
// catch the errors: forgot to implement serialization/deserialization
|
// catch the errors: forgot to implement
|
||||||
throw new RuntimeException("serialization operation is not supported");
|
// serialization/deserialization
|
||||||
|
throw new RuntimeException(
|
||||||
|
"serialization operation is not supported");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,8 +142,8 @@ public class SerializationHelper {
|
|||||||
case SERIAL_TYPE_DebugResponseCallgraph:
|
case SERIAL_TYPE_DebugResponseCallgraph:
|
||||||
object = DebugResponseCallgraph.deserialize(din);
|
object = DebugResponseCallgraph.deserialize(din);
|
||||||
break;
|
break;
|
||||||
case SERIAL_TYPE_DebugResponseStack:
|
case SERIAL_TYPE_DebugResponseVariables:
|
||||||
object = DebugResponseStack.deserialize(din);
|
object = DebugResponseVariables.deserialize(din);
|
||||||
break;
|
break;
|
||||||
case SERIAL_TYPE_DebugRequestType:
|
case SERIAL_TYPE_DebugRequestType:
|
||||||
object = DebugRequestType.deserialize(din);
|
object = DebugRequestType.deserialize(din);
|
||||||
@@ -167,7 +170,8 @@ public class SerializationHelper {
|
|||||||
object = DebugEvent.deserialize(din);
|
object = DebugEvent.deserialize(din);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("deserialization operation is not supported");
|
throw new RuntimeException(
|
||||||
|
"deserialization operation is not supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
@@ -52,8 +52,10 @@ public class DebugRequest implements Serializable {
|
|||||||
SerializationHelper.serialize(type, out);
|
SerializationHelper.serialize(type, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugRequest deserialize(DataInputStream in) throws IOException {
|
public static DebugRequest deserialize(DataInputStream in)
|
||||||
DebugRequestType type = (DebugRequestType) SerializationHelper.deserialize(in);
|
throws IOException {
|
||||||
|
DebugRequestType type = (DebugRequestType) SerializationHelper
|
||||||
|
.deserialize(in);
|
||||||
return new DebugRequest(type);
|
return new DebugRequest(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class DebugRequestType extends EnumType {
|
|||||||
public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10);
|
public static final DebugRequestType stepInto = new DebugRequestType("stepInto", 10);
|
||||||
public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11);
|
public static final DebugRequestType stepOver = new DebugRequestType("stepOver", 11);
|
||||||
public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12);
|
public static final DebugRequestType stepReturn = new DebugRequestType("stepReturn", 12);
|
||||||
|
public static final DebugRequestType global = new DebugRequestType("global", 13);
|
||||||
|
|
||||||
protected static final DebugRequestType[] ENUMS = new DebugRequestType[] {
|
protected static final DebugRequestType[] ENUMS = new DebugRequestType[] {
|
||||||
start,
|
start,
|
||||||
@@ -55,7 +56,8 @@ public class DebugRequestType extends EnumType {
|
|||||||
stack,
|
stack,
|
||||||
stepInto,
|
stepInto,
|
||||||
stepOver,
|
stepOver,
|
||||||
stepReturn
|
stepReturn,
|
||||||
|
global
|
||||||
};
|
};
|
||||||
|
|
||||||
public DebugRequestType(String name, int ordinal) {
|
public DebugRequestType(String name, int ordinal) {
|
||||||
|
|||||||
@@ -28,10 +28,10 @@ import java.io.IOException;
|
|||||||
import lua.debug.SerializationHelper;
|
import lua.debug.SerializationHelper;
|
||||||
import lua.debug.Variable;
|
import lua.debug.Variable;
|
||||||
|
|
||||||
public class DebugResponseStack implements DebugResponse {
|
public class DebugResponseVariables implements DebugResponse {
|
||||||
protected Variable[] variables;
|
protected Variable[] variables;
|
||||||
|
|
||||||
public DebugResponseStack(Variable[] variables) {
|
public DebugResponseVariables(Variable[] variables) {
|
||||||
if (variables == null) {
|
if (variables == null) {
|
||||||
this.variables = new Variable[0];
|
this.variables = new Variable[0];
|
||||||
} else {
|
} else {
|
||||||
@@ -54,7 +54,8 @@ public class DebugResponseStack implements DebugResponse {
|
|||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void serialize(DataOutputStream out, DebugResponseStack response)
|
public static void serialize(DataOutputStream out,
|
||||||
|
DebugResponseVariables response)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Variable[] variables = response.getVariables();
|
Variable[] variables = response.getVariables();
|
||||||
out.writeInt(variables == null ? 0 : variables.length);
|
out.writeInt(variables == null ? 0 : variables.length);
|
||||||
@@ -63,12 +64,13 @@ public class DebugResponseStack implements DebugResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DebugResponseStack deserialize(DataInputStream in) throws IOException {
|
public static DebugResponseVariables deserialize(DataInputStream in)
|
||||||
|
throws IOException {
|
||||||
int count = in.readInt();
|
int count = in.readInt();
|
||||||
Variable[] variables = new Variable[count];
|
Variable[] variables = new Variable[count];
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
variables[i] = (Variable) SerializationHelper.deserialize(in);
|
||||||
}
|
}
|
||||||
return new DebugResponseStack(variables);
|
return new DebugResponseVariables(variables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import junit.framework.TestCase;
|
|||||||
import lua.Lua;
|
import lua.Lua;
|
||||||
import lua.debug.response.DebugResponseCallgraph;
|
import lua.debug.response.DebugResponseCallgraph;
|
||||||
import lua.debug.response.DebugResponseSimple;
|
import lua.debug.response.DebugResponseSimple;
|
||||||
import lua.debug.response.DebugResponseStack;
|
import lua.debug.response.DebugResponseVariables;
|
||||||
|
|
||||||
public class DebugResponseTest extends TestCase {
|
public class DebugResponseTest extends TestCase {
|
||||||
public void testDebugResponseSimpleSerialization() {
|
public void testDebugResponseSimpleSerialization() {
|
||||||
@@ -46,10 +46,10 @@ public class DebugResponseTest extends TestCase {
|
|||||||
|
|
||||||
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
private void doTestDebugResponseStackSerialization(Variable[] variables)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
DebugResponseStack stackIn = new DebugResponseStack(variables);
|
DebugResponseVariables stackIn = new DebugResponseVariables(variables);
|
||||||
byte[] data = SerializationHelper.serialize(stackIn);
|
byte[] data = SerializationHelper.serialize(stackIn);
|
||||||
DebugResponseStack stackOut
|
DebugResponseVariables stackOut
|
||||||
= (DebugResponseStack) SerializationHelper.deserialize(data);
|
= (DebugResponseVariables) SerializationHelper.deserialize(data);
|
||||||
Variable[] variablesIn = stackIn.getVariables();
|
Variable[] variablesIn = stackIn.getVariables();
|
||||||
Variable[] variablesOut = stackOut.getVariables();
|
Variable[] variablesOut = stackOut.getVariables();
|
||||||
assertNotNull(variablesIn);
|
assertNotNull(variablesIn);
|
||||||
|
|||||||
Reference in New Issue
Block a user