Search in sources :

Example 26 with Breakpoint

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

the class SuspendedEventTest method testOtherThreadAccess.

@Test
public void testOtherThreadAccess() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(bar, VARIABLE(bar0, 41), VARIABLE(bar1, 40), STATEMENT),\n" + "  DEFINE(foo, ROOT(VARIABLE(foo0, 42), \n" + "                   STATEMENT(CALL(bar)))),\n" + "  STATEMENT(VARIABLE(root0, 43)),\n" + "  STATEMENT(CALL(foo))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        final Breakpoint breakpoint = session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(4).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            run(() -> event.getBreakpointConditionException(breakpoint));
            run(() -> event.getSession());
            run(() -> event.getSourceSection());
            run(() -> event.getBreakpoints());
            run(() -> event.getSuspendAnchor());
            run(() -> event.toString());
            run(() -> {
                event.prepareStepInto(1);
                return null;
            });
            run(() -> {
                event.prepareStepOut(1);
                return null;
            });
            run(() -> {
                event.prepareStepOver(1);
                return null;
            });
            run(() -> {
                event.prepareContinue();
                return null;
            });
            run(() -> {
                event.prepareKill();
                return null;
            });
            runExpectIllegalState(() -> event.getStackFrames());
            runExpectIllegalState(() -> event.getTopStackFrame());
            runExpectIllegalState(() -> event.getReturnValue());
            for (DebugStackFrame frame : event.getStackFrames()) {
                for (DebugValue value : frame) {
                    runExpectIllegalState(() -> value.as(String.class));
                    runExpectIllegalState(() -> {
                        value.set(null);
                        return null;
                    });
                    // Name is known
                    value.getName();
                    runExpectIllegalState(() -> value.isReadable());
                    runExpectIllegalState(() -> value.isWritable());
                }
                run(() -> frame.getName());
                run(() -> frame.getSourceSection());
                run(() -> frame.isInternal());
                run(() -> frame.toString());
                runExpectIllegalState(() -> frame.getScope().getDeclaredValue(""));
                runExpectIllegalState(() -> frame.getScope().getDeclaredValues().iterator());
                runExpectIllegalState(() -> frame.eval(""));
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 27 with Breakpoint

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

the class SuspensionFilterTest method testInternalStepping.

@Test
public void testInternalStepping() throws Exception {
    final Source internSource = Source.newBuilder(InstrumentationTestLanguage.ID, "ROOT(\n" + "  DEFINE(intern, \n" + "    STATEMENT(EXPRESSION),\n" + "    STATEMENT(CONSTANT(42))\n" + "  ),\n" + "  CALL(intern)\n" + ")\n", "intern").internal(true).build();
    final Source source = testSource("ROOT(\n" + "  STATEMENT(CALL(intern)),\n" + "  STATEMENT(CONSTANT(1)),\n" + "  STATEMENT(CALL(intern))\n" + ")\n");
    SuspensionFilter suspensionFilter = SuspensionFilter.newBuilder().includeInternal(false).build();
    try (DebuggerSession session = startSession()) {
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        startEval(internSource);
        // does not stop in internal source
        expectDone();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT(CALL(intern))");
            event.prepareStepInto(1);
        });
        // Step into does not go into the internal source:
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(CONSTANT(1))");
            Breakpoint bp = Breakpoint.newBuilder(getSourceImpl(internSource)).lineIs(3).build();
            session.install(bp);
            event.prepareContinue();
        });
        // Breakpoint stops there:
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "STATEMENT(EXPRESSION)");
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 28 with Breakpoint

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

the class SuspensionFilterTest method testInitializationFilterChange.

@Test
public void testInitializationFilterChange() {
    // Set to skip the initialization, but put two breakpoints there.
    // Verify that step just skips the code to the next breakpoint.
    // After second breakpoint is hit, change the filter to allow stepping
    // in the initialization code.
    String initCode = "ROOT(\n" + "  DEFINE(initFoo, \n" + // Skipped by suspensionFilter
    "    STATEMENT(EXPRESSION),\n" + // l. 4 Breakpoint
    "    STATEMENT(EXPRESSION),\n" + // Skipped by suspensionFilter
    "    STATEMENT(CONSTANT(2)),\n" + // l. 6 Breakpoint, filter changed
    "    STATEMENT(EXPRESSION),\n" + "    LOOP(2,\n" + // l. 8 Step stops here
    "      STATEMENT(CONSTANT(1)))\n" + "  ), \n" + "  STATEMENT(CALL(initFoo))\n" + ")\n";
    Source initSource = Source.newBuilder(InstrumentationTestLanguage.ID, initCode, "<init>").buildLiteral();
    InstrumentationTestLanguage.envConfig = Collections.singletonMap("initSource", initSource);
    final Source source = testSource("ROOT(\n" + "  STATEMENT(CONSTANT(42))\n" + ")\n");
    SuspensionFilter.Builder filterBuilder = SuspensionFilter.newBuilder().ignoreLanguageContextInitialization(true);
    SuspensionFilter suspensionFilter = filterBuilder.build();
    try (DebuggerSession session = startSession()) {
        session.setSteppingFilter(suspensionFilter);
        session.suspendNextExecution();
        Breakpoint bp4 = Breakpoint.newBuilder(getSourceImpl(initSource)).lineIs(4).build();
        Breakpoint bp6 = Breakpoint.newBuilder(getSourceImpl(initSource)).lineIs(6).build();
        session.install(bp4);
        session.install(bp6);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 4, true, "STATEMENT(EXPRESSION)");
            Assert.assertFalse(event.isLanguageContextInitialized());
            Assert.assertTrue(event.getBreakpoints().contains(bp4));
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, true, "STATEMENT(EXPRESSION)");
            Assert.assertFalse(event.isLanguageContextInitialized());
            Assert.assertTrue(event.getBreakpoints().contains(bp6));
            filterBuilder.ignoreLanguageContextInitialization(false);
            session.setSteppingFilter(filterBuilder.build());
            event.prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            Assert.assertFalse(event.isLanguageContextInitialized());
            checkState(event, 8, true, "STATEMENT(CONSTANT(1))").prepareContinue();
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) SuspensionFilter(com.oracle.truffle.api.debug.SuspensionFilter) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 29 with Breakpoint

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

the class ConcurrentDebuggingTest method testConcurrentBreakpoints.

@Test
public void testConcurrentBreakpoints() {
    int numThreads = 100;
    String code = "ROOT(DEFINE(foo,\n" + "  STATEMENT\n" + "),\n" + "LOOP(" + numThreads + ", SPAWN(foo)),\n" + "JOIN())";
    final Source source = Source.create(InstrumentationTestLanguage.ID, code);
    Breakpoint breakpoint = Breakpoint.newBuilder(source.getURI()).lineIs(2).build();
    Context context = Context.newBuilder().allowCreateThread(true).build();
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    AtomicInteger hits = new AtomicInteger(0);
    try (DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
        assertEquals(1, event.getBreakpoints().size());
        assertEquals(breakpoint, event.getBreakpoints().get(0));
        hits.incrementAndGet();
    })) {
        session.install(breakpoint);
        context.eval(source);
    }
    assertEquals(numThreads, hits.get());
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 30 with Breakpoint

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

the class BreakpointDisposeListener 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.getNewValue());
    Assert.assertNotEquals(globalBreakpoint, event.getOldValue());
    Breakpoint oldBP = (Breakpoint) event.getOldValue();
    try {
        oldBP.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)

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