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;
}
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;
}
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);
}
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;
}
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);
}
Aggregations