Search in sources :

Example 1 with Breakpoint

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

the class StepTest method testMultipleActions.

@Test
public void testMultipleActions() throws Throwable {
    final Source source = testSource(// 1
    "ROOT(\n" + "  DEFINE(bar, STATEMENT),\n" + "  DEFINE(foo, ROOT(STATEMENT(CALL(bar)), \n" + "                   STATEMENT(CALL(loop)))),\n" + // 5
    "  DEFINE(loop,\n" + "    LOOP(3,\n" + "      STATEMENT),\n" + "    STATEMENT\n" + "  ),\n" + // 10
    "  STATEMENT(CALL(foo)),\n" + "  STATEMENT(CALL(foo)),\n" + "  STATEMENT,\n" + "  STATEMENT(CALL(loop)),\n" + "  STATEMENT,\n" + // 15
    "  STATEMENT,\n" + "  STATEMENT(CALL(loop)),\n" + "  STATEMENT\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        Breakpoint bp14 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(14).build();
        Breakpoint bp17 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(17).build();
        session.install(bp14);
        session.install(bp17);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 10, true, "STATEMENT(CALL(foo))").prepareStepInto(1).prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareStepOut(1).prepareStepInto(2).prepareStepOver(3);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 8, true, "STATEMENT").prepareStepOut(2).prepareStepInto(3);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT").prepareStepOver(1).prepareStepInto(2);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT").prepareStepOver(3);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 8, true, "STATEMENT").prepareStepOut(2).prepareStepOver(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 12, true, "STATEMENT").prepareStepOver(1).prepareContinue();
        });
        // Breakpoint is hit
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 14, true, "STATEMENT").prepareStepInto(5).prepareKill();
        });
        // Breakpoint on line 17 not hit because of the kill
        expectKilled();
        Assert.assertEquals(1, bp14.getHitCount());
        Assert.assertEquals(0, bp17.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 2 with Breakpoint

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

the class StepTest method testNoPreparesAfterContinueOrKill.

@Test
public void testNoPreparesAfterContinueOrKill() throws Throwable {
    final Source source = testSource("ROOT(\n" + "  DEFINE(loop,\n" + "    LOOP(3,\n" + "      STATEMENT),\n" + "    STATEMENT\n" + "  ),\n" + "  STATEMENT(CALL(loop))\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        session.suspendNextExecution();
        Breakpoint bp5 = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(5).build();
        session.install(bp5);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 7, true, "STATEMENT(CALL(loop))").prepareContinue();
            try {
                event.prepareStepInto(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOver(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOut(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareContinue();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareKill();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
        });
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 5, true, "STATEMENT").prepareKill();
            try {
                event.prepareStepInto(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOver(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareStepOut(1);
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareContinue();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
            try {
                event.prepareKill();
                Assert.fail("IllegalStateException should have been thrown.");
            } catch (IllegalStateException ex) {
            // expected
            }
        });
        expectKilled();
    }
}
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 3 with Breakpoint

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

the class StepTest method testIncompatibleSourceElements.

@Test
public void testIncompatibleSourceElements() {
    final Source source = testSource("ROOT(\n" + "  STATEMENT,\n" + "  EXPRESSION\n" + ")\n");
    // No SourceElements, no stepping/suspensions
    try (DebuggerSession session = startSession(new SourceElement[] {})) {
        startEval(source);
        session.suspendNextExecution();
        expectDone();
    }
    try (DebuggerSession session = startSession(new SourceElement[] {})) {
        Breakpoint breakpoint = Breakpoint.newBuilder(DebuggerTester.getSourceImpl(source)).lineIs(2).oneShot().build();
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.STATEMENT).build());
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
            try {
                event.prepareStepInto(1);
                fail();
            } catch (IllegalStateException ex) {
            // O.K.
            }
        });
        expectDone();
    }
    try (DebuggerSession session = startSession()) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 2, true, "STATEMENT");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
                fail();
            } catch (IllegalArgumentException ex) {
            // O.K.
            }
        });
        expectDone();
    }
    try (DebuggerSession session = startSession(SourceElement.EXPRESSION)) {
        startEval(source);
        session.suspendNextExecution();
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 3, true, "EXPRESSION");
            try {
                event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.STATEMENT).build());
                fail();
            } catch (IllegalArgumentException ex) {
            // O.K.
            }
            // O.K.
            event.prepareStepInto(1);
            // O.K.
            event.prepareStepInto(StepConfig.newBuilder().sourceElements(SourceElement.EXPRESSION).build());
        });
        expectDone();
    }
}
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 4 with Breakpoint

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

the class ValueLanguageTest method testValueLanguage.

@Test
public void testValueLanguage() {
    Source source1 = Source.create(ValuesLanguage1.ID, "i=10\n" + "s=test\n" + "a=null\n" + "b={}\n" + "b.a={}\n" + "b.j=100\n" + "b.k=200\n");
    Source source2 = Source.create(ValuesLanguage2.ID, "j=20\n" + "s=test2\n" + "d=null\n" + "e={}\n" + "b.c={}\n" + "e.d={}\n" + "e.k=200\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint bp1 = Breakpoint.newBuilder(getSourceImpl(source1)).lineIs(7).build();
        session.install(bp1);
        startEval(source1);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value = frame.getScope().getDeclaredValue("i");
            assertNull(value.getOriginalLanguage());
            assertEquals("L1:10", value.as(String.class));
            value = frame.getScope().getDeclaredValue("s");
            assertNull(value.getOriginalLanguage());
            assertEquals("L1:test", value.as(String.class));
            value = frame.getScope().getDeclaredValue("a");
            assertNull(value.getOriginalLanguage());
            assertEquals("null", value.as(String.class));
            value = frame.getScope().getDeclaredValue("b");
            LanguageInfo lang = value.getOriginalLanguage();
            assertNotNull(lang);
            assertEquals(ValuesLanguage1.NAME, lang.getName());
            assertEquals("{a={}, j=100}", value.as(String.class));
            event.prepareContinue();
        });
        expectDone();
        Breakpoint bp2 = Breakpoint.newBuilder(getSourceImpl(source2)).lineIs(7).build();
        session.install(bp2);
        startEval(source2);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugValue value = frame.getScope().getDeclaredValue("j");
            assertNull(value.getOriginalLanguage());
            assertEquals("L2:20", value.as(String.class));
            value = frame.getScope().getDeclaredValue("s");
            assertNull(value.getOriginalLanguage());
            assertEquals("L2:test2", value.as(String.class));
            value = frame.getScope().getDeclaredValue("e");
            LanguageInfo lang2 = value.getOriginalLanguage();
            assertNotNull(lang2);
            assertEquals(ValuesLanguage2.NAME, lang2.getName());
            assertEquals("{d={}}", value.as(String.class));
            value = frame.getScope().getDeclaredValue("b");
            LanguageInfo lang1 = value.getOriginalLanguage();
            assertNotNull(lang1);
            assertNotEquals(lang1, lang2);
            assertEquals(ValuesLanguage1.NAME, lang1.getName());
            // info from current lang2:
            assertEquals("Object", value.as(String.class));
            assertEquals("L2:Object", value.getMetaObject().as(String.class));
            // info from original lang1:
            value = value.asInLanguage(lang1);
            assertEquals("{a={}, j=100, k=200, c={}}", value.as(String.class));
            assertEquals("L1:Map", value.getMetaObject().as(String.class));
            assertEquals("L2:Map", value.getMetaObject().asInLanguage(lang2).as(String.class));
            // Properties are always in the original language:
            value = frame.getScope().getDeclaredValue("b");
            DebugValue a = value.getProperties().iterator().next();
            assertEquals(lang1, a.getOriginalLanguage());
            Iterator<DebugValue> it = value.getProperties().iterator();
            it.next();
            it.next();
            it.next();
            DebugValue c = it.next();
            assertEquals(lang2, c.getOriginalLanguage());
            value = value.asInLanguage(lang2);
            a = value.getProperties().iterator().next();
            assertEquals(lang1, a.getOriginalLanguage());
            it = value.getProperties().iterator();
            it.next();
            it.next();
            it.next();
            c = it.next();
            assertEquals(lang2, c.getOriginalLanguage());
            value = frame.getScope().getDeclaredValue("j");
            assertNull(value.getSourceLocation());
            value = value.asInLanguage(lang1);
            assertEquals("L1:20", value.as(String.class));
            assertNull(value.getSourceLocation());
            value = frame.getScope().getDeclaredValue("d");
            assertEquals("null", value.as(String.class));
            value = value.asInLanguage(lang1);
            assertEquals("null", value.as(String.class));
            value = frame.getScope().getDeclaredValue("e");
            assertEquals(getSourceImpl(source2).createSection(4, 3, 2), value.getSourceLocation());
            value = value.asInLanguage(lang1);
            assertNull(value.getSourceLocation());
            event.prepareContinue();
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) 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 5 with Breakpoint

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

the class DoubleHaltTest method testCallLoopStepInto.

@Test
public void testCallLoopStepInto() throws Throwable {
    Source testSource = testSource("ROOT(\n" + "  DEFINE(foo,\n" + "    LOOP(3,\n" + "      STATEMENT)\n" + "  ),\n" + "  CALL(foo)\n" + ")\n");
    try (DebuggerSession session = startSession()) {
        Breakpoint breakpoint4 = session.install(Breakpoint.newBuilder(getSourceImpl(testSource)).lineIs(4).build());
        session.suspendNextExecution();
        startEval(testSource);
        for (int i = 0; i < 3; i++) {
            final int modI = i % 3;
            expectSuspended((SuspendedEvent event) -> {
                SuspendedEvent e = checkState(event, 4, true, "STATEMENT");
                assertEquals(1, e.getBreakpoints().size());
                assertSame(breakpoint4, e.getBreakpoints().iterator().next());
                switch(modI) {
                    case 0:
                        /*
                             * Note Chumer: breakpoints should always hit independent if we are
                             * currently stepping out or not. thats why step out does not step out
                             * here.
                             */
                        e.prepareStepOut(1);
                        break;
                    case 1:
                        e.prepareStepInto(1);
                        break;
                    case 2:
                        e.prepareStepOver(1);
                        break;
                }
            });
        }
        expectSuspended((SuspendedEvent event) -> {
            checkState(event, 6, false, "CALL(foo)");
        });
        expectDone();
    }
}
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) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) 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