From 65171699b3763e81750f21bb23a1b0e9b67eba4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Mon, 18 Jul 2005 07:14:53 +0000 Subject: [PATCH] Added Process collection git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@202 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Service/WindowsDebugger.cs | 17 ++--- .../Project/Debugger.Core.csproj | 2 + .../Src/Debugger/Internal/ManagedCallback.cs | 14 +++- .../Project/Src/Debugger/NDebugger.cs | 56 +++------------ .../Src/Threads/NDebugger-Processes.cs | 71 +++++++++++++++++++ .../Project/Src/Threads/Process.cs | 2 +- .../Src/Threads/ProcessEventHandler.cs | 27 +++++++ 7 files changed, 131 insertions(+), 58 deletions(-) create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs create mode 100644 src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ProcessEventHandler.cs diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs index 1151083f51..81cef5984c 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs @@ -172,10 +172,10 @@ namespace ICSharpCode.SharpDevelop.Services debugger.DebuggerTraceMessage += new MessageEventHandler(DebuggerTraceMessage); debugger.LogMessage += new MessageEventHandler(LogMessage); - debugger.DebuggingStarted += new DebuggerEventHandler(DebuggingStarted); + debugger.ProcessStarted += new ProcessEventHandler(ProcessStarted); debugger.DebuggingPaused += new DebuggingPausedEventHandler(DebuggingPaused); debugger.DebuggingResumed += new DebuggerEventHandler(DebuggingResumed); - debugger.DebuggingStopped += new DebuggerEventHandler(DebuggingStopped); + debugger.ProcessExited += new ProcessEventHandler(ProcessExited); debugger.IsDebuggingChanged += new DebuggerEventHandler(OnIsDebuggingChanged); debugger.IsProcessRunningChanged += new DebuggerEventHandler(DebuggerStateChanged); debugger.BreakpointStateChanged += new DebuggerLibrary.BreakpointEventHandler(RestoreSharpdevelopBreakpoint); @@ -200,10 +200,10 @@ namespace ICSharpCode.SharpDevelop.Services { debugger.DebuggerTraceMessage -= new MessageEventHandler(DebuggerTraceMessage); debugger.LogMessage -= new MessageEventHandler(LogMessage); - debugger.DebuggingStarted -= new DebuggerEventHandler(DebuggingStarted); + debugger.ProcessStarted -= new ProcessEventHandler(ProcessStarted); debugger.DebuggingPaused -= new DebuggingPausedEventHandler(DebuggingPaused); debugger.DebuggingResumed -= new DebuggerEventHandler(DebuggingResumed); - debugger.DebuggingStopped -= new DebuggerEventHandler(DebuggingStopped); + debugger.ProcessExited -= new ProcessEventHandler(ProcessExited); debugger.IsDebuggingChanged -= new DebuggerEventHandler(OnIsDebuggingChanged); debugger.IsProcessRunningChanged -= new DebuggerEventHandler(DebuggerStateChanged); debugger.BreakpointStateChanged -= new DebuggerLibrary.BreakpointEventHandler(RestoreSharpdevelopBreakpoint); @@ -332,7 +332,7 @@ namespace ICSharpCode.SharpDevelop.Services } } - void DebuggingStarted(object sender, DebuggerEventArgs e) + void ProcessStarted(object sender, ProcessEventArgs e) { // Initialize /*PadDescriptor cmv = (CompilerMessageView)WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)); @@ -387,10 +387,11 @@ namespace ICSharpCode.SharpDevelop.Services DebuggerService.RemoveCurrentLineMarker(); } - void DebuggingStopped(object sender, DebuggerEventArgs e) + void ProcessExited(object sender, ProcessEventArgs e) { - exceptionHistory.Clear(); - //DebuggerService.Stop();//TODO: delete + if (debugger.Processes.Count == 0) { + exceptionHistory.Clear(); + } } public void JumpToCurrentLine() diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj index 2ff00fd2e5..c786eff614 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -73,8 +73,10 @@ + + diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs index 033db53d6b..177b8fe650 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Internal/ManagedCallback.cs @@ -300,8 +300,9 @@ namespace DebuggerLibrary Thread thread = debugger.GetThread(pThread); - if (debugger.CurrentThread == thread) + if (debugger.CurrentThread == thread) { debugger.CurrentThread = null; + } debugger.RemoveThread(thread); @@ -319,8 +320,17 @@ namespace DebuggerLibrary { EnterCallback("ExitProcess"); - debugger.ResetEnvironment(); + Process process = debugger.GetProcess(pProcess); + + if (debugger.CurrentProcess == process) { + debugger.CurrentProcess = null; + } + debugger.RemoveProcess(process); + + if (debugger.Processes.Count == 0) { + debugger.ResetEnvironment(); + } } #endregion diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs index 1a877ee769..fdfc5b59a5 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger.cs @@ -11,6 +11,7 @@ using System.Threading; using DebuggerInterop.Core; using DebuggerInterop.MetaData; +using System.Collections.Generic; namespace DebuggerLibrary { @@ -19,8 +20,6 @@ namespace DebuggerLibrary ICorDebug corDebug; ManagedCallback managedCallback; ManagedCallbackProxy managedCallbackProxy; - - Process mainProcess; public bool CatchHandledExceptions = false; @@ -46,27 +45,6 @@ namespace DebuggerLibrary } } - internal Process CurrentProcess { - get { - return mainProcess; - } - set { - if (mainProcess == value) return; - - mainProcess = value; - if (value != null) { - OnDebuggingStarted(); - OnIsDebuggingChanged(); - OnIsProcessRunningChanged(); - } else { - //OnDebuggingPaused(PausedReason.ProcessExited); - OnIsProcessRunningChanged(); - OnDebuggingStopped(); - OnIsDebuggingChanged(); - } - } - } - internal ManagedCallback ManagedCallback { get { return managedCallback; @@ -114,8 +92,11 @@ namespace DebuggerLibrary ResetBreakpoints(); ClearThreads(); + + OnIsProcessRunningChanged(); + OnIsDebuggingChanged(); - CurrentProcess = null; + currentProcess = null; evalQueue = new EvalQueue(); @@ -128,17 +109,6 @@ namespace DebuggerLibrary #region Public events - public event DebuggerEventHandler DebuggingStarted; - - protected internal virtual void OnDebuggingStarted() - { - TraceMessage ("Debugger event: OnDebuggingStarted()"); - if (DebuggingStarted != null) { - DebuggingStarted(null, new DebuggerEventArgs()); - } - } - - public event DebuggingPausedEventHandler DebuggingPaused; protected internal virtual void OnDebuggingPaused(PausedReason reason) @@ -183,17 +153,6 @@ namespace DebuggerLibrary } - public event DebuggerEventHandler DebuggingStopped; - - protected internal virtual void OnDebuggingStopped() - { - TraceMessage ("Debugger event: OnDebuggingStopped()"); - if (DebuggingStopped != null) { - DebuggingStopped(null, new DebuggerEventArgs()); - } - } - - public event DebuggerEventHandler IsProcessRunningChanged; protected internal virtual void OnIsProcessRunningChanged() @@ -267,7 +226,10 @@ namespace DebuggerLibrary public void Start(string filename, string workingDirectory, string arguments) { - CurrentProcess = Process.CreateProcess(this, filename, workingDirectory, arguments); + Process process = Process.CreateProcess(this, filename, workingDirectory, arguments); + AddProcess(process); + OnIsDebuggingChanged(); + OnIsProcessRunningChanged(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs new file mode 100644 index 0000000000..72b8f4cbc6 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Processes.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DebuggerInterop.Core; + +namespace DebuggerLibrary +{ + public partial class NDebugger + { + List processCollection = new List(); + + Process currentProcess; + + public event ProcessEventHandler ProcessStarted; + public event ProcessEventHandler ProcessExited; + + public Process CurrentProcess { + get { + if (currentProcess == null && Processes.Count > 0) { + currentProcess = Processes[0]; + } + return currentProcess; + } + set { + currentProcess = value; + } + } + + public IList Processes { + get { + return processCollection.AsReadOnly(); + } + } + + internal Process GetProcess(ICorDebugProcess corProcess) + { + foreach (Process process in Processes) { + if (process.CorProcess == corProcess) { + return process; + } + } + throw new DebuggerException("Process not found"); + } + + internal void AddProcess(Process process) + { + processCollection.Add(process); + OnProcessStarted(process); + } + + internal void RemoveProcess(Process process) + { + processCollection.Remove(process); + OnProcessExited(process); + } + + protected virtual void OnProcessStarted(Process process) + { + if (ProcessStarted != null) { + ProcessStarted(this, new ProcessEventArgs(process)); + } + } + + protected virtual void OnProcessExited(Process process) + { + if (ProcessExited != null) { + ProcessExited(this, new ProcessEventArgs(process)); + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs index 83f5e2a7eb..c95d1d456a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Process.cs @@ -19,7 +19,7 @@ namespace DebuggerLibrary ICorDebugProcess corProcess; Thread currentThread; - bool isProcessRunning; + bool isProcessRunning = true; internal Process(NDebugger debugger, ICorDebugProcess corProcess) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ProcessEventHandler.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ProcessEventHandler.cs new file mode 100644 index 0000000000..51f54aea64 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ProcessEventHandler.cs @@ -0,0 +1,27 @@ +// +// +// + +using System; + +namespace DebuggerLibrary +{ + public delegate void ProcessEventHandler (object sender, ProcessEventArgs args); + + [Serializable] + public class ProcessEventArgs: EventArgs + { + Process process; + + public Process Process { + get { + return process; + } + } + + public ProcessEventArgs(Process process) + { + this.process = process; + } + } +}