public override void InitStreams(LaunchOptions options, out StreamReader reader, out StreamWriter writer) { PipeLaunchOptions pipeOptions = (PipeLaunchOptions)options; if (!LocalLaunchOptions.CheckDirectoryPath(pipeOptions.PipeCwd)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, MICoreResources.Error_InvalidLocalDirectoryPath, pipeOptions.PipeCwd)); } if (!LocalLaunchOptions.CheckFilePath(pipeOptions.PipePath)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, MICoreResources.Error_InvalidLocalExePath, pipeOptions.PipePath)); } _cmdArgs = pipeOptions.PipeCommandArguments; Process proc = new Process(); _pipePath = pipeOptions.PipePath; proc.StartInfo.FileName = pipeOptions.PipePath; proc.StartInfo.Arguments = pipeOptions.PipeArguments; proc.StartInfo.WorkingDirectory = pipeOptions.PipeCwd; foreach (EnvironmentEntry entry in pipeOptions.PipeEnvironment) { proc.StartInfo.SetEnvironmentVariable(entry.Name, entry.Value); } InitProcess(proc, out reader, out writer); }
public override int ExecuteSyncCommand(string commandDescription, string commandText, int timeout, out string output, out string error) { output = null; error = null; int exitCode = -1; Process proc = new Process(); proc.StartInfo.FileName = _pipePath; proc.StartInfo.Arguments = PipeLaunchOptions.ReplaceDebuggerCommandToken(_cmdArgs, commandText, true); Logger.WriteLine("Running process {0} {1}", proc.StartInfo.FileName, proc.StartInfo.Arguments); proc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(_pipePath); proc.EnableRaisingEvents = false; proc.StartInfo.RedirectStandardInput = false; proc.StartInfo.RedirectStandardOutput = true; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.UseShellExecute = false; proc.StartInfo.CreateNoWindow = true; proc.Start(); proc.WaitForExit(timeout); exitCode = proc.ExitCode; output = proc.StandardOutput.ReadToEnd(); error = proc.StandardError.ReadToEnd(); return(exitCode); }
private int WrappedExecuteSyncCommand(string commandDescription, string commandText, int timeout) { int exitCode = -1; string output = null; string error = null; string pipeArgs = PipeLaunchOptions.ReplaceDebuggerCommandToken(_cmdArgs, commandText, true); string fullCommand = string.Format(CultureInfo.InvariantCulture, "{0} {1}", _pipePath, pipeArgs); try { exitCode = ExecuteSyncCommand(commandDescription, commandText, timeout, out output, out error); if (exitCode != 0) { this.Callback.OnStdErrorLine(string.Format(CultureInfo.InvariantCulture, MICoreResources.Warn_ProcessExit, fullCommand, exitCode)); } } catch (Exception e) { this.Callback.OnStdErrorLine(string.Format(CultureInfo.InvariantCulture, MICoreResources.Warn_ProcessException, fullCommand, e.Message)); } return(exitCode); }
static internal PipeLaunchOptions CreateFromXml(Xml.LaunchOptions.PipeLaunchOptions source) { var options = new PipeLaunchOptions(RequireAttribute(source.PipePath, "PipePath"), source.PipeArguments); options.InitializeCommonOptions(source); return(options); }
public override void InitStreams(LaunchOptions options, out StreamReader reader, out StreamWriter writer) { PipeLaunchOptions pipeOptions = (PipeLaunchOptions)options; Process proc = new Process(); proc.StartInfo.FileName = pipeOptions.PipePath; proc.StartInfo.Arguments = pipeOptions.PipeArguments; proc.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(pipeOptions.PipePath); InitProcess(proc, out reader, out writer); }
public override void InitStreams(LaunchOptions options, out StreamReader reader, out StreamWriter writer) { PipeLaunchOptions pipeOptions = (PipeLaunchOptions)options; string workingDirectory = pipeOptions.PipeCwd; if (!string.IsNullOrWhiteSpace(workingDirectory)) { if (!LocalLaunchOptions.CheckDirectoryPath(workingDirectory)) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, MICoreResources.Error_InvalidLocalDirectoryPath, workingDirectory)); } } else { workingDirectory = Path.GetDirectoryName(pipeOptions.PipePath); if (!LocalLaunchOptions.CheckDirectoryPath(workingDirectory)) { // If provided PipeCwd is not an absolute path, the working directory will be set to null. workingDirectory = null; } } if (string.IsNullOrWhiteSpace(pipeOptions.PipePath)) { throw new ArgumentException(MICoreResources.Error_EmptyPipePath); } _cmdArgs = pipeOptions.PipeCommandArguments; Process proc = new Process(); _pipePath = pipeOptions.PipePath; proc.StartInfo.FileName = pipeOptions.PipePath; proc.StartInfo.Arguments = pipeOptions.PipeArguments; proc.StartInfo.WorkingDirectory = workingDirectory; foreach (EnvironmentEntry entry in pipeOptions.PipeEnvironment) { proc.StartInfo.SetEnvironmentVariable(entry.Name, entry.Value); } InitProcess(proc, out reader, out writer); }
public static LaunchOptions GetInstance(string registryRoot, string exePath, string args, string dir, string options, IDeviceAppLauncherEventCallback eventCallback, TargetEngine targetEngine) { if (string.IsNullOrWhiteSpace(exePath)) { throw new ArgumentNullException("exePath"); } if (string.IsNullOrWhiteSpace(options)) { throw new InvalidLaunchOptionsException(MICoreResources.Error_StringIsNullOrEmpty); } if (string.IsNullOrEmpty(registryRoot)) { throw new ArgumentNullException("registryRoot"); } Logger.WriteTextBlock("LaunchOptions", options); LaunchOptions launchOptions = null; Guid clsidLauncher = Guid.Empty; object launcherXmlOptions = null; try { using (XmlReader reader = OpenXml(options)) { switch (reader.LocalName) { case "LocalLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.LocalLaunchOptionsSerializer(); var xmlLaunchOptions = (Xml.LaunchOptions.LocalLaunchOptions)Deserialize(serializer, reader); launchOptions = LocalLaunchOptions.CreateFromXml(xmlLaunchOptions); } break; case "SerialPortLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.SerialPortLaunchOptionsSerializer(); var xmlLaunchOptions = (Xml.LaunchOptions.SerialPortLaunchOptions)Deserialize(serializer, reader); launchOptions = SerialLaunchOptions.CreateFromXml(xmlLaunchOptions); } break; case "PipeLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.PipeLaunchOptionsSerializer(); var xmlLaunchOptions = (Xml.LaunchOptions.PipeLaunchOptions)Deserialize(serializer, reader); launchOptions = PipeLaunchOptions.CreateFromXml(xmlLaunchOptions); } break; case "TcpLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.TcpLaunchOptionsSerializer(); var xmlLaunchOptions = (Xml.LaunchOptions.TcpLaunchOptions)Deserialize(serializer, reader); launchOptions = TcpLaunchOptions.CreateFromXml(xmlLaunchOptions); } break; case "IOSLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.IOSLaunchOptionsSerializer(); launcherXmlOptions = Deserialize(serializer, reader); clsidLauncher = new Guid("316783D1-1824-4847-B3D3-FB048960EDCF"); } break; case "AndroidLaunchOptions": { var serializer = new Microsoft.Xml.Serialization.GeneratedAssembly.AndroidLaunchOptionsSerializer(); launcherXmlOptions = Deserialize(serializer, reader); clsidLauncher = new Guid("C9A403DA-D3AA-4632-A572-E81FF6301E9B"); } break; default: { throw new XmlException(string.Format(CultureInfo.CurrentCulture, MICoreResources.Error_UnknownXmlElement, reader.LocalName)); } } // Read any remaining bits of XML to catch other errors while (reader.NodeType != XmlNodeType.None) { reader.Read(); } } } catch (XmlException e) { throw new InvalidLaunchOptionsException(e.Message); } if (clsidLauncher != Guid.Empty) { launchOptions = ExecuteLauncher(registryRoot, clsidLauncher, exePath, args, dir, launcherXmlOptions, eventCallback, targetEngine); } if (targetEngine == TargetEngine.Native) { if (launchOptions.ExePath == null) { launchOptions.ExePath = exePath; } } if (string.IsNullOrEmpty(launchOptions.ExeArguments)) { launchOptions.ExeArguments = args; } if (string.IsNullOrEmpty(launchOptions.WorkingDirectory)) { launchOptions.WorkingDirectory = dir; } if (launchOptions._setupCommands == null) { launchOptions._setupCommands = new List <LaunchCommand>(capacity: 0).AsReadOnly(); } launchOptions._initializationComplete = true; return(launchOptions); }
internal static PipeLaunchOptions CreateFromXml(Xml.LaunchOptions.PipeLaunchOptions source) { var options = new PipeLaunchOptions(RequireAttribute(source.PipePath, "PipePath"), source.PipeArguments); options.InitializeCommonOptions(source); return options; }
public void SetupForDebugging(out LaunchOptions debuggerLaunchOptions) { int currentPID = Process.GetCurrentProcess().Id; int currentHostID = Interlocked.Increment(ref HostID); string eventCtrlCName = string.Concat("HostCtrlC-", currentHostID, "-", currentPID); string eventTerminateName = string.Concat("HostTerminate-", currentHostID, "-", currentPID); _eventCtrlC = new EventWaitHandle(false, EventResetMode.AutoReset, eventCtrlCName); _eventTerminate = new EventWaitHandle(false, EventResetMode.AutoReset, eventTerminateName); // GDB-Host process requires a specific order of arguments: // 1. the name of the event, which set will trigger the Ctrl+C signal to the GDB // 2. the name of the event, which set will exit the host process and GDB // 3. the path to GDB executable itself, that will run // 4. optional settings for GDBHost (-s => disable custom console logs, -c => skip checking for GDB-executable existence) // 5. all the other arguments that should be passed to GDB (although it's possible to pass arguments to GDB via the executable path, // but in practice they can't be escaped this way; that's why passing them as last arguments of the host are the recommended approach) var args = string.Concat(eventCtrlCName, " ", eventTerminateName, " -sc ", "\"", _launchOptions.GdbPath, "\" ", "--interpreter=mi2"); debuggerLaunchOptions = new PipeLaunchOptions(_launchOptions.GdbHostPath, args); debuggerLaunchOptions.AdditionalSOLibSearchPath = _launchOptions.AdditionalSOLibSearchPath; debuggerLaunchOptions.DebuggerMIMode = MIMode.Gdb; debuggerLaunchOptions.TargetArchitecture = _launchOptions.TargetArchitecture; debuggerLaunchOptions.UseUnixSymbolPaths = false; debuggerLaunchOptions.CustomLaunchSetupCommands = GetCustomLaunchSetupCommands(); debuggerLaunchOptions.LaunchCompleteCommand = GetLaunchCompleteCommand(); }