Search in sources :

Example 6 with Breakpoint

use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.

the class DoubleHaltTest method testBreakpointStepping.

@Test
public void testBreakpointStepping() throws Throwable {
    Source testSource = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint2 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
        Breakpoint breakpoint3 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(3).build());
        Breakpoint breakpoint5 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(5).build());
        Breakpoint breakpoint6 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(6).build());
        session.suspendNextExecution();
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint2, event.getBreakpoints().iterator().next());
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint3, event.getBreakpoints().iterator().next());
            event.prepareStepOver(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint5, event.getBreakpoints().iterator().next());
            event.prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT");
            assertEquals(1, event.getBreakpoints().size());
            assertSame(breakpoint6, event.getBreakpoints().iterator().next());
            event.prepareContinue();
        });
        expectDone();
        assertEquals(1, breakpoint2.getHitCount());
        assertEquals(1, breakpoint3.getHitCount());
        assertEquals(1, breakpoint5.getHitCount());
        assertEquals(1, breakpoint6.getHitCount());
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 7 with Breakpoint

use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.

the class BreakpointsHandler method createURLBreakpoint.

Params createURLBreakpoint(Object url, int line, int column, String condition) {
    JSONArray locations = new JSONArray();
    long id;
    LoadScriptListener scriptListener;
    synchronized (bpIDs) {
        id = ++lastID;
        scriptListener = script -> {
            if (url instanceof Pattern ? ((Pattern) url).matcher(script.getUrl()).matches() : url.equals(script.getUrl())) {
                Breakpoint bp = createBuilder(script.getSource(), line, column).resolveListener(resolvedHandler).build();
                if (condition != null && !condition.isEmpty()) {
                    bp.setCondition(condition);
                }
                bp = ds.install(bp);
                synchronized (bpIDs) {
                    bpIDs.put(bp, id);
                    SourceSection section = resolvedBreakpoints.remove(bp);
                    if (section != null) {
                        Location resolvedLocation = new Location(script.getId(), section.getStartLine(), section.getStartColumn());
                        locations.put(resolvedLocation.toJSON());
                    }
                }
            }
        };
        scriptListeners.put(id, scriptListener);
    }
    slh.addLoadScriptListener(scriptListener);
    JSONObject json = new JSONObject();
    json.put("breakpointId", Long.toString(id));
    json.put("locations", locations);
    return new Params(json);
}
Also used : Pattern(java.util.regex.Pattern) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) Params(com.oracle.truffle.tools.chromeinspector.commands.Params) SourceSection(com.oracle.truffle.api.source.SourceSection) LoadScriptListener(com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener) Location(com.oracle.truffle.tools.chromeinspector.types.Location)

Example 8 with Breakpoint

use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.

the class BreakpointListener method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent event) {
    notified[0] = true;
    Assert.assertEquals(Debugger.PROPERTY_BREAKPOINTS, event.getPropertyName());
    Assert.assertEquals(debugger, event.getSource());
    Assert.assertNull(event.getOldValue());
    Assert.assertNotEquals(globalBreakpoint, event.getNewValue());
    Breakpoint newBP = (Breakpoint) event.getNewValue();
    try {
        newBP.dispose();
        Assert.fail("Public dispose must not be possible for global breakpoints.");
    } catch (IllegalStateException ex) {
    // O.K.
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint)

Example 9 with Breakpoint

use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.

the class BreakpointTest method testGlobalBreakpointsInMultipleSessions.

@Test
public void testGlobalBreakpointsInMultipleSessions() throws Throwable {
    try {
        Class.forName("java.beans.PropertyChangeListener");
    } catch (ClassNotFoundException ex) {
        // skip the test if running only with java.base JDK9 module
        return;
    }
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    Debugger debugger = getDebugger();
    Breakpoint globalBreakpoint1 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).build();
    debugger.install(globalBreakpoint1);
    Breakpoint globalBreakpoint2 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build();
    debugger.install(globalBreakpoint2);
    Breakpoint globalBreakpoint3 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build();
    debugger.install(globalBreakpoint3);
    Breakpoint globalBreakpoint4 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(8).build();
    debugger.install(globalBreakpoint4);
    // Breakpoints are in the install order:
    List<Breakpoint> breakpoints = debugger.getBreakpoints();
    Assert.assertEquals(4, breakpoints.size());
    Assert.assertTrue(breakpoints.get(0).getLocationDescription().contains("line=2"));
    Assert.assertTrue(breakpoints.get(1).getLocationDescription().contains("line=4"));
    Assert.assertTrue(breakpoints.get(2).getLocationDescription().contains("line=6"));
    DebuggerSession session1 = startSession();
    // global breakpoints are not among session breakpoints
    Assert.assertTrue(session1.getBreakpoints().isEmpty());
    try (DebuggerSession session2 = startSession()) {
        // global breakpoints are not among session breakpoints
        Assert.assertTrue(session2.getBreakpoints().isEmpty());
        startEval(source);
        // Both sessions should break here:
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session1, event.getSession());
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session2, event.getSession());
            checkState(event, 2, true, "STATEMENT").prepareContinue();
        });
        // We close session2 after the next BP:
        expectSuspended((SuspendedEvent event) -> {
            assertSame(session1, event.getSession());
            checkState(event, 4, true, "STATEMENT");
        });
    }
    expectSuspended((SuspendedEvent event) -> {
        assertNotSame(session1, event.getSession());
        checkState(event, 4, true, "STATEMENT").prepareContinue();
    });
    // The last breakpoint is hit once only in the session1:
    expectSuspended((SuspendedEvent event) -> {
        assertSame(session1, event.getSession());
        checkState(event, 6, true, "STATEMENT").prepareStepOver(1);
    });
    expectSuspended((SuspendedEvent event) -> {
        assertSame(session1, event.getSession());
        checkState(event, 7, true, "STATEMENT");
        session1.close();
        event.prepareContinue();
    });
    // Breakpoint at line 8 was not hit at all, the session was closed right before continue
    // from line 7.
    expectDone();
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 10 with Breakpoint

use of com.oracle.truffle.api.debug.Breakpoint in project graal by oracle.

the class BreakpointTest method testBreakSource.

@Test
public void testBreakSource() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  STATEMENT,\n" + // break here
    "  STATEMENT,\n" + "  STATEMENT,\n" + "  STATEMENT\n" + ")\n");
    Breakpoint sessionBreakpoint = null;
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        sessionBreakpoint = breakpoint;
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT");
            Assert.assertEquals(1, event.getBreakpoints().size());
            Assert.assertSame(breakpoint, event.getBreakpoints().get(0));
        });
        Assert.assertEquals(1, breakpoint.getHitCount());
        Assert.assertEquals(true, breakpoint.isEnabled());
        Assert.assertEquals(true, breakpoint.isResolved());
        expectDone();
    }
    Assert.assertEquals(false, sessionBreakpoint.isResolved());
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Aggregations

Breakpoint (com.oracle.truffle.api.debug.Breakpoint)44 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)36 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)36 Source (org.graalvm.polyglot.Source)35 Test (org.junit.Test)33 SourceSection (com.oracle.truffle.api.source.SourceSection)7 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)4 Debugger (com.oracle.truffle.api.debug.Debugger)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Pattern (java.util.regex.Pattern)3 DebugValue (com.oracle.truffle.api.debug.DebugValue)2 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)2 LoadScriptListener (com.oracle.truffle.tools.chromeinspector.ScriptsHandler.LoadScriptListener)2 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)2 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)2 Location (com.oracle.truffle.tools.chromeinspector.types.Location)2 Script (com.oracle.truffle.tools.chromeinspector.types.Script)2 Matcher (java.util.regex.Matcher)2 JSONArray (org.json.JSONArray)2