org.eclipse.debug.core.model.IDebugTarget Java Examples

The following examples show how to use org.eclipse.debug.core.model.IDebugTarget. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsoleCompletionsPageParticipant.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Gets the completions at the passed offset.
 */
@Override
public ICompletionProposalHandle[] 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;
}
 
Example #2
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Display.getDefault().asyncExec(new Runnable() {

		@Override
		public void run() {
			IDebugTarget[] debugTargets = debugTarget.getLaunch().getDebugTargets();
			for (IDebugTarget current : debugTargets) {
				ILaunch launch = current.getLaunch();
				SCTDebugTarget target = (SCTDebugTarget) launch.getDebugTarget();
				try {
					target.getLaunch().terminate();
				} catch (CoreException e) {
					e.printStackTrace();
				}
			}
			ILaunchConfiguration launchConfiguration = debugTarget.getLaunch().getLaunchConfiguration();
			DebugUITools.launch(launchConfiguration, debugTarget.getLaunch().getLaunchMode());
		}
	});
}
 
Example #3
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void openEditorForTarget(final IDebugTarget debugTarget) {
	if (this.debugTarget != null && debugTarget instanceof SCTDebugTarget
			&& ((SCTDebugTarget) debugTarget).isPrimary()) {
		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);
				}
			});
		}
	}
}
 
Example #4
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Display.getDefault().asyncExec(new Runnable() {

		@Override
		public void run() {
			IDebugTarget[] debugTargets = debugTarget.getLaunch().getDebugTargets();
			for (IDebugTarget current : debugTargets) {
				if (current instanceof IStep) {
					try {
						((IStep) current).stepOver();
					} catch (DebugException e) {
						e.printStackTrace();
					}
				}
			}
		}
	});
}
 
Example #5
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
protected void createSimulationSessionViewer(Composite parent) {
	simulationSessionViewer = SimulationSessionViewerFactory.createViewer(parent);
	selectionChangedListener = new ISelectionChangedListener() {
		@Override
		public void selectionChanged(SelectionChangedEvent event) {
			Object selection = ((StructuredSelection) event.getSelection()).getFirstElement();
			if (selection instanceof IDebugTarget)
				changeTarget((IDebugTarget) selection);
			else if (selection instanceof ILaunch)
				changeTarget(((ILaunch) selection).getDebugTarget());
			SourceLookupManager.getDefault().displaySource(selection, getSite().getPage(), true);
		}
	};
	simulationSessionViewer.addSelectionChangedListener(selectionChangedListener);

	MenuManager contextMenu = new MenuManager();
	addSimulationSessionActions(contextMenu);
	Menu menu = contextMenu.createContextMenu(simulationSessionViewer.getControl());
	simulationSessionViewer.getControl().setMenu(menu);
}
 
Example #6
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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();
				}
			}
		}
	}
}
 
Example #7
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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);
	}

}
 
Example #8
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Display.getDefault().asyncExec(new Runnable() {

		@Override
		public void run() {
			try {
				IDebugTarget[] debugTargets = debugTarget.getLaunch().getDebugTargets();
				for (IDebugTarget current : debugTargets) {
					current.terminate();
				}
			} catch (DebugException e) {
				e.printStackTrace();
			}
		}
	});
}
 
Example #9
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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;

}
 
Example #10
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Display.getDefault().asyncExec(new Runnable() {

		@Override
		public void run() {
			try {
				IDebugTarget[] debugTargets = debugTarget.getLaunch().getDebugTargets();
				for (IDebugTarget current : debugTargets) {
					current.suspend();
				}
			} catch (DebugException e) {
				e.printStackTrace();
			}
		}
	});
}
 
Example #11
Source File: SimulationView.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run() {
	Display.getDefault().asyncExec(new Runnable() {

		@Override
		public void run() {
			try {
				IDebugTarget[] debugTargets = debugTarget.getLaunch().getDebugTargets();
				for (IDebugTarget current : debugTargets) {
					current.resume();
				}
			} catch (DebugException e) {
				e.printStackTrace();
			}
		}
	});
}
 
Example #12
Source File: PyDebugTargetServer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: DebugPluginListener.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public void handleDebugEvents(DebugEvent[] events) {
	for (DebugEvent event : events) {
		Object source = event.getSource();
		if (source instanceof IJavaThread)
			synchronized (this) {
				lastThread = (IJavaThread) source;
			}
		else if (source instanceof IStackFrame)
			synchronized (this) {
				lastFrame = (IStackFrame) source;
			}
		else if (source instanceof IDebugTarget)
			synchronized (this) {
				if (event.getKind() == DebugEvent.TERMINATE) {
					if (lastThread != null && lastThread.getDebugTarget() == source)
						lastThread = null;
					if (lastFrame != null && lastFrame.getDebugTarget() == source)
						lastFrame = null;
				}
			}
	}
}
 
Example #14
Source File: ProcessServerOutputStream.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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);
                }
            }
        }
    }
}
 
Example #15
Source File: PydevIProcessFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static String getEncodingFromFrame(PyStackFrame selectedFrame) {
    try {
        IDebugTarget adapter = 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";
    }
}
 
Example #16
Source File: TestResultsView.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Collects targets associated with a process. -- copied from ConsoleTerminateAction
 *
 * @param process
 *            the process to collect {@link IDebugTarget}s for
 * @return associated targets
 */
private List<ITerminate> collectTargets(IProcess process) {
	ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
	ILaunch[] launches = launchManager.getLaunches();
	List<ITerminate> targets = new ArrayList<>();
	for (int i = 0; i < launches.length; i++) {
		ILaunch launch = launches[i];
		IProcess[] processes = launch.getProcesses();
		for (int j = 0; j < processes.length; j++) {
			IProcess process2 = processes[j];
			if (process2.equals(process)) {
				IDebugTarget[] debugTargets = launch.getDebugTargets();
				for (int k = 0; k < debugTargets.length; k++) {
					targets.add(debugTargets[k]);
				}
				return targets; // all possible targets have been terminated for the launch.
			}
		}
	}
	return targets;
}
 
Example #17
Source File: PydevConsoleInterpreter.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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);
                }
            }
        }
    }

}
 
Example #18
Source File: BaseTest.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void checkMode(CodewindApplication app, StartMode mode) throws Exception {
	for (int i = 0; i < 5 && app.getStartMode() != mode; i++) {
		Thread.sleep(1000);
	}
	assertTrue("App is in " + app.getStartMode() + " when it should be in " + mode + " mode.", app.getStartMode() == mode);
	ILaunch launch = getLaunch(app);
	if (StartMode.DEBUG_MODES.contains(mode)) {
		assertNotNull("There should be a launch for the app", launch);
    	IDebugTarget debugTarget = launch.getDebugTarget();
 	assertNotNull("The launch should have a debug target", debugTarget);
 	assertTrue("The debug target should have threads", debugTarget.hasThreads());
	} else {
		// There could be a launch if the app was previously in debug mode, but it should be terminated
		if (launch != null) {
			assertTrue("Any launch from a previous debug session should be terminated", launch.isTerminated());
		}
	}
}
 
Example #19
Source File: HotModelReplacementListener.java    From statecharts with Eclipse Public License 1.0 6 votes vote down vote up
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();
	}
}
 
Example #20
Source File: CurrentExceptionView.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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);
}
 
Example #21
Source File: PySourceLocator.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@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) {
            edInput = locatorBase.createEditorInput(path, true, pyStackFrame, lastProject);
        }

    }
    return edInput;
}
 
Example #22
Source File: CodewindEclipseApplication.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void reconnectDebugger() {
	// First check if there is a launch and it is registered
	if (launch != null) {
		ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
		for (ILaunch launchItem : launchManager.getLaunches()) {
			if (launch.equals(launchItem)) {
				// Check if the debugger is still attached (for Liberty, a small change to the app does not require a server restart)
				IDebugTarget debugTarget = launch.getDebugTarget();
				if (debugTarget == null || debugTarget.isDisconnected()) {
					// Clean up
					clearDebugger();
					// Reconnect the debugger
					connectDebugger();
				}
			}
		}
	}
}
 
Example #23
Source File: SCTHotModelReplacementManager.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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);
				}
			}
		}
	}
}
 
Example #24
Source File: RemoteLaunchConfigDelegate.java    From codewind-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void addDebugEventListener(final ILaunch launch) {
	// Add the debug listener
	DebugPlugin.getDefault().addDebugEventListener(new IDebugEventSetListener() {
		@Override
		public void handleDebugEvents(DebugEvent[] events) {
			for (DebugEvent event : events) {
				if (event.getKind() == DebugEvent.TERMINATE && event.getSource() instanceof IDebugTarget
						&& ((IDebugTarget) event.getSource()).getLaunch() == launch) {
					// Remove this listener
					DebugPlugin.getDefault().removeDebugEventListener(this);

					// Make sure the port forward is terminated
					Arrays.stream(launch.getProcesses()).filter(process -> !process.isTerminated()).forEach(process -> {
						try {
							process.terminate();
						} catch (DebugException e) {
							Logger.logError("An error occurred trying to terminate the process: " + process.getLabel(), e);
						}
					});

					// No need to process the rest of the events
					break;
				}
			}
		}
	});
}
 
Example #25
Source File: SCTSourceDisplay.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleDebugTargetTerminated(DebugEvent debugEvent) {
	Object source = debugEvent.getSource();
	if (source instanceof IDebugTarget) {
		IDebugTarget target = (IDebugTarget) source;
		if (activeLaunch == target.getLaunch()) {
			activeLaunch = null;
			for (IDynamicNotationHandler current : handler.values()) {
				current.terminate();
			}
			handler.clear();
		}
	}
}
 
Example #26
Source File: TerminateLaunchStatusHandler.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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;
}
 
Example #27
Source File: DebuggerTestUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Waits until a debug target is available in the passed launch
 * @return the debug target found
 */
public IDebugTarget waitForDebugTargetAvailable(final ILaunch launch) throws Throwable {
    waitForCondition(new ICallback() {

        @Override
        public Object call(Object args) throws Exception {
            return launch.getDebugTarget() != null;
        }
    }, "waitForDebugTargetAvailable");

    return launch.getDebugTarget();
}
 
Example #28
Source File: PyThread.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <T> T getAdapter(Class<T> adapter) {
    AdapterDebug.print(this, adapter);

    if (adapter.equals(ILaunch.class) || adapter.equals(IResource.class)) {
        return target.getAdapter(adapter);

    } else if (adapter.equals(ITaskListResourceAdapter.class)) {
        return null;

    } else if (adapter.equals(IDebugTarget.class)) {
        return (T) target;

    } else if (adapter.equals(org.eclipse.debug.ui.actions.IRunToLineTarget.class)) {
        return (T) this.target.getRunToLineTarget();

    } else if (adapter.equals(IPropertySource.class) || adapter.equals(ITaskListResourceAdapter.class)
            || adapter.equals(org.eclipse.debug.ui.actions.IToggleBreakpointsTarget.class)
            || adapter.equals(org.eclipse.ui.IContributorResourceAdapter.class)
            || adapter.equals(org.eclipse.ui.model.IWorkbenchAdapter.class)
            || adapter.equals(org.eclipse.ui.IActionFilter.class)) {
        return super.getAdapter(adapter);
    }
    //Platform.getAdapterManager().getAdapter(this, adapter);
    AdapterDebug.printDontKnow(this, adapter);
    // ongoing, I do not fully understand all the interfaces they'd like me to support
    return super.getAdapter(adapter);
}
 
Example #29
Source File: CurrentExceptionViewContentProvider.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object[] getElements(Object inputElement) {
    List<IDebugTarget> elements = (List<IDebugTarget>) inputElement;
    for (IDebugTarget iDebugTarget : elements) {
        getChildren(iDebugTarget); //just to make sure we'll cache this level in the parentCache.
    }
    return elements.toArray(new IDebugTarget[elements.size()]);
}
 
Example #30
Source File: PyReloadCode.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void onSave(BaseEditor baseEditor, IProgressMonitor monitor) {
    if (!DebugPrefsPage.getReloadModuleOnChange()) {
        return;
    }
    PyEdit edit = (PyEdit) baseEditor;
    File file = edit.getEditorFile();
    if (file != null) {

        IDebugTarget[] debugTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
        if (debugTargets.length > 0) {
            ICallback<Boolean, IDebugTarget> callbackThatFilters = new ICallback<Boolean, IDebugTarget>() {

                @Override
                public Boolean call(IDebugTarget arg) {
                    return arg instanceof AbstractDebugTarget;
                }
            };
            List<IDebugTarget> filter = ArrayUtils.filter(debugTargets, callbackThatFilters);
            if (filter.size() > 0) {
                try {
                    IPythonNature pythonNature = edit.getPythonNature();
                    if (pythonNature != null) {
                        String moduleName = pythonNature.resolveModule(file);
                        if (moduleName != null) {
                            for (IDebugTarget iDebugTarget : filter) {
                                AbstractDebugTarget target = (AbstractDebugTarget) iDebugTarget;
                                target.postCommand(new ReloadCodeCommand(target, moduleName));
                            }
                        }
                    }
                } catch (MisconfigurationException e) {
                    Log.log(e);
                }
            }
        }
    }
}