예제 #1
0
        void OnProcessCreated(System.Diagnostics.Process defaultAppProcess, WebProjectOptions debugData)
        {
            if (attached)
            {
                return;
            }
            string processName = WebProjectService.WorkerProcessName;
            var    processes   = System.Diagnostics.Process.GetProcesses();
            int    index       = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));

            Attach(processes[index]);

            if (!attached)
            {
                if (debugData.Data.WebServer == WebServer.IIS)
                {
                    string format = ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.NoIISWP");
                    MessageService.ShowMessage(string.Format(format, processName));
                }
                else
                {
                    Attach(defaultAppProcess);
                    if (!attached)
                    {
                        MessageService.ShowMessage(ResourceService.GetString("ICSharpCode.WepProjectOptionsPanel.UnableToAttach"));
                    }
                }
            }
        }
예제 #2
0
        public void Attach(System.Diagnostics.Process existingProcess)
        {
            if (existingProcess == null)
            {
                return;
            }

            if (IsDebugging)
            {
                MessageBox.Show(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(existingProcess.MainModule.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageBox.Show("Net10NotSupported");
            }
            else
            {
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try
                {
                    // set the JIT flag for evaluating optimized code
                    Process.DebugMode = DebugModeFlag.Debug;

                    Process process = debugger.Attach(existingProcess);
                    attached = true;
                    SelectProcess(process);
                }
                catch (System.Exception e)
                {
                    // CORDBG_E_DEBUGGER_ALREADY_ATTACHED
                    if (e is COMException || e is UnauthorizedAccessException)
                    {
                        string msg = "CannotAttachToProcess";
                        MessageBox.Show(msg + " " + e.Message);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
예제 #3
0
        public void Attach(System.Diagnostics.Process existingProcess)
        {
            if (existingProcess == null)
            {
                return;
            }

            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            string version = debugger.GetProgramVersion(existingProcess.MainModule.FileName);

            if (version.StartsWith("v1.0"))
            {
                MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
            }
            else
            {
                if (DebugStarting != null)
                {
                    DebugStarting(this, EventArgs.Empty);
                }

                try {
                    Process process = debugger.Attach(existingProcess);
                    attached = true;
                    SelectProcess(process);

                    process.Modules.Added += process_Modules_Added;
                } catch (System.Exception e) {
                    // CORDBG_E_DEBUGGER_ALREADY_ATTACHED
                    if (e is COMException || e is UnauthorizedAccessException)
                    {
                        string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotAttachToProcess}");
                        MessageService.ShowMessage(msg + " " + e.Message);

                        if (DebugStopped != null)
                        {
                            DebugStopped(this, EventArgs.Empty);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
예제 #4
0
        public void Start(ProcessStartInfo processStartInfo)
        {
            if (IsDebugging)
            {
                MessageService.ShowMessage(errorDebugging);
                return;
            }
            if (!ServiceInitialized)
            {
                InitializeService();
            }

            if (FileUtility.IsUrl(processStartInfo.FileName))
            {
                if (!CheckWebProjectStartInfo())
                {
                    return;
                }

                var project = ProjectService.OpenSolution.Preferences.StartupProject as CompilableProject;
                var options = WebProjectsOptions.Instance.GetWebProjectOptions(project.Name);
                System.Diagnostics.Process defaultAppProcess = null;

                if (options.Data.WebServer != WebServer.None)
                {
                    string processName = WebProjectService.WorkerProcessName;

                    // try find the worker process directly or using the process monitor callback
                    var processes = System.Diagnostics.Process.GetProcesses();
                    int index     = processes.FindIndex(p => p.ProcessName.Equals(processName, StringComparison.OrdinalIgnoreCase));
                    if (index > -1)
                    {
                        Attach(processes[index]);
                    }
                    else
                    {
                        try {
                            this.monitor = new ProcessMonitor(processName);
                            this.monitor.ProcessCreated += delegate {
                                WorkbenchSingleton.SafeThreadCall((Action)(() => OnProcessCreated(defaultAppProcess, options)));
                            };
                            this.monitor.Start();
                        }
                        catch (System.Exception ex) {
                            LoggingService.ErrorFormatted("Process Monitor exception: {0}", ex.Message);
                        }
                    }

                    if (options.Data.WebServer == WebServer.IISExpress)
                    {
                        // start IIS express and attach to it
                        if (WebProjectService.IISVersion == IISVersion.IISExpress)
                        {
                            System.Diagnostics.Process.Start(WebProjectService.IISExpressProcessLocation);
                        }
                        else
                        {
                            MessageService.ShowError("${res:ICSharpCode.WepProjectOptionsPanel.NoProjectUrlOrProgramAction}");
                            return;
                        }
                    }
                }

                // start default application(e.g. browser)
                if (project.StartAction == StartAction.StartURL)
                {
                    defaultAppProcess = System.Diagnostics.Process.Start(project.StartUrl);
                }
                else
                {
                    if (!string.IsNullOrEmpty(options.Data.ProjectUrl) && options.Data.WebServer == WebServer.IIS)
                    {
                        defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                    }
                    else
                    {
                        if (options.Data.WebServer == WebServer.IISExpress)
                        {
                            defaultAppProcess = System.Diagnostics.Process.Start(options.Data.ProjectUrl);
                        }
                    }
                }
            }
            else
            {
                string version = debugger.GetProgramVersion(processStartInfo.FileName);

                if (version.StartsWith("v1.0"))
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}");
                }
                else if (version.StartsWith("v1.1"))
                {
                    MessageService.ShowMessage(StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.Net10NotSupported}").Replace("1.0", "1.1"));
//					} else if (string.IsNullOrEmpty(version)) {
//					// Not a managed assembly
//					MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.BadAssembly}");
                }
                else if (debugger.IsKernelDebuggerEnabled)
                {
                    MessageService.ShowMessage("${res:XML.MainMenu.DebugMenu.Error.KernelDebuggerEnabled}");
                }
                else
                {
                    attached = false;
                    if (DebugStarting != null)
                    {
                        DebugStarting(this, EventArgs.Empty);
                    }

                    try {
                        Process process = debugger.Start(processStartInfo.FileName,
                                                         processStartInfo.WorkingDirectory,
                                                         processStartInfo.Arguments);
                        SelectProcess(process);
                    } catch (System.Exception e) {
                        // COMException: The request is not supported. (Exception from HRESULT: 0x80070032)
                        // COMException: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail. (Exception from HRESULT: 0x800736B1)
                        // COMException: The requested operation requires elevation. (Exception from HRESULT: 0x800702E4)
                        // COMException: The directory name is invalid. (Exception from HRESULT: 0x8007010B)
                        // BadImageFormatException:  is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)
                        // UnauthorizedAccessException: Отказано в доступе. (Исключение из HRESULT: 0x80070005 (E_ACCESSDENIED))
                        if (e is COMException || e is BadImageFormatException || e is UnauthorizedAccessException)
                        {
                            string msg = StringParser.Parse("${res:XML.MainMenu.DebugMenu.Error.CannotStartProcess}");
                            msg += " " + e.Message;
                            // TODO: Remove
                            if (e is COMException && ((uint)((COMException)e).ErrorCode == 0x80070032))
                            {
                                msg += Environment.NewLine + Environment.NewLine;
                                msg += "64-bit debugging is not supported.  Please set Project -> Project Options... -> Compiling -> Target CPU to 32bit.";
                            }
                            MessageService.ShowMessage(msg);

                            if (DebugStopped != null)
                            {
                                DebugStopped(this, EventArgs.Empty);
                            }
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }