Search in sources :

Example 76 with SuspendedEvent

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

the class DebugValueTest method testNumValue.

@Test
public void testNumValue() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  VARIABLE(a, 42), \n" + "  VARIABLE(inf, infinity), \n" + "  STATEMENT()\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value42 = frame.getScope().getDeclaredValue("a");
            assertEquals("a", value42.getName());
            assertFalse(value42.isArray());
            assertNull(value42.getArray());
            assertNull(value42.getProperties());
            assertEquals("Integer", value42.getMetaObject().as(String.class));
            assertEquals("Infinity", frame.getScope().getDeclaredValue("inf").getMetaObject().as(String.class));
            SourceSection integerSS = value42.getSourceLocation();
            assertEquals("source integer", integerSS.getCharacters());
            SourceSection infinitySS = frame.getScope().getDeclaredValue("inf").getSourceLocation();
            assertEquals("source infinity", infinitySS.getCharacters());
        });
        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) SourceSection(com.oracle.truffle.api.source.SourceSection) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 77 with SuspendedEvent

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

the class DebugValueTest method testValueAttributes.

/**
 * Test of {@link DebugValue#isReadable()}, {@link DebugValue#isWritable()} and
 * {@link DebugValue#isInternal()}.
 */
@Test
public void testValueAttributes() throws Throwable {
    final Source source = testSource("DEFINE(function, ROOT(\n" + "  ARGUMENT(a), \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);
    // Test of the default attribute values:
    NoAttributesTruffleObject nao = new NoAttributesTruffleObject();
    boolean[] suspended = new boolean[] { false };
    DebuggerSession session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
        assertNotNull(value);
        DebugValue attributesTOValue = value.getProperties().iterator().next();
        assertEquals("property", attributesTOValue.getName());
        // Property is readable by default
        assertTrue(attributesTOValue.isReadable());
        // Property is writable by default
        assertTrue(attributesTOValue.isWritable());
        // Property is not internal by default
        assertFalse(attributesTOValue.isInternal());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
    functionValue.execute(nao);
    session.close();
    assertTrue(suspended[0]);
    // Test of the modified attribute values:
    suspended[0] = false;
    final ModifiableAttributesTruffleObject mao = new ModifiableAttributesTruffleObject();
    session = debugger.startSession((SuspendedEvent event) -> {
        assertFalse(suspended[0]);
        DebugValue value = event.getTopStackFrame().getScope().getDeclaredValue("a");
        assertNotNull(value);
        DebugValue attributesTOValue = value.getProperties().iterator().next();
        assertEquals("property", attributesTOValue.getName());
        // All false initially
        assertFalse(attributesTOValue.isReadable());
        assertFalse(attributesTOValue.isWritable());
        assertFalse(attributesTOValue.isInternal());
        mao.setIsReadable(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isReadable());
        mao.setIsWritable(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isWritable());
        mao.setIsInternal(true);
        attributesTOValue = value.getProperties().iterator().next();
        assertTrue(attributesTOValue.isInternal());
        event.prepareContinue();
        suspended[0] = true;
    });
    session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(3).build());
    functionValue.execute(mao);
    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 78 with SuspendedEvent

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

the class DebuggerContextsTest method testSingleContext.

@Test
public void testSingleContext() {
    final Source source = testSource("STATEMENT()");
    TestContextsListener contextsListener = new TestContextsListener();
    List<ContextEvent> events = contextsListener.events;
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        session.setContextsListener(contextsListener, false);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(2, events.size());
            assertTrue(events.get(0).created);
            assertEquals(InstrumentationTestLanguage.ID, events.get(0).language.getId());
            assertNotNull(events.get(0).context);
            assertTrue(events.get(1).languageInitialized);
        });
        expectDone();
        closeEngine();
        assertEquals(5, events.size());
        assertTrue(events.get(2).languageFinalized);
        assertEquals(InstrumentationTestLanguage.ID, events.get(2).language.getId());
        assertEquals(events.get(0).context, events.get(2).context);
        assertFalse(events.get(3).created);
        assertEquals(InstrumentationTestLanguage.ID, events.get(3).language.getId());
        assertEquals(events.get(0).context, events.get(3).context);
        assertFalse(events.get(4).created);
        assertNull(events.get(4).language);
        assertEquals(events.get(0).context, events.get(4).context);
    }
    events.clear();
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 79 with SuspendedEvent

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

the class DebuggerContextsTest method testGetActiveContexts.

@Test
public void testGetActiveContexts() {
    final DebuggerSession[] sessionPtr = new DebuggerSession[1];
    try (Engine engine = Engine.create()) {
        TestContextsListener contextsListener = new TestContextsListener();
        List<ContextEvent> events = contextsListener.events;
        Debugger debugger = engine.getInstruments().get("debugger").lookup(Debugger.class);
        try (DebuggerSession session = debugger.startSession(new SuspendedCallback() {

            @Override
            public void onSuspend(SuspendedEvent event) {
                sessionPtr[0].setContextsListener(contextsListener, true);
                assertEquals(3, events.size());
                assertTrue(events.get(0).created);
                assertNull(events.get(0).language);
                assertTrue(events.get(1).created);
                assertEquals(InstrumentationTestLanguage.ID, events.get(1).language.getId());
                assertTrue(events.get(2).languageInitialized);
            }
        })) {
            session.setContextsListener(contextsListener, true);
            try (Context context = Context.newBuilder().engine(engine).build()) {
                context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
                assertEquals(3, events.size());
                // Have creation of polyglot context and a language
                assertTrue(events.get(0).created);
                assertNotNull(events.get(0).context);
                assertNull(events.get(0).language);
                assertTrue(events.get(1).created);
                assertNotNull(events.get(1).language);
                assertTrue(events.get(2).languageInitialized);
            }
            assertEquals(6, events.size());
            session.setContextsListener(null, true);
            events.clear();
            // Contexts created and closed:
            try (Context context = Context.newBuilder().engine(engine).build()) {
                context.eval(Source.create(InstrumentationTestLanguage.ID, "STATEMENT()"));
                context.eval(Source.create(InstrumentationTestLanguage.ID, "CONTEXT(STATEMENT())"));
            }
            assertEquals(0, events.size());
            sessionPtr[0] = session;
            session.suspendNextExecution();
            Context context = Context.newBuilder().engine(engine).build();
            context.eval(Source.create(InstrumentationTestLanguage.ID, "ROOT(CONTEXT(EXPRESSION()), CONTEXT(STATEMENT))"));
        }
    }
}
Also used : Debugger(com.oracle.truffle.api.debug.Debugger) DebugContext(com.oracle.truffle.api.debug.DebugContext) Context(org.graalvm.polyglot.Context) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Engine(org.graalvm.polyglot.Engine) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) Test(org.junit.Test)

Example 80 with SuspendedEvent

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

the class DebuggerSessionTest method testClosing2.

@Test
public void testClosing2() throws Exception {
    Source testSource = testSource("ROOT(\n" + "STATEMENT,\n" + "STATEMENT)");
    Context context = Context.create();
    final AtomicBoolean suspend = new AtomicBoolean();
    Debugger debugger = context.getEngine().getInstruments().get("debugger").lookup(Debugger.class);
    DebuggerSession session = debugger.startSession(new SuspendedCallback() {

        public void onSuspend(SuspendedEvent event) {
            suspend.set(true);
        }
    });
    context.eval(testSource);
    context.close();
    // if the engine disposes the session should still work
    session.suspendNextExecution();
    suspend(session, Thread.currentThread());
    suspendAll(session);
    session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
    resume(session, Thread.currentThread());
    session.resumeAll();
    session.getDebugger();
    session.getBreakpoints();
    // after closing the session none of these methods should work
    session.close();
    try {
        session.suspendNextExecution();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        suspend(session, Thread.currentThread());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        suspendAll(session);
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(2).build());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        resume(session, Thread.currentThread());
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.resumeAll();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    try {
        session.getBreakpoints();
        Assert.fail();
    } catch (IllegalStateException e) {
    }
    // still works after closing
    session.getDebugger();
}
Also used : Context(org.graalvm.polyglot.Context) Debugger(com.oracle.truffle.api.debug.Debugger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) Source(org.graalvm.polyglot.Source) SuspendedCallback(com.oracle.truffle.api.debug.SuspendedCallback) 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