Search in sources :

Example 31 with DebugException

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

the class VariablesHandler method getDebugValue.

static DebugValue getDebugValue(DebugStackFrame frame, String value) {
    try {
        return frame.eval(value);
    } catch (DebugException de) {
    }
    DebugValue receiver = frame.getScope().getReceiver();
    if (receiver != null && value.equals(receiver.getName())) {
        return receiver;
    }
    DebugScope scope = frame.getScope();
    while (scope != null) {
        DebugValue debugValue = scope.getDeclaredValue(value);
        if (debugValue != null) {
            return debugValue;
        }
        scope = scope.getParent();
    }
    return null;
}
Also used : DebugScope(com.oracle.truffle.api.debug.DebugScope) DebugValue(com.oracle.truffle.api.debug.DebugValue) DebugException(com.oracle.truffle.api.debug.DebugException)

Example 32 with DebugException

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

the class RemoteObject method initFromValue.

private boolean initFromValue() {
    DebugValue debugValue = valueValue;
    LanguageInfo originalLanguage = debugValue.getOriginalLanguage();
    // Setup the object with a language-specific value
    if (originalLanguage != null) {
        debugValue = debugValue.asInLanguage(originalLanguage);
    }
    PrintWriter err = context != null ? context.getErr() : null;
    this.typeInfo = TypeInfo.fromValue(debugValue, typeMark, originalLanguage, err);
    boolean readable = debugValue.isReadable();
    String toString;
    boolean addType = true;
    Object rawValue = null;
    String unserializable = null;
    boolean replicableRawValue = true;
    try {
        if (typeInfo.subtype == SUBTYPE.INTERNAL_ENTRY) {
            toString = createMapEntryDescription(debugValue, context.areToStringSideEffectsAllowed(), err);
            addType = false;
        } else if (readable) {
            SourceSection sourceSection;
            if (typeInfo.isFunction && (sourceSection = debugValue.getSourceLocation()) != null && sourceSection.isAvailable() && sourceSection.getSource().hasCharacters()) {
                toString = sourceSection.getCharacters().toString();
                addType = false;
            } else {
                toString = debugValue.toDisplayString(context.areToStringSideEffectsAllowed());
                if (typeInfo.type == TYPE.STRING || typeInfo.type == TYPE.SYMBOL) {
                    // The whole description is rendered as a String in quotes, or highlighted
                    // as a symbol. Do not prepend the type.
                    addType = false;
                }
            }
        } else {
            toString = InspectorExecutionContext.VALUE_NOT_READABLE;
            replicableRawValue = false;
        }
        if (readable && !typeInfo.isObject) {
            if (typeInfo.subtype == SUBTYPE.NULL && typeInfo.type == TYPE.OBJECT) {
                replicableRawValue = false;
            } else if (typeInfo.type == TYPE.UNDEFINED) {
                replicableRawValue = false;
            } else {
                if (debugValue.isBoolean()) {
                    rawValue = debugValue.asBoolean();
                } else if (debugValue.isNumber()) {
                    rawValue = TypeInfo.toNumber(debugValue);
                    if (!isFinite((Number) rawValue)) {
                        unserializable = rawValue.toString();
                        rawValue = null;
                    }
                } else {
                    replicableRawValue = false;
                    rawValue = toString;
                }
            }
        }
    } catch (DebugException ex) {
        if (err != null && ex.isInternalError()) {
            err.println(debugValue.getName() + " toDisplayString() has caused: " + ex);
            ex.printStackTrace(err);
        }
        throw ex;
    }
    this.value = rawValue;
    this.replicableValue = replicableRawValue;
    this.unserializableValue = unserializable;
    if (addType && typeInfo.descriptionType != null && !typeInfo.descriptionType.equals(toString)) {
        this.description = typeInfo.descriptionType + ((toString != null && !toString.isEmpty()) ? " " + toString : "");
    } else {
        this.description = toString;
    }
    if (typeInfo.isObject && addType && typeInfo.isJS && generatePreview) {
        try {
            this.preview = ObjectPreview.create(debugValue, typeInfo.type, typeInfo.subtype, context.areToStringSideEffectsAllowed(), originalLanguage, err);
        } catch (DebugException ex) {
            if (err != null && ex.isInternalError()) {
                err.println(debugValue.getName() + " preview has caused: " + ex);
                ex.printStackTrace(err);
            }
        }
    }
    if (readable && context != null && context.isCustomObjectFormatterEnabled()) {
        if (originalLanguage != null) {
            try {
                this.customPreview = CustomPreview.create(debugValue, originalLanguage, context);
            } catch (DebugException ex) {
                if (err != null) {
                    if (ex.isInternalError()) {
                        err.println(debugValue.getName() + " custom preview has caused: " + ex);
                        ex.printStackTrace(err);
                    } else {
                        err.println("Custom Formatter Failed: " + ex.getLocalizedMessage());
                    }
                }
            }
        }
    }
    return typeInfo.isObject;
}
Also used : LanguageInfo(com.oracle.truffle.api.nodes.LanguageInfo) DebugValue(com.oracle.truffle.api.debug.DebugValue) JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) NullObject(com.oracle.truffle.tools.chromeinspector.objects.NullObject) SourceSection(com.oracle.truffle.api.source.SourceSection) DebugException(com.oracle.truffle.api.debug.DebugException) PrintWriter(java.io.PrintWriter)

Example 33 with DebugException

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

the class RemoteObject method createJSONResultValue.

/**
 * Create a JSON object representing the provided {@link DebugValue}. Use when a reply by value
 * is requested.
 */
public static JSONObject createJSONResultValue(DebugValue debugValue, boolean allowToStringSideEffects, PrintWriter err) {
    JSONObject json = new JSONObject();
    DebugValue metaObject = getMetaObject(debugValue, null, err);
    boolean isObject = TypeInfo.isObject(debugValue, err);
    boolean isJS = LanguageChecks.isJS(debugValue.getOriginalLanguage());
    String vtype = null;
    if (metaObject != null & isJS) {
        try {
            Collection<DebugValue> properties = metaObject.getProperties();
            if (properties != null) {
                for (DebugValue prop : properties) {
                    String name = prop.getName();
                    if ("type".equals(name)) {
                        vtype = toMetaName(prop, err);
                    }
                }
            }
        } catch (DebugException ex) {
            if (err != null && ex.isInternalError()) {
                err.println("getProperties of meta object of (" + debugValue.getName() + ") has caused: " + ex);
                ex.printStackTrace(err);
            }
            throw ex;
        }
    }
    if (vtype == null) {
        if (isObject) {
            vtype = "object";
        } else {
            vtype = (metaObject != null) ? toString(metaObject, allowToStringSideEffects, err) : "object";
        }
    }
    json.put("type", vtype);
    String[] unserializablePtr = new String[1];
    try {
        json.putOpt("value", createJSONValue(debugValue, allowToStringSideEffects, unserializablePtr, err));
    } catch (DebugException ex) {
        if (err != null && ex.isInternalError()) {
            err.println("getProperties(" + debugValue.getName() + ") has caused: " + ex);
            ex.printStackTrace(err);
        }
        throw ex;
    }
    json.putOpt("unserializableValue", unserializablePtr[0]);
    return json;
}
Also used : JSONObject(com.oracle.truffle.tools.utils.json.JSONObject) DebugValue(com.oracle.truffle.api.debug.DebugValue) DebugException(com.oracle.truffle.api.debug.DebugException)

Example 34 with DebugException

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

the class LanguageExceptionsTest method testBuggyLanguageCalls.

private void testBuggyLanguageCalls(ProxyLanguage language, SuspendedCallback callback, String prefix) {
    ProxyLanguage.setDelegate(language);
    DebuggerSession session = tester.startSession();
    session.suspendNextExecution();
    Source source = Source.create(ProxyLanguage.ID, prefix + "1");
    tester.startEval(source);
    tester.expectSuspended((SuspendedEvent event) -> {
        try {
            callback.onSuspend(event);
            Assert.fail("No DebugException is thrown!");
        } catch (DebugException dex) {
            Assert.assertEquals("1", dex.getLocalizedMessage());
            verifyExStack(dex, IllegalStateException.class.getName());
        } catch (Throwable t) {
            Assert.fail(t.getLocalizedMessage());
        }
    });
    tester.expectDone();
    source = Source.create(ProxyLanguage.ID, prefix + "2");
    session.suspendNextExecution();
    tester.startEval(source);
    tester.expectSuspended((SuspendedEvent event) -> {
        try {
            callback.onSuspend(event);
            Assert.fail("No DebugException is thrown!");
        } catch (DebugException dex) {
            Assert.assertEquals("A TruffleException", dex.getLocalizedMessage());
            Assert.assertNull(Objects.toString(dex.getCause()), dex.getCause());
        } catch (Throwable t) {
            Assert.fail(t.getLocalizedMessage());
        }
    });
    tester.expectDone();
    source = Source.create(ProxyLanguage.ID, prefix + "3");
    session.suspendNextExecution();
    tester.startEval(source);
    tester.expectSuspended((SuspendedEvent event) -> {
        try {
            callback.onSuspend(event);
            Assert.fail("No DebugException is thrown!");
        } catch (DebugException dex) {
            Assert.assertEquals("3", dex.getLocalizedMessage());
            verifyExStack(dex, AssertionError.class.getName());
        } catch (Throwable t) {
            Assert.fail(t.getLocalizedMessage());
        }
    });
    tester.expectDone();
}
Also used : DebuggerSession(com.oracle.truffle.api.debug.DebuggerSession) SuspendedEvent(com.oracle.truffle.api.debug.SuspendedEvent) DebugException(com.oracle.truffle.api.debug.DebugException) Source(org.graalvm.polyglot.Source)

Aggregations

DebugException (com.oracle.truffle.api.debug.DebugException)34 DebugValue (com.oracle.truffle.api.debug.DebugValue)20 Breakpoint (com.oracle.truffle.api.debug.Breakpoint)12 DebuggerSession (com.oracle.truffle.api.debug.DebuggerSession)12 JSONObject (com.oracle.truffle.tools.utils.json.JSONObject)12 SuspendedEvent (com.oracle.truffle.api.debug.SuspendedEvent)11 Source (org.graalvm.polyglot.Source)11 SourceSection (com.oracle.truffle.api.source.SourceSection)10 Test (org.junit.Test)10 PrintWriter (java.io.PrintWriter)8 DebugScope (com.oracle.truffle.api.debug.DebugScope)7 CommandProcessException (com.oracle.truffle.tools.chromeinspector.server.CommandProcessException)7 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)6 NoSuspendedThreadException (com.oracle.truffle.tools.chromeinspector.InspectorExecutionContext.NoSuspendedThreadException)6 JSONArray (com.oracle.truffle.tools.utils.json.JSONArray)6 Params (com.oracle.truffle.tools.chromeinspector.commands.Params)5 RemoteObject (com.oracle.truffle.tools.chromeinspector.types.RemoteObject)5 ArrayList (java.util.ArrayList)5 CatchLocation (com.oracle.truffle.api.debug.DebugException.CatchLocation)3 DebugStackFrame (com.oracle.truffle.api.debug.DebugStackFrame)3