private static void AttachDebuggerRetrying(IVsDebugger4 debugger, VsDebugTargetInfo4 debugTarget) { bool attachedSuccesfully = false; int tries = 0; while (!attachedSuccesfully) { try { debugger.LaunchDebugTargets4(1, new[] { debugTarget }, new VsDebugTargetProcessInfo[1]); attachedSuccesfully = true; } catch (Exception) { // workaround for exceptions: System.Runtime.InteropServices.COMException (0x80010001): Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) tries++; if (tries == MaxAttachTries) { throw; } Thread.Sleep(AttachRetryWaitingTimeInMs); } } }
public int DebugLaunch(uint flags) { VsDebugTargetInfo2[] targets; int hr = QueryDebugTargets(out targets); if (ErrorHandler.Failed(hr)) { return(hr); } flags |= (uint)__VSDBGLAUNCHFLAGS140.DBGLAUNCH_ContainsStartupTask; VsDebugTargetInfo4[] appPackageDebugTarget = new VsDebugTargetInfo4[1]; int targetLength = (int)Marshal.SizeOf(typeof(VsDebugTargetInfo4)); this.CopyDebugTargetInfo(ref targets[0], ref appPackageDebugTarget[0], flags); IVsAppContainerBootstrapperResult result = this.BootstrapForDebuggingSync(targets[0].bstrRemoteMachine); appPackageDebugTarget[0].bstrRemoteMachine = result.Address; // Pass the debug launch targets to the debugger IVsDebugger4 debugger4 = (IVsDebugger4)serviceProvider.GetService(typeof(SVsShellDebugger)); VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[1]; debugger4.LaunchDebugTargets4(1, appPackageDebugTarget, results); return(VSConstants.S_OK); }
/// <summary> /// Launches the Visual Studio debugger. /// </summary> protected async Task <IReadOnlyList <VsDebugTargetProcessInfo> > DoLaunchAsync(params IDebugLaunchSettings[] launchSettings) { VsDebugTargetInfo4[] launchSettingsNative = launchSettings.Select(GetDebuggerStruct4).ToArray(); if (launchSettingsNative.Length == 0) { return(Array.Empty <VsDebugTargetProcessInfo>()); } try { // The debugger needs to be called on the UI thread await ThreadingService.SwitchToUIThread(); IVsDebugger4 shellDebugger = await _vsDebuggerService.GetValueAsync(); var launchResults = new VsDebugTargetProcessInfo[launchSettingsNative.Length]; shellDebugger.LaunchDebugTargets4((uint)launchSettingsNative.Length, launchSettingsNative, launchResults); return(launchResults); } finally { // Free up the memory allocated to the (mostly) managed debugger structure. foreach (VsDebugTargetInfo4 nativeStruct in launchSettingsNative) { FreeVsDebugTargetInfoStruct(nativeStruct); } } }
public bool LaunchAndDoInject() { IVsOutputWindowPane output = (IVsOutputWindowPane)Package.GetGlobalService(typeof(SVsGeneralOutputWindowPane)); String exepath = ""; String workdir = ""; String environment = ""; String addindir = ""; Solution sln = _applicationObject.Solution; String startup = (String)((Array)sln.SolutionBuild.StartupProjects).GetValue(0); foreach (EnvDTE.Project project in sln.Projects) { if (project.UniqueName == startup) { VCProject vcproj = (VCProject)project.Object; if (vcproj == null) { // this is not a visual c++ project continue; } IVCCollection cfgs = vcproj.Configurations; VCConfiguration cfg = cfgs.Item(1); exepath = cfg.Evaluate("$(LocalDebuggerCommand)"); workdir = cfg.Evaluate("$(LocalDebuggerWorkingDirectory)"); environment = cfg.Evaluate("$(LocalDebuggerEnvironment)"); addindir = cfg.Evaluate("$(USERPROFILE)\\Documents\\Visual Studio 2012\\Addins"); output.OutputString(exepath); } } uint pid = dpVSHelper.ExecuteSuspended(exepath, addindir, environment); if (pid != 0) { VsDebugTargetProcessInfo[] res = new VsDebugTargetProcessInfo[1]; VsDebugTargetInfo4[] info = new VsDebugTargetInfo4[1]; info[0].bstrExe = exepath; info[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning; //info[0].dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AttachToSuspendedLaunchProcess; // somehow this makes debugger not work info[0].dwProcessId = pid; info[0].LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_StopDebuggingOnEnd | (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop; Guid guidDbgEngine = VSConstants.DebugEnginesGuids.ManagedAndNative_guid; IntPtr pGuids = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDbgEngine)); Marshal.StructureToPtr(guidDbgEngine, pGuids, false); info[0].pDebugEngines = pGuids; info[0].dwDebugEngineCount = 1; IVsDebugger4 idbg = (IVsDebugger4)Package.GetGlobalService(typeof(SVsShellDebugger)); idbg.LaunchDebugTargets4(1, info, res); dpVSHelper.Resume(pid); } return(true); }
public void LaunchVsDebugger(VsDebugTargetInfo4 target) { var targets = new VsDebugTargetInfo4[1] { target }; VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[targets.Length]; IVsDebugger4 vsDebugger = (IVsDebugger4)project.GetService(typeof(SVsShellDebugger)); vsDebugger.LaunchDebugTargets4((uint)targets.Length, targets, results); }
public static void LaunchDebugTarget(string filePath, string options, Guid engineId) { IVsDebugger4 debugger = (IVsDebugger4)Package.GetGlobalService(typeof(IVsDebugger)); VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = filePath; debugTargets[0].bstrOptions = options; debugTargets[0].guidLaunchDebugEngine = engineId; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); }
private void LaunchDebugTarget(string filePath, string options) { IVsDebugger4 debugger = (IVsDebugger4)GetService(typeof(IVsDebugger)); VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = filePath; debugTargets[0].bstrOptions = options; debugTargets[0].guidLaunchDebugEngine = Microsoft.MIDebugEngine.EngineConstants.EngineId; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); }
public int DebugLaunch(uint flags) { VsDebugTargetInfo2[] targets; int hr = QueryDebugTargets(out targets); if (ErrorHandler.Failed(hr)) { return(hr); } flags |= (uint)__VSDBGLAUNCHFLAGS140.DBGLAUNCH_ContainsStartupTask; VsDebugTargetInfo4[] appPackageDebugTarget = new VsDebugTargetInfo4[1]; int targetLength = (int)Marshal.SizeOf(typeof(VsDebugTargetInfo4)); appPackageDebugTarget[0].AppPackageLaunchInfo.AppUserModelID = DeployAppUserModelID; appPackageDebugTarget[0].AppPackageLaunchInfo.PackageMoniker = DeployPackageMoniker; appPackageDebugTarget[0].dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AppPackageDebug; appPackageDebugTarget[0].LaunchFlags = flags; appPackageDebugTarget[0].bstrRemoteMachine = targets[0].bstrRemoteMachine; appPackageDebugTarget[0].bstrExe = targets[0].bstrExe; appPackageDebugTarget[0].bstrArg = targets[0].bstrArg; appPackageDebugTarget[0].bstrCurDir = targets[0].bstrCurDir; appPackageDebugTarget[0].bstrEnv = targets[0].bstrEnv; appPackageDebugTarget[0].dwProcessId = targets[0].dwProcessId; appPackageDebugTarget[0].pStartupInfo = IntPtr.Zero; //? appPackageDebugTarget[0].guidLaunchDebugEngine = targets[0].guidLaunchDebugEngine; appPackageDebugTarget[0].dwDebugEngineCount = targets[0].dwDebugEngineCount; appPackageDebugTarget[0].pDebugEngines = targets[0].pDebugEngines; appPackageDebugTarget[0].guidPortSupplier = targets[0].guidPortSupplier; appPackageDebugTarget[0].bstrPortName = targets[0].bstrPortName; appPackageDebugTarget[0].bstrOptions = targets[0].bstrOptions; appPackageDebugTarget[0].fSendToOutputWindow = targets[0].fSendToOutputWindow; appPackageDebugTarget[0].pUnknown = targets[0].pUnknown; appPackageDebugTarget[0].guidProcessLanguage = targets[0].guidProcessLanguage; appPackageDebugTarget[0].project = this.project; // Pass the debug launch targets to the debugger System.IServiceProvider sp = this.project as System.IServiceProvider; IVsDebugger4 debugger4 = (IVsDebugger4)sp.GetService(typeof(SVsShellDebugger)); VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[1]; debugger4.LaunchDebugTargets4(1, appPackageDebugTarget, results); return(VSConstants.S_OK); }
// Token: 0x06000012 RID: 18 RVA: 0x0000229C File Offset: 0x0000049C public bool StartDebugger(SoftDebuggerSession session, StartInfo startInfo) { DebugLauncher.tracer.Verbose("Entering Launch for: {0}", new object[] { this }); IVsDebugger4 service = ServiceProvider.GlobalProvider.GetService <SVsShellDebugger, IVsDebugger4>(); SessionMarshalling obj = new SessionMarshalling(session, startInfo); VsDebugTargetInfo4 vsDebugTargetInfo = default(VsDebugTargetInfo4); vsDebugTargetInfo.dlo = 1U; vsDebugTargetInfo.bstrExe = "Mono"; vsDebugTargetInfo.bstrCurDir = ""; vsDebugTargetInfo.bstrArg = null; vsDebugTargetInfo.bstrRemoteMachine = null; vsDebugTargetInfo.fSendToOutputWindow = 0; vsDebugTargetInfo.guidPortSupplier = Guids.PortSupplierGuid; vsDebugTargetInfo.guidLaunchDebugEngine = Guids.EngineGuid; vsDebugTargetInfo.bstrPortName = "Mono"; using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = new BinaryFormatter(); ObjRef graph = RemotingServices.Marshal(obj); binaryFormatter.Serialize(memoryStream, graph); vsDebugTargetInfo.bstrOptions = Convert.ToBase64String(memoryStream.ToArray()); } bool result; try { VsDebugTargetProcessInfo[] array = new VsDebugTargetProcessInfo[1]; service.LaunchDebugTargets4(1U, new VsDebugTargetInfo4[] { vsDebugTargetInfo }, array); result = true; } catch (Exception ex) { DebugLauncher.tracer.Error("Controller.Launch ()", new object[] { ex }); throw; } return(result); }
public override async Task LaunchAsync(DebugLaunchOptions launchOptions) { // The properties that are available via DebuggerProperties are determined by the property XAML files in your project. var debuggerProperties = await this.DebuggerProperties.GetMocheDebuggerPropertiesAsync(); LocalLaunchOptions llo = new LocalLaunchOptions(); llo.ExePath = await debuggerProperties.LocalDebuggerCommand.GetEvaluatedValueAtEndAsync(); llo.ExeArguments = await debuggerProperties.LocalDebuggerCommandArguments.GetEvaluatedValueAtEndAsync(); llo.WorkingDirectory = await debuggerProperties.LocalDebuggerWorkingDirectory.GetEvaluatedValueAtEndAsync(); llo.MIDebuggerPath = await debuggerProperties.LocalDebuggerPath.GetEvaluatedValueAtEndAsync(); MIMode miMode; if (Enum.TryParse(await debuggerProperties.LocalDebuggerType.GetEvaluatedValueAtEndAsync(), out miMode)) { llo.MIMode = miMode; llo.MIModeSpecified = true; } if (llo.ExePath == null) { var generalProperties = await this.DebuggerProperties.GetConfigurationGeneralPropertiesAsync(); llo.ExePath = await generalProperties.TargetPath.GetEvaluatedValueAtEndAsync(); } IVsDebugger4 debugger = (IVsDebugger4)ServiceProvider.GetService(typeof(IVsDebugger)); VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = llo.MIDebuggerPath; using (MemoryStream s = new MemoryStream()) { new System.Xml.Serialization.XmlSerializer(typeof(LocalLaunchOptions)).Serialize(s, llo); s.Flush(); s.Seek(0, SeekOrigin.Begin); debugTargets[0].bstrOptions = await new StreamReader(s).ReadToEndAsync(); } debugTargets[0].guidLaunchDebugEngine = Microsoft.MIDebugEngine.EngineConstants.EngineId; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); }
public bool StartDebugger(SoftDebuggerSession session, StartInfo startInfo) { IVsDebugger4 service = ServiceProvider.GlobalProvider.GetService(typeof(SVsShellDebugger)) as IVsDebugger4; if (service == null) { return(false); } SessionMarshalling sessionMarshalling = new SessionMarshalling(session, startInfo); VsDebugTargetInfo4 debugTargetInfo4 = new VsDebugTargetInfo4 { dlo = 1U, bstrExe = string.Format("CRYENGINE - {0}", startInfo.StartupProject.Name), bstrCurDir = "", bstrArg = null, bstrRemoteMachine = null, fSendToOutputWindow = 0, guidPortSupplier = Guids.PortSupplierGuid, guidLaunchDebugEngine = Guids.EngineGuid, bstrPortName = "Mono" }; using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = new BinaryFormatter(); ObjRef objRef = RemotingServices.Marshal(sessionMarshalling); binaryFormatter.Serialize(memoryStream, objRef); debugTargetInfo4.bstrOptions = Convert.ToBase64String(memoryStream.ToArray()); } try { VsDebugTargetProcessInfo[] pLaunchResults = new VsDebugTargetProcessInfo[1]; service.LaunchDebugTargets4(1U, new VsDebugTargetInfo4[1] { debugTargetInfo4 }, pLaunchResults); return(true); } catch { throw; } }
private void LaunchDebugTarget(string filePath, string options) { //////////////////////////////////////////////////////// // EXPERIMENTAL to launch debug from VS command line // //////////////////////////////////////////////////////// IVsDebugger4 debugger = (IVsDebugger4)GetService(typeof(IVsDebugger)); VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = typeof(CorDebugProcess).Assembly.Location; debugTargets[0].bstrArg = options; debugTargets[0].guidPortSupplier = DebugPortSupplier.PortSupplierGuid; debugTargets[0].guidLaunchDebugEngine = CorDebug.EngineGuid; debugTargets[0].bstrCurDir = filePath; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); }
private async System.Threading.Tasks.Task LaunchDebugTargetAsync(string filePath, string options) { //////////////////////////////////////////////////////// // EXPERIMENTAL to launch debug from VS command line // //////////////////////////////////////////////////////// await JoinableTaskFactory.SwitchToMainThreadAsync(); IVsDebugger4 debugger = (IVsDebugger4)GetServiceAsync(typeof(IVsDebugger)); VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = typeof(CorDebugProcess).Assembly.Location; debugTargets[0].bstrArg = options; debugTargets[0].guidPortSupplier = DebugPortSupplier.PortSupplierGuid; debugTargets[0].guidLaunchDebugEngine = CorDebug.EngineGuid; debugTargets[0].bstrCurDir = filePath; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); }
private void LaunchInBuiltinDebugger(string file) { VsDebugTargetInfo4[] targets = new VsDebugTargetInfo4[1]; targets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; targets[0].guidLaunchDebugEngine = Constants.NativeOnlyEngine; targets[0].bstrExe = file; if (!string.IsNullOrEmpty(_debugConfig.CommandLineArgs)) { targets[0].bstrArg = _debugConfig.CommandLineArgs; } if (!string.IsNullOrEmpty(_debugConfig.WorkingDir)) { targets[0].bstrCurDir = _debugConfig.WorkingDir; } VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[targets.Length]; IVsDebugger4 vsDebugger = (IVsDebugger4)_project.GetService(typeof(SVsShellDebugger)); vsDebugger.LaunchDebugTargets4((uint)targets.Length, targets, results); }
private void LaunchDebugTarget(string filePath, string options) { ThreadHelper.ThrowIfNotOnUIThread(); IVsDebugger4 debugger = (IVsDebugger4)GetService(typeof(IVsDebugger)); if (debugger != null) { VsDebugTargetInfo4[] debugTargets = new VsDebugTargetInfo4[1]; debugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; debugTargets[0].bstrExe = filePath; debugTargets[0].bstrOptions = options; debugTargets[0].guidLaunchDebugEngine = Microsoft.MIDebugEngine.EngineConstants.EngineId; VsDebugTargetProcessInfo[] processInfo = new VsDebugTargetProcessInfo[debugTargets.Length]; debugger.LaunchDebugTargets4(1, debugTargets, processInfo); } else { throw new InvalidOperationException("Why is IVsDebugger4 null?"); } }
/// <summary> /// IVsDebuggableProjectCfg /// </summary> public int DebugLaunch(uint grfLaunch) { VsDebugTargetInfo4 info = new VsDebugTargetInfo4(); info.dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; info.guidLaunchDebugEngine = CLSID_ComPlusOnlyDebugEngine4; // Note. A bug in the debugger will cause a failure if a PID is set but the exe name // is NULL. So we just blindly set it here. info.bstrExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "cmd.exe"); info.bstrArg = null; info.bstrCurDir = null; info.LaunchFlags = grfLaunch; IVsDebugger4 debugger = ServiceProvider.GlobalProvider.GetService(typeof(SVsShellDebugger)) as IVsDebugger4; var debugTargetInfos = new VsDebugTargetInfo4[] { info }; // Debugger will throw on failure var tpi = new VsDebugTargetProcessInfo[1]; debugger.LaunchDebugTargets4(1, debugTargetInfos, tpi); return(VSConstants.S_OK); }
private void AttachToRemoteProcessV4(string machineName, string processName) { IVsDebugger4 vsDebugger = Package.GetGlobalService(typeof(IVsDebugger)) as IVsDebugger4; VsDebugTargetInfo4[] arrDebugTargetInfo = new VsDebugTargetInfo4[1]; VsDebugTargetProcessInfo[] arrTargetProcessInfo = new VsDebugTargetProcessInfo[1]; arrDebugTargetInfo[0].bstrExe = processName; arrDebugTargetInfo[0].bstrRemoteMachine = machineName; arrDebugTargetInfo[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_AlreadyRunning; arrDebugTargetInfo[0].guidLaunchDebugEngine = Guid.Empty; arrDebugTargetInfo[0].dwDebugEngineCount = 1; arrDebugTargetInfo[0].LaunchFlags = (uint)__VSDBGLAUNCHFLAGS.DBGLAUNCH_DetachOnStop; Guid guidDbgEngine = VSConstants.DebugEnginesGuids.ManagedAndNative_guid; IntPtr pGuids = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDbgEngine)); Marshal.StructureToPtr(guidDbgEngine, pGuids, false); arrDebugTargetInfo[0].pDebugEngines = pGuids; var t = new System.Threading.Thread(() => { vsDebugger.LaunchDebugTargets4(1, arrDebugTargetInfo, arrTargetProcessInfo); }); t.Start(); InputUserPassword(); t.Join(); // cleanup if (pGuids != IntPtr.Zero) { Marshal.FreeCoTaskMem(pGuids); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { // Get the open folder filename EnvDTE80.DTE2 dte = ServiceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; EnvDTE100.Solution4 solution = dte.Solution as EnvDTE100.Solution4; string filename = solution.FileName; // Parse settings XML string MachineName, Path; try { System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.Load(filename + "\\.vs\\RemoteDebug.xml"); System.Xml.XmlNode root = doc.SelectSingleNode("RemoteDebug"); MachineName = root.SelectSingleNode("MachineName").InnerText; Path = root.SelectSingleNode("Path").InnerText; } catch (Exception exception) { // Report any exceptions as message box VsShellUtilities.ShowMessageBox( this.ServiceProvider, exception.Message, "Remote Debug Launch", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); return; } // Get a pointer to the debug engine Guid guidDebugEngine = Microsoft.VisualStudio.VSConstants.DebugEnginesGuids.ManagedAndNative_guid; IntPtr pguidDebugEngine = Marshal.AllocCoTaskMem(Marshal.SizeOf(guidDebugEngine)); Marshal.StructureToPtr(guidDebugEngine, pguidDebugEngine, false); // Setup target info VsDebugTargetInfo4[] pDebugTargets = new VsDebugTargetInfo4[1]; pDebugTargets[0].bstrExe = Path; pDebugTargets[0].bstrRemoteMachine = MachineName; pDebugTargets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; pDebugTargets[0].guidLaunchDebugEngine = Guid.Empty; pDebugTargets[0].dwDebugEngineCount = 1; pDebugTargets[0].pDebugEngines = pguidDebugEngine; try { // Launch debugger IVsDebugger4 vsdbg = Package.GetGlobalService(typeof(IVsDebugger)) as IVsDebugger4; VsDebugTargetProcessInfo[] pLaunchResults = new VsDebugTargetProcessInfo[1]; vsdbg.LaunchDebugTargets4(1, pDebugTargets, pLaunchResults); } catch (Exception exception) { // Report any exceptions as message box VsShellUtilities.ShowMessageBox( this.ServiceProvider, exception.Message, "Remote Debug Launch", OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } // Cleanup marshalled data if (pguidDebugEngine != IntPtr.Zero) { Marshal.FreeCoTaskMem(pguidDebugEngine); } }
public int DebugLaunch(uint grfLaunch) { if (PythonConfig.IsAppxPackageableProject()) { VsDebugTargetInfo2[] targets; int hr = QueryDebugTargets(out targets); if (ErrorHandler.Failed(hr)) { return(hr); } VsDebugTargetInfo4[] appPackageDebugTarget = new VsDebugTargetInfo4[1]; int targetLength = (int)Marshal.SizeOf(typeof(VsDebugTargetInfo4)); // Setup the app-specific parameters appPackageDebugTarget[0].AppPackageLaunchInfo.AppUserModelID = DeployAppUserModelID; appPackageDebugTarget[0].AppPackageLaunchInfo.PackageMoniker = DeployPackageMoniker; appPackageDebugTarget[0].AppPackageLaunchInfo.AppPlatform = VsAppPackagePlatform.APPPLAT_WindowsAppx; #if DEV14_OR_LATER // Check if this project contains a startup task and set launch flag appropriately IVsBuildPropertyStorage bps = (IVsBuildPropertyStorage)this.PythonConfig; string canonicalName; string containsStartupTaskValue = null; bool containsStartupTask = false; get_CanonicalName(out canonicalName); bps.GetPropertyValue("ContainsStartupTask", canonicalName, (uint)_PersistStorageType.PST_PROJECT_FILE, out containsStartupTaskValue); if (containsStartupTaskValue != null && bool.TryParse(containsStartupTaskValue, out containsStartupTask) && containsStartupTask) { grfLaunch |= (uint)__VSDBGLAUNCHFLAGS140.DBGLAUNCH_ContainsStartupTask; } #endif appPackageDebugTarget[0].dlo = (uint)_DEBUG_LAUNCH_OPERATION4.DLO_AppPackageDebug; appPackageDebugTarget[0].LaunchFlags = grfLaunch; appPackageDebugTarget[0].bstrRemoteMachine = targets[0].bstrRemoteMachine; appPackageDebugTarget[0].bstrExe = targets[0].bstrExe; appPackageDebugTarget[0].bstrArg = targets[0].bstrArg; appPackageDebugTarget[0].bstrCurDir = targets[0].bstrCurDir; appPackageDebugTarget[0].bstrEnv = targets[0].bstrEnv; appPackageDebugTarget[0].dwProcessId = targets[0].dwProcessId; appPackageDebugTarget[0].pStartupInfo = IntPtr.Zero; appPackageDebugTarget[0].guidLaunchDebugEngine = targets[0].guidLaunchDebugEngine; appPackageDebugTarget[0].dwDebugEngineCount = targets[0].dwDebugEngineCount; appPackageDebugTarget[0].pDebugEngines = targets[0].pDebugEngines; appPackageDebugTarget[0].guidPortSupplier = targets[0].guidPortSupplier; appPackageDebugTarget[0].bstrPortName = targets[0].bstrPortName; appPackageDebugTarget[0].bstrOptions = targets[0].bstrOptions; appPackageDebugTarget[0].fSendToOutputWindow = targets[0].fSendToOutputWindow; appPackageDebugTarget[0].pUnknown = targets[0].pUnknown; appPackageDebugTarget[0].guidProcessLanguage = targets[0].guidProcessLanguage; appPackageDebugTarget[0].project = PythonConfig; // Pass the debug launch targets to the debugger IVsDebugger4 debugger4 = (IVsDebugger4)Package.GetGlobalService(typeof(SVsShellDebugger)); VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[1]; IVsDebugger debugger = (IVsDebugger)debugger4; // Launch task to monitor to attach to Python remote process var sourceDir = Path.GetFullPath(PythonConfig.GetProjectProperty("ProjectDir")).Trim('\\'); var targetDir = Path.GetFullPath(this.LayoutDir).Trim('\\'); var debugPort = PythonConfig.GetProjectProperty("RemoteDebugPort") ?? DefaultRemoteDebugPort; var debugId = Guid.NewGuid(); var serializer = new JavaScriptSerializer(); var debugCmdJson = serializer.Serialize(new string[] { "visualstudio_py_remote_launcher.py", debugPort.ToString(), debugId.ToString(), "--redirect-output" }); Debugger.PythonRemoteDebugEvents.Instance.RemoteDebugCommandInfo = Encoding.Unicode.GetBytes(debugCmdJson); Debugger.PythonRemoteDebugEvents.Instance.AttachRemoteProcessFunction = () => { return(RemoteProcessAttachAsync( appPackageDebugTarget[0].bstrRemoteMachine, debugId.ToString(), debugPort, sourceDir, targetDir)); }; int result = debugger.AdviseDebugEventCallback(Debugger.PythonRemoteDebugEvents.Instance); if (result == VSConstants.S_OK) { debugger4.LaunchDebugTargets4(1, appPackageDebugTarget, results); } else { Debug.Fail(string.Format(CultureInfo.CurrentCulture, "Failure {0}", result)); } return(result); } else { IVsDebuggableProjectCfg cfg = _pythonCfg as IVsDebuggableProjectCfg; if (cfg != null) { return(cfg.DebugLaunch(grfLaunch)); } return(VSConstants.E_NOTIMPL); } }
private void LaunchInGdbDebugger(string file) { var targets = new VsDebugTargetInfo4[1]; targets[0].dlo = (uint)DEBUG_LAUNCH_OPERATION.DLO_CreateProcess; targets[0].bstrExe = file; targets[0].guidLaunchDebugEngine = new Guid(EngineConstants.EngineId); bool useCustomPath = GetDebugProperty <bool>("UseCustomGdbPath"); string gdbPath; if (useCustomPath) { gdbPath = GetDebugProperty <string>("DebuggerLocation"); } else { gdbPath = Path.Combine( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "gdb", GuessArchitecture(), "bin\\gdb"); } string gdbArgs = "-q " + // quiet "-interpreter=mi " + // use machine interface GetDebugProperty <string>("ExtraArgs"); // add extra options from Visual Rust/Debugging options page var options = new StringBuilder(); using (var writer = XmlWriter.Create(options, new XmlWriterSettings { OmitXmlDeclaration = true })) { writer.WriteStartElement("PipeLaunchOptions", "http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014"); writer.WriteAttributeString("PipePath", gdbPath); writer.WriteAttributeString("PipeArguments", gdbArgs); writer.WriteAttributeString("ExePath", EscapePath(file)); if (!string.IsNullOrEmpty(debugConfig.CommandLineArgs)) { writer.WriteAttributeString("ExeArguments", debugConfig.CommandLineArgs); } if (!string.IsNullOrEmpty(debugConfig.WorkingDir)) { writer.WriteAttributeString("WorkingDirectory", EscapePath(debugConfig.WorkingDir)); // GDB won't search working directory by default, but this is expected on Windows. string rustBinPath = RustBinPath(); string additionalPath; if (rustBinPath != null) { additionalPath = rustBinPath + ";" + debugConfig.WorkingDir; } else { additionalPath = debugConfig.WorkingDir; } writer.WriteAttributeString("AdditionalSOLibSearchPath", additionalPath); } else { writer.WriteAttributeString("WorkingDirectory", EscapePath(Path.GetDirectoryName(file))); string rustBinPath = RustBinPath(); if (rustBinPath != null) { writer.WriteAttributeString("AdditionalSOLibSearchPath", rustBinPath); } } // this affects the number of bytes the engine reads when disassembling commands, // x64 has the largest maximum command size, so it should be safe to use for x86 as well writer.WriteAttributeString("TargetArchitecture", "x64"); // GDB engine expects to find a shell on the other end of the pipe, so the first thing it sends over is "gdb --interpreter=mi", // (which GDB complains about, since this isn't a valid command). // Since we are launching GDB directly, here we create a noop alias for "gdb" to make the error message go away. writer.WriteElementString("Command", "alias -a gdb=echo"); // launch debuggee in a new console window writer.WriteElementString("Command", "set new-console on"); if (!string.IsNullOrEmpty(debugConfig.DebuggerScript)) { foreach (string cmd in debugConfig.DebuggerScript.Split('\r', '\n')) { if (!string.IsNullOrEmpty(cmd)) { writer.WriteElementString("Command", cmd); } } } writer.WriteEndElement(); } targets[0].bstrOptions = options.ToString(); VsDebugTargetProcessInfo[] results = new VsDebugTargetProcessInfo[targets.Length]; IVsDebugger4 vsDebugger = (IVsDebugger4)project.GetService(typeof(SVsShellDebugger)); vsDebugger.LaunchDebugTargets4((uint)targets.Length, targets, results); }