Esempio n. 1
0
        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())
                                      );
                }
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
0
        internal static string GetErrorMessage(this ConnErrorMessages attachRes)
        {
            string msg;

            if (!errMessages.TryGetValue(attachRes, out msg))
            {
                msg = Strings.ConnErrorMessages_UnknownError;
            }
            return(msg);
        }
Esempio n. 5
0
 public ConnectionException(ConnErrorMessages error, Exception innerException)
     : base(null, innerException)
 {
     Error = error;
 }
Esempio n. 6
0
 public ConnectionException(ConnErrorMessages error)
 {
     Error = error;
 }
Esempio n. 7
0
 private DebugAttach(EventWaitHandle attachDone, ConnErrorMessages error, int langVersion) {
     _attachDone = attachDone;
     _error = error;
     _langVersion = langVersion;
 }
Esempio n. 8
0
 private DebugAttach(ConnErrorMessages error) {
     _error = error;
 }
Esempio n. 9
0
 public ConnectionException(ConnErrorMessages error, Exception innerException)
     : base(null, innerException) {
     Error = error;
 }
Esempio n. 10
0
 public ConnectionException(ConnErrorMessages error) {
     Error = error;
 }
Esempio n. 11
0
 private DebugAttach(EventWaitHandle attachDone, ConnErrorMessages error, int langVersion)
 {
     _attachDone  = attachDone;
     _error       = error;
     _langVersion = langVersion;
 }
Esempio n. 12
0
 private DebugAttach(ConnErrorMessages error)
 {
     _error = error;
 }
Esempio n. 13
0
 public AttachException(ConnErrorMessages error)
 {
     _error = error;
 }
Esempio n. 14
0
        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())
                    );
                }
            }
        }
Esempio n. 15
0
 public AttachException(ConnErrorMessages error)
 {
     _error = error;
 }