Search in sources :

Example 1 with Breakpoint

use of org.exist.debugger.model.Breakpoint in project exist by eXist-db.

the class DebuggeeJointImpl method removeBreakpoint.

public Breakpoint removeBreakpoint(int breakpointID) {
    Breakpoint breakpoint = breakpoints.get(breakpointID);
    if (breakpoint == null)
        return breakpoint;
    String fileName = breakpoint.getFilename();
    Integer lineNo = breakpoint.getLineno();
    Map<Integer, Breakpoint> fileBreakpoints = null;
    synchronized (breakpoints) {
        if (filesBreakpoints.containsKey(fileName)) {
            fileBreakpoints = filesBreakpoints.get(fileName);
            if (fileBreakpoints.containsKey(lineNo)) {
                fileBreakpoints.remove(lineNo);
                if (fileBreakpoints.isEmpty()) {
                    filesBreakpoints.remove(fileName);
                }
            }
        }
        breakpoints.remove(breakpointID);
        activeBreakpoints.remove(breakpoint);
    }
    return breakpoint;
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint)

Example 2 with Breakpoint

use of org.exist.debugger.model.Breakpoint in project exist by eXist-db.

the class DebuggerTest method testBreakpoints.

@Test
public void testBreakpoints() throws IOException {
    Debugger debugger = DebuggerImpl.getDebugger();
    try {
        // jetty.port.jetty
        DebuggingSource source = debugger.init("http://127.0.0.1:" + existWebServer.getPort() + "/exist/xquery/fibo.xql");
        assertNotNull("Debugging source can't be NULL.", source);
        Breakpoint breakpoint = source.newBreakpoint();
        breakpoint.setLineno(24);
        breakpoint.sync();
        source.run();
        List<Location> stack = source.getStackFrames();
        assertEquals(1, stack.size());
        assertEquals(24, stack.get(0).getLineBegin());
        breakpoint.remove();
        source.run();
    } catch (IOException e) {
        assertNotNull("IO exception: " + e.getMessage(), null);
    } catch (ExceptionTimeout e) {
        assertNotNull("Timeout exception: " + e.getMessage(), null);
    }
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint) IOException(java.io.IOException) Location(org.exist.debugger.model.Location)

Example 3 with Breakpoint

use of org.exist.debugger.model.Breakpoint in project exist by eXist-db.

the class DebuggerTest method testEvaluation2.

@Test
public void testEvaluation2() throws IOException {
    Debugger debugger = DebuggerImpl.getDebugger();
    try {
        // sending init request
        // jetty.port.jetty
        DebuggingSource source = debugger.init("http://127.0.0.1:" + existWebServer.getPort() + "/exist/xquery/debug-test.xql");
        assertNotNull("Debugging source can't be NULL.", source);
        Breakpoint breakpoint = source.newBreakpoint();
        breakpoint.setLineno(19);
        breakpoint.sync();
        source.run();
        List<Location> stack = source.getStackFrames();
        assertEquals(1, stack.size());
        assertEquals(19, stack.get(0).getLineBegin());
        String res = source.evaluate("$t:XML");
        assertNotNull(res);
        // $t:XML: " + res
        assertEquals("<root><a id=\"a1\"/><b id=\"b1\" type=\"t\"/><c id=\"c1\">text</c><d id=\"d1\"><e>text</e></d></root>", res);
        breakpoint.remove();
        source.stop();
    } catch (IOException e) {
        assertNotNull("IO exception: " + e.getMessage(), null);
    } catch (ExceptionTimeout e) {
        assertNotNull("Timeout exception: " + e.getMessage(), null);
    }
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint) IOException(java.io.IOException) Location(org.exist.debugger.model.Location)

Example 4 with Breakpoint

use of org.exist.debugger.model.Breakpoint in project exist by eXist-db.

the class DebuggeeJointImpl method expressionStart.

/* (non-Javadoc)
	 * @see org.exist.debuggee.DebuggeeJoint#expressionStart(org.exist.xquery.Expression)
	 */
public void expressionStart(Expression expr) throws TerminatedException {
    if (LOG.isDebugEnabled())
        LOG.debug("" + expr.getLine() + " expr = " + expr.toString());
    if (compiledXQuery == null)
        return;
    if (firstExpression == null)
        firstExpression = expr;
    stack.set(stackDepth, expr);
    String fileName = Command.getFileuri(expr.getSource());
    Integer lineNo = expr.getLine();
    // check breakpoint
    for (Breakpoint breakpoint : activeBreakpoints) {
        if (breakpoint.getFilename().equals(fileName) && breakpoint.getType().equals(Breakpoint.TYPE_LINE)) {
            if (breakpoint.getLineno() != lineNo) {
                activeBreakpoints.remove(breakpoint);
            }
        }
    }
    Map<Integer, Breakpoint> fileBreakpoints = null;
    while (true) {
        // didn't receive any command, wait for any
        if (command == null || // the status is break, wait for changes
        command.isStatus(BREAK)) {
            waitCommand();
            continue;
        }
        // wait for connection
        if (command.is(CommandContinuation.INIT) && command.isStatus(STARTING)) {
            Init init = (Init) command;
            init.getSession().setAttribute("joint", this);
            init.setFileURI(compiledXQuery.getSource());
            // break on first line
            command.setStatus(BREAK);
        }
        // disconnected
        if (compiledXQuery == null)
            return;
        // stop command, terminate
        if (command.is(CommandContinuation.STOP) && !command.isStatus(STOPPED)) {
            command.setStatus(STOPPED);
            sessionClosed(true);
            throw new TerminatedException(expr.getLine(), expr.getColumn(), "Debuggee STOP command.");
        }
        // step-into is done
        if (command.is(CommandContinuation.STEP_INTO) && command.isStatus(RUNNING)) {
            command.setStatus(BREAK);
        // step-over should stop on same call's stack depth
        } else if (command.is(CommandContinuation.STEP_OVER) && command.getCallStackDepth() == stackDepth && command.isStatus(RUNNING)) {
            command.setStatus(BREAK);
        }
        // checking breakpoints
        synchronized (breakpoints) {
            if (filesBreakpoints.containsKey(fileName)) {
                fileBreakpoints = filesBreakpoints.get(fileName);
                if (fileBreakpoints.containsKey(lineNo)) {
                    Breakpoint breakpoint = fileBreakpoints.get(lineNo);
                    if (!activeBreakpoints.contains(breakpoint) && breakpoint.getState() && breakpoint.getType().equals(Breakpoint.TYPE_LINE)) {
                        activeBreakpoints.add(breakpoint);
                        command.setStatus(BREAK);
                    // waitCommand();
                    // break;
                    }
                }
            }
        }
        // RUN command with status RUNNING can be break only on breakpoints
        if (command.getType() >= CommandContinuation.RUN && command.isStatus(RUNNING)) {
            break;
        // any continuation command with status RUNNING
        } else if (command.getType() >= CommandContinuation.RUN && command.isStatus(STARTING)) {
            command.setStatus(RUNNING);
            break;
        }
        waitCommand();
    }
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint) Init(org.exist.debuggee.dbgp.packets.Init) TerminatedException(org.exist.xquery.TerminatedException)

Example 5 with Breakpoint

use of org.exist.debugger.model.Breakpoint in project exist by eXist-db.

the class BreakpointList method responseBytes.

public byte[] responseBytes() {
    if (breakpoints != null) {
        StringBuilder responce = new StringBuilder();
        responce.append(xml_declaration);
        responce.append("<response " + namespaces + "command=\"breakpoint_list\" transaction_id=\"");
        responce.append(transactionID);
        responce.append("\">");
        for (Breakpoint breakpoint : breakpoints.values()) responce.append(breakpoint.toXMLString());
        responce.append("</response>");
        return responce.toString().getBytes();
    }
    return errorBytes("breakpoint_list");
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint)

Aggregations

Breakpoint (org.exist.debugger.model.Breakpoint)7 IOException (java.io.IOException)4 Location (org.exist.debugger.model.Location)4 Init (org.exist.debuggee.dbgp.packets.Init)1 TerminatedException (org.exist.xquery.TerminatedException)1