use of org.develnext.jphp.debug.impl.DebugTick in project jphp by jphp-compiler.
the class StackGetCommand method run.
@Override
public void run(Debugger context, CommandArguments args, Document result) {
DebugTick tick = context.getRegisteredTick();
Element response = createResponse(args, result);
CallStack callStack = tick.getCallStack();
List<CallStackItem> list = new ArrayList<>();
Collections.addAll(list, callStack.getSnapshot());
CallStackItem last = list.get(list.size() - 1);
if (list.size() > 1) {
CallStackItem prevLast = list.get(list.size() - 2);
TraceInfo trace = prevLast.getTrace();
prevLast.setTrace(new TraceInfo(trace.getContext(), last.getTrace().getStartLine(), trace.getEndLine(), last.getTrace().getStartPosition(), trace.getEndLine()));
}
last.setTrace(tick.getTrace());
Collections.reverse(list);
int depth = args.containsKey("d") ? Integer.parseInt(args.get("d")) : -1;
if (depth > -1) {
list = list.subList(0, depth + 1);
}
int i = 0;
for (CallStackItem stackItem : list) {
Element stack = result.createElement("stack");
stack.setAttribute("level", String.valueOf(i));
stack.setAttribute("type", "file");
stack.setAttribute("filename", context.getFileName(stackItem.trace.getFileName()));
stack.setAttribute("lineno", String.valueOf(stackItem.trace.getStartLine() + 1));
stack.setAttribute("where", stackItem.getWhere());
response.appendChild(stack);
i++;
}
}
use of org.develnext.jphp.debug.impl.DebugTick in project jphp by jphp-compiler.
the class StepOutCommand method run.
@Override
public void run(Debugger context, CommandArguments args, Document result) {
DebugTick tick = context.waitTick(Debugger.Step.OUT);
Element response = createResponse(args, result);
response.setAttribute("reason", "ok");
response.setAttribute("status", "break");
if (tick.getTrace() != null) {
Element message = result.createElement("xdebug:message");
message.setAttribute("filename", context.getFileName(tick.getTrace().getFileName()));
message.setAttribute("lineno", String.valueOf(tick.getTrace().getStartLine() + 1));
response.appendChild(message);
}
}
use of org.develnext.jphp.debug.impl.DebugTick in project jphp by jphp-compiler.
the class DebugTickHandler method onTick.
@Override
public void onTick(Environment env, TraceInfo trace, ArrayMemory locals) {
waitDebugger();
if (!init) {
init = true;
debugger.registerBreak(null, env, trace, locals);
return;
}
DebugTick oldTick = debugger.getRegisteredTick();
Debugger.Step waitStep = debugger.getWaitStep();
Breakpoint breakpoint = debugger.breakpointManager.findFor(env, trace);
switch(waitStep) {
case OVER:
if (oldTick.getCallStack().getTop() >= env.getCallStackTop()) {
debugger.registerBreak(breakpoint, env, trace, locals);
}
break;
case OUT:
if (oldTick.getCallStack().getTop() > env.getCallStackTop()) {
debugger.registerBreak(breakpoint, env, trace, locals);
}
break;
case INTO:
debugger.registerBreak(breakpoint, env, trace, locals);
break;
case RUN:
if (breakpoint != null) {
debugger.registerBreak(breakpoint, env, trace, locals);
}
}
waitDebugger();
}
use of org.develnext.jphp.debug.impl.DebugTick in project jphp by jphp-compiler.
the class ContextGetCommand method run.
@Override
public void run(Debugger context, CommandArguments args, Document result) {
Element response = createResponse(args, result);
String contextId = args.get("c");
response.setAttribute("context", contextId);
ContextValueProvider contextValueProvider = new ContextValueProvider(context, result);
switch(contextId) {
case "0":
DebugTick tick = context.getRegisteredTick();
ForeachIterator iterator = tick.getLocals().foreachIterator(true, false);
while (iterator.next()) {
Memory value = iterator.getValue().toValue();
if (value.isUndefined()) {
continue;
}
response.appendChild(contextValueProvider.getProperty(iterator.getKey().toString(), value));
}
break;
}
}
use of org.develnext.jphp.debug.impl.DebugTick in project jphp by jphp-compiler.
the class PropertySetCommand method run.
@Override
public void run(Debugger context, CommandArguments args, Document result) {
DebugTick tick = context.getRegisteredTick();
Element response = createResponse(args, result);
response.setAttribute("success", "1");
String varName = args.get("n");
if (varName.startsWith("$")) {
varName = varName.substring(1);
}
Memory data = EvalCommand.getValue(context, args.getContent());
ArrayMemory locals = tick.getLocals();
if (!locals.containsKey(varName) || data == null) {
response.setAttribute("success", "0");
return;
}
Memory memory = locals.refOfIndex(varName);
Memory.Type type = null;
if (args.containsKey("t")) {
switch(args.get("t")) {
case "boolean":
case "bool":
type = Memory.Type.BOOL;
break;
case "int":
case "integer":
type = Memory.Type.INT;
break;
case "float":
case "double":
type = Memory.Type.DOUBLE;
break;
case "string":
type = Memory.Type.STRING;
break;
case "array":
type = Memory.Type.ARRAY;
break;
case "null":
type = Memory.Type.NULL;
break;
}
}
if (type != null) {
switch(type) {
case BOOL:
data = data.toBoolean() ? Memory.TRUE : Memory.FALSE;
break;
case INT:
data = LongMemory.valueOf(data.toLong());
break;
case DOUBLE:
data = DoubleMemory.valueOf(data.toDouble());
break;
case NULL:
data = Memory.NULL;
break;
case ARRAY:
data = new ArrayMemory();
break;
}
}
memory.assign(data);
}
Aggregations