use of com.intellij.debugger.DebugEnvironment in project intellij-community by JetBrains.
the class DebuggerPanelsManager method attachVirtualMachine.
@Nullable
public RunContentDescriptor attachVirtualMachine(DebugUIEnvironment environment) throws ExecutionException {
final DebugEnvironment modelEnvironment = environment.getEnvironment();
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(myProject).attachVirtualMachine(modelEnvironment);
if (debuggerSession == null) {
return null;
}
XDebugSession debugSession = XDebuggerManager.getInstance(myProject).startSessionAndShowTab(modelEnvironment.getSessionName(), environment.getReuseContent(), new XDebugProcessStarter() {
@Override
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
return JavaDebugProcess.create(session, debuggerSession);
}
});
return debugSession.getRunContentDescriptor();
}
use of com.intellij.debugger.DebugEnvironment in project intellij-community by JetBrains.
the class GenericDebuggerRunner method attachVirtualMachine.
@Nullable
protected RunContentDescriptor attachVirtualMachine(RunProfileState state, @NotNull ExecutionEnvironment env, RemoteConnection connection, long pollTimeout) throws ExecutionException {
DebugEnvironment environment = new DefaultDebugEnvironment(env, state, connection, pollTimeout);
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(env.getProject()).attachVirtualMachine(environment);
if (debuggerSession == null) {
return null;
}
final DebugProcessImpl debugProcess = debuggerSession.getProcess();
return XDebuggerManager.getInstance(env.getProject()).startSession(env, new XDebugProcessStarter() {
@Override
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
XDebugSessionImpl sessionImpl = (XDebugSessionImpl) session;
ExecutionResult executionResult = debugProcess.getExecutionResult();
sessionImpl.addExtraActions(executionResult.getActions());
if (executionResult instanceof DefaultExecutionResult) {
sessionImpl.addRestartActions(((DefaultExecutionResult) executionResult).getRestartActions());
}
return JavaDebugProcess.create(session, debuggerSession);
}
}).getRunContentDescriptor();
}
use of com.intellij.debugger.DebugEnvironment in project buck by facebook.
the class TestExecutionState method attachDebugger.
private void attachDebugger(String title, String port) {
final RemoteConnection remoteConnection = new RemoteConnection(/* useSockets */
true, "localhost", port, /* serverMode */
false);
final RemoteStateState state = new RemoteStateState(mProject, remoteConnection);
final String name = title + " debugger (" + port + ")";
final ConfigurationFactory cfgFactory = ConfigurationTypeUtil.findConfigurationType("Remote").getConfigurationFactories()[0];
RunnerAndConfigurationSettings runSettings = RunManager.getInstance(mProject).createRunConfiguration(name, cfgFactory);
final Executor debugExecutor = DefaultDebugExecutor.getDebugExecutorInstance();
final ExecutionEnvironment env = new ExecutionEnvironmentBuilder(mProject, debugExecutor).runProfile(runSettings.getConfiguration()).build();
final int pollTimeout = 3000;
final DebugEnvironment environment = new DefaultDebugEnvironment(env, state, remoteConnection, pollTimeout);
ApplicationManager.getApplication().invokeLater(() -> {
try {
final DebuggerSession debuggerSession = DebuggerManagerEx.getInstanceEx(mProject).attachVirtualMachine(environment);
if (debuggerSession == null) {
return;
}
XDebuggerManager.getInstance(mProject).startSessionAndShowTab(name, null, new XDebugProcessStarter() {
@Override
@NotNull
public XDebugProcess start(@NotNull XDebugSession session) {
return JavaDebugProcess.create(session, debuggerSession);
}
});
} catch (ExecutionException e) {
LOG.error("failed to attach to debugger on port " + port + " with polling timeout " + pollTimeout);
}
});
}
use of com.intellij.debugger.DebugEnvironment in project intellij-community by JetBrains.
the class JavaTestFrameworkDebuggerRunner method createContentDescriptor.
@Nullable
@Override
protected RunContentDescriptor createContentDescriptor(@NotNull final RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
final RunContentDescriptor res = super.createContentDescriptor(state, environment);
final ServerSocket socket = ((JavaTestFrameworkRunnableState) state).getForkSocket();
if (socket != null) {
Thread thread = new Thread(getThreadName() + " debugger runner") {
@Override
public void run() {
try {
final Socket accept = socket.accept();
try {
DataInputStream stream = new DataInputStream(accept.getInputStream());
try {
int read = stream.readInt();
while (read != -1) {
final DebugProcess process = DebuggerManager.getInstance(environment.getProject()).getDebugProcess(res.getProcessHandler());
if (process == null)
break;
final RemoteConnection connection = new RemoteConnection(true, "127.0.0.1", String.valueOf(read), true);
final DebugEnvironment env = new DefaultDebugEnvironment(environment, state, connection, true);
SwingUtilities.invokeLater(() -> {
try {
((DebugProcessImpl) process).reattach(env);
accept.getOutputStream().write(0);
} catch (Exception e) {
e.printStackTrace();
}
});
read = stream.readInt();
}
} finally {
stream.close();
}
} finally {
accept.close();
}
} catch (EOFException ignored) {
} catch (IOException e) {
e.printStackTrace();
}
}
};
thread.setDaemon(true);
thread.start();
}
return res;
}
use of com.intellij.debugger.DebugEnvironment in project intellij-community by JetBrains.
the class JavaDebuggerLauncherImpl method startDebugSession.
@Override
public void startDebugSession(@NotNull JavaDebugConnectionData info, @NotNull ExecutionEnvironment executionEnvironment, @NotNull RemoteServer<?> server) throws ExecutionException {
final Project project = executionEnvironment.getProject();
final DebuggerPanelsManager manager = DebuggerPanelsManager.getInstance(project);
final JavaDebugServerModeHandler serverModeHandler = info.getServerModeHandler();
boolean serverMode = serverModeHandler != null;
final RemoteConnection remoteConnection = new RemoteConnection(true, info.getHost(), String.valueOf(info.getPort()), serverMode);
DebugEnvironment debugEnvironment = new RemoteServerDebugEnvironment(project, remoteConnection, executionEnvironment.getRunProfile());
DebugUIEnvironment debugUIEnvironment = new RemoteServerDebugUIEnvironment(debugEnvironment, executionEnvironment);
RunContentDescriptor debugContentDescriptor = manager.attachVirtualMachine(debugUIEnvironment);
LOG.assertTrue(debugContentDescriptor != null);
ProcessHandler processHandler = debugContentDescriptor.getProcessHandler();
LOG.assertTrue(processHandler != null);
if (serverMode) {
serverModeHandler.attachRemote();
DebuggerManager.getInstance(executionEnvironment.getProject()).addDebugProcessListener(processHandler, new DebugProcessListener() {
public void processDetached(DebugProcess process, boolean closedByUser) {
try {
serverModeHandler.detachRemote();
} catch (ExecutionException e) {
LOG.info(e);
}
}
});
}
}
Aggregations