예제 #1
0
        public ITargetHostProcess LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)
        {
            // ITargetHostInterop provides a convenience wrapper to start the process
            // return targetInterop.ExecuteCommandAsync(path, "");

            // If you need more control use the DebugAdapterProcess
            return(DebugAdapterProcess.Start(launchInfo.LaunchJson));
        }
예제 #2
0
        public ITargetHostProcess LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)
        {
            if (launchInfo.LaunchType == LaunchType.Attach)
            {
                var debugAttachInfo = (DebugAttachInfo)_debugInfo;
                return(DebugAdapterRemoteProcess.Attach(debugAttachInfo));
            }

            var debugLaunchInfo         = (DebugLaunchInfo)_debugInfo;
            var debugPyAdapterDirectory = Path.GetDirectoryName(PythonToolsInstallPath.GetFile("debugpy\\adapter\\__init__.py"));
            var targetProcess           = new DebugAdapterProcess(_adapterHostContext, targetInterop, debugPyAdapterDirectory);

            return(targetProcess.StartProcess(debugLaunchInfo.InterpreterPathAndArguments.FirstOrDefault(), debugLaunchInfo.LaunchWebPageUrl));
        }
예제 #3
0
 public DebugAdapterProcess(ITargetHostInterop targetInterop, string debuggerAdapterDirectory)
 {
     _targetInterop            = targetInterop ?? throw new ArgumentNullException(nameof(targetInterop));
     _debuggerAdapterDirectory = debuggerAdapterDirectory ?? throw new ArgumentNullException(nameof(debuggerAdapterDirectory));
 }
예제 #4
0
        /// <inheritdoc />
        public ITargetHostProcess LaunchAdapter(IAdapterLaunchInfo launchInfo, ITargetHostInterop targetInterop)
        {
            ITargetHostProcess resultProcess = null;

            try
            {
                ITargetHostProcess runningProcess = null;

                // Check if an emulicious process is running and reuse it.
                var emuliciousProcess = Process.GetProcesses().Where(process => process.ProcessName.Contains("java") && process.MainWindowTitle == "Emulicious").ToList();

                var processId = -1;
                if (emuliciousProcess.Count > 0)
                {
                    // use the process and capture it in an ITargetHostProcess.
                    runningProcess = new ExistingTargetHostProcess(emuliciousProcess[0]);
                    processId      = emuliciousProcess.First().Id;
                }

                // Check if an instance of Emulicious is already running.
                // If so capture it as the instance to debug.
                // Otherwise launch a new instance.
                // If launching an instance. Wait to connect.
                if (runningProcess == null)
                {
                    // Launch emulicious.

                    var emuliciousExec = EmuliciousDebuggerLaunchProvider.EmuliciousExecutable;

                    /*
                     * File.WriteAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "Properties.log"),
                     *  new []
                     *  {
                     *      emuliciousExec,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousDebugFolder,
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousAttach.ToString(),
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousLaunchDelay.ToString(),
                     *      EmuliciousDebuggerLaunchProvider.EmuliciousPort.ToString(),
                     *      EmuliciousPackage.DebugAdapterPath
                     *  });
                     */
                    var args = new List <string>();

                    if (EmuliciousDebuggerLaunchProvider.EmuliciousRemoteDebugArgument)
                    {
                        args.Add(string.Format("-remotedebug {0}", EmuliciousDebuggerLaunchProvider.EmuliciousPort));
                    }

                    try
                    {
                        var process = Process.Start(emuliciousExec, string.Join(" ", args));
                        if (process != null)
                        {
                            process.WaitForExit();
                        }
                    }
                    catch (Exception err)
                    {
                        File.WriteAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "LaunchProcess.log"),
                                           new[]
                        {
                            emuliciousExec,
                            err.ToString()
                        });
                    }

                    Thread.Sleep(EmuliciousDebuggerLaunchProvider.EmuliciousLaunchDelay);

                    // Capture the emulicious process id for destruction if not attaching.
                    emuliciousProcess = Process.GetProcesses().Where(process =>
                                                                     process.ProcessName.Contains("java") && process.MainWindowTitle == "Emulicious").ToList();

                    if (emuliciousProcess.Count > 0)
                    {
                        // Update process id for debugger disconnection.
                        processId = emuliciousProcess.First().Id;
                    }
                    else
                    {
                        // No process was found, this is a failure.
                        processId = -1;
                    }
                }

                resultProcess = new EmuliciousTargetHostProcessWrapper(targetInterop.ExecuteCommandAsync(
                                                                           EmuliciousPackage.DebugAdapterPath,
                                                                           string.Format("{0} \"{1}\" \"{2}\"",
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousPort,
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousDebugFolder,
                                                                                         EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath)), processId,
                                                                       !EmuliciousDebuggerLaunchProvider.EmuliciousAttach);

#if __ADAPTER_LOG__
                File.AppendAllLines(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "AdapterLog.log"),
                                    new [] { "Process result: " + resultProcess + " Proc id: " + processId });
#endif
            }
            catch (Exception e)
            {
                // Capture any exceptions and save them for research.
                File.WriteAllText(Path.Combine(EmuliciousDebuggerLaunchProvider.EmuliciousMappingPath, "Exception.log"),
                                  e.ToString());
                throw;
            }

            return(resultProcess);
        }