protected void createLocalProcess(String className) throws ExecutionException, InterruptedException, InvocationTargetException { LOG.assertTrue(myDebugProcess == null); myDebuggerSession = createLocalProcess(DebuggerSettings.SOCKET_TRANSPORT, createJavaParameters(className)); myDebugProcess = myDebuggerSession.getProcess(); }
protected DebuggerSession createRemoteProcess( final int transport, final boolean serverMode, JavaParameters javaParameters) throws ExecutionException, InterruptedException, InvocationTargetException { boolean useSockets = transport == DebuggerSettings.SOCKET_TRANSPORT; RemoteConnection remoteConnection = new RemoteConnection(useSockets, "127.0.0.1", String.valueOf(DEFAULT_ADDRESS), serverMode); String launchCommandLine = remoteConnection.getLaunchCommandLine(); launchCommandLine = StringUtil.replace(launchCommandLine, RemoteConnection.ONTHROW, ""); launchCommandLine = StringUtil.replace(launchCommandLine, RemoteConnection.ONUNCAUGHT, ""); launchCommandLine = StringUtil.replace(launchCommandLine, "suspend=n", "suspend=y"); println(launchCommandLine, ProcessOutputTypes.SYSTEM); for (StringTokenizer tokenizer = new StringTokenizer(launchCommandLine); tokenizer.hasMoreTokens(); ) { String token = tokenizer.nextToken(); javaParameters.getVMParametersList().add(token); } GeneralCommandLine commandLine = CommandLineBuilder.createFromJavaParameters(javaParameters); DebuggerSession debuggerSession; if (serverMode) { debuggerSession = attachVM(remoteConnection, false); commandLine.createProcess(); } else { commandLine.createProcess(); debuggerSession = attachVM(remoteConnection, true); } ProcessHandler processHandler = debuggerSession.getProcess().getProcessHandler(); DebugProcessImpl process = (DebugProcessImpl) DebuggerManagerEx.getInstanceEx(myProject).getDebugProcess(processHandler); assertNotNull(process); return debuggerSession; }
@Override protected DebugProcessImpl getDebugProcess() { return myDebuggerSession != null ? myDebuggerSession.getProcess() : null; }
protected DebuggerSession createLocalSession(final JavaParameters javaParameters) throws ExecutionException, InterruptedException { createBreakpoints(javaParameters.getMainClass()); DebuggerSettings.getInstance().DEBUGGER_TRANSPORT = DebuggerSettings.SOCKET_TRANSPORT; GenericDebuggerRunnerSettings debuggerRunnerSettings = new GenericDebuggerRunnerSettings(); debuggerRunnerSettings.LOCAL = true; final RemoteConnection debugParameters = DebuggerManagerImpl.createDebugParameters(javaParameters, debuggerRunnerSettings, false); ExecutionEnvironment environment = new ExecutionEnvironmentBuilder(myProject, DefaultDebugExecutor.getDebugExecutorInstance()) .runnerSettings(debuggerRunnerSettings) .runProfile(new MockConfiguration()) .build(); final JavaCommandLineState javaCommandLineState = new JavaCommandLineState(environment) { @Override protected JavaParameters createJavaParameters() { return javaParameters; } @Override protected GeneralCommandLine createCommandLine() throws ExecutionException { return CommandLineBuilder.createFromJavaParameters(getJavaParameters()); } }; ApplicationManager.getApplication() .invokeAndWait( () -> { try { myDebuggerSession = DebuggerManagerEx.getInstanceEx(myProject) .attachVirtualMachine( new DefaultDebugEnvironment( new ExecutionEnvironmentBuilder( myProject, DefaultDebugExecutor.getDebugExecutorInstance()) .runProfile(new MockConfiguration()) .build(), javaCommandLineState, debugParameters, false)); XDebuggerManager.getInstance(myProject) .startSession( javaCommandLineState.getEnvironment(), new XDebugProcessStarter() { @Override @NotNull public XDebugProcess start(@NotNull XDebugSession session) { return JavaDebugProcess.create(session, myDebuggerSession); } }); } catch (ExecutionException e) { LOG.error(e); } }); myDebugProcess = myDebuggerSession.getProcess(); myDebugProcess.addProcessListener( new ProcessAdapter() { @Override public void onTextAvailable(ProcessEvent event, Key outputType) { print(event.getText(), outputType); } }); assertNotNull(myDebuggerSession); assertNotNull(myDebugProcess); return myDebuggerSession; }