Search in sources :

Example 71 with SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 72 with SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 73 with SuspendedEvent

use of com.oracle.truffle.api.debug.SuspendedEvent 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 74 with SuspendedEvent

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

the class DebugScopeTest method testArguments.

@Test
public void testArguments() {
    final Source source = testSource("DEFINE(function, ROOT(\n" + "  STATEMENT()\n" + "))\n");
    Context context = Context.create();
    context.eval(source);
    Value functionValue = context.getBindings(InstrumentationTestLanguage.ID).getMember("function");
    assertNotNull(functionValue);
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    boolean[] suspended = new boolean[] { false };
    DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        Iterable<DebugValue> arguments = event.getTopStackFrame().getScope().getArguments();
        assertNotNull(arguments);
        Iterator<DebugValue> iterator = arguments.iterator();
        assertTrue(iterator.hasNext());
        DebugValue arg = iterator.next();
        assertEquals("0", arg.getName());
        assertEquals("true", arg.as(String.class));
        assertTrue(iterator.hasNext());
        arg = iterator.next();
        assertEquals("1", arg.getName());
        assertEquals("10", arg.as(String.class));
        assertFalse(iterator.hasNext());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.suspendNextExecution();
    functionValue.execute(true, 10);
    session.close();
    assertTrue(suspended[0]);
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Value(org.graalvm.polyglot.Value) DebugValue(com.oracle.truffle.api.debug.DebugValue) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 75 with SuspendedEvent

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

the class DebugStackFrameTest method testFrameValidity.

@Test
public void testFrameValidity() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(b, 43), \n" + "  VARIABLE(c, 44), \n" + "  STATEMENT(),\n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        class SharedData {

            DebugStackFrame frame;

            DebugValue stackValueWithGetValue;

            DebugValue stackValueWithIterator;

            Iterator<DebugStackFrame> frameIterator2;

            DebugValue heapValue;
        }
        SharedData data = new SharedData();
        expectSuspended((SuspendedEvent event) -> {
            data.frame = event.getTopStackFrame();
            Iterator<DebugStackFrame> frameIterator = event.getStackFrames().iterator();
            assertSame(data.frame, frameIterator.next());
            assertFalse(frameIterator.hasNext());
            checkStack(data.frame, "a", "42", "b", "43", "c", "44");
            // values for verifying state checks
            data.frameIterator2 = event.getStackFrames().iterator();
            data.stackValueWithGetValue = data.frame.getScope().getDeclaredValue("a");
            data.stackValueWithIterator = data.frame.getScope().getDeclaredValues().iterator().next();
            // should dynamically create a local variable
            data.heapValue = data.frame.eval("VARIABLE(d, 45)");
            // should render all pointers invalid
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            // next event everything should be invalidated except heap values
            assertInvalidFrame(data.frame);
            assertInvalidIterator(data.frameIterator2);
            assertInvalidDebugValue(data.stackValueWithGetValue);
            assertInvalidDebugValue(data.stackValueWithIterator);
            assertEquals("45", data.heapValue.as(String.class));
            assertFalse(data.heapValue.isWritable());
            assertTrue(data.heapValue.isReadable());
            try {
                data.heapValue.set(data.heapValue);
                fail();
            } catch (IllegalStateException e) {
            }
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) DebugValue(com.oracle.truffle.api.debug.DebugValue) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Iterator(java.util.Iterator) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Aggregations

SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)100 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)97 Source (org.graalvm.polyglot.Source)95 Test (org.junit.Test)93 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)45 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)19 DebugValue (com.oracle.truffle.api.debug.DebugValue)14 Debugger (com.oracle.truffle.api.debug.Debugger)11 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)9 Context (org.graalvm.polyglot.Context)9 SourceSection (com.oracle.truffle.api.source.SourceSection)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 DebugScope (com.oracle.truffle.api.debug.DebugScope)5 HashMap (java.util.HashMap)3 DebugContext (com.oracle.truffle.api.debug.DebugContext)2 Map (java.util.Map)2 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Matcher (java.util.regex.Matcher)2