private static void WriteErrorToOutputWindow(ConnErrorMessages result, PythonProcess targetProcess) { var outWin = (IVsOutputWindow)Package.GetGlobalService(typeof(IVsOutputWindow)); IVsOutputWindowPane pane; if (outWin != null && ErrorHandler.Succeeded(outWin.GetPane(VSConstants.GUID_OutWindowDebugPane, out pane))) { pane.Activate(); string moduleName; try { moduleName = Process.GetProcessById(targetProcess.Id).MainModule.ModuleName; } catch { // either the process is no longer around, or it's a 64-bit process // and we can't get the EXE name. moduleName = null; } if (moduleName != null) { pane.OutputString(Strings.DebugConnectionFailedToConnectToProcessWithModule.FormatUI( targetProcess.Id, moduleName, result.GetErrorMessage()) ); } else { pane.OutputString(Strings.DebugConnectionFailedToConnectToProcessWithoutModule.FormatUI( targetProcess.Id, result.GetErrorMessage()) ); } } }
internal static ConnErrorMessages AttachDkmWorker(int pid) { var hProcess = NativeMethods.OpenProcess(ProcessAccessFlags.All, false, pid); if (hProcess == IntPtr.Zero) { return(ConnErrorMessages.CannotOpenProcess); } string dllName = string.Format("Microsoft.PythonTools.Debugger.Helper.{0}.dll", IntPtr.Size == 4 ? "x86" : "x64"); string dllPath = PythonToolsInstallPath.GetFile(dllName); if (!File.Exists(dllPath)) { return(ConnErrorMessages.PyDebugAttachNotFound); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682631(v=vs.85).aspx // If the module list in the target process is corrupted or not yet initialized, // or if the module list changes during the function call as a result of DLLs // being loaded or unloaded, EnumProcessModules may fail or return incorrect // information. // So we'll retry a handful of times to get the attach... ConnErrorMessages error = ConnErrorMessages.None; for (int i = 0; i < 5; i++) { IntPtr hKernel32; if ((error = FindKernel32(hProcess, out hKernel32)) == ConnErrorMessages.None) { return(InjectDll(dllPath, hProcess, hKernel32)); } } return(error); }
/// <summary> /// Attaches to the specified PID and returns a DebugAttach object indicating the result. /// </summary> internal static DebugAttach AttachAD7Worker(int pid, int portNum, Guid debugId, string debugOptions, EventWaitHandle attachDoneEvent = null) { var hProcess = NativeMethods.OpenProcess(ProcessAccessFlags.All, false, pid); if (hProcess != IntPtr.Zero) { string dllPath; if (IntPtr.Size == 4) { dllPath = PythonToolsInstallPath.GetFile("PyDebugAttachX86.dll"); } else { dllPath = PythonToolsInstallPath.GetFile("PyDebugAttach.dll"); } if (!File.Exists(dllPath)) { return new DebugAttach(ConnErrorMessages.PyDebugAttachNotFound); } // load our code into the process... // http://msdn.microsoft.com/en-us/library/windows/desktop/ms682631(v=vs.85).aspx // If the module list in the target process is corrupted or not yet initialized, // or if the module list changes during the function call as a result of DLLs // being loaded or unloaded, EnumProcessModules may fail or return incorrect // information. // So we'll retry a handful of times to get the attach... ConnErrorMessages error = ConnErrorMessages.None; for (int i = 0; i < 5; i++) { IntPtr hKernel32; if ((error = FindKernel32(hProcess, out hKernel32)) == ConnErrorMessages.None) { return InjectDebugger(dllPath, hProcess, hKernel32, portNum, pid, debugId, debugOptions, attachDoneEvent); } } return new DebugAttach(error); } return new DebugAttach(ConnErrorMessages.CannotOpenProcess); }
internal static string GetErrorMessage(this ConnErrorMessages attachRes) { string msg; if (!errMessages.TryGetValue(attachRes, out msg)) { msg = Strings.ConnErrorMessages_UnknownError; } return(msg); }
public ConnectionException(ConnErrorMessages error, Exception innerException) : base(null, innerException) { Error = error; }
public ConnectionException(ConnErrorMessages error) { Error = error; }
private DebugAttach(EventWaitHandle attachDone, ConnErrorMessages error, int langVersion) { _attachDone = attachDone; _error = error; _langVersion = langVersion; }
private DebugAttach(ConnErrorMessages error) { _error = error; }
public AttachException(ConnErrorMessages error) { _error = error; }
private static void WriteErrorToOutputWindow(ConnErrorMessages result, PythonProcess targetProcess) { var outWin = (IVsOutputWindow)Package.GetGlobalService(typeof(IVsOutputWindow)); IVsOutputWindowPane pane; if (outWin != null && ErrorHandler.Succeeded(outWin.GetPane(VSConstants.GUID_OutWindowDebugPane, out pane))) { pane.Activate(); string moduleName; try { moduleName = Process.GetProcessById(targetProcess.Id).MainModule.ModuleName; } catch { // either the process is no longer around, or it's a 64-bit process // and we can't get the EXE name. moduleName = null; } if (moduleName != null) { pane.OutputString(String.Format("Failed to connect to process {0} ({1}): {2}", targetProcess.Id, moduleName, result.GetErrorMessage()) ); } else { pane.OutputString(String.Format("Failed to connect to process {0}: {1}", targetProcess.Id, result.GetErrorMessage()) ); } } }