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"); }
internal DebugProcess(DebugContext context, ICorDebugProcess process) { this.context = context; this.process = process; this.Process = Process.GetProcessById(process.GetID()); }
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"); }
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; }
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; }
internal Process GetProcess(ICorDebugProcess corProcess) { foreach (Process process in this.Processes) { if (process.CorProcess == corProcess) { return process; } } return null; }
public void Detach(ICorDebugProcess process) { if (this.runningProcesses.Remove(process)) { process.Stop(Constants.Infinite); process.Detach(); } }
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); }
// // 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; }
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]; } }
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?*/ }
// 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); */ }
public ExitProcessDebugCallbackEventArgs(ICorDebugProcess pProcess) : base(pProcess) { }
public DnAppDomain TryGetValidAppDomain(ICorDebugProcess comProcess, ICorDebugAppDomain comAppDomain) { DebugVerifyThread(); var process = TryGetValidProcess(comProcess); if (process == null) return null; return process.TryGetValidAppDomain(comAppDomain); }
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);
public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, IntPtr pConnName) { EnterCallback("CreateConnection", pProcess); ExitCallback(); }
protected AppDomainDebugCallbackEventArgs(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain) : base(pProcess) { this.Process = pProcess; this.AppDomain = pAppDomain; }
public DestroyConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId) : base(pProcess, dwConnectionId) { }
public void ExitProcess(ICorDebugProcess pProcess) { Console.WriteLine("ExitProcess"); pProcess.Continue(0); }
public void CreateProcess(ICorDebugProcess pProcess) { Console.WriteLine("CreateProcess"); pProcess.Continue(0); }
public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId) { Console.WriteLine("DestroyConnection"); pProcess.Continue(0); }
public void CreateConnection(ICorDebugProcess pProcess, uint dwConnectionId, ref ushort pConnName) { Console.WriteLine("CreateConnection"); pProcess.Continue(0); }
public void ControlCTrap(ICorDebugProcess pProcess) { Console.WriteLine("ControlCTrap"); pProcess.Continue(0); }
public void ExitAppDomain(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain) { Console.WriteLine("ExitAppDomain"); pAppDomain.Continue(0); }
void ICorDebugManagedCallback2.ChangeConnection(ICorDebugProcess process, uint connectionId) { Debug.Assert(false); }
void ICorDebugManagedCallback.ExitProcess( ICorDebugProcess process) { HandleEvent(ManagedCallbackType.OnProcessExit, new CorProcessEventArgs(process == null ? null : CorProcess.GetCorProcess(process), ManagedCallbackType.OnProcessExit)); }
public void DebuggerError(ICorDebugProcess pProcess, int errorHR, uint errorCode) { Console.WriteLine("DebuggerError"); pProcess.Continue(0); }
public ExitAppDomainDebugCallbackEventArgs(ICorDebugProcess pProcess, ICorDebugAppDomain pAppDomain) : base(pProcess, pAppDomain) { }
protected ConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId) : base(pProcess) { this.Process = pProcess; this.Id = dwConnectionId; }
public void ChangeConnection(ICorDebugProcess pProcess, uint dwConnectionId) { EnterCallback("ChangeConnection", pProcess); ExitCallback(); }
public ProcessExitedEventArgs( ICorDebugProcess process) { Process = process; }
public void DestroyConnection(ICorDebugProcess pProcess, uint dwConnectionId) { EnterCallback("DestroyConnection", pProcess); ExitCallback(); }
void ICorDebugManagedCallback2.CreateConnection(ICorDebugProcess process, uint connectionId, ref ushort connectionName) { // Not Implemented Debug.Assert(false); }
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);
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); }
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)); }
/// <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; }
public CreateProcessDebugCallbackEventArgs(ICorDebugProcess pProcess) : base(pProcess) { }
private CorProcess(ICorDebugProcess process) : base(process) { }
public ControlCTrapDebugCallbackEventArgs(ICorDebugProcess pProcess) : base(pProcess) { this.Process = pProcess; }
void ICorDebugManagedCallback.CreateProcess( ICorDebugProcess process) { HandleEvent(ManagedCallbackType.OnCreateProcess, new CorProcessEventArgs( process == null ? null : CorProcess.GetCorProcess(process), ManagedCallbackType.OnCreateProcess)); }
int ICorDebugAppDomain.GetProcess(out ICorDebugProcess ppProcess) { ppProcess = this.Process; return(Utility.COM_HResults.S_OK); }
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)); }
public CreateConnectionDebugCallbackEventArgs(ICorDebugProcess pProcess, uint dwConnectionId, string pConnName) : base(pProcess, dwConnectionId) { this.Name = pConnName; }
void ICorDebugManagedCallback.ControlCTrap(ICorDebugProcess process) { HandleEvent(ManagedCallbackType.OnControlCTrap, new CorProcessEventArgs( process == null ? null : CorProcess.GetCorProcess(process), ManagedCallbackType.OnControlCTrap)); }
protected ProcessDebugCallbackEventArgs(ICorDebugProcess pProcess) : base(pProcess) { this.Process = pProcess; }
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);