Search in sources :

Example 1 with DebugTick

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++;
    }
}
Also used : DebugTick(org.develnext.jphp.debug.impl.DebugTick) CallStackItem(php.runtime.env.CallStackItem) CallStack(php.runtime.env.CallStack) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) TraceInfo(php.runtime.env.TraceInfo)

Example 2 with DebugTick

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);
    }
}
Also used : DebugTick(org.develnext.jphp.debug.impl.DebugTick) Element(org.w3c.dom.Element)

Example 3 with DebugTick

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();
}
Also used : Debugger(org.develnext.jphp.debug.impl.Debugger) DebugTick(org.develnext.jphp.debug.impl.DebugTick) Breakpoint(org.develnext.jphp.debug.impl.breakpoint.Breakpoint)

Example 4 with DebugTick

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;
    }
}
Also used : DebugTick(org.develnext.jphp.debug.impl.DebugTick) ForeachIterator(php.runtime.lang.ForeachIterator) ContextValueProvider(org.develnext.jphp.debug.impl.command.support.ContextValueProvider) Memory(php.runtime.Memory) Element(org.w3c.dom.Element)

Example 5 with DebugTick

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);
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) DebugTick(org.develnext.jphp.debug.impl.DebugTick) DoubleMemory(php.runtime.memory.DoubleMemory) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) LongMemory(php.runtime.memory.LongMemory) StringMemory(php.runtime.memory.StringMemory) Element(org.w3c.dom.Element)

Aggregations

DebugTick (org.develnext.jphp.debug.impl.DebugTick)10 Element (org.w3c.dom.Element)8 ContextValueProvider (org.develnext.jphp.debug.impl.command.support.ContextValueProvider)2 Memory (php.runtime.Memory)2 ArrayMemory (php.runtime.memory.ArrayMemory)2 ArrayList (java.util.ArrayList)1 Debugger (org.develnext.jphp.debug.impl.Debugger)1 Breakpoint (org.develnext.jphp.debug.impl.breakpoint.Breakpoint)1 CallStack (php.runtime.env.CallStack)1 CallStackItem (php.runtime.env.CallStackItem)1 CompileScope (php.runtime.env.CompileScope)1 Environment (php.runtime.env.Environment)1 TraceInfo (php.runtime.env.TraceInfo)1 ForeachIterator (php.runtime.lang.ForeachIterator)1 DoubleMemory (php.runtime.memory.DoubleMemory)1 LongMemory (php.runtime.memory.LongMemory)1 StringMemory (php.runtime.memory.StringMemory)1