private int LaunchMIDebug(uint nCmdExecOpt, IntPtr pvaIn, IntPtr pvaOut) { int hr; if (IsQueryParameterList(pvaIn, pvaOut, nCmdExecOpt)) { Marshal.GetNativeVariantForObject("$ /switchdefs:\"" + LaunchMIDebugCommandSyntax + "\"", pvaOut); return(VSConstants.S_OK); } string arguments; hr = EnsureString(pvaIn, out arguments); if (hr != VSConstants.S_OK) { return(hr); } IVsParseCommandLine parseCommandLine = (IVsParseCommandLine)GetService(typeof(SVsParseCommandLine)); hr = parseCommandLine.ParseCommandTail(arguments, iMaxParams: -1); if (ErrorHandler.Failed(hr)) { return(hr); } hr = parseCommandLine.HasParams(); if (ErrorHandler.Failed(hr)) { return(hr); } if (hr == VSConstants.S_OK || parseCommandLine.HasSwitches() != VSConstants.S_OK) { string message = string.Concat("Unexpected syntax for MIDebugLaunch command. Expected:\n", "Debug.MIDebugLaunch /Executable:<path_or_logical_name> /OptionsFile:<path>"); throw new ApplicationException(message); } hr = parseCommandLine.EvaluateSwitches(LaunchMIDebugCommandSyntax); if (ErrorHandler.Failed(hr)) { return(hr); } string executable; if (parseCommandLine.GetSwitchValue((int)LaunchMIDebugCommandSwitchEnum.Executable, out executable) != VSConstants.S_OK || string.IsNullOrWhiteSpace(executable)) { throw new ArgumentException("Executable must be specified"); } bool checkExecutableExists = false; string options = string.Empty; string optionsFilePath; if (parseCommandLine.GetSwitchValue((int)LaunchMIDebugCommandSwitchEnum.OptionsFile, out optionsFilePath) == 0) { // When using the options file, we want to allow the executable to be just a logical name, but if // one enters a real path, we should make sure it isn't mistyped. If the path contains a slash, we assume it // is meant to be a real path so enforce that it exists checkExecutableExists = (executable.IndexOf('\\') >= 0); if (string.IsNullOrWhiteSpace(optionsFilePath)) { throw new ArgumentException("Value expected for '/OptionsFile' option"); } if (!File.Exists(optionsFilePath)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Options file '{0}' does not exist", optionsFilePath)); } options = File.ReadAllText(optionsFilePath); } if (checkExecutableExists) { if (!File.Exists(executable)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Executable '{0}' does not exist", executable)); } executable = Path.GetFullPath(executable); } LaunchDebugTarget(executable, options); return(0); }
private int MIDebugLog(uint nCmdLogOpt, IntPtr pvaIn, IntPtr pvaOut) { int hr; if (IsQueryParameterList(pvaIn, pvaOut, nCmdLogOpt)) { Marshal.GetNativeVariantForObject("$ /switchdefs:\"" + LogMIDebugCommandSyntax + "\"", pvaOut); return(VSConstants.S_OK); } string arguments; hr = EnsureString(pvaIn, out arguments); if (hr != VSConstants.S_OK) { return(hr); } IVsParseCommandLine parseCommandLine = (IVsParseCommandLine)GetService(typeof(SVsParseCommandLine)); hr = parseCommandLine.ParseCommandTail(arguments, iMaxParams: -1); if (ErrorHandler.Failed(hr)) { return(hr); } hr = parseCommandLine.HasParams(); if (ErrorHandler.Failed(hr)) { return(hr); } if (hr == VSConstants.S_OK || parseCommandLine.HasSwitches() != VSConstants.S_OK) { string message = string.Concat("Unexpected syntax for MIDebugLaunch command. Expected:\n", "Debug.MIDebugLog [/On:<optional_path> [/OutputWindow] | /Off]"); throw new ApplicationException(message); } hr = parseCommandLine.EvaluateSwitches(LogMIDebugCommandSyntax); if (ErrorHandler.Failed(hr)) { return(hr); } string logPath = string.Empty; bool logToOutput = false; if (parseCommandLine.GetSwitchValue((int)LogMIDebugCommandSwitchEnum.On, out logPath) == VSConstants.S_OK) { logToOutput = parseCommandLine.IsSwitchPresent((int)LogMIDebugCommandSwitchEnum.OutputWindow) == VSConstants.S_OK; if (parseCommandLine.IsSwitchPresent((int)LogMIDebugCommandSwitchEnum.Off) == VSConstants.S_OK) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "/On and /Off cannot both appear on command line")); } if (!logToOutput && string.IsNullOrEmpty(logPath)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Must specify a log file (/On:<path>) or /OutputWindow")); } } else if (parseCommandLine.IsSwitchPresent((int)LogMIDebugCommandSwitchEnum.Off) != VSConstants.S_OK) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "One of /On or /Off must be present on command line")); } EnableLogging(logToOutput, logPath); return(0); }