diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/AttachToProcessForm.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/AttachToProcessForm.cs index a0d7aa3640..964f35eb3d 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/AttachToProcessForm.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/AttachToProcessForm.cs @@ -57,6 +57,7 @@ namespace ICSharpCode.SharpDevelop.Services Process currentProcess = Process.GetCurrentProcess(); foreach (Process process in Process.GetProcesses()) { try { + if (process.HasExited) continue; // Prevent attaching to our own process. if (currentProcess.Id != process.Id) { ProcessListViewItem item = new ProcessListViewItem(process, debugger); diff --git a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs index 5e62a70437..bf7c9a2dca 100644 --- a/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs +++ b/src/AddIns/Debugger/Debugger.AddIn/Service/WindowsDebugger.cs @@ -13,6 +13,7 @@ using System.Windows.Forms; using Debugger; using Debugger.AddIn; using Debugger.AddIn.TreeModel; +using Debugger.Interop; using Debugger.Interop.CorPublish; using ICSharpCode.Core; using ICSharpCode.Core.WinForms; @@ -362,10 +363,8 @@ namespace ICSharpCode.SharpDevelop.Services public bool IsManaged(int processId) { - if (corPublish == null) { - corPublish = new CorpubPublishClass(); - Debugger.Interop.TrackedComObjects.Track(corPublish); - } + corPublish = new CorpubPublishClass(); + Debugger.Interop.TrackedComObjects.Track(corPublish); ICorPublishProcess process = corPublish.GetProcess((uint)processId); if (process != null) { diff --git a/src/AddIns/Debugger/Debugger.Core/NDebugger.cs b/src/AddIns/Debugger/Debugger.Core/NDebugger.cs index 88f46150f6..61ecb39eb5 100644 --- a/src/AddIns/Debugger/Debugger.Core/NDebugger.cs +++ b/src/AddIns/Debugger/Debugger.Core/NDebugger.cs @@ -212,8 +212,10 @@ namespace Debugger } // Detach all processes. - while (this.Processes.Count > 0) { - Process process = this.Processes[0]; + for (int i = 0; i < this.Processes.Count; ++i) { + Process process = this.Processes[i]; + if (process == null || process.HasExited) + continue; process.Detach(); } } diff --git a/src/AddIns/Debugger/Debugger.Core/Process.cs b/src/AddIns/Debugger/Debugger.Core/Process.cs index ae2bf8a526..8616e618e1 100644 --- a/src/AddIns/Debugger/Debugger.Core/Process.cs +++ b/src/AddIns/Debugger/Debugger.Core/Process.cs @@ -3,10 +3,12 @@ using System; using System.Collections.Generic; +using System.Runtime.InteropServices; + +using Debugger.Interop; using Debugger.Interop.CorDebug; using ICSharpCode.NRefactory.Ast; using ICSharpCode.NRefactory.Visitors; -using System.Runtime.InteropServices; namespace Debugger { @@ -400,6 +402,7 @@ namespace Debugger corProcess.Stop(uint.MaxValue); NotifyPaused(PausedReason.ForcedBreak); } + // This is necessary for detach foreach(Stepper s in this.Steppers) { if (s.CorStepper.IsActive() == 1) { @@ -407,8 +410,21 @@ namespace Debugger } } this.Steppers.Clear(); + corProcess.Detach(); - NotifyHasExited(); + + // modules + foreach(Module m in this.Modules) + { + m.Dispose(); + } + + this.modules.Clear(); + + // threads + this.threads.Clear(); + + NotifyHasExited(); } public void Continue()