/** * Returns a language top scope. The top scopes have global validity and unlike * {@link DebugStackFrame#getScope()} have no relation to the suspended location. * * @since 0.30 */ public DebugScope getTopScope(String languageId) { LanguageInfo info = debugger.getEnv().getLanguages().get(languageId); if (info == null) { return null; } Iterable<Scope> scopes = debugger.getEnv().findTopScopes(languageId); Iterator<Scope> it = scopes.iterator(); if (!it.hasNext()) { return null; } return new DebugScope(it.next(), it, debugger, info); }
/** * Find a list of top scopes of a language. The iteration order corresponds with the scope * nesting, from the inner-most to the outer-most. * * @param languageId a language id. * @return a list of top scopes, can be empty when no top scopes are provided by the * language * @see TruffleLanguage#findTopScopes(java.lang.Object) * @since 0.30 */ public Iterable<Scope> findTopScopes(String languageId) { LanguageInfo languageInfo = getLanguages().get(languageId); if (languageInfo == null) { throw new IllegalArgumentException("Unknown language: " + languageId + ". Known languages are: " + getLanguages().keySet()); } final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return findTopScopes(env); }
/** * Find a list of top scopes of a language. The iteration order corresponds with the scope * nesting, from the inner-most to the outer-most. * * @param languageId a language id. * @return a list of top scopes, can be empty when no top scopes are provided by the * language * @see TruffleLanguage#findTopScopes(java.lang.Object) * @since 0.30 */ public Iterable<Scope> findTopScopes(String languageId) { LanguageInfo languageInfo = getLanguages().get(languageId); if (languageInfo == null) { throw new IllegalArgumentException("Unknown language: " + languageId + ". Known languages are: " + getLanguages().keySet()); } final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(languageInfo); return findTopScopes(env); }
/** * Returns a language top scope. The top scopes have global validity and unlike * {@link DebugStackFrame#getScope()} have no relation to the suspended location. * * @throws DebugException when guest language code throws an exception * @since 0.30 */ public DebugScope getTopScope(String languageId) throws DebugException { LanguageInfo info = debugger.getEnv().getLanguages().get(languageId); if (info == null) { return null; } try { Iterable<Scope> scopes = debugger.getEnv().findTopScopes(languageId); Iterator<Scope> it = scopes.iterator(); if (!it.hasNext()) { return null; } return new DebugScope(it.next(), it, this, info); } catch (ThreadDeath td) { throw td; } catch (Throwable ex) { throw new DebugException(this, ex, info, null, true, null); } }
/** * Evaluate the given code in this context. * * @param code the code to evaluate * @param languageId the language to evaluate the code in * @return result of the evaluation * @since 0.30 */ public DebugValue evaluate(String code, String languageId) { assert code != null; Object prevContext = context.enter(); try { Debugger debugger = executionLifecycle.getDebugger(); CallTarget target = debugger.getEnv().parse(Source.newBuilder(languageId, code, "eval").build()); Object result = target.call(); LanguageInfo languageInfo = debugger.getEnv().getLanguages().get(languageId); return new DebugValue.HeapValue(executionLifecycle.getSession(), languageInfo, null, result); } catch (IOException ex) { throw new RuntimeException(ex); } finally { context.leave(prevContext); } }
/** * Evaluate the given code in this context. * * @param code the code to evaluate * @param languageId the language to evaluate the code in * @return result of the evaluation * @since 0.30 */ public DebugValue evaluate(String code, String languageId) { assert code != null; Object prevContext = context.enter(); try { Debugger debugger = executionLifecycle.getDebugger(); CallTarget target = debugger.getEnv().parse(Source.newBuilder(code).language(languageId).name("eval").build()); Object result = target.call(); LanguageInfo languageInfo = debugger.getEnv().getLanguages().get(languageId); return new DebugValue.HeapValue(debugger, languageInfo, null, result); } catch (IOException ex) { throw new RuntimeException(ex); } finally { context.leave(prevContext); } }