Пример #1
0
		void EnterCallback(PausedReason pausedReason, string name, ICorDebugProcess pProcess)
		{
			isInCallback = true;
			
			process.TraceMessage("Callback: " + name);
			System.Diagnostics.Debug.Assert(process.CorProcess == pProcess);
			
			// After break is pressed we may receive some messages that were already queued
			if (process.IsPaused && process.PauseSession.PausedReason == PausedReason.ForcedBreak) {
				// TODO: This does not work well if exception if being processed and the user continues it
				process.TraceMessage("Processing post-break callback");
				// This compensates for the break call and we are in normal callback handling mode
				process.AsyncContinue(DebuggeeStateAction.Keep, new Thread[] {}, null);
				// Start of call back - create new pause session (as usual)
				process.NotifyPaused(pausedReason);
				// Make sure we stay pause after the callback is handled
				pauseOnNextExit = true;
				return;
			}
			
			if (process.IsRunning) {
				process.NotifyPaused(pausedReason);
				return;
			}
			
			throw new DebuggerException("Invalid state at the start of callback");
		}
Пример #2
0
        internal DebugProcess(DebugContext context, ICorDebugProcess process)
        {
            this.context = context;
            this.process = process;

            this.Process = Process.GetProcessById(process.GetID());
        }
Пример #3
0
		void EnterCallback(string name, ICorDebugProcess pProcess)
		{
			isInCallback = true;
			
			process.TraceMessage("Callback: " + name);
			System.Diagnostics.Debug.Assert(process.CorProcess == pProcess);
			
			// After break is pressed we may receive some messages that were already queued
			if (process.IsPaused) {
				process.TraceMessage("Processing post-break callback");
				// Decrese the "break count" from 2 to 1 - does not actually continue
				// TODO: This inccorectly marks the debugger as running
				process.AsyncContinue(DebuggeeStateAction.Keep);
				// Make sure we stay paused after the callback is handled
				pauseOnNextExit = true;
				return;
			}
			
			if (process.IsRunning) {
				process.NotifyPaused();
				return;
			}
			
			throw new DebuggerException("Invalid state at the start of callback");
		}
Пример #4
0
		public ManagedCallback GetProcessCallbackInterface(string name, ICorDebugProcess pProcess)
		{
			Process process;
			// We have to wait until the created process is added into the collection
			lock(debugger.ProcessIsBeingCreatedLock) {
				process = debugger.GetProcess(pProcess);
			}
			// Make *really* sure the process is not dead
			if (process == null) {
				debugger.TraceMessage("Ignoring callback \"" + name + "\": Process not found");
				return null;
			}
			if (process.HasExited) {
				debugger.TraceMessage("Ignoring callback \"" + name + "\": Process has exited");
				return null;
			}
			if (process.TerminateCommandIssued && !(name == "ExitProcess")) {
				debugger.TraceMessage("Ignoring callback \"" + name + "\": Terminate command was issued for the process");
				return null;
			}
			// Check that the process is not exited
			try {
				int isRunning = process.CorProcess.IsRunning();
			} catch (COMException e) {
				process.TraceMessage("Ignoring callback \"" + name + "\": " + e.Message);
				return null;
			}
			return process.CallbackInterface;
		}
Пример #5
0
 internal DnProcess(DnDebugger ownerDebugger, ICorDebugProcess process, int incrementedId)
 {
     this.ownerDebugger = ownerDebugger;
     this.appDomains = new DebuggerCollection<ICorDebugAppDomain, DnAppDomain>(CreateAppDomain);
     this.threads = new DebuggerCollection<ICorDebugThread, DnThread>(CreateThread);
     this.process = new CorProcess(process);
     this.incrementedId = incrementedId;
 }
Пример #6
0
		internal Process GetProcess(ICorDebugProcess corProcess) {
			foreach (Process process in this.Processes) {
				if (process.CorProcess == corProcess) {
					return process;
				}
			}
			return null;
		}
Пример #7
0
 public void Detach(ICorDebugProcess process)
 {
     if (this.runningProcesses.Remove(process))
     {
         process.Stop(Constants.Infinite);
         process.Detach();
     }
 }
Пример #8
0
        public void CreateAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
        {
            var domain = new DebugDomain(null, pAppDomain);
            Logger.WriteLine("App domain {0} created", domain.Name);

            pAppDomain.Attach();

            pProcess.Continue(0);
        }
Пример #9
0
 //
 // IEnumerator interface
 //
 public bool MoveNext()
 {
     ICorDebugProcess[] a = new ICorDebugProcess[1];
     uint c = 0;
     int r = m_enum.Next ((uint) a.Length, a, out c);
     if (r==0 && c==1) // S_OK && we got 1 new element
         m_proc =  CorProcess.GetCorProcess(a[0]);
     else
         m_proc = null;
     return m_proc != null;
 }
Пример #10
0
        internal Process(NDebugger debugger, ICorDebugProcess corProcess, string workingDirectory)
        {
            this.debugger = debugger;
            this.corProcess = corProcess;
            this.workingDirectory = workingDirectory;

            this.callbackInterface = new ManagedCallback(this);

            activeEvals = new EvalCollection(debugger);
            modules = new ModuleCollection(debugger);
            modules.Added += OnModulesAdded;
            threads = new ThreadCollection(debugger);
            appDomains = new AppDomainCollection(debugger);
        }
 public static CorProcess GetCorProcess(ICorDebugProcess process)
 {
     Debug.Assert(process != null);
     lock (m_instances)
     {
         if (!m_instances.Contains(process))
         {
             CorProcess p = new CorProcess(process);
             m_instances.Add(process, p);
             return p;
         }
         return (CorProcess)m_instances[process];
     }
 }
Пример #12
0
        int ICorDebug.GetProcess(uint dwProcessId, out ICorDebugProcess ppProcess)
        {
            ppProcess = null;

            foreach (CorDebugProcess process in m_processes)
            {
                uint id = process.PhysicalProcessId.dwProcessId;

                if (dwProcessId == id)
                {
                    ppProcess = process;
                    break;
                }
            }

            return Utility.COM_HResults.BOOL_TO_HRESULT_FAIL( ppProcess != null ); /*better failure?*/
        }
Пример #13
0
		// API for this class
		public void Attach(uint processId)
		{
			if (_debug == null)
				Init();
			_activeProcess = _debug.DebugActiveProcess(processId, 0);
			ICorDebugThreadEnum threads = 
				_activeProcess.EnumerateThreads();
			uint count = 0;
			//threads.GetCount(out count);
			count = threads.GetCount();
			Console.WriteLine("thread count: " + count);
			/*
			Type type = threads.GetType();
			MethodInfo mi = type.GetMethod("GetCount");
			count = (uint)mi.Invoke(threads, new Object[] { });
			Console.WriteLine("thread count: " + count);
			*/
		}
Пример #14
0
 public ExitProcessDebugCallbackEventArgs(ICorDebugProcess pProcess)
     : base(pProcess)
 {
 }
Пример #15
0
 public DnAppDomain TryGetValidAppDomain(ICorDebugProcess comProcess, ICorDebugAppDomain comAppDomain)
 {
     DebugVerifyThread();
     var process = TryGetValidProcess(comProcess);
     if (process == null)
         return null;
     return process.TryGetValidAppDomain(comAppDomain);
 }
Пример #16
0
        void InitializeCurrentDebuggerState(DebugCallbackEventArgs e, ICorDebugProcess comProcess, ICorDebugAppDomain comAppDomain, ICorDebugThread comThread)
        {
            if (comThread != null) {
                if (comProcess == null)
                    comThread.GetProcess(out comProcess);
                if (comAppDomain == null)
                    comThread.GetAppDomain(out comAppDomain);
            }

            if (comAppDomain != null) {
                if (comProcess == null)
                    comAppDomain.GetProcess(out comProcess);
            }

            var process = TryGetValidProcess(comProcess);
            DnAppDomain appDomain;
            DnThread thread;
            if (process != null) {
                appDomain = process.TryGetAppDomain(comAppDomain);
                thread = process.TryGetThread(comThread);
            }
            else {
                appDomain = null;
                thread = null;
            }

            if (thread == null && appDomain == null && process != null)
                appDomain = process.AppDomains.FirstOrDefault();
            if (thread == null) {
                if (appDomain != null)
                    thread = appDomain.Threads.FirstOrDefault();
                else if (process != null)
                    thread = process.Threads.FirstOrDefault();
            }

            if (process == null)
                SetDefaultCurrentProcess(e);
            else
                AddDebuggerState(new DebuggerState(e, process, appDomain, thread));
        }
 public virtual extern void GetProcess([In] uint dwProcessId, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);
Пример #18
0
		public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, IntPtr pConnName)
		{
			EnterCallback("CreateConnection", pProcess);
			
			ExitCallback();
		}
Пример #19
0
 protected AppDomainDebugCallbackEventArgs(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
     : base(pProcess)
 {
     this.Process   = pProcess;
     this.AppDomain = pAppDomain;
 }
Пример #20
0
 public DestroyConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId)
     : base(pProcess, dwConnectionId)
 {
 }
Пример #21
0
 public void ExitProcess(ICorDebugProcess pProcess)
 {
     Console.WriteLine("ExitProcess");
     pProcess.Continue(0);
 }
Пример #22
0
 public void CreateProcess(ICorDebugProcess pProcess)
 {
     Console.WriteLine("CreateProcess");
     pProcess.Continue(0);
 }
Пример #23
0
 public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId)
 {
     Console.WriteLine("DestroyConnection");
     pProcess.Continue(0);
 }
Пример #24
0
 public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, ref ushort pConnName)
 {
     Console.WriteLine("CreateConnection");
     pProcess.Continue(0);
 }
Пример #25
0
 public void ControlCTrap(ICorDebugProcess pProcess)
 {
     Console.WriteLine("ControlCTrap");
     pProcess.Continue(0);
 }
Пример #26
0
 public void ExitAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
 {
     Console.WriteLine("ExitAppDomain");
     pAppDomain.Continue(0);
 }
Пример #27
0
 void ICorDebugManagedCallback2.ChangeConnection(ICorDebugProcess process, uint connectionId)
 {
     Debug.Assert(false);
 }
Пример #28
0
 void ICorDebugManagedCallback.ExitProcess(
                          ICorDebugProcess process)
 {
     HandleEvent(ManagedCallbackType.OnProcessExit,
                        new CorProcessEventArgs(process == null ? null : CorProcess.GetCorProcess(process),
                                                 ManagedCallbackType.OnProcessExit));
 }
Пример #29
0
 public void DebuggerError(ICorDebugProcess pProcess, int errorHR, uint errorCode)
 {
     Console.WriteLine("DebuggerError");
     pProcess.Continue(0);
 }
Пример #30
0
 public ExitAppDomainDebugCallbackEventArgs(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain)
     : base(pProcess, pAppDomain)
 {
 }
Пример #31
0
 protected ConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId)
     : base(pProcess)
 {
     this.Process = pProcess;
     this.Id      = dwConnectionId;
 }
Пример #32
0
		public void ChangeConnection(ICorDebugProcess pProcess, uint dwConnectionId)
		{
			EnterCallback("ChangeConnection", pProcess);
			
			ExitCallback();
		}
Пример #33
0
 public ProcessExitedEventArgs(
     ICorDebugProcess process)
 {
     Process = process;
 }
Пример #34
0
		public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId)
		{
			EnterCallback("DestroyConnection", pProcess);
			
			ExitCallback();
		}
Пример #35
0
 void ICorDebugManagedCallback2.CreateConnection(ICorDebugProcess process, uint connectionId, ref ushort connectionName)
 {
     // Not Implemented
     Debug.Assert(false);
 }
Пример #36
0
 DnProcess CreateDnProcess(ICorDebugProcess comProcess, int id)
 {
     return new DnProcess(this, comProcess, id);
 }
 public virtual extern void DebugActiveProcess([In] uint id, [In] int win32Attach, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);
Пример #38
0
        DnProcess TryAdd(ICorDebugProcess comProcess)
        {
            if (comProcess == null)
                return null;

            // This method is called twice, once from DebugProcess() and once from the CreateProcess
            // handler. It's possible that it's been terminated before DebugProcess() calls this method.

            // Check if it's terminated. Error should be 0x8013134F: CORDBG_E_OBJECT_NEUTERED
            int running;
            if (comProcess.IsRunning(out running) < 0)
                return null;

            return processes.Add(comProcess);
        }
Пример #39
0
 void ICorDebugManagedCallback.ExitAppDomain(
                            ICorDebugProcess process,
                            ICorDebugAppDomain appDomain)
 {
     HandleEvent(ManagedCallbackType.OnAppDomainExit,
                       new CorAppDomainEventArgs( process == null ? null : CorProcess.GetCorProcess(process),
                                                  appDomain == null ? null : new CorAppDomain(appDomain),
                                                  ManagedCallbackType.OnAppDomainExit));
 }
Пример #40
0
 /// <summary>
 /// Gets a process or null if it has exited
 /// </summary>
 /// <param name="comProcess">Process</param>
 /// <returns></returns>
 public DnProcess TryGetValidProcess(ICorDebugProcess comProcess)
 {
     DebugVerifyThread();
     var process = processes.TryGet(comProcess);
     if (process == null)
         return null;
     if (!process.CheckValid())
         return null;
     return process;
 }
Пример #41
0
 public CreateProcessDebugCallbackEventArgs(ICorDebugProcess pProcess)
     : base(pProcess)
 {
 }
 private CorProcess(ICorDebugProcess process)
     : base(process)
 {
 }
Пример #43
0
 public ControlCTrapDebugCallbackEventArgs(ICorDebugProcess pProcess)
     : base(pProcess)
 {
     this.Process = pProcess;
 }
Пример #44
0
 void ICorDebugManagedCallback.CreateProcess(
                            ICorDebugProcess process)
 {
     HandleEvent(ManagedCallbackType.OnCreateProcess,
                       new CorProcessEventArgs( process == null ? null : CorProcess.GetCorProcess(process),
                                                ManagedCallbackType.OnCreateProcess));
 }
Пример #45
0
        int ICorDebugAppDomain.GetProcess(out ICorDebugProcess ppProcess)
        {
            ppProcess = this.Process;

            return(Utility.COM_HResults.S_OK);
        }
Пример #46
0
 void ICorDebugManagedCallback.DebuggerError(
                            ICorDebugProcess process,
                            int errorHR,
                            uint errorCode)
 {
     HandleEvent(ManagedCallbackType.OnDebuggerError,
                       new CorDebuggerErrorEventArgs( process == null ? null : CorProcess.GetCorProcess(process),
                                                      errorHR,
                                                      (int)errorCode,
                                                      ManagedCallbackType.OnDebuggerError));
 }
Пример #47
0
 public CreateConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId, string pConnName)
     : base(pProcess, dwConnectionId)
 {
     this.Name = pConnName;
 }
Пример #48
0
 void ICorDebugManagedCallback.ControlCTrap(ICorDebugProcess process)
 {
     HandleEvent(ManagedCallbackType.OnControlCTrap,
                       new CorProcessEventArgs( process == null ? null : CorProcess.GetCorProcess(process),
                                                ManagedCallbackType.OnControlCTrap));
 }
Пример #49
0
 protected ProcessDebugCallbackEventArgs(ICorDebugProcess pProcess)
     : base(pProcess)
 {
     this.Process = pProcess;
 }
Пример #50
0
 void ICorDebugManagedCallback2.DestroyConnection(ICorDebugProcess process, uint connectionId)
 {
     // Not Implemented
     Debug.Assert(false);
 }
 //public virtual extern void CreateProcess([In, MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, [In] ref _SECURITY_ATTRIBUTES lpProcessAttributes, [In] ref _SECURITY_ATTRIBUTES lpThreadAttributes, [In] int bInheritHandles, [In] uint dwCreationFlags, [In] IntPtr lpEnvironment, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory, [In, ComAliasName("Debugger.Interop.CorDebug.ULONG_PTR")] uint lpStartupInfo, [In, ComAliasName("Debugger.Interop.CorDebug.ULONG_PTR")] uint lpProcessInformation, [In] CorDebugCreateProcessFlags debuggingFlags, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);
 public virtual extern void CreateProcess([In, MarshalAs(UnmanagedType.LPWStr)] string lpApplicationName, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCommandLine, [In] ref _SECURITY_ATTRIBUTES lpProcessAttributes, [In] ref _SECURITY_ATTRIBUTES lpThreadAttributes, [In] int bInheritHandles, [In] uint dwCreationFlags, [In] IntPtr lpEnvironment, [In, MarshalAs(UnmanagedType.LPWStr)] string lpCurrentDirectory, STARTUPINFO lpStartupInfo, [In, ComAliasName("Debugger.Interop.CorDebug.ULONG_PTR")] uint lpProcessInformation, [In] CorDebugCreateProcessFlags debuggingFlags, [MarshalAs(UnmanagedType.Interface)] out ICorDebugProcess ppProcess);