Inheritance: System.MarshalByRefObject
Esempio n. 1
22
        private Dictionary<int, ThreadInfo> processThreads; //has relating thread id to its threadInfo object

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor for ProcessInfo
        /// </summary>
        /// <param name="procID">The id of the process</param>
        /// <param name="debugger">The debugger</param>
        public ProcessInfo(Process process, CorDebugger debug)
        {
            if (debug == null)
            {
                throw new ArgumentException("Null Debugger Exception");
            }

            processThreads = new Dictionary<int, ThreadInfo>();
            processCorThreads = new List<CorThread>();
            generalThreadInfos = new Dictionary<int, ProcessThread>();

            attachedCompletedProcessEvent = new ManualResetEvent(false);
            debugger = debug;
            processId = process.Id;
            generalProcessInfo = Process.GetProcessById(processId);

            //CorPublish cp = new CorPublish();
            //cpp = cp.GetProcess(processId);
            processFullName = process.MainModule.FileName;
            processShortName = System.IO.Path.GetFileName(process.MainModule.FileName);
            FileVersionInfo fileInfo = FileVersionInfo.GetVersionInfo(processFullName);
            description = fileInfo.FileDescription;
            company = fileInfo.CompanyName;

            //debuggerProcessInfo will be set when the updateInfo function is called
            //the reason for this is that the process must be stopped for this to take place
            //this happen only when we want it to
        }
Esempio n. 2
0
        private void prepareDebugger(string arguments)
        {
            var debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion());
            _process = debugger.CreateProcess(_assembly, arguments);

            _process.OnCreateAppDomain += new CorAppDomainEventHandler(process_OnCreateAppDomain);
            _process.OnProcessExit += new CorProcessEventHandler(process_OnProcessExit);
            _process.OnBreakpoint += new BreakpointEventHandler(process_OnBreakpoint);
            _process.OnStepComplete += new StepCompleteEventHandler(_process_OnStepComplete);
            _process.OnModuleLoad += new CorModuleEventHandler(_process_OnModuleLoad);
            _process.OnDebuggerError += new DebuggerErrorEventHandler(_process_OnDebuggerError);
        }
Esempio n. 3
0
 public void Debug(int processID)
 {
     debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion());
     process = debugger.DebugActiveProcess(processID, false);
     process.OnException += OnException;
     process.OnCreateAppDomain += OnNewAppDomain;
     process.OnProcessExit += OnExit;
     process.OnModuleLoad += OnModuleLoad;
     process.OnBreakpoint += OnBreakpoint;
     process.OnStepComplete += OnStepComplete;
     process.Continue(false);
     state = ProcessState.Started;
     subscriber.Published(string.Format("Successfully attached to Process with ID [{0}]", processID));
 }
Esempio n. 4
0
 public ManagedCallback (CorDebugger outer)
 {
     m_outer = outer;
 }
		void OnProcessExit (object sender, CorProcessEventArgs e)
		{
			TargetEventArgs args = new TargetEventArgs (TargetEventType.TargetExited);

			// If the main thread stopped, terminate the debugger session
			if (e.Process.Id == process.Id) {
				lock (terminateLock) {
					process = null;
					ThreadPool.QueueUserWorkItem (delegate
					{
						// The Terminate call will fail if called in the event handler
						dbg.Terminate ();
						dbg = null;
						GC.Collect ();
					});
				}
			}

			OnTargetEvent (args);
		}
		protected override void OnRun (DebuggerStartInfo startInfo)
		{
			// Create the debugger

			string dversion;
			try {
				dversion = CorDebugger.GetDebuggerVersionFromFile (startInfo.Command);
			}
			catch {
				dversion = CorDebugger.GetDefaultDebuggerVersion ();
			}
			dbg = new CorDebugger (dversion);

			Dictionary<string, string> env = new Dictionary<string, string> ();
			foreach (DictionaryEntry de in Environment.GetEnvironmentVariables ())
				env[(string) de.Key] = (string) de.Value;

			foreach (KeyValuePair<string, string> var in startInfo.EnvironmentVariables)
				env[var.Key] = var.Value;

            // The second parameter of CreateProcess is the command line, and it includes the application being launched
            string cmdLine = "\"" + startInfo.Command + "\" " + startInfo.Arguments;

			int flags = 0;
			if (!startInfo.UseExternalConsole) {
				flags = 0x08000000; /* CREATE_NO_WINDOW*/
				flags |= CorDebugger.CREATE_REDIRECT_STD;
			}

			process = dbg.CreateProcess (startInfo.Command, cmdLine, startInfo.WorkingDirectory, env, flags);
			processId = process.Id;

			process.OnCreateProcess += new CorProcessEventHandler (OnCreateProcess);
			process.OnCreateAppDomain += new CorAppDomainEventHandler (OnCreateAppDomain);
			process.OnAssemblyLoad += new CorAssemblyEventHandler (OnAssemblyLoad);
			process.OnAssemblyUnload += new CorAssemblyEventHandler (OnAssemblyUnload);
			process.OnCreateThread += new CorThreadEventHandler (OnCreateThread);
			process.OnThreadExit += new CorThreadEventHandler (OnThreadExit);
			process.OnModuleLoad += new CorModuleEventHandler (OnModuleLoad);
			process.OnModuleUnload += new CorModuleEventHandler (OnModuleUnload);
			process.OnProcessExit += new CorProcessEventHandler (OnProcessExit);
			process.OnUpdateModuleSymbols += new UpdateModuleSymbolsEventHandler (OnUpdateModuleSymbols);
			process.OnDebuggerError += new DebuggerErrorEventHandler (OnDebuggerError);
			process.OnBreakpoint += new BreakpointEventHandler (OnBreakpoint);
			process.OnStepComplete += new StepCompleteEventHandler (OnStepComplete);
			process.OnBreak += new CorThreadEventHandler (OnBreak);
			process.OnNameChange += new CorThreadEventHandler (OnNameChange);
			process.OnEvalComplete += new EvalEventHandler (OnEvalComplete);
			process.OnEvalException += new EvalEventHandler (OnEvalException);
			process.OnLogMessage += new LogMessageEventHandler (OnLogMessage);
			process.OnStdOutput += new CorTargetOutputEventHandler (OnStdOutput);

			process.Continue (false);

			OnStarted ();
		}
Esempio n. 7
0
 //////////////////////////////////////////////////////////////////////////////////
 //
 // Controlling Commands
 //
 //////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// creates a new debugged process.
 /// </summary>
 /// <param name="commandLine">The command to run.</param>
 /// <param name="commandArguments">The arguments for the command.</param>
 /// <param name="debugMode">The debug mode to run with.</param>
 /// <param name="deeVersion">The version of debugging interfaces that should be used for
 ///   debugging of the started program. If this value is null, the default (latest) version
 ///   of interface is used.
 /// </param>
 /// <returns>The resulting MDbgProcess.</returns>
 public MDbgProcess CreateProcess(string commandLine, string commandArguments,
                                  DebugModeFlag debugMode, string deeVersion)
 {
     CorDebugger debugger;
     if (deeVersion == null)
     {
         debugger = new CorDebugger(CorDebugger.GetDefaultDebuggerVersion());
     }
     else
     {
         debugger = new CorDebugger(deeVersion);
     }
     MDbgProcess p = m_processMgr.CreateLocalProcess(debugger);
     p.DebugMode = debugMode;
     p.CreateProcess(commandLine, commandArguments);
     return p;
 }
        /// <summary>
        /// Refreshes the processes hash which stores info on all managed process running
        /// </summary>
        public void RefreshProcessList()
        {
            processes.Clear();

            foreach (var process in Process.GetProcesses())
            {
                if (Process.GetCurrentProcess().Id == process.Id)
                {
                    // let's hide our process
                    continue;
                }

                // list the loaded runtimes in each process, if the ClrMetaHost APIs are available
                CLRMetaHost mh;
                try
                {
                    mh = new CLRMetaHost();
                }
                catch (Exception)
                {
                    continue;
                }

                IEnumerable<CLRRuntimeInfo> runtimes;
                try
                {
                    runtimes = mh.EnumerateLoadedRuntimes(process.Id);
                }
                catch (Exception)
                {
                    continue;
                }

                // TODO: only one CLR version for now...
                if (runtimes.Any())
                {
                    var version = MdbgVersionPolicy.GetDefaultAttachVersion(process.Id);
                    var debugger = new CorDebugger(version);
                    processes[process.Id] = new ProcessInfo(process, debugger);
                }
            }
        }
Esempio n. 9
0
 static private MDbgProcess GetProcessFromCordb(ICorDebug cordbg)
 {
     Debugger.Processes.FreeStaleUnmanagedResources();
     CorDebugger cordebugger = new CorDebugger(cordbg);
     Debugger.Processes.RegisterDebuggerForCleanup(cordebugger);
     return new MDbgProcess(Debugger, cordebugger);
 }
		public override void Dispose ( )
		{
			if (dbg != null && !terminated) {
				// The Terminate call will fail if this Dispose is being called from the handler
				// of a debugger event. Just in case, we run it in a separate thread.
				CorDebugger dd = dbg;
				ThreadPool.QueueUserWorkItem (delegate {
					if (!terminated)
						dd.Terminate ();
				});
			}
			base.Dispose ();

			// There is no explicit way of disposing the metadata objects, so we have
			// to rely on the GC to do it.

			modules = null;
			documents = null;
			threads = null;
			process = null;
			processes = null;
			dbg = null;
			activeThread = null;
			GC.Collect ();
		}
Esempio n. 11
0
        /// <summary>Creates an empty process object.
        /// This object can be used to start a debugging session by calling
        /// CreateProcess or Attach method on it.
        /// </summary>
        /// <param name="engine">Root engine object that manages this process.</param>
        /// <param name="debugger">CorDebugger object that will be used to do an actual
        /// debugging</param>
        public MDbgProcess(MDbgEngine engine, CorDebugger debugger)
        {
            Debug.Assert(debugger != null);
            if (debugger == null)
                throw new ArgumentNullException("debugger");

            m_corDebugger = debugger;

            CommonInit(engine);
        }
Esempio n. 12
0
 /// <summary>
 /// Adds the specified CorDebugger object to the cleanup list
 /// </summary>
 /// <param name="debugger"></param>
 public void RegisterDebuggerForCleanup(CorDebugger debugger)
 {
     if (null == debugger)
         throw new ArgumentNullException();
     lock (m_CleanupList)
     {
         m_CleanupList.Add(debugger, false);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Creates a new process which can be debugged using the given ICorDebug instance
        /// </summary>
        /// <param name="debugger">CorDebugger to use for the process</param>
        /// <returns>The Process that got created.</returns>
        public MDbgProcess CreateLocalProcess(CorDebugger debugger)
        {
            Debug.Assert(debugger != null);

            // This is called on the Main thread so it's safe to flush
            FreeStaleUnmanagedResources();
            RegisterDebuggerForCleanup(debugger);
            return new MDbgProcess(m_engine, debugger);
        }