/** * Starts a new {@link DebuggerSession session} provided with a callback that gets notified * whenever the execution is suspended. Uses {@link SourceElement#STATEMENT} as the source * element available for stepping. Use * {@link #startSession(SuspendedCallback, SourceElement...)} to specify a different set of * source elements. * * @param callback the callback to notify * @see DebuggerSession * @see SuspendedEvent * @see #startSession(SuspendedCallback, SourceElement...) * @since 0.17 */ public DebuggerSession startSession(SuspendedCallback callback) { return startSession(callback, SourceElement.STATEMENT); }
public Debugger create(Env env) { return new Debugger(env); } });
DebuggerExecutionLifecycle(Debugger debugger) { this.debugger = debugger; this.lifecycleInstrumenter = debugger.getEnv().getInstrumenter(); }
public void run() { Debugger.find(engine).startSession(new SuspendedCallback() { public void onSuspend(SuspendedEvent event) { pauseRequested = true; event.prepareKill(); } }); } }, 10, TimeUnit.SECONDS);
static ValuePropertiesCollection getProperties(Object value, Debugger debugger, LanguageInfo language, DebugScope scope) { ValuePropertiesCollection properties = null; if (value instanceof TruffleObject) { TruffleObject object = (TruffleObject) value; Map<Object, Object> map = ObjectStructures.asMap(debugger.getMessageNodes(), object); if (map != null) { properties = new ValuePropertiesCollection(debugger, language, object, map, map.entrySet(), scope); } } return properties; }
@Override public void onExecute(ExecuteSourceEvent event) { if (sourceResolved[0]) { return; } sourceResolved[0] = true; synchronized (Breakpoint.this) { if (sourceBinding != null) { sourceBinding.dispose(); } } Source source = event.getSource(); SourceSection location = locationKey.adjustLocation(source, debugger.getEnv(), suspendAnchor); if (location != null) { resolveBreakpoint(location); } SourceSectionFilter locationFilter = locationKey.createLocationFilter(source, suspendAnchor); breakpointBinding = debugger.getInstrumenter().attachExecutionEventFactory(locationFilter, new BreakpointNodeFactory()); } }, true);
private void trace(String msg, Object... parameters) { Debugger.trace(this + ": " + msg, parameters); }
private List<DebuggerNode> collectDebuggerNodes(Node iNode, SuspendAnchor suspendAnchor) { List<DebuggerNode> nodes = new ArrayList<>(); for (EventBinding<?> binding : allBindings) { DebuggerNode node = (DebuggerNode) debugger.getInstrumenter().lookupExecutionEventNode(iNode, binding); if (node != null && node.isActiveAt(suspendAnchor)) { nodes.add(node); } } return nodes; }
/** * Closes the current debugging session and disposes all installed breakpoints. * * @since 0.17 */ public synchronized void close() { if (Debugger.TRACE) { trace("close session"); } if (closed) { throw new IllegalStateException("session already closed"); } clearStrategies(); removeBindings(); for (Breakpoint breakpoint : this.breakpoints) { breakpoint.sessionClosed(this); } currentSuspendedEventMap.clear(); allBindings.clear(); debugger.disposedSession(this); closed = true; }
/** * Permanently prevents this breakpoint from affecting execution. When not * {@link #isModifiable() modifiable}, {@link IllegalStateException} is thrown. * * @since 0.9 */ public synchronized void dispose() { if (!disposed) { setEnabled(false); if (sourceBinding != null) { sourceBinding.dispose(); sourceBinding = null; } for (DebuggerSession session : sessions) { session.disposeBreakpoint(this); } if (debugger != null) { debugger.disposeBreakpoint(this); debugger = null; } disposed = true; } }
/** @since 0.15 */ @Test public void testRootNodeName() throws Exception { final int[] haltCount = new int[1]; final String name = applyNumbers(); final String[] actualName = new String[1]; final PolyglotEngine engine = prepareVM(PolyglotEngine.newBuilder()); final PolyglotEngine.Value apply = engine.findGlobalSymbol(name); final int value = RANDOM.nextInt(100); final TruffleObject fn = JavaInterop.asTruffleFunction(ObjectBinaryOperation.class, new ConstantFunction(value)); try (DebuggerSession session = Debugger.find(engine).startSession(new SuspendedCallback() { public void onSuspend(SuspendedEvent ev) { actualName[0] = ev.getTopStackFrame().getName(); haltCount[0] = haltCount[0] + 1; } })) { session.suspendNextExecution(); apply.execute(fn).as(Number.class); } assertEquals(1, haltCount[0]); assertEquals(name, actualName[0]); }
static ValuePropertiesCollection getProperties(Object value, DebuggerSession session, LanguageInfo language, DebugScope scope) { ValuePropertiesCollection properties = null; if (value instanceof TruffleObject) { TruffleObject object = (TruffleObject) value; Map<Object, Object> map = ObjectStructures.asMap(session.getDebugger().getMessageNodes(), object); if (map != null) { properties = new ValuePropertiesCollection(session, language, object, map, map.entrySet(), scope); } } return properties; }
private void trace(String msg, Object... parameters) { Debugger.trace(this + ": " + msg, parameters); }
private EventBinding<? extends ExecutionEventNodeFactory> createBinding(SourceSectionFilter locationFilter) { EventBinding<BreakpointNodeFactory> binding = debugger.getInstrumenter().attachExecutionEventFactory(locationFilter, new BreakpointNodeFactory()); synchronized (this) { for (DebuggerSession s : sessions) { s.allBindings.add(binding); } } return binding; }
/** * Closes the current debugging session and disposes all installed breakpoints. * * @since 0.17 */ public synchronized void close() { if (Debugger.TRACE) { trace("close session"); } if (closed) { throw new IllegalStateException("session already closed"); } clearStrategies(); removeBindings(); for (Breakpoint breakpoint : this.breakpoints) { breakpoint.sessionClosed(this); } currentSuspendedEventMap.clear(); debugger.disposedSession(this); closed = true; }
/** * Permanently prevents this breakpoint from affecting execution. When not * {@link #isModifiable() modifiable}, {@link IllegalStateException} is thrown. * * @since 0.9 */ public synchronized void dispose() { if (!disposed) { setEnabled(false); if (sourceBinding != null) { sourceBinding.dispose(); sourceBinding = null; } for (DebuggerSession session : sessions) { session.disposeBreakpoint(this); } if (debugger != null) { debugger.disposeBreakpoint(this); debugger = null; } disposed = true; } }
@Override public Set<Map.Entry<String, DebugValue>> entrySet() { Set<Map.Entry<String, DebugValue>> entries = new LinkedHashSet<>(); for (Map.Entry<String, ? extends Object> symbol : debugger.getEnv().getExportedSymbols().entrySet()) { DebugValue value = new DebugValue.HeapValue(DebuggerSession.this, symbol.getKey(), symbol.getValue()); entries.add(new SimpleImmutableEntry<>(symbol.getKey(), value)); } return Collections.unmodifiableSet(entries); }
/** * Starts a new {@link DebuggerSession session} provided with a callback that gets notified * whenever the execution is suspended. Uses {@link SourceElement#STATEMENT} as the source * element available for stepping. Use * {@link #startSession(SuspendedCallback, SourceElement...)} to specify a different set of * source elements. * * @param callback the callback to notify * @see DebuggerSession * @see SuspendedEvent * @see #startSession(SuspendedCallback, SourceElement...) * @since 0.17 */ public DebuggerSession startSession(SuspendedCallback callback) { return startSession(callback, SourceElement.STATEMENT); }
@Override public FrameInstance visitFrame(FrameInstance frameInstance) { Node node; if (depth == 0) { node = throwNode; } else { node = frameInstance.getCallNode(); } if (node != null) { Node catchNode = getCatchNode(debugger.getMessageNodes(), node, exception); if (catchNode != null) { catchLocationPtr[0] = new CatchLocation(catchNode.getSourceSection(), frameInstance, depth); return frameInstance; } } depth++; return null; } });
void disposeBreakpoint(Breakpoint breakpoint) { boolean removed; synchronized (this) { removed = breakpoints.remove(breakpoint); } if (removed) { BreakpointsPropertyChangeEvent.firePropertyChange(this, breakpoint, null); } if (Debugger.TRACE) { trace("disposed debugger breakpoint %s", breakpoint); } }