/** * Test {@link DSLDebugTargetAdapter#getThreads()}. * * @throws DebugException * if fail */ @Test public void getThreads() throws DebugException { DebugTarget eDebugTarget = DebugPackage.eINSTANCE.getDebugFactory().createDebugTarget(); eDebugTarget.setName("Debug target"); final TestEventProcessor testEventProcessor = new TestEventProcessor(); final DSLEclipseDebugIntegration integration = new DSLEclipseDebugIntegration("id", null, eDebugTarget, new ModelUpdater(), testEventProcessor); final DSLDebugTargetAdapter debugTarget = integration.getDebugTarget(); createThreads(eDebugTarget); final IThread[] threads = debugTarget.getThreads(); assertEquals(0, testEventProcessor.getEvents().size()); assertEquals(8, threads.length); }
/** * Render a selected variable. * * @param selection * the selection object * @param element * the variable element * @throws DebugException */ private void displayVariable(IStructuredSelection selection, IDebugElement element) throws DebugException { IValue value = ((IVariable) element).getValue(); if (value instanceof IJavaPrimitiveValue) { setBrowserTextToPrimitive((IJavaPrimitiveValue) value); } else { TreePath firstElementTreePath = ((TreeSelection) selection).getPaths()[0]; String watchExpression = generateWatchExpression(firstElementTreePath); String messageExpression = generateMessageExpression(watchExpression); // Iterate all threads and run our rendering // expression in them in the hopes that we can find // the relevant selection in only one thread // FIXME find a better way to derive the correct thread! IWatchExpressionDelegate delegate = DebugPlugin.getDefault().getExpressionManager() .newWatchExpressionDelegate(element.getModelIdentifier()); for (IThread thread : element.getDebugTarget().getThreads()) { delegate.evaluateExpression(messageExpression, thread, this); } } }
@Override public IThread[] getThreads() throws DebugException { if (debugger == null) { return null; } if (threads == null) { ThreadListCommand cmd = new ThreadListCommand(this); this.postCommand(cmd); try { cmd.waitUntilDone(1000); threads = cmd.getThreads(); } catch (InterruptedException e) { threads = new PyThread[0]; } } return threads; }
/** * Waits until some thread is suspended. */ protected IThread waitForSuspendedThread(final PyDebugTarget target) throws Throwable { final IThread[] ret = new IThread[1]; waitForCondition(new ICallback() { @Override public Object call(Object args) throws Exception { IThread[] threads = target.getThreads(); for (IThread thread : threads) { if (thread.isSuspended()) { ret[0] = thread; return true; } } return false; } }, "waitForSuspendedThread"); return ret[0]; }
/** * Returns the current stack frame context, or <code>null</code> if none. * * @return the current stack frame context, or <code>null</code> if none */ public static IJavaStackFrame getStackFrame() { IAdaptable adaptable = DebugUITools.getDebugContext(); if (adaptable != null) { Object x = adaptable.getAdapter(IJavaStackFrame.class); if (x != null) return (IJavaStackFrame)x; } try { for (ILaunch launch: DebugPlugin.getDefault().getLaunchManager().getLaunches()) { for (IThread thread: launch.getDebugTarget().getThreads()) { IStackFrame[] frames = thread.getStackFrames(); if (frames.length > 0) return (IJavaStackFrame)frames[0]; } } } catch (DebugException e) { throw new RuntimeException(e); } return null; }
/** * Initializes {@link DSLEclipseDebugIntegration#SUPPORTED_TYPES}. * * @return the {@link Set} of * {@link org.eclipse.emf.common.notify.AdapterFactory#isFactoryForType(Object) supported * types}. */ private static Set<Object> initSupportedTypes() { final Set<Object> res = new HashSet<Object>(); res.add(IThread.class); res.add(IDebugTarget.class); res.add(IStackFrame.class); res.add(IVariable.class); res.add(IBreakpoint.class); return res; }
/** * Gets an {@link IThread} form a {@link Thread}. * * @param thread * the {@link Thread} * @return the {@link IThread} */ public DSLThreadAdapter getThread(Thread thread) { synchronized(thread) { final DSLThreadAdapter res = (DSLThreadAdapter)adapt(thread, IThread.class); if (res == null) { throw new IllegalStateException("can't addapt Thread to IThread."); } return res; } }
/** * {@inheritDoc} * * @see org.eclipse.debug.core.model.IDebugTarget#getThreads() */ public IThread[] getThreads() throws DebugException { final List<IThread> res = new ArrayList<IThread>(); for (Thread thread : getHost().getThreads()) { res.add(factory.getThread(thread)); } return res.toArray(new IThread[res.size()]); }
static void stepInto(ExecutionEvent event) { if(launch != null) { try { for(IThread t : launch.getDebugTarget().getThreads()) if(t.canStepInto()) t.stepInto(); } catch (DebugException e) { e.printStackTrace(); } } // showView(event); }
static void stepOver(ExecutionEvent event) { if(launch != null) { try { for(IThread t : launch.getDebugTarget().getThreads()) if(t.canStepOver()) t.stepOver(); } catch (DebugException e) { e.printStackTrace(); } } // showView(event); }
static void stepReturn(ExecutionEvent event) { if(launch != null) { try { for(IThread t : launch.getDebugTarget().getThreads()) if(t.canStepReturn()) t.stepReturn(); } catch (DebugException e) { e.printStackTrace(); } } // showView(event); }
public void handleDebugEvents(DebugEvent[] events) { if (events != null) { int size = events.length; for (int i = 0; i < size; i++) { if (events[i].getKind() == DebugEvent.TERMINATE) { Object source = events[i].getSource(); // THe event source should be a thread as remote debugging // does not launch a separate local process // However, multiple threads may be associated with the // debug target, so to check if an app // is disconnected from the debugger, additional termination // checks need to be performed on the debug target // itself if (source instanceof IThread) { IDebugTarget debugTarget = ((IThread) source).getDebugTarget(); // Be sure to only handle events from the debugger // source that generated the termination event. Do not // handle // any other application that is currently connected to // the debugger. if (eventSource.equals(debugTarget) && debugTarget.isDisconnected()) { DebugPlugin.getDefault().removeDebugEventListener(this); ApplicationDebugLauncher.terminateLaunch(launchId); return; } } } } } }
public void handleDebugEvents(DebugEvent[] events) { if (events != null) { int size = events.length; for (int i = 0; i < size; i++) { if (events[i].getKind() == DebugEvent.TERMINATE) { Object source = events[i].getSource(); // THe event source should be a thread as remote debugging // does not launch a separate local process // However, multiple threads may be associated with the // debug target, so to check if an app // is disconnected from the debugger, additional termination // checks need to be performed on the debug target // itself if (source instanceof IThread) { IDebugTarget debugTarget = ((IThread) source).getDebugTarget(); // Be sure to only handle events from the debugger // source that generated the termination event. Do not // handle // any other application that is currently connected to // the debugger. if (eventSource.equals(debugTarget) && debugTarget.isDisconnected()) { DebugPlugin.getDefault().removeDebugEventListener(this); DebugOperations.terminateLaunch(launchId); return; } } } } } }
private void fireEventForThread(int kind, int detail) { try { IThread[] threads = debugTargetState.getThreads(); if (threads.length > 0) { DebugTargetImpl.fireDebugEvent(new DebugEvent(threads[0], kind, detail)); } } catch (DebugException e) { // Actually, this is not thrown in our getThreads() return; } }
protected void createRequests() { for (final IThread thread : this.getThreads()) { if (thread instanceof JiveThread) { ((JiveThread) thread).createRequests(); } } eventHandlerFactory.createRequests(); }
protected void removeRequests() { for (final IThread thread : this.getThreads()) { if (thread instanceof JiveThread) { ((JiveThread) thread).removeRequests(); } } eventHandlerFactory.removeRequests(); }
private IStackFrame createStackFrame(final IJiveDebugTarget target, final IJiveEvent event) { try { final IThread thread = new MockThread(target, event); return thread.getTopStackFrame(); } catch (final DebugException e) { throw new IllegalStateException("This should never occur since a mock object is returned."); } }
public MockStackFrame(final IJiveDebugTarget target, final IJiveEvent event, final IThread thread) { super(target); this.event = event; this.thread = thread; }
@Override public void selectionChanged(final IWorkbenchPart part, final ISelection selection) { // allow views to be selectively enabled/disabled if (part instanceof IDebugView && selection instanceof IStructuredSelection) { Object object = ((IStructuredSelection) selection).getFirstElement(); if (!selection.isEmpty()) { // Determine if an IJiveDebugTarget is associated with the selection if (object instanceof IStackFrame) { object = ((IStackFrame) object).getThread(); } if (object instanceof IThread) { object = ((IThread) object).getDebugTarget(); } if (object instanceof IProcess) { object = ((IProcess) object).getLaunch(); } if (object instanceof ILaunch) { object = ((ILaunch) object).getDebugTarget(); } } // Display the debug target if (object instanceof IJiveDebugTarget) { JiveLaunchManager.INSTANCE.targetSelected((IJiveDebugTarget) object); } } }
/** * @return an existing thread with a given id (null if none) */ protected PyThread findThreadByID(String thread_id) { for (IThread thread : threads) { if (thread_id.equals(((PyThread) thread).getId())) { return (PyThread) thread; } } return null; }
public PyDebugTargetConsole(PydevConsoleCommunication scriptConsoleCommunication, ILaunch launch, IProcess process, RemoteDebuggerConsole debugger) { super(launch, process, null, debugger, null); virtualConsoleThread = new PyThreadConsole(this); virtualConsoleThreads = new IThread[] { virtualConsoleThread }; }
@Override public IThread[] getThreads() throws DebugException { if (isTerminated()) { return new IThread[0]; } IThread[] realThreads = super.getThreads(); if (realThreads != null) { return ArrayUtils.concatArrays(virtualConsoleThreads, realThreads); } else { return virtualConsoleThreads; } }
@Override public boolean isAdapterForType(Object type) { return super.isAdapterForType(type) || type == IThread.class; }
@Override public void removeAnnotations(IEditorPart editorPart, IThread thread) { // nothing to do here }
@Override public IThread getThread() { return thread; }
@Override public IThread[] getThreads() throws DebugException { return new IThread[0]; }
public synchronized IThread[] getThreads() throws DebugException { return new IThread[] {}; }
@Override public IThread[] getThreads() throws DebugException { return threads.stream().toArray(MontoThread[]::new); }
@Override public void removeAnnotations(IEditorPart editorPart, IThread thread) { }
@Override public IThread[] getThreads() throws DebugException { return new IThread[] {this.thread}; }
@Override public IThread getThread() { return this.ownerThread; }
@Override IThread[] getThreads() throws DebugException { return disconnectAspect.isDisconnected() ? DebugTargetImpl.EMPTY_THREADS : threadArray; }
@Override public IThread[] getThreads() throws DebugException { return currentState.getThreads(); }
@Override IThread[] getThreads() throws DebugException { return DebugTargetImpl.EMPTY_THREADS; }