public bool AttachToProcess(ProcessOutput processOutput, Guid portSupplier, string transportQualifierUri) { var debugger3 = (EnvDTE90.Debugger3)GetDTE().Debugger; var transports = debugger3.Transports; EnvDTE80.Transport transport = null; for (int i = 1; i <= transports.Count; ++i) { var t = transports.Item(i); if (Guid.Parse(t.ID) == portSupplier) { transport = t; break; } } if (transport == null) { return(false); } var processes = debugger3.GetProcesses(transport, transportQualifierUri); if (processes.Count < 1) { return(false); } var process = processes.Item(1); return(AttachToProcess(processOutput, process)); }
private unsafe void AttachDebugger(Uri uri) { var dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); var debugger = (EnvDTE90.Debugger3)dte.Debugger; var transports = debugger.Transports; EnvDTE80.Transport transport = null; for (int i = 1; i <= transports.Count; ++i) { var t = transports.Item(i); Guid tid; if (Guid.TryParse(t.ID, out tid) && tid == PythonRemoteDebugPortSupplier.PortSupplierGuid) { transport = t; } } if (transport == null) { throw new InvalidOperationException("Python remote debugging transport is missing."); } var processes = debugger.GetProcesses(transport, uri.ToString()); if (processes.Count == 0) { throw new InvalidOperationException("No Python processes found on remote host."); } foreach (EnvDTE.Process process in processes) { process.Attach(); } }
private bool AttachToProcess(Process testProcess, Guid portSupplier, string transportQualifierUri) { var dte = this.GetDTE(); var debugger3 = (EnvDTE90.Debugger3)dte.Debugger; var transports = debugger3.Transports; EnvDTE80.Transport transport = null; for (var i = 1; i <= transports.Count; ++i) { var t = transports.Item(i); if (Guid.Parse(t.ID) == portSupplier) { transport = t; break; } } if (transport == null) { return(false); } var processes = debugger3.GetProcesses(transport, transportQualifierUri); if (processes.Count < 1) { return(false); } var process = processes.Item(1); // Retry the attach itself 3 times before displaying a Retry/Cancel // dialog to the user. dte.SuppressUI = true; try { process.Attach(); return(true); } catch (COMException) { if (testProcess.WaitForExit(milliseconds: 500)) { // Process exited while we were trying return(false); } } finally { dte.SuppressUI = false; } // Another attempt, but display UI. process.Attach(); return(true); }
public bool AttachToProcess(ProcessOutput proc, Guid portSupplier, string transportQualifierUri) { var debugger3 = (EnvDTE90.Debugger3)DTE.Debugger; var transports = debugger3.Transports; EnvDTE80.Transport transport = null; for (int i = 1; i <= transports.Count; ++i) { var t = transports.Item(i); if (Guid.Parse(t.ID) == portSupplier) { transport = t; break; } } if (transport == null) { return(false); } var processes = debugger3.GetProcesses(transport, transportQualifierUri); if (processes.Count < 1) { return(false); } // Retry the attach itself 3 times before displaying a Retry/Cancel // dialog to the user. DTE.SuppressUI = true; try { try { processes.Item(1).Attach(); return(true); } catch (COMException) { if (proc.Wait(TimeSpan.FromMilliseconds(500))) { // Process exited while we were trying return(false); } } } finally { DTE.SuppressUI = false; } // Another attempt, but display UI. processes.Item(1).Attach(); return(true); }
private void AttachToW3wp(List <int> currentWorkerProcess) { EnvDTE80.Debugger2 dbg2 = _applicationObject.Debugger as EnvDTE80.Debugger2; EnvDTE80.Transport transport = dbg2.Transports.Item("Default"); EnvDTE80.Engine dbgEngine = null; string targetVersion = GetFrameworkVersion(); Trace.WriteLine("Attach Debug Engine: " + targetVersion); foreach (EnvDTE80.Engine item in transport.Engines) { if (item.Name.IndexOf(targetVersion) != -1) { dbgEngine = item; break; } } if (dbgEngine == null) { ShowMessage("Can't determine project's TargetFrameworkVersion - " + targetVersion); return; } Trace.WriteLine("Debug Engine Type: " + dbgEngine.Name); EnvDTE80.Process2 w3wpProcess = null; foreach (var proc in dbg2.LocalProcesses) { EnvDTE80.Process2 process = proc as EnvDTE80.Process2; if (process == null) { continue; } // Skip process in recycle. if (currentWorkerProcess.Contains(process.ProcessID) == true) { continue; } if (process.Name.IndexOf("W3WP.EXE", 0, StringComparison.OrdinalIgnoreCase) != -1) { w3wpProcess = process; break; } } if (w3wpProcess != null) { bool attached = false; string txt = string.Format("{0}({1})", w3wpProcess.Name, w3wpProcess.ProcessID); System.Diagnostics.Trace.WriteLine("Attaching to: " + txt); try { // I don't know why Attach2 method hang // when Visual Studio 2013 try to attach w3wp.exe hosting .NET 2.0/3.0/3.5 Web Application. if (targetVersion == "v2.0") { w3wpProcess.Attach(); } else { w3wpProcess.Attach2(dbgEngine); } attached = true; System.Diagnostics.Trace.WriteLine("Attached to: " + txt); } catch { } if (attached == true) { string startupUrl = GetProjectItemValue("WebApplication.IISUrl"); if (string.IsNullOrEmpty(startupUrl) == false) { RunInternetExplorer(startupUrl); } } } else { ShowMessage("Make sure the AppPool's Start Mode is AlwaysRunning"); } }