Search in sources :

Example 1 with CatchLocation

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

the class DebugExceptionTest method testCaughtException1.

@Test
public void testCaughtException1() {
    Source testSource = testSource("TRY(STATEMENT(THROW(NPE, TestExceptionMessage)), CATCH(NPE, STATEMENT))\n");
    Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, true).build();
    try (DebuggerSession session = startSession()) {
        session.install(caughtBreakpoint);
        assertTrue(caughtBreakpoint.isResolved());
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(caughtBreakpoint, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
            DebugException exception = event.getException();
            assertEquals("TestExceptionMessage", exception.getMessage());
            CatchLocation catchLocation = exception.getCatchLocation();
            assertEquals("TRY(STATEMENT(THROW(NPE, TestExceptionMessage))", catchLocation.getSourceSection().getCharacters());
            assertEquals(event.getTopStackFrame(), catchLocation.getFrame());
            SourceSection throwLocation = exception.getThrowLocation();
            assertEquals("THROW(NPE, TestExceptionMessage)", throwLocation.getCharacters());
            assertEquals("NPE: TestExceptionMessage", exception.getExceptionObject().toDisplayString());
            assertDebugStackTrace(exception.getDebugStackTrace(), " <1:15, 1:46>");
            assertStack(exception.getStackTrace(), "<instrumentation-test-language>.(Unnamed:1)");
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) CatchLocation(com.oracle.truffle.api.debug.DebugException.CatchLocation) SourceSection(com.oracle.truffle.api.source.SourceSection) DebugException(com.oracle.truffle.api.debug.DebugException) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 2 with CatchLocation

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

the class DebugExceptionTest method testLocationBreakpointOnException.

@Test
public void testLocationBreakpointOnException() {
    final Source source = testSource("ROOT(\n" + "  TRY(STATEMENT(THROW(a, b)), CATCH(a, EXPRESSION)),\n" + "  STATEMENT\n" + ")\n");
    Breakpoint breakpoint = Breakpoint.newBuilder(getSourceImpl(source)).lineIs(2).suspendAnchor(SuspendAnchor.AFTER).build();
    try (DebuggerSession session = startSession()) {
        session.install(breakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(breakpoint, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
            DebugException exception = event.getException();
            assertEquals("b", exception.getMessage());
            CatchLocation catchLocation = exception.getCatchLocation();
            assertEquals("TRY(STATEMENT(THROW(a, b))", catchLocation.getSourceSection().getCharacters());
            assertEquals(event.getTopStackFrame(), catchLocation.getFrame());
            SourceSection throwLocation = exception.getThrowLocation();
            assertEquals("THROW(a, b)", throwLocation.getCharacters());
            assertEquals("a: b", exception.getExceptionObject().toDisplayString());
        });
        expectDone();
        // Add exception breakpoints to test which breakpoints were hit
        Breakpoint uncaughtBreakpoint = Breakpoint.newExceptionBuilder(false, true).build();
        Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, false).build();
        session.install(uncaughtBreakpoint);
        session.install(caughtBreakpoint);
        startEval(source);
        expectSuspended((SuspendedEvent event) -> {
            assertEquals(2, event.getBreakpoints().size());
            assertSame(caughtBreakpoint, event.getBreakpoints().get(0));
            assertSame(breakpoint, event.getBreakpoints().get(1));
            DebugException exception = event.getException();
            assertEquals("b", exception.getMessage());
        });
        expectDone();
    }
}
Also used : Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) CatchLocation(com.oracle.truffle.api.debug.DebugException.CatchLocation) SourceSection(com.oracle.truffle.api.source.SourceSection) DebugException(com.oracle.truffle.api.debug.DebugException) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 3 with CatchLocation

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

the class DebugExceptionTest method testCaughtException2.

@Test
public void testCaughtException2() {
    Source testSource = testSource("ROOT(\n" + "DEFINE(CaughtThrow,\n" + "  TRY(STATEMENT(CALL(ThrownNPE)),\n" + "      CATCH(NPE, STATEMENT))\n" + "),\n" + "DEFINE(ThrownNPE,\n" + "  STATEMENT(THROW(NPE, TestExceptionMessage))\n" + "),\n" + "CALL(CaughtThrow))");
    Breakpoint caughtBreakpoint = Breakpoint.newExceptionBuilder(true, false).build();
    try (DebuggerSession session = startSession()) {
        session.install(caughtBreakpoint);
        assertTrue(caughtBreakpoint.isResolved());
        startEval(testSource);
        expectSuspended((SuspendedEvent event) -> {
            assertSame(caughtBreakpoint, event.getBreakpoints().iterator().next());
            assertSame(SuspendAnchor.AFTER, event.getSuspendAnchor());
            DebugException exception = event.getException();
            assertEquals("TestExceptionMessage", exception.getMessage());
            CatchLocation catchLocation = exception.getCatchLocation();
            assertEquals("TRY(STATEMENT(CALL(ThrownNPE))", catchLocation.getSourceSection().getCharacters());
            Iterator<DebugStackFrame> stackFrames = event.getStackFrames().iterator();
            stackFrames.next();
            DebugStackFrame nextFrame = stackFrames.next();
            assertEquals(nextFrame, catchLocation.getFrame());
            SourceSection throwLocation = exception.getThrowLocation();
            assertEquals("THROW(NPE, TestExceptionMessage)", throwLocation.getCharacters());
            assertEquals("NPE: TestExceptionMessage", exception.getExceptionObject().toDisplayString());
            assertDebugStackTrace(exception.getDebugStackTrace(), "ThrownNPE <7:13, 7:44>", "CaughtThrow <3:17, 3:31>", " <9:1, 9:17>");
            assertStack(exception.getStackTrace(), "<instrumentation-test-language>.ThrownNPE(Unnamed:7)", "<instrumentation-test-language>.CaughtThrow(Unnamed:3)", "<instrumentation-test-language>.(Unnamed:9)");
        });
        expectDone();
    }
}
Also used : DebugStackFrame(com.oracle.truffle.api.debug.DebugStackFrame) Breakpoint(com.oracle.truffle.api.debug.Breakpoint) DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) CatchLocation(com.oracle.truffle.api.debug.DebugException.CatchLocation) SourceSection(com.oracle.truffle.api.source.SourceSection) DebugException(com.oracle.truffle.api.debug.DebugException) Source(org.graalvm.polyglot.Source) Test(org.junit.Test)

Example 4 with CatchLocation

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

the class BreakpointExceptionFilter method testExceptionCaught.

@TruffleBoundary
private Match testExceptionCaught(Node throwNode, Throwable exception) {
    if (!InteropLibrary.getUncached().isException(exception)) {
        return uncaught ? Match.MATCHED : Match.UNMATCHED;
    }
    CatchLocation catchLocation = getCatchNode(throwNode, exception);
    boolean exceptionCaught = catchLocation != null;
    return new Match(caught && exceptionCaught || uncaught && !exceptionCaught, catchLocation);
}
Also used : CatchLocation(com.oracle.truffle.api.debug.DebugException.CatchLocation) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

CatchLocation (com.oracle.truffle.api.debug.DebugException.CatchLocation)4 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)3 DebugException (com.oracle.truffle.api.debug.DebugException)3 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)3 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)3 SourceSection (com.oracle.truffle.api.source.SourceSection)3 Source (org.graalvm.polyglot.Source)3 Test (org.junit.Test)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)1