Search in sources :

Example 1 with TransportServiceWrapper

use of com.intellij.debugger.apiAdapters.TransportServiceWrapper 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)

Aggregations

TransportServiceWrapper (com.intellij.debugger.apiAdapters.TransportServiceWrapper)1 ExecutionException (com.intellij.execution.ExecutionException)1 RemoteConnection (com.intellij.execution.configurations.RemoteConnection)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1