public void Detach() { if (IsRunning) { corProcess.Stop(uint.MaxValue); NotifyPaused(PausedReason.ForcedBreak); } // This is necessary for detach foreach (Stepper s in this.Steppers) { if (s.CorStepper.IsActive() == 1) { s.CorStepper.Deactivate(); } } this.Steppers.Clear(); corProcess.Detach(); // modules foreach (Module m in this.Modules) { m.Dispose(); } this.modules.Clear(); // threads this.threads.Clear(); NotifyHasExited(); }
public void Detach(ICorDebugProcess process) { if (this.runningProcesses.Remove(process)) { process.Stop(Constants.Infinite); process.Detach(); } }
private void DebuggerThread() { Console.WriteLine($"Attaching to {_process.ProcessName}, pid: {_process.Id}"); var metahost = CorDebugHelper.GetClrMetaHost(); var runtimes = metahost.EnumerateLoadedRuntimes(_process.Handle); string version = null; ICorDebug corDebug = null; while (runtimes.Next(1, out var rgelt, IntPtr.Zero) == 0) { var runtimeInfo = (ICLRRuntimeInfo)rgelt; var pwzBuffer = new StringBuilder(30); int capacity = pwzBuffer.Capacity; runtimeInfo.GetVersionString(pwzBuffer, ref capacity); version = pwzBuffer.ToString(); var riid = typeof(ICorDebug).GUID; var rclsid = typeof(ClrDebuggingLegacy).GUID; corDebug = (ICorDebug)runtimeInfo.GetInterface(ref rclsid, ref riid); } if (corDebug == null) { throw new Exception("error: cannot take corDebug"); } Console.WriteLine($"info: runtime: {version}"); corDebug.Initialize(); corDebug.SetManagedHandler(_debuggerCallbacks); corDebug.SetUnmanagedHandler(_debuggerCallbacks); corDebug.DebugActiveProcess((uint)_process.Id, 0, out _debugger); while (_debuggingActive) { Thread.Sleep(WAIT_INTERVAL); } if (!_process.HasExited) { _debugger.Stop(WAIT_INTERVAL); _debugger.Detach(); } }
public void Detach() { if (IsRunning) { corProcess.Stop(uint.MaxValue); NotifyPaused(); } // Deactivate breakpoints foreach (Breakpoint b in this.Debugger.Breakpoints) { b.IsEnabled = false; } // This is necessary for detach foreach (Stepper s in this.Steppers) { if (s.CorStepper.IsActive() == 1) { s.CorStepper.Deactivate(); } } this.Steppers.Clear(); corProcess.Detach(); // modules foreach (Module m in this.Modules) { m.Dispose(); } this.modules.Clear(); // threads this.threads.Clear(); OnExited(); }