Search in sources :

Example 6 with RemoteConnection

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;
}
Also used : StackCapturingLineBreakpoint(com.intellij.debugger.ui.breakpoints.StackCapturingLineBreakpoint) XBreakpoint(com.intellij.xdebugger.breakpoints.XBreakpoint) Breakpoint(com.intellij.debugger.ui.breakpoints.Breakpoint) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) InternalException(com.sun.jdi.InternalException)

Example 7 with RemoteConnection

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);
}
Also used : TransportServiceWrapper(com.intellij.debugger.apiAdapters.TransportServiceWrapper) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection)

Example 8 with RemoteConnection

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;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaTestFrameworkRunnableState(com.intellij.execution.JavaTestFrameworkRunnableState) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExecutionException(com.intellij.execution.ExecutionException) IOException(java.io.IOException) EOFException(java.io.EOFException) DebugProcess(com.intellij.debugger.engine.DebugProcess) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugProcessImpl(com.intellij.debugger.engine.DebugProcessImpl) EOFException(java.io.EOFException) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) DefaultDebugEnvironment(com.intellij.debugger.DefaultDebugEnvironment) DebugEnvironment(com.intellij.debugger.DebugEnvironment) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with RemoteConnection

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);
                }
            }
        });
    }
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) JavaDebugServerModeHandler(com.intellij.remoteServer.runtime.deployment.debug.JavaDebugServerModeHandler) Project(com.intellij.openapi.project.Project) DebugProcess(com.intellij.debugger.engine.DebugProcess) DebugProcessListener(com.intellij.debugger.engine.DebugProcessListener) DebuggerPanelsManager(com.intellij.debugger.ui.DebuggerPanelsManager) RemoteDebugProcessHandler(com.intellij.debugger.engine.RemoteDebugProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionException(com.intellij.execution.ExecutionException) DebugEnvironment(com.intellij.debugger.DebugEnvironment) DebugUIEnvironment(com.intellij.debugger.DebugUIEnvironment)

Example 10 with RemoteConnection

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;
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) IDevice(com.android.ddmlib.IDevice) RunProfile(com.intellij.execution.configurations.RunProfile) ExecutionException(com.intellij.execution.ExecutionException) RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) ProcessHandler(com.intellij.execution.process.ProcessHandler) RemoteConnection(com.intellij.execution.configurations.RemoteConnection) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) ExecutionException(com.intellij.execution.ExecutionException) Client(com.android.ddmlib.Client) NullOutputReceiver(com.android.ddmlib.NullOutputReceiver)

Aggregations

RemoteConnection (com.intellij.execution.configurations.RemoteConnection)10 ExecutionException (com.intellij.execution.ExecutionException)6 DebugEnvironment (com.intellij.debugger.DebugEnvironment)3 RunContentDescriptor (com.intellij.execution.ui.RunContentDescriptor)3 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)2 DebugProcess (com.intellij.debugger.engine.DebugProcess)2 ProcessHandler (com.intellij.execution.process.ProcessHandler)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)2 IOException (java.io.IOException)2 Client (com.android.ddmlib.Client)1 IDevice (com.android.ddmlib.IDevice)1 NullOutputReceiver (com.android.ddmlib.NullOutputReceiver)1 DebugUIEnvironment (com.intellij.debugger.DebugUIEnvironment)1 TransportServiceWrapper (com.intellij.debugger.apiAdapters.TransportServiceWrapper)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 DebugProcessListener (com.intellij.debugger.engine.DebugProcessListener)1 RemoteDebugProcessHandler (com.intellij.debugger.engine.RemoteDebugProcessHandler)1 RemoteStateState (com.intellij.debugger.engine.RemoteStateState)1 DebuggerSession (com.intellij.debugger.impl.DebuggerSession)1