use of com.intellij.execution.configurations.RemoteConnection in project intellij-community by JetBrains.
the class DebugProcessEvents method getEventText.
public String getEventText(Pair<Breakpoint, Event> descriptor) {
String text = "";
final Event event = descriptor.getSecond();
final Breakpoint breakpoint = descriptor.getFirst();
if (event instanceof LocatableEvent) {
try {
text = breakpoint != null ? breakpoint.getEventMessage(((LocatableEvent) event)) : DebuggerBundle.message("status.generic.breakpoint.reached");
} catch (InternalException e) {
text = DebuggerBundle.message("status.generic.breakpoint.reached");
}
} else if (event instanceof VMStartEvent) {
text = DebuggerBundle.message("status.process.started");
} else if (event instanceof VMDeathEvent) {
text = DebuggerBundle.message("status.process.terminated");
} else if (event instanceof VMDisconnectEvent) {
final RemoteConnection connection = getConnection();
final String addressDisplayName = DebuggerBundle.getAddressDisplayName(connection);
final String transportName = DebuggerBundle.getTransportName(connection);
text = DebuggerBundle.message("status.disconnected", addressDisplayName, transportName);
}
return text;
}
use of com.intellij.execution.configurations.RemoteConnection in project intellij-community by JetBrains.
the class DebuggerManagerImpl method createDebugParameters.
@SuppressWarnings({ "HardCodedStringLiteral" })
public static RemoteConnection createDebugParameters(final JavaParameters parameters, final boolean debuggerInServerMode, int transport, final String debugPort, boolean checkValidity) throws ExecutionException {
if (checkValidity) {
checkTargetJPDAInstalled(parameters);
}
final boolean useSockets = transport == DebuggerSettings.SOCKET_TRANSPORT;
String address = "";
if (StringUtil.isEmptyOrSpaces(debugPort)) {
try {
address = DebuggerUtils.getInstance().findAvailableDebugAddress(useSockets);
} catch (ExecutionException e) {
if (checkValidity) {
throw e;
}
}
} else {
address = debugPort;
}
final TransportServiceWrapper transportService = TransportServiceWrapper.getTransportService(useSockets);
final String debugAddress = debuggerInServerMode && useSockets ? "127.0.0.1:" + address : address;
String debuggeeRunProperties = "transport=" + transportService.transportId() + ",address=" + debugAddress;
if (debuggerInServerMode) {
debuggeeRunProperties += ",suspend=y,server=n";
} else {
debuggeeRunProperties += ",suspend=n,server=y";
}
if (StringUtil.containsWhitespaces(debuggeeRunProperties)) {
debuggeeRunProperties = "\"" + debuggeeRunProperties + "\"";
}
final String _debuggeeRunProperties = debuggeeRunProperties;
ApplicationManager.getApplication().runReadAction(() -> {
JavaSdkUtil.addRtJar(parameters.getClassPath());
final Sdk jdk = parameters.getJdk();
final boolean forceClassicVM = shouldForceClassicVM(jdk);
final boolean forceNoJIT = shouldForceNoJIT(jdk);
final String debugKey = System.getProperty(DEBUG_KEY_NAME, "-Xdebug");
final boolean needDebugKey = shouldAddXdebugKey(jdk) || !"-Xdebug".equals(debugKey);
if (forceClassicVM || forceNoJIT || needDebugKey || !isJVMTIAvailable(jdk)) {
parameters.getVMParametersList().replaceOrPrepend("-Xrunjdwp:", "-Xrunjdwp:" + _debuggeeRunProperties);
} else {
// use newer JVMTI if available
parameters.getVMParametersList().replaceOrPrepend("-Xrunjdwp:", "");
parameters.getVMParametersList().replaceOrPrepend("-agentlib:jdwp=", "-agentlib:jdwp=" + _debuggeeRunProperties);
}
if (forceNoJIT) {
parameters.getVMParametersList().replaceOrPrepend("-Djava.compiler=", "-Djava.compiler=NONE");
parameters.getVMParametersList().replaceOrPrepend("-Xnoagent", "-Xnoagent");
}
if (needDebugKey) {
parameters.getVMParametersList().replaceOrPrepend(debugKey, debugKey);
} else {
// deliberately skip outdated parameter because it can disable full-speed debugging for some jdk builds
// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6272174
parameters.getVMParametersList().replaceOrPrepend("-Xdebug", "");
}
parameters.getVMParametersList().replaceOrPrepend("-classic", forceClassicVM ? "-classic" : "");
});
return new RemoteConnection(useSockets, "127.0.0.1", address, debuggerInServerMode);
}
use of com.intellij.execution.configurations.RemoteConnection 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.execution.configurations.RemoteConnection 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);
}
}
});
}
}
use of com.intellij.execution.configurations.RemoteConnection in project android by JetBrains.
the class ConnectJavaDebuggerTask method launchDebugger.
@Override
public ProcessHandler launchDebugger(@NotNull LaunchInfo currentLaunchInfo, @NotNull final Client client, @NotNull ProcessHandlerLaunchStatus launchStatus, @NotNull ProcessHandlerConsolePrinter printer) {
String debugPort = Integer.toString(client.getDebuggerListenPort());
final int pid = client.getClientData().getPid();
Logger.getInstance(ConnectJavaDebuggerTask.class).info(String.format(Locale.US, "Attempting to connect debugger to port %1$s [client %2$d]", debugPort, pid));
// detach old process handler
RunContentDescriptor descriptor = currentLaunchInfo.env.getContentToReuse();
// reach here before the EDT gets around to creating the descriptor?
assert descriptor != null : "ConnectJavaDebuggerTask expects an existing descriptor that will be reused";
final ProcessHandler processHandler = descriptor.getProcessHandler();
assert processHandler != null;
// create a new process handler
RemoteConnection connection = new RemoteConnection(true, "localhost", debugPort, false);
final AndroidRemoteDebugProcessHandler debugProcessHandler = new AndroidRemoteDebugProcessHandler(myProject, myMonitorRemoteProcess);
// switch the launch status and console printers to point to the new process handler
// this is required, esp. for AndroidTestListener which holds a reference to the launch status and printers, and those should
// be updated to point to the new process handlers, otherwise test results will not be forwarded appropriately
launchStatus.setProcessHandler(debugProcessHandler);
printer.setProcessHandler(debugProcessHandler);
// detach after the launch status has been updated to point to the new process handler
processHandler.detachProcess();
AndroidDebugState debugState = new AndroidDebugState(myProject, debugProcessHandler, connection, currentLaunchInfo.consoleProvider);
RunContentDescriptor debugDescriptor;
try {
// @formatter:off
ExecutionEnvironment debugEnv = new ExecutionEnvironmentBuilder(currentLaunchInfo.env).executor(currentLaunchInfo.executor).runner(currentLaunchInfo.runner).contentToReuse(descriptor).build();
debugDescriptor = DebuggerPanelsManager.getInstance(myProject).attachVirtualMachine(debugEnv, debugState, connection, false);
// @formatter:on
} catch (ExecutionException e) {
processHandler.notifyTextAvailable("ExecutionException: " + e.getMessage() + '.', STDERR);
return null;
}
if (debugDescriptor == null) {
processHandler.notifyTextAvailable("Unable to connect debugger to Android application", STDERR);
return null;
}
// re-run the collected text from the old process handler to the new
// TODO: is there a race between messages received once the debugger has been connected, and these messages that are printed out?
final AndroidProcessText oldText = AndroidProcessText.get(processHandler);
if (oldText != null) {
oldText.printTo(debugProcessHandler);
}
RunProfile runProfile = currentLaunchInfo.env.getRunProfile();
int uniqueId = runProfile instanceof RunConfigurationBase ? ((RunConfigurationBase) runProfile).getUniqueID() : -1;
AndroidSessionInfo value = new AndroidSessionInfo(debugProcessHandler, debugDescriptor, uniqueId, currentLaunchInfo.executor.getId(), InstantRunUtils.isInstantRunEnabled(currentLaunchInfo.env));
debugProcessHandler.putUserData(AndroidSessionInfo.KEY, value);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEBUG_CLIENT, client);
debugProcessHandler.putUserData(AndroidSessionInfo.ANDROID_DEVICE_API_LEVEL, client.getDevice().getVersion());
final String pkgName = client.getClientData().getClientDescription();
final IDevice device = client.getDevice();
// kill the process when the debugger is stopped
debugProcessHandler.addProcessListener(new ProcessAdapter() {
@Override
public void processTerminated(ProcessEvent event) {
debugProcessHandler.removeProcessListener(this);
Client currentClient = device.getClient(pkgName);
if (currentClient != null && currentClient.getClientData().getPid() != pid) {
// a new process has been launched for the same package name, we aren't interested in killing this
return;
}
Logger.getInstance(ConnectJavaDebuggerTask.class).info("Debugger terminating, so terminating process: " + pkgName);
// Note: client.kill() doesn't work when the debugger is attached, we explicitly stop by package id..
try {
device.executeShellCommand("am force-stop " + pkgName, new NullOutputReceiver());
} catch (Exception e) {
// don't care..
}
}
});
return debugProcessHandler;
}
Aggregations