Search in sources :

Example 1 with Location

use of org.exist.debugger.model.Location 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 2 with Location

use of org.exist.debugger.model.Location 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 3 with Location

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

the class DebuggerTest method testStoredInDB.

@Test
public void testStoredInDB() throws Exception {
    store("script.xql", script);
    // jetty.port.jetty
    String url = "http://127.0.0.1:" + existWebServer.getPort() + "/exist/rest/db/test/script.xql";
    for (int i = 0; i < 10; i++) {
        Debugger debugger = DebuggerImpl.getDebugger();
        DebuggingSource debuggerSource = debugger.init(url);
        // send stepInto
        debuggerSource.stepInto();
        // Thread.sleep(1000);
        // send getStackFrames
        List<Location> stack = debuggerSource.getStackFrames();
        assertEquals(1, stack.size());
        assertEquals(16, stack.get(0).getLineBegin());
        assertEquals(18, stack.get(0).getColumnBegin());
        // send stop
        debuggerSource.stop();
        // Thread.sleep(1000);
        // stoped
        DebuggerImpl.shutdownDebugger();
    }
}
Also used : Breakpoint(org.exist.debugger.model.Breakpoint) Location(org.exist.debugger.model.Location)

Example 4 with Location

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

the class DebuggerTest method testDebugger.

@Test
public void testDebugger() {
    Debugger debugger;
    try {
        debugger = DebuggerImpl.getDebugger();
        // sending init request
        // 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);
        // get stack frames
        List<Location> stack = source.getStackFrames();
        assertEquals(1, stack.size());
        assertEquals(15, stack.get(0).getLineBegin());
        // sending step-into
        source.stepInto(this);
        try {
            // TODO: query current stage or wait for BREAK status ???
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
        // "get stack frames
        stack = source.getStackFrames();
        assertEquals(1, stack.size());
        assertEquals(16, stack.get(0).getLineBegin());
        for (int i = 0; i < 9; i++) {
            source.stepInto(this);
        }
        try {
            // TODO: query current stage or wait for BREAK status ???
            Thread.sleep(5000);
        } catch (InterruptedException e) {
        }
        // get stack frames
        stack = source.getStackFrames();
        assertEquals(3, stack.size());
        assertEquals(8, stack.get(0).getLineBegin());
        assertEquals(24, stack.get(1).getLineBegin());
        assertEquals(78, stack.get(1).getColumnBegin());
        assertEquals(24, stack.get(2).getLineBegin());
        assertEquals(42, stack.get(2).getColumnBegin());
        // sending get-variables first time
        List<Variable> vars = source.getVariables();
        assertEquals(2, vars.size());
        for (Variable var : vars) {
            if (var.getName().equals("n"))
                assertEquals("1", var.getValue());
            else if (var.getName().equals("dbgp:session"))
                assertEquals("default", var.getValue());
        }
        // sending get-local-variables
        vars = source.getLocalVariables();
        assertEquals(1, vars.size());
        for (Variable var : vars) {
            assertEquals("n", var.getName());
            assertEquals("1", var.getValue());
        }
        // sending get-glocal-variables
        vars = source.getGlobalVariables();
        assertEquals(1, vars.size());
        for (Variable var : vars) {
            assertEquals("DBGp:session", var.getName());
            assertEquals("default", var.getValue());
        }
        // sending step-into & waiting stop status
        for (int i = 0; i < 7; i++) {
            source.stepInto();
        }
        // sending get-variables second time
        vars = source.getVariables();
        assertEquals(2, vars.size());
        for (Variable var : vars) {
            if (var.getName().equals("n"))
                assertEquals("2", var.getValue());
            else if (var.getName().equals("dbgp:session"))
                assertEquals("default", var.getValue());
        }
        // sending step-over
        source.stepOver(this);
        // sending step-out
        source.stepOut(this);
        // sending run
        source.run(this);
    } catch (IOException e) {
        assertNotNull("IO exception: " + e.getMessage(), null);
    } catch (ExceptionTimeout e) {
        assertNotNull("Timeout exception: " + e.getMessage(), null);
    }
}
Also used : Variable(org.exist.debugger.model.Variable) IOException(java.io.IOException) Breakpoint(org.exist.debugger.model.Breakpoint) Location(org.exist.debugger.model.Location)

Example 5 with Location

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

the class DebuggerImpl method getStackFrames.

public List<Location> getStackFrames() throws IOException {
    StackGet command = new StackGet(session, " -i " + getNextTransaction());
    command.toDebuggee();
    Response response = getResponse(command.getTransactionId());
    // XXX: handle errors
    List<Location> variables = new ArrayList<Location>();
    NodeList children = response.getElemetsByName("stack");
    for (int i = 0; i < children.getLength(); i++) {
        variables.add(new LocationImpl(children.item(i)));
    }
    return variables;
}
Also used : NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) LocationImpl(org.exist.debugger.model.LocationImpl) Breakpoint(org.exist.debugger.model.Breakpoint) Location(org.exist.debugger.model.Location)

Aggregations

Breakpoint (org.exist.debugger.model.Breakpoint)8 Location (org.exist.debugger.model.Location)8 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)1 LocationImpl (org.exist.debugger.model.LocationImpl)1 Variable (org.exist.debugger.model.Variable)1 NodeList (org.w3c.dom.NodeList)1