use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class DebuggerManagerImpl method attachVirtualMachine.
@Override
@Nullable
public DebuggerSession attachVirtualMachine(@NotNull DebugEnvironment environment) throws ExecutionException {
ApplicationManager.getApplication().assertIsDispatchThread();
DebugProcessEvents debugProcess = new DebugProcessEvents(myProject);
DebuggerSession session = DebuggerSession.create(environment.getSessionName(), debugProcess, environment);
ExecutionResult executionResult = session.getProcess().getExecutionResult();
if (executionResult == null) {
return null;
}
session.getContextManager().addListener(mySessionListener);
getContextManager().setState(DebuggerContextUtil.createDebuggerContext(session, session.getContextManager().getContext().getSuspendContext()), session.getState(), DebuggerSession.Event.CONTEXT, null);
final ProcessHandler processHandler = executionResult.getProcessHandler();
synchronized (mySessions) {
mySessions.put(processHandler, session);
}
if (!(processHandler instanceof RemoteDebugProcessHandler)) {
// add listener only to non-remote process handler:
// on Unix systems destroying process does not cause VMDeathEvent to be generated,
// so we need to call debugProcess.stop() explicitly for graceful termination.
// RemoteProcessHandler on the other hand will call debugProcess.stop() as a part of destroyProcess() and detachProcess() implementation,
// so we shouldn't add the listener to avoid calling stop() twice
processHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processWillTerminate(ProcessEvent event, boolean willBeDestroyed) {
ProcessHandler processHandler = event.getProcessHandler();
final DebugProcessImpl debugProcess = getDebugProcess(processHandler);
if (debugProcess != null) {
// if current thread is a "debugger manager thread", stop will execute synchronously
// it is KillableColoredProcessHandler responsibility to terminate VM
debugProcess.stop(willBeDestroyed && !(processHandler instanceof KillableColoredProcessHandler && ((KillableColoredProcessHandler) processHandler).shouldKillProcessSoftly()));
// if processWillTerminate() is called from AWT thread debugProcess.waitFor() will block it and the whole app will hang
if (!DebuggerManagerThreadImpl.isManagerThread()) {
if (SwingUtilities.isEventDispatchThread()) {
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressManager.getInstance().getProgressIndicator().setIndeterminate(true);
debugProcess.waitFor(10000);
}, "Waiting For Debugger Response", false, debugProcess.getProject());
} else {
debugProcess.waitFor(10000);
}
}
}
}
});
}
myDispatcher.getMulticaster().sessionCreated(session);
if (debugProcess.isDetached() || debugProcess.isDetaching()) {
session.dispose();
return null;
}
if (environment.isRemote()) {
// optimization: that way BatchEvaluator will not try to lookup the class file in remote VM
// which is an expensive operation when executed first time
debugProcess.putUserData(BatchEvaluator.REMOTE_SESSION_KEY, Boolean.TRUE);
}
return session;
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class BaseJavaApplicationCommandLineState method startProcess.
@NotNull
@Override
protected OSProcessHandler startProcess() throws ExecutionException {
OSProcessHandler handler = new KillableColoredProcessHandler(createCommandLine());
ProcessTerminatedListener.attach(handler);
JavaRunConfigurationExtensionManager.getInstance().attachExtensionsToProcess(getConfiguration(), handler, getRunnerSettings());
return handler;
}
use of com.intellij.execution.process.KillableColoredProcessHandler in project intellij-community by JetBrains.
the class PyDebuggerTask method killDebugProcess.
private void killDebugProcess() {
if (myDebugProcess.getProcessHandler() instanceof KillableColoredProcessHandler) {
KillableColoredProcessHandler h = (KillableColoredProcessHandler) myDebugProcess.getProcessHandler();
h.killProcess();
} else {
myDebugProcess.getProcessHandler().destroyProcess();
}
}
Aggregations