Search in sources :

Example 51 with DebuggerSession

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

the class DebuggerTesterSnippets method assertBreakpoints.

private void assertBreakpoints(Source source, List<Breakpoint> breakpoints, Set<Breakpoint> breakpointsResolved, List<Breakpoint> breakpointsHit) {
    try (DebuggerSession session = startSession()) {
        for (Breakpoint breakpoint : breakpoints) {
            session.install(breakpoint);
        }
        startEval(source);
        while (breakpointsHit.size() != breakpoints.size()) {
            expectSuspended((SuspendedEvent event) -> {
                breakpointsHit.addAll(event.getBreakpoints());
                event.prepareContinue();
            });
        }
        expectDone();
    }
    Assert.assertEquals(breakpoints.size(), breakpointsResolved.size());
    Assert.assertEquals(breakpoints.size(), breakpointsHit.size());
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent)

Example 52 with DebuggerSession

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

the class DebuggerTesterSnippets method testDebugging.

// BEGIN: DebuggerTesterSnippets.testDebugging
public void testDebugging() {
    try (DebuggerTester tester = new DebuggerTester()) {
        // use your guest language source here
        Source source = null;
        try (DebuggerSession session = tester.startSession()) {
            session.suspendNextExecution();
            tester.startEval(source);
            tester.expectSuspended(new SuspendedCallback() {

                @Override
                public void onSuspend(SuspendedEvent event) {
                    // assert suspended event is proper here
                    event.prepareStepInto(1);
                }
            });
            tester.expectSuspended(new SuspendedCallback() {

                @Override
                public void onSuspend(SuspendedEvent event) {
                    // assert another suspended event is proper here
                    event.prepareContinue();
                }
            });
            // expect no more suspended events
            tester.expectDone();
        }
    }
}
Also used : 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)

Example 53 with DebuggerSession

use of com.oracle.truffle.api.debug.DebuggerSession in project sulong by graalvm.

the class LLVMDebugTest method runTest.

private void runTest(Source source, Source bitcode, Trace trace) {
    try (DebuggerSession session = tester.startSession()) {
        trace.requestedBreakpoints().forEach(line -> session.install(buildBreakPoint(source, line)));
        if (trace.suspendOnEntry()) {
            session.suspendNextExecution();
        }
        tester.startEval(bitcode);
        final BreakInfo info = new BreakInfo();
        for (StopRequest bpr : trace) {
            final TestCallback expectedEvent = new TestCallback(info, bpr);
            do {
                tester.expectSuspended(expectedEvent);
            } while (!expectedEvent.isDone());
        }
        tester.expectDone();
    }
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession)

Example 54 with DebuggerSession

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

the class SLDebugTest method testUnwindAndReenter.

@Test
public void testUnwindAndReenter() {
    final Source source = slCode("function main() {\n" + "  return fac(10);\n" + "}\n" + "function fac(n) {\n" + "  if (n <= 1) {\n" + // break
    "    return 1;\n" + "  }\n" + "  return n * fac(n - 1);\n" + "}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(source)).lineIs(6).build());
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
            Iterator<DebugStackFrame> frames = event.getStackFrames().iterator();
            for (int i = 0; i < 5; i++) {
                frames.next();
            }
            event.prepareUnwindFrame(frames.next());
        });
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(8, event.getTopStackFrame().getSourceSection().getStartLine());
            assertEquals("7", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
            event.prepareStepInto(1);
        });
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(5, event.getTopStackFrame().getSourceSection().getStartLine());
            assertEquals("6", event.getTopStackFrame().getScope().getDeclaredValue("n").as(String.class));
            event.prepareContinue();
        });
        expectSuspended((SuspendedEvent event) -> {
            // The breakpoint hit again
            assertEquals(6, event.getTopStackFrame().getSourceSection().getStartLine());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) 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)

Example 55 with DebuggerSession

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

the class SLDebugTest method testDebugValue.

@Test
public void testDebugValue() throws Throwable {
    final Source varsSource = slCode("function main() {\n" + "  a = doNull();\n" + "  b = 10 == 10;\n" + "  c = 10;\n" + "  d = \"str\";\n" + "  e = new();\n" + "  e.p1 = 1;\n" + "  e.p2 = new();\n" + "  e.p2.p21 = 21;\n" + "  return;\n" + "}\n" + "function doNull() {}\n");
    try (DebuggerSession session = startSession()) {
        session.install(Breakpoint.newBuilder(getSourceImpl(varsSource)).lineIs(10).build());
        startEval(varsSource);
        expectSuspended((SuspendedEvent event) -> {
            DebugStackFrame frame = event.getTopStackFrame();
            DebugScope scope = frame.getScope();
            DebugValue a = scope.getDeclaredValue("a");
            assertFalse(a.isArray());
            assertNull(a.getArray());
            assertNull(a.getProperties());
            DebugValue b = scope.getDeclaredValue("b");
            assertFalse(b.isArray());
            assertNull(b.getArray());
            assertNull(b.getProperties());
            DebugValue c = scope.getDeclaredValue("c");
            assertFalse(c.isArray());
            assertEquals("10", c.as(String.class));
            assertNull(c.getArray());
            assertNull(c.getProperties());
            DebugValue d = scope.getDeclaredValue("d");
            assertFalse(d.isArray());
            assertEquals("str", d.as(String.class));
            assertNull(d.getArray());
            assertNull(d.getProperties());
            DebugValue e = scope.getDeclaredValue("e");
            assertFalse(e.isArray());
            assertNull(e.getArray());
            assertEquals(scope, e.getScope());
            Collection<DebugValue> propertyValues = e.getProperties();
            assertEquals(2, propertyValues.size());
            Iterator<DebugValue> propertiesIt = propertyValues.iterator();
            assertTrue(propertiesIt.hasNext());
            DebugValue p1 = propertiesIt.next();
            assertEquals("p1", p1.getName());
            assertEquals("1", p1.as(String.class));
            assertNull(p1.getScope());
            assertTrue(propertiesIt.hasNext());
            DebugValue p2 = propertiesIt.next();
            assertEquals("p2", p2.getName());
            assertNull(p2.getScope());
            assertFalse(propertiesIt.hasNext());
            propertyValues = p2.getProperties();
            assertEquals(1, propertyValues.size());
            propertiesIt = propertyValues.iterator();
            assertTrue(propertiesIt.hasNext());
            DebugValue p21 = propertiesIt.next();
            assertEquals("p21", p21.getName());
            assertEquals("21", p21.as(String.class));
            assertNull(p21.getScope());
            assertFalse(propertiesIt.hasNext());
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) DebugScope(com.oracle.truffle.api.debug.DebugScope) 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)

Aggregations

DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)110 Source (org.graalvm.polyglot.Source)103 Test (org.junit.Test)102 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)97 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)49 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)20 DebugValue (com.oracle.truffle.api.debug.DebugValue)16 Debugger (com.oracle.truffle.api.debug.Debugger)14 Context (org.graalvm.polyglot.Context)11 SourceSection (com.oracle.truffle.api.source.SourceSection)8 SuspensionFilter (com.oracle.truffle.api.debug.SuspensionFilter)7 DebugContext (com.oracle.truffle.api.debug.DebugContext)6 SuspendedCallback (com.oracle.truffle.api.debug.SuspendedCallback)6 DebugScope (com.oracle.truffle.api.debug.DebugScope)5 Engine (org.graalvm.polyglot.Engine)5 HashMap (java.util.HashMap)3 Value (org.graalvm.polyglot.Value)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2