コード例 #1
0
ファイル: O2MDbgUtils.cs プロジェクト: pusp/o2platform
 public static List<String> getListOfManagedProcess(bool showDetails)
 {
     var managedProcesses = new List<String>();
     int currentProcessId = Process.GetCurrentProcess().Id;
     var corPublish = new CorPublish();
     foreach (CorPublishProcess corPublishProcess in corPublish.EnumProcesses())
         if (currentProcessId != corPublishProcess.ProcessId)
             // don't include the current process                                                
             if (showDetails)
                 managedProcesses.Add("[" + corPublishProcess.ProcessId + "] [ver=" +
                                      CorDebugger.GetDebuggerVersionFromPid(corPublishProcess.ProcessId) + "] " +
                                      corPublishProcess.DisplayName);
             else
                 managedProcesses.Add(corPublishProcess.DisplayName);
     return managedProcesses;
 }
コード例 #2
0
ファイル: AttachProcess.cs プロジェクト: pusp/o2platform
        private void RefreshProcesses()
        {
            listBoxProcesses.Items.Clear();

            CorPublish cp = null;

            int curPid = Process.GetCurrentProcess().Id;
            try
            {
                int count = 0;

                cp = new CorPublish();
                {
                    foreach (CorPublishProcess cpp in cp.EnumProcesses())
                    {
                        if (curPid != cpp.ProcessId) // let's hide our process
                        {
                            string version = CorDebugger.GetDebuggerVersionFromPid(cpp.ProcessId);
                            string s = "[" + cpp.ProcessId + "] [ver=" + version + "] " + cpp.DisplayName;
                            listBoxProcesses.Items.Add(new Item(cpp.ProcessId, s));
                            count++;
                        }
                    }
                } // using

                if (count == 0)
                {
                    listBoxProcesses.Items.Add(new Item(0, "(No active processes)"));
                }
            }
            catch (Exception)
            {
                if (cp == null)
                {
                    listBoxProcesses.Items.Add(new Item(0, "(Can't enumerate processes"));
                }
            }
        }
コード例 #3
0
        public static void ProcessEnumCmd(string arguments, O2Thread.FuncVoidT1<CorPublishProcess> handleManagedProcess) // extended with Lambda method
        {
            var cp = new CorPublish();

            CommandBase.WriteOutput("Active processes on current machine:");
            foreach (CorPublishProcess cpp in cp.EnumProcesses())
            {
                if (Process.GetCurrentProcess().Id == cpp.ProcessId) // let's hide our process
                {
                    continue;
                }

                // Try and get the list of AppDomains, but watch for the process terminating
                IEnumerable appDomainEnum;
                try
                {
                    appDomainEnum = cpp.EnumAppDomains();
                }
                catch (COMException e)
                {
                    if ((uint) e.ErrorCode == 0x80131301) //CORDBG_E_PROCESS_TERMINATED
                    {
                        continue; // process was terminated, ignore it
                    }
                    throw; // let error propogate up
                }
                if (handleManagedProcess != null)
                    handleManagedProcess(cpp);
                else
                {
                    CommandBase.WriteOutput("(PID: " + cpp.ProcessId + ") " + cpp.DisplayName);
                    foreach (CorPublishAppDomain cpad in appDomainEnum)
                        CommandBase.WriteOutput("\t(ID: " + cpad.Id + ") " + cpad.Name);
                }
            }
        }
コード例 #4
0
ファイル: mdbgCommands.cs プロジェクト: pusp/o2platform
        public static void ActiveProcess(string arguments)
        {
            var ap = new ArgParser(arguments);
            if (ap.Count > 1)
            {
                throw new MDbgShellException("Wrong # of arguments.");
            }

            if (ap.Exists(0))
            {
                int logicalPID = ap.AsInt(0);
                bool found = false;
                foreach (MDbgProcess ps in Debugger.Processes)
                    if (ps.Number == logicalPID)
                    {
                        Debugger.Processes.Active = ps;
                        found = true;
                        break;
                    }
                if (found)
                {
                    Shell.DisplayCurrentLocation();
                }
                else
                {
                    throw new MDbgShellException("Invalid process number");
                }
            }
            else
            {
                MDbgProcess ActiveProcess = Debugger.Processes.HaveActive ? Debugger.Processes.Active : null;

                WriteOutput("Active Process:");
                bool haveProcesses = false;

                CorPublish corPublish = null;
                foreach (MDbgProcess p in Debugger.Processes)
                {
                    haveProcesses = true;
                    string processName = p.Name;
                    string launchMode;
                    if (processName == null)
                    {
                        // in case we're attached (as opposed to launching),
                        // we don't know process name.
                        // Let's find it through CorPublishApi
                        try
                        {
                            if (corPublish == null)
                            {
                                corPublish = new CorPublish();
                            }
                            processName = corPublish.GetProcess(p.CorProcess.Id).DisplayName;
                        }
                        catch
                        {
                            processName = "N/A";
                        }
                        launchMode = "attached";
                    }
                    else
                    {
                        launchMode = "launched";
                    }
                    WriteOutput((ActiveProcess == p ? "*" : " ") +
                                string.Format(CultureInfo.InvariantCulture, "{0}. [PID: {1}, {2}] {3}", p.Number,
                                              p.CorProcess.Id, launchMode, processName));
                }
                if (!haveProcesses)
                {
                    WriteOutput("No Active Process!");
                }
            }
        }