public void hotCodeReplaceFailed(final List<IDebugTarget> targets) { final Display display = Display.getDefault(); try { final String title = "Model changed during simulation"; display.asyncExec(new Runnable() { public void run() { if (display.isDisposed()) { return; } SimulationLaunchErrorDialog dialog = new SimulationLaunchErrorDialog( DebugUIPlugin.getShell(), title, MESSAGE, status, targets); dialog.setBlockOnOpen(false); dialog.open(); } }); } catch (Exception ex) { ex.printStackTrace(); } }
private void handleCloseEvent(IResourceChangeEvent event) { if (event.getResource() instanceof IProject) { IProject project = ((IProject) event.getResource()); for (IDebugTarget target : activeTargets) { EObject object = (EObject) target.getAdapter(EObject.class); IFile file = WorkspaceSynchronizer.getFile(object.eResource()); if (project.equals(file.getProject())) { try { target.terminate(); } catch (DebugException e) { e.printStackTrace(); } } } } }
private void handleHotModelReplacement() { // first implementation: If the underlying model does not change // semantically, no notification is required... List<IDebugTarget> targets = getAffectedTargets(); List<IDebugTarget> modelReplacementFailedTargets = new ArrayList<IDebugTarget>(); for (IDebugTarget sctDebugTarget : targets) { // Reload the Statechart form the changes resource Statechart newStatechart = ResourceUtil.loadStatechart(((SCTDebugElement) sctDebugTarget) .getResourceString()); if (!EcoreUtil.equals(newStatechart, (EObject) sctDebugTarget.getAdapter(EObject.class))) { // The model semantically changed, we have to create a // notificiation for that.... modelReplacementFailedTargets.add(sctDebugTarget); } } if (modelReplacementFailedTargets.size() > 0) { notifyHotModelReplacementFailed(targets); } }
private List<IDebugTarget> getAffectedTargets() { List<IDebugTarget> targets = new ArrayList<IDebugTarget>(); synchronized (activeTargets) { for (IDebugTarget debugTarget : activeTargets) { if (debugTarget instanceof SCTDebugTarget) { String resourceString = ((SCTDebugElement) debugTarget).getResourceString(); IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(resourceString); if (changedFiles.contains(resource)) { targets.add(debugTarget); } } } } return targets; }
@Override public void interpreterFinished(InterpreterState state, List<EventReason> reasons) { this.isStopped = true; this.isSuspended = false; IDebugTarget target = null; if (DebugPlugin.getDefault() != null) { synchronized (this.debugElements) { for (DebugElement element : this.debugElements) { element.fireTerminateEvent(); target = element.getDebugTarget(); } } DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[]{new DebugEvent(BfProcess.this, DebugEvent.TERMINATE)}); if (target != null && target instanceof BfDebugTarget) { ((BfDebugTarget) target).fireTerminateEvent(); } } }
public static List<ConnectedTargetData> getAllConnectedTargetDatas() { IDebugTarget[] array = DebugPlugin.getDefault().getLaunchManager().getDebugTargets(); List<ConnectedTargetData> result = new ArrayList<ConnectedTargetData>(array.length); for (IDebugTarget target : array) { if (target instanceof DebugTargetImpl == false) { continue; } if (target.getLaunch().isTerminated()) { continue; } DebugTargetImpl debugTargetImpl = (DebugTargetImpl) target; ConnectedTargetData connectedData = debugTargetImpl.getConnectedDataOrNull(); if (connectedData == null) { continue; } result.add(connectedData); } return result; }
public static ConnectedTargetData getConnectionTargetData(Object element) { IDebugTarget debugTarget; if (element instanceof ILaunch) { ILaunch launch = (ILaunch) element; debugTarget = launch.getDebugTarget(); } else if (element instanceof IDebugElement) { IDebugElement debugElement = (IDebugElement) element; debugTarget = debugElement.getDebugTarget(); } else { return null; } if (debugTarget instanceof DebugTargetImpl == false) { return null; } DebugTargetImpl debugTargetImpl = (DebugTargetImpl) debugTarget; return debugTargetImpl.getConnectedOrNull(); }
@Override public void handleDebugEvents(DebugEvent[] events) { for (DebugEvent event : events) { switch (event.getKind()) { case DebugEvent.CREATE: if (event.getSource() instanceof IDebugTarget) { WatchDogEventType.START_DEBUG.process(this); } break; case DebugEvent.TERMINATE: if (event.getSource() instanceof IDebugTarget) { WatchDogEventType.END_DEBUG.process(this); } break; default: break; } } }
public PyDebugTargetServer(ILaunch launch, IPath[] file, RemoteDebuggerServer debugger) { this.file = file; this.debugger = debugger; this.threads = new PyThread[0]; this.launch = launch; if (launch != null) { for (IDebugTarget target : launch.getDebugTargets()) { if (target instanceof PyDebugTargetServer && target.isTerminated()) { launch.removeDebugTarget(target); } } launch.addDebugTarget(this); } debugger.addTarget(this); PyExceptionBreakPointManager.getInstance().addListener(this); PyPropertyTraceManager.getInstance().addListener(this); IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); breakpointManager.addBreakpointListener(this); // we have to know when we get removed, so that we can shut off the debugger DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); }
/** * Checks if the last thing entered was a new line, and if it was, notifies clients about it. */ private void checkFinishedLine() { String s = this.toString(); this.reset(); char c; if (s.length() > 0 && ((c = s.charAt(s.length() - 1)) == '\n' || c == '\r')) { IAdaptable context = DebugUITools.getDebugContext(); if (context != null) { s = StringUtils.rightTrim(s); Object adapter = context.getAdapter(IDebugTarget.class); if (adapter instanceof AbstractDebugTarget) { AbstractDebugTarget target = (AbstractDebugTarget) adapter; for (IConsoleInputListener listener : participants) { listener.newLineReceived(s, target); } } } } }
public static String getEncodingFromFrame(PyStackFrame selectedFrame) { try { IDebugTarget adapter = (IDebugTarget) selectedFrame.getAdapter(IDebugTarget.class); if (adapter == null) { return "UTF-8"; } IProcess process = adapter.getProcess(); if (process == null) { return "UTF-8"; } ILaunch launch = process.getLaunch(); if (launch == null) { Log.log("Unable to get launch for: " + process); return "UTF-8"; } return getEncodingFromLaunch(launch); } catch (Exception e) { Log.log(e); return "UTF-8"; } }
public void setLaunchAndRelatedInfo(ILaunch launch) { this.setLaunch(launch); if (launch != null) { IDebugTarget debugTarget = launch.getDebugTarget(); IInterpreterInfo projectInterpreter = null; if (debugTarget instanceof PyDebugTarget) { PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget; PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project); if (nature != null) { ArrayList<IPythonNature> natures = new ArrayList<>(1); natures.add(nature); this.setNaturesUsed(natures); try { projectInterpreter = nature.getProjectInterpreter(); this.setInterpreterInfo(projectInterpreter); } catch (Throwable e1) { Log.log(e1); } } } } }
@Override protected void onSetTreeInput() { IDebugTarget[] debugTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets(); List<AbstractDebugTarget> targets = new ArrayList<AbstractDebugTarget>(); if (debugTargets.length > 0) { for (IDebugTarget iDebugTarget : debugTargets) { if (iDebugTarget instanceof AbstractDebugTarget) { AbstractDebugTarget debugTarget = (AbstractDebugTarget) iDebugTarget; if (!debugTarget.isTerminated() && !debugTarget.isDisconnected()) { if (debugTarget.hasCurrExceptions()) { targets.add(debugTarget); } } } } } viewer.setInput(targets); }
@Override public IEditorInput getEditorInput(Object element) { IEditorInput edInput = null; if (element instanceof PyStackFrame) { PyStackFrame pyStackFrame = (PyStackFrame) element; IPath path = pyStackFrame.getPath(); // get the project of the file that is being debugged Object target = pyStackFrame.getAdapter(IDebugTarget.class); if (target instanceof PyDebugTarget) { lastProject = ((PyDebugTarget) target).project; } if (path != null && !path.toString().startsWith("<")) { edInput = locatorBase.createEditorInput(path, true, pyStackFrame, lastProject); } } return edInput; }
/** * Gets the completions at the passed offset. */ @Override public ICompletionProposal[] getCompletions(String text, String actTok, int offset, boolean showForTabCompletion) throws Exception { this.text = text; this.actTok = actTok; this.offset = offset; PyStackFrame stackFrame = currentPyStackFrameForConsole.getLastSelectedFrame(); if (stackFrame != null) { AbstractDebugTarget target = (AbstractDebugTarget) stackFrame.getAdapter(IDebugTarget.class); if (target != null) { GetCompletionsCommand cmd = new GetCompletionsCommand(target, actTok, stackFrame.getLocalsLocator() .getPyDBLocation()); cmd.setCompletionListener(this); target.postCommand(cmd); } return waitForCommand(); } return EMPTY_COMPLETION_PROPOSALS; }
/** * Test {@link DSLDebugTargetAdapter#isAdapterForType(Object)}. */ @Test public void isAdapterForType() { 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(); assertTrue(debugTarget.isAdapterForType(IDebugTarget.class)); }
/** * 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 IDebugTarget} form a {@link DebugTarget}. * * @param target * the {@link DebugTarget} * @return the {@link IDebugTarget} */ public DSLDebugTargetAdapter getDebugTarget(DebugTarget target) { synchronized(target) { final DSLDebugTargetAdapter res = (DSLDebugTargetAdapter)adapt(target, IDebugTarget.class); if (res == null) { throw new IllegalStateException("can't addapt DebugTarget to IDebugTarget."); } return res; } }
/** * Changes the current {@link IStackFrame}. * * @param frame * the selected {@link IStackFrame} */ protected void changeCurrentStackFrame(IStackFrame frame) { final IDebugTarget debugTarget = frame.getDebugTarget(); for (IDSLCurrentInstructionListener listener : ((DSLDebugTargetAdapter)debugTarget) .getCurrentInstructionListeners()) { listener.setCurrentFrame(frame.getModelIdentifier(), ((DSLStackFrameAdapter)frame).getHost()); } }
static void resume(ExecutionEvent event) { if(launch != null) { try { IDebugTarget debugTarget = launch.getDebugTarget(); if(debugTarget != null) debugTarget.resume(); } catch (DebugException e) { e.printStackTrace(); } } // showView(event); }
static void terminate(ExecutionEvent event) { if(launch != null) { try { IDebugTarget debugTarget = launch.getDebugTarget(); if(debugTarget != null) debugTarget.terminate(); } catch (DebugException e) { e.printStackTrace(); } } // showView(event); }
@Override public String getText(Object element) { if (element instanceof IDebugTarget) { try { IDebugTarget target = (IDebugTarget) element; String text = target.getName(); return target.isTerminated() ? Messages.getString("target.terminated", text) : text; } catch (DebugException ex) { logger.log(Level.FINE, "Unexpected execption", ex); /* FALLTHROUGH */ } } return super.getText(element); }
@Override public Image getImage(Object element) { if (element instanceof IDebugTarget) { if (image == null) { image = SharedImages.CLOUDSDK_IMAGE_DESCRIPTOR.createImage(); } return image; } return super.getImage(element); }
@Override public boolean canTerminate() { for (IProcess p : processes) { if (p.canTerminate()) { return true; } } for (IDebugTarget t : targets) { if (t.canTerminate()) { return true; } } return false; }
@Override public boolean isTerminated() { for (IProcess p : processes) { if (!p.isTerminated()) { return false; } } for (IDebugTarget t : targets) { if (!t.isTerminated()) { return false; } } return true; }
@Override public void terminate() throws DebugException { for (Iterator<IProcess> iter = processes.iterator(); iter.hasNext(); iter.remove()) { IProcess p = iter.next(); if (p.canTerminate()) { p.terminate(); } } for (Iterator<IDebugTarget> iter = targets.iterator(); iter.hasNext(); iter.remove()) { IDebugTarget t = iter.next(); if (t.canTerminate()) { t.terminate(); } } }
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; } } } } } }
protected Object getDebugTarget() { IDebugTarget[] debugTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets(); for (IDebugTarget iDebugTarget : debugTargets) { if (iDebugTarget.isTerminated()) continue; if (iDebugTarget.getAdapter(ISimulationEngine.class) == this) return iDebugTarget; } return null; }
protected boolean allTargetsTerminated() { ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); for (ILaunch launch : launches) { for (IDebugTarget target : launch.getDebugTargets()) { if (!target.isTerminated()) return false; } } return true; }
protected void setActiveSession() { // if a simulation session is running, we should initialize with its // content IAdaptable debugContext = DebugUITools.getDebugContext(); if (debugContext != null) { IDebugTarget debugTarget = (IDebugTarget) debugContext.getAdapter(IDebugTarget.class); if (debugTarget != null) { if (!debugTarget.isTerminated()) { this.debugTarget = (IDebugTarget) debugTarget; activeTargetChanged(this.debugTarget); } } } }
protected void changeTarget(IDebugTarget newTarget) { if (newTarget == debugTarget) { return; } if (newTarget != debugTarget && newTarget != null && !newTarget.isTerminated()) { debugTarget = newTarget; activeTargetChanged(newTarget); } else { setActiveSession(); } }
protected void activeTargetChanged(final IDebugTarget debugTarget) { openEditorForTarget(debugTarget); updateTypeSystem(debugTarget); ISimulationEngine engine = (ISimulationEngine) debugTarget.getAdapter(ISimulationEngine.class); timeScheduler = (DefaultTimeTaskScheduler) engine.getTimeTaskScheduler(); setViewerInput(engine.getExecutionContext()); updateActions(); updateSessionDropdownInput(debugTarget); }
protected void openEditorForTarget(final IDebugTarget debugTarget) { if (this.debugTarget != null) { EObject adapter = debugTarget.getAdapter(EObject.class); if (adapter instanceof Statechart) { Statechart statechart = (Statechart) adapter; Diagram diagram = DiagramPartitioningUtil.getDiagramContaining(statechart); Display.getDefault().asyncExec(new Runnable() { @Override public void run() { DiagramPartitioningUtil.openEditor(diagram); } }); } } }
protected void updateSessionDropdownInput(final IDebugTarget debugTarget) { Display.getDefault().asyncExec(() -> { if (debugTarget != null) { if (!targets.contains(debugTarget)) { targets.add(debugTarget); sessionDropdown.setInput(targets); sessionDropdown.setSelection(new StructuredSelection(debugTarget), true); changeTarget(debugTarget); } sessionDropdown.refresh(); } }); }
@Override public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); IDebugTarget debugTarget = (IDebugTarget) selection.getFirstElement(); if (debugTarget != null) { changeTarget(debugTarget); sctSourceDisplayDispatcher.displaySource(debugTarget, SimulationView.this.getSite().getPage(), true); } }
public void debugContextChanged(DebugContextEvent event) { if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { PlatformObject object = (PlatformObject) ((IStructuredSelection) event.getContext()).getFirstElement(); if (object == null) return; IDebugTarget newTarget = (IDebugTarget) object.getAdapter(IDebugTarget.class); if (newTarget != debugTarget && newTarget != null && !newTarget.isTerminated()) { debugTarget = newTarget; } } }
protected SCTDebugTarget unwrapTarget(Object element) { if (element instanceof Launch) { IDebugTarget debugTarget = ((Launch) element).getDebugTarget(); if (debugTarget instanceof SCTDebugTarget) return (SCTDebugTarget) debugTarget; } else if (element instanceof SCTDebugElement) { return (SCTDebugTarget) ((SCTDebugElement) element).getDebugTarget(); } return null; }
protected void handleDebugTargetTerminated(DebugEvent debugEvent) { Object source = debugEvent.getSource(); if (source instanceof IDebugTarget) { IDebugTarget target = (IDebugTarget) source; if (target == activeDebugTarget) { activeSourceDisplay.terminate(true); activeSourceDisplay = null; } } }
public Object handleStatus(final IStatus status, final Object source) { Display.getDefault().asyncExec(new Runnable() { public void run() { Shell shell = DebugUIPlugin.getShell(); SimulationLaunchErrorDialog dialog = new SimulationLaunchErrorDialog(shell, "Exception occured during simulation", ERROR_MSG, status, Collections .singletonList((IDebugTarget) source)); dialog.setBlockOnOpen(false); dialog.open(); } }); return null; }
public void handleDebugEvents(DebugEvent[] events) { for (DebugEvent debugEvent : events) { if (debugEvent.getKind() == DebugEvent.TERMINATE) { Object source = debugEvent.getSource(); if (source instanceof IAdaptable) { Object adapter = ((IAdaptable) source).getAdapter(IDebugTarget.class); if (adapter instanceof SCTDebugTarget) { unregisterSCTTarget((SCTDebugTarget) adapter); } } } } }