Search in sources :

Example 1 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class DebugExprTypeofNode method getLLVMSourceType.

@Specialization
public LLVMSourceType getLLVMSourceType(VirtualFrame frame) {
    NodeLibrary nodeLibrary = NodeLibrary.getUncached();
    InteropLibrary interopLibrary = InteropLibrary.getUncached();
    try {
        LLVMDebuggerValue entries = (LLVMDebuggerValue) nodeLibrary.getScope(location, frame, false);
        if (interopLibrary.isMemberReadable(entries, name)) {
            Object member = interopLibrary.readMember(entries, name);
            LLVMDebuggerValue ldv = (LLVMDebuggerValue) member;
            Object metaObj = ldv.resolveMetaObject();
            return (LLVMSourceType) metaObj;
        }
    } catch (ClassCastException e) {
        // OR metaObj is no primitive type
        throw DebugExprException.create(this, "\"%s\" cannot be casted to a LLVMDebuggerValue", name);
    } catch (UnsupportedMessageException e) {
        // should only happen if hasMembers == false
        throw DebugExprException.symbolNotFound(this, name, null);
    } catch (UnknownIdentifierException e) {
        throw DebugExprException.symbolNotFound(this, e.getUnknownIdentifier(), null);
    }
    return LLVMSourceType.UNKNOWN;
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) LLVMDebuggerValue(com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue) LLVMSourceType(com.oracle.truffle.llvm.runtime.debug.type.LLVMSourceType) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 2 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class HoverRequestHandler method tryFrameScope.

private Hover tryFrameScope(MaterializedFrame frame, CoverageEventNode node, String textAtHoverPosition, LanguageInfo langInfo, SourceSection hoverSection) {
    Node instrumentedNode = node.getInstrumentedNode();
    NodeLibrary nodeLibrary = NodeLibrary.getUncached(instrumentedNode);
    if (nodeLibrary.hasScope(instrumentedNode, frame)) {
        try {
            Object scope = nodeLibrary.getScope(instrumentedNode, frame, true);
            Object keys = INTEROP.getMembers(scope);
            long size = INTEROP.getArraySize(keys);
            for (long i = 0; i < size; i++) {
                String key = INTEROP.asString(INTEROP.readArrayElement(keys, i));
                if (key.equals(textAtHoverPosition)) {
                    Object var = INTEROP.readMember(scope, key);
                    return Hover.create(createDefaultHoverInfos(textAtHoverPosition, var, langInfo)).setRange(SourceUtils.sourceSectionToRange(hoverSection));
                }
            }
        } catch (UnsupportedMessageException | UnknownIdentifierException | InvalidArrayIndexException e) {
        }
    }
    return null;
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) InvalidArrayIndexException(com.oracle.truffle.api.interop.InvalidArrayIndexException) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) UnknownIdentifierException(com.oracle.truffle.api.interop.UnknownIdentifierException) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) CoverageEventNode(org.graalvm.tools.lsp.server.utils.CoverageEventNode) TruffleObject(com.oracle.truffle.api.interop.TruffleObject)

Example 3 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class EventContextObject method iterateFrames.

@CompilerDirectives.TruffleBoundary
private static Object iterateFrames(Object[] args, EventContextObject obj) throws ArityException, UnsupportedTypeException {
    if (args.length == 0) {
        throw ArityException.create(0, 0, args.length);
    }
    final NodeLibrary lib = NodeLibrary.getUncached();
    final InteropLibrary iop = InteropLibrary.getUncached();
    final Object callback = args[0];
    if (!iop.isExecutable(callback)) {
        Object displayCallback = iop.toDisplayString(callback, false);
        throw UnsupportedTypeException.create(new Object[] { callback }, "Cannot execute " + displayCallback);
    }
    Object retValue = Truffle.getRuntime().iterateFrames((frameInstance) -> {
        final Node n = frameInstance.getCallNode();
        if (n == null || n.getRootNode() == null || n.getRootNode().isInternal()) {
            // skip top most record of the instrument and any internal frames
            return null;
        }
        LocationObject location = new LocationObject(n);
        final SourceSection ss = location.getInstrumentedSourceSection();
        if (ss == null || ss.getSource().isInternal()) {
            // skip internal frames
            return null;
        }
        final Frame frame = frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE);
        Node instrumentableNode = findInstrumentableParent(n);
        if (instrumentableNode != null && lib.hasScope(instrumentableNode, frame)) {
            try {
                Object frameVars = new CurrentScopeView(lib.getScope(instrumentableNode, frame, false));
                Object ret = iop.execute(callback, location, frameVars);
                return iop.isNull(ret) ? null : ret;
            } catch (UnsupportedMessageException | UnsupportedTypeException | ArityException ex) {
                throw InsightException.raise(ex);
            }
        }
        return null;
    });
    return NullObject.nullCheck(retValue);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) Frame(com.oracle.truffle.api.frame.Frame) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) InteropLibrary(com.oracle.truffle.api.interop.InteropLibrary) Node(com.oracle.truffle.api.nodes.Node) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) UnsupportedTypeException(com.oracle.truffle.api.interop.UnsupportedTypeException) SourceSection(com.oracle.truffle.api.source.SourceSection) ArityException(com.oracle.truffle.api.interop.ArityException)

Example 4 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class BreakpointSnippets method notifyIndirectHit.

/**
 * Returns <code>true</code> if it should appear in the breakpoints list.
 *
 * @throws BreakpointConditionFailure
 */
boolean notifyIndirectHit(EventContext context, DebuggerNode source, DebuggerNode node, MaterializedFrame frame, DebugException exception) throws BreakpointConditionFailure {
    if (!isEnabled()) {
        return false;
    }
    assert node.getBreakpoint() == this;
    if (source != node) {
        // We're testing a different breakpoint at the same location
        if (rootInstanceRef != null) {
            Object rootInstance = rootInstanceRef.get();
            if (rootInstance != null) {
                Node contextNode = context.getInstrumentedNode();
                NodeLibrary contextNodeLibrary = NodeLibrary.getUncached(contextNode);
                if (contextNodeLibrary.hasRootInstance(contextNode, frame)) {
                    try {
                        if (rootInstance != contextNodeLibrary.getRootInstance(contextNode, frame)) {
                            return false;
                        }
                    } catch (UnsupportedMessageException e) {
                        throw CompilerDirectives.shouldNotReachHere(e);
                    }
                }
            }
        }
        AbstractBreakpointNode breakpointNode = ((AbstractBreakpointNode) node);
        if (!breakpointNode.testCondition(frame)) {
            return false;
        }
        if (exceptionFilter != null && exception != null) {
            Throwable throwable = exception.getRawException();
            assert throwable != null;
            BreakpointExceptionFilter.Match matched = exceptionFilter.matchException(node, throwable);
            if (!matched.isMatched) {
                return false;
            }
        }
        if (this.hitCount.incrementAndGet() <= ignoreCount) {
            // breakpoint hit was ignored
            return false;
        }
    }
    if (isOneShot()) {
        setEnabled(false);
    }
    return true;
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) ExecutableNode(com.oracle.truffle.api.nodes.ExecutableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Node(com.oracle.truffle.api.nodes.Node) ExecutionEventNode(com.oracle.truffle.api.instrumentation.ExecutionEventNode)

Example 5 with NodeLibrary

use of com.oracle.truffle.api.interop.NodeLibrary in project graal by oracle.

the class NodeDefaultsTest method testScopeDefaults.

@Test
public void testScopeDefaults() {
    Node n = new TestNode();
    NodeLibrary l = createLibrary(NodeLibrary.class, n);
    assertFalse(l.hasScope(n, null));
    assertFails(() -> l.getScope(n, null, true), UnsupportedMessageException.class);
    assertFails(() -> l.getScope(n, null, false), UnsupportedMessageException.class);
}
Also used : NodeLibrary(com.oracle.truffle.api.interop.NodeLibrary) Node(com.oracle.truffle.api.nodes.Node) ProbeNode(com.oracle.truffle.api.instrumentation.ProbeNode) InstrumentableNode(com.oracle.truffle.api.instrumentation.InstrumentableNode) RootNode(com.oracle.truffle.api.nodes.RootNode) Test(org.junit.Test)

Aggregations

NodeLibrary (com.oracle.truffle.api.interop.NodeLibrary)17 InstrumentableNode (com.oracle.truffle.api.instrumentation.InstrumentableNode)8 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)8 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)8 Node (com.oracle.truffle.api.nodes.Node)8 Test (org.junit.Test)8 RootNode (com.oracle.truffle.api.nodes.RootNode)6 Frame (com.oracle.truffle.api.frame.Frame)4 ProbeNode (com.oracle.truffle.api.instrumentation.ProbeNode)4 InteropLibrary (com.oracle.truffle.api.interop.InteropLibrary)4 UnknownIdentifierException (com.oracle.truffle.api.interop.UnknownIdentifierException)4 ExecutableNode (com.oracle.truffle.api.nodes.ExecutableNode)3 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)2 LanguageInfo (com.oracle.truffle.api.nodes.LanguageInfo)2 ProxyLanguage (com.oracle.truffle.api.test.polyglot.ProxyLanguage)2 LLVMDebuggerValue (com.oracle.truffle.llvm.runtime.debug.LLVMDebuggerValue)2 Context (org.graalvm.polyglot.Context)2 CoverageData (org.graalvm.tools.lsp.server.utils.CoverageData)2 CoverageEventNode (org.graalvm.tools.lsp.server.utils.CoverageEventNode)2 Specialization (com.oracle.truffle.api.dsl.Specialization)1