diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BreakPointsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BreakPointsPad.cs index f05e3fae33..2cb1c5236a 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BreakPointsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/BreakPointsPad.cs @@ -56,10 +56,10 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads path.Width = 400; NDebugger.DebuggingResumed += new DebuggerEventHandler(debuggerService_OnDebuggingResumed); - NDebugger.Breakpoints.BreakpointAdded += new DebuggerLibrary.BreakpointEventHandler(AddBreakpoint); - NDebugger.Breakpoints.BreakpointStateChanged += new DebuggerLibrary.BreakpointEventHandler(RefreshBreakpoint); - NDebugger.Breakpoints.BreakpointRemoved += new DebuggerLibrary.BreakpointEventHandler(RemoveBreakpoint); - NDebugger.Breakpoints.BreakpointHit += new DebuggerLibrary.BreakpointEventHandler(Breakpoints_OnBreakpointHit); + NDebugger.Instance.BreakpointAdded += new DebuggerLibrary.BreakpointEventHandler(AddBreakpoint); + NDebugger.Instance.BreakpointStateChanged += new DebuggerLibrary.BreakpointEventHandler(RefreshBreakpoint); + NDebugger.Instance.BreakpointRemoved += new DebuggerLibrary.BreakpointEventHandler(RemoveBreakpoint); + NDebugger.Instance.BreakpointHit += new DebuggerLibrary.BreakpointEventHandler(Breakpoints_OnBreakpointHit); RedrawContent(); } @@ -88,7 +88,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breakpointsList.ItemCheck -= new ItemCheckEventHandler(BreakpointsListItemCheck); breakpointsList.BeginUpdate(); breakpointsList.Items.Clear(); - foreach(DebuggerLibrary.Breakpoint b in NDebugger.Breakpoints) { + foreach(DebuggerLibrary.Breakpoint b in NDebugger.Instance.Breakpoints) { AddBreakpoint(this, new BreakpointEventArgs(b)); } breakpointsList.EndUpdate(); @@ -138,7 +138,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads void debuggerService_OnDebuggingResumed(object sender, DebuggerEventArgs e) { breakpointsList.BeginUpdate(); - foreach(DebuggerLibrary.Breakpoint b in NDebugger.Breakpoints) + foreach(DebuggerLibrary.Breakpoint b in NDebugger.Instance.Breakpoints) RefreshBreakpoint(this, new BreakpointEventArgs(b)); breakpointsList.EndUpdate(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs index 60f50852f8..6dd78b87a6 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/LoadedModulesPad.cs @@ -64,8 +64,8 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads timestamp.Width = 0;//80; information.Width = 130; - NDebugger.Modules.ModuleAdded += new DebuggerLibrary.ModuleEventHandler(AddModule); - NDebugger.Modules.ModuleRemoved += new DebuggerLibrary.ModuleEventHandler(RemoveModule); + NDebugger.Instance.ModuleLoaded += new DebuggerLibrary.ModuleEventHandler(AddModule); + NDebugger.Instance.ModuleUnloaded += new DebuggerLibrary.ModuleEventHandler(RemoveModule); RedrawContent(); } @@ -83,7 +83,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads information.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.InformationColumn}"); loadedModulesList.Items.Clear(); - foreach(Module m in NDebugger.Modules) { + foreach(Module m in NDebugger.Instance.Modules) { AddModule(this, new ModuleEventArgs(m)); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs index b107843f80..dd99833a71 100644 --- a/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs +++ b/src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Pads/RunningThreadsPad.cs @@ -65,9 +65,9 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads breaked.Width = 80; - NDebugger.Threads.ThreadAdded += new ThreadEventHandler(AddThread); - NDebugger.Threads.ThreadStateChanged += new ThreadEventHandler(RefreshThread); - NDebugger.Threads.ThreadRemoved += new ThreadEventHandler(RemoveThread); + NDebugger.Instance.ThreadStarted += new ThreadEventHandler(AddThread); + NDebugger.Instance.ThreadStateChanged += new ThreadEventHandler(RefreshThread); + NDebugger.Instance.ThreadExited += new ThreadEventHandler(RemoveThread); NDebugger.IsProcessRunningChanged += new DebuggerEventHandler(DebuggerStateChanged); RedrawContent(); @@ -135,7 +135,7 @@ namespace ICSharpCode.SharpDevelop.Gui.Pads private void RefreshAllItems() { - foreach (Thread t in NDebugger.Threads) { + foreach (Thread t in NDebugger.Instance.Threads) { RefreshThread(this, new ThreadEventArgs(t)); } } 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 0dee7fd777..4b923401f6 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 @@ -379,7 +379,7 @@ namespace ICSharpCode.SharpDevelop.Services Point logicPos = iconBar.TextArea.TextView.GetLogicalPosition(0, mousepos.Y - viewRect.Top); if (logicPos.Y >= 0 && logicPos.Y < iconBar.TextArea.Document.TotalNumberOfLines) { - NDebugger.ToggleBreakpointAt(iconBar.TextArea.MotherTextEditorControl.FileName , logicPos.Y + 1, 0); + NDebugger.Instance.ToggleBreakpointAt(iconBar.TextArea.MotherTextEditorControl.FileName , logicPos.Y + 1, 0); RefreshBreakpointMarkersInEditor(iconBar.TextArea.MotherTextEditorControl); iconBar.TextArea.Refresh(iconBar); } @@ -399,7 +399,7 @@ namespace ICSharpCode.SharpDevelop.Services } } // Add breakpoint markers - foreach (DebuggerLibrary.Breakpoint b in NDebugger.Breakpoints) { + foreach (DebuggerLibrary.Breakpoint b in NDebugger.Instance.Breakpoints) { if (b.SourcecodeSegment.SourceFilename.ToLower() == textEditor.FileName.ToLower()) { LineSegment lineSeg = document.GetLineSegment((int)b.SourcecodeSegment.StartLine - 1); document.MarkerStrategy.TextMarker.Add(new BreakpointMarker(lineSeg.Offset, lineSeg.Length , TextMarkerType.SolidBlock, Color.Red)); @@ -486,7 +486,7 @@ namespace ICSharpCode.SharpDevelop.Services /// void PaintIconBar(AbstractMargin iconBar, Graphics g, Rectangle rect) { - foreach (DebuggerLibrary.Breakpoint breakpoint in NDebugger.Breakpoints) { + foreach (DebuggerLibrary.Breakpoint breakpoint in NDebugger.Instance.Breakpoints) { if (Path.GetFullPath(breakpoint.SourcecodeSegment.SourceFilename) == Path.GetFullPath(iconBar.TextArea.MotherTextEditorControl.FileName)) { int lineNumber = iconBar.TextArea.Document.GetVisibleLine((int)breakpoint.SourcecodeSegment.StartLine - 1); int yPos = (int)(lineNumber * iconBar.TextArea.TextView.FontHeight) - iconBar.TextArea.VirtualTop.Y; 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 fc13e67ffe..7fc4dece1e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj @@ -1,4 +1,4 @@ - + Debug AnyCPU @@ -9,6 +9,9 @@ Debugger.Core Debugger.Core 4 + + + File true @@ -38,8 +41,8 @@ - + @@ -57,14 +60,13 @@ - + - + - diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj.user b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj.user index f45750bf21..ef10b99d6c 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj.user +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Debugger.Core.csproj.user @@ -1,7 +1,8 @@ - + 8.0.41115 ShowAllFiles 0 + \ No newline at end of file diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs index c27336b109..929bd9cf9b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/Breakpoint.cs @@ -138,8 +138,8 @@ namespace DebuggerLibrary { try { - module = NDebugger.Modules[seg.ModuleFilename]; - symReader = NDebugger.Modules[seg.ModuleFilename].SymReader; + module = NDebugger.Instance.GetModule(seg.ModuleFilename); + symReader = NDebugger.Instance.GetModule(seg.ModuleFilename).SymReader; symDoc = symReader.GetDocument(seg.SourceFilename,Guid.Empty,Guid.Empty,Guid.Empty); } catch {} @@ -147,7 +147,7 @@ namespace DebuggerLibrary // search all modules if (symDoc == null) { - foreach (Module m in NDebugger.Modules) { + foreach (Module m in NDebugger.Instance.Modules) { module = m; symReader = m.SymReader; if (symReader == null) { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/BreakpointCollection.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/BreakpointCollection.cs deleted file mode 100644 index 70e027efd9..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/BreakpointCollection.cs +++ /dev/null @@ -1,156 +0,0 @@ -// -// -// - -using System; -using System.Runtime.InteropServices; -using System.Collections; - -using DebuggerInterop.Core; -using DebuggerInterop.MetaData; - -namespace DebuggerLibrary -{ - public class BreakpointCollection: CollectionBase - { - internal BreakpointCollection() - { - NDebugger.Modules.ModuleAdded += new ModuleEventHandler(SetBreakpointsInModule); - } - - public event BreakpointEventHandler BreakpointAdded; - - private void OnBreakpointAdded(Breakpoint breakpoint) - { - breakpoint.BreakpointStateChanged += new BreakpointEventHandler(OnBreakpointStateChanged); - breakpoint.BreakpointHit += new BreakpointEventHandler(OnBreakpointHit); - if (BreakpointAdded != null) - BreakpointAdded(this, new BreakpointEventArgs(breakpoint)); - } - - - public event BreakpointEventHandler BreakpointRemoved; - - private void OnBreakpointRemoved(Breakpoint breakpoint) - { - breakpoint.BreakpointStateChanged -= new BreakpointEventHandler(OnBreakpointStateChanged); - breakpoint.BreakpointHit -= new BreakpointEventHandler(OnBreakpointHit); - if (BreakpointRemoved != null) - BreakpointRemoved(this, new BreakpointEventArgs(breakpoint)); - } - - - public event BreakpointEventHandler BreakpointStateChanged; - - private void OnBreakpointStateChanged(object sender, BreakpointEventArgs e) - { - if (BreakpointStateChanged != null) - BreakpointStateChanged(this, new BreakpointEventArgs(e.Breakpoint)); - } - - - public event BreakpointEventHandler BreakpointHit; - - private void OnBreakpointHit(object sender, BreakpointEventArgs e) - { - if (BreakpointHit != null) - BreakpointHit(this, new BreakpointEventArgs(e.Breakpoint)); - } - - - public Breakpoint this[int index] - { - get - { - return( (Breakpoint) List[index] ); - } - set - { - Breakpoint oldValue = (Breakpoint)List[index]; - List[index] = value; - OnBreakpointRemoved( oldValue ); - OnBreakpointAdded( value ); - } - } - - internal Breakpoint this[ICorDebugBreakpoint corBreakpoint] - { - get - { - foreach(Breakpoint breakpoint in InnerList) - if (breakpoint == corBreakpoint) - return breakpoint; - - throw new UnableToGetPropertyException(this, "this[ICorDebugBreakpoint]", "Breakpoint is not in collection"); - } - } - - public int Add(Breakpoint breakpoint) - { - System.Diagnostics.Trace.Assert(breakpoint != null); - if (breakpoint != null) - { - int retVal = List.Add(breakpoint); - breakpoint.SetBreakpoint(); - OnBreakpointAdded(breakpoint); - return retVal; - } else { - return -1; - } - } - - public int Add(SourcecodeSegment segment) - { - return Add(new Breakpoint(segment)); - } - - public int Add(int line) - { - return Add(new Breakpoint(line)); - } - - public int Add(string sourceFilename, int line) - { - return Add(new Breakpoint(sourceFilename, line)); - } - - public int Add(string sourceFilename, int line, int column) - { - return Add(new Breakpoint(sourceFilename, line, column)); - } - - public int IndexOf( Breakpoint breakpoint ) - { - return( List.IndexOf( breakpoint ) ); - } - - public void Insert( int index, Breakpoint breakpoint ) - { - System.Diagnostics.Trace.Assert(breakpoint != null); - if (breakpoint != null) - { - List.Insert( index, breakpoint ); - OnBreakpointAdded(breakpoint); - } - } - - public void Remove( Breakpoint breakpoint ) - { - breakpoint.Enabled = false; - List.Remove( breakpoint ); - OnBreakpointRemoved( breakpoint); - } - - public bool Contains( Breakpoint breakpoint ) - { - return( List.Contains( breakpoint ) ); - } - - private void SetBreakpointsInModule(object sender, ModuleEventArgs e) - { - foreach (Breakpoint b in InnerList) { - b.SetBreakpoint(); - } - } - } -} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/NDebugger-Breakpoints.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/NDebugger-Breakpoints.cs new file mode 100644 index 0000000000..94a6b778a7 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/NDebugger-Breakpoints.cs @@ -0,0 +1,125 @@ +// +// +// + +using System; +using System.Runtime.InteropServices; +using System.Collections.Generic; + +using DebuggerInterop.Core; +using DebuggerInterop.MetaData; + +namespace DebuggerLibrary +{ + public partial class NDebugger + { + List breakpointCollection = new List(); + + public event BreakpointEventHandler BreakpointAdded; + public event BreakpointEventHandler BreakpointRemoved; + public event BreakpointEventHandler BreakpointStateChanged; + public event BreakpointEventHandler BreakpointHit; + + protected void OnBreakpointAdded(Breakpoint breakpoint) + { + if (BreakpointAdded != null) { + BreakpointAdded(this, new BreakpointEventArgs(breakpoint)); + } + } + + protected void OnBreakpointRemoved(Breakpoint breakpoint) + { + if (BreakpointRemoved != null) { + BreakpointRemoved(this, new BreakpointEventArgs(breakpoint)); + } + } + + protected void OnBreakpointStateChanged(object sender, BreakpointEventArgs e) + { + if (BreakpointStateChanged != null) { + BreakpointStateChanged(this, new BreakpointEventArgs(e.Breakpoint)); + } + } + + protected void OnBreakpointHit(object sender, BreakpointEventArgs e) + { + if (BreakpointHit != null) { + BreakpointHit(this, new BreakpointEventArgs(e.Breakpoint)); + } + } + + public IList Breakpoints { + get { + return breakpointCollection.AsReadOnly(); + } + } + + internal Breakpoint GetBreakpoint(ICorDebugBreakpoint corBreakpoint) + { + foreach(Breakpoint breakpoint in breakpointCollection) { + if (breakpoint == corBreakpoint) { + return breakpoint; + } + } + + throw new UnableToGetPropertyException(this, "GetBreakpoint(ICorDebugBreakpoint corBreakpoint)", "Breakpoint is not in collection"); + } + + public Breakpoint AddBreakpoint(Breakpoint breakpoint) + { + breakpointCollection.Add(breakpoint); + + breakpoint.SetBreakpoint(); + breakpoint.BreakpointStateChanged += new BreakpointEventHandler(OnBreakpointStateChanged); + breakpoint.BreakpointHit += new BreakpointEventHandler(OnBreakpointHit); + + OnBreakpointAdded(breakpoint); + + return breakpoint; + } + + public Breakpoint AddBreakpoint(SourcecodeSegment segment) + { + return AddBreakpoint(new Breakpoint(segment)); + } + + public Breakpoint AddBreakpoint(int line) + { + return AddBreakpoint(new Breakpoint(line)); + } + + public Breakpoint AddBreakpoint(string sourceFilename, int line) + { + return AddBreakpoint(new Breakpoint(sourceFilename, line)); + } + + public Breakpoint AddBreakpoint(string sourceFilename, int line, int column) + { + return AddBreakpoint(new Breakpoint(sourceFilename, line, column)); + } + + public void RemoveBreakpoint(Breakpoint breakpoint) + { + breakpoint.BreakpointStateChanged -= new BreakpointEventHandler(OnBreakpointStateChanged); + breakpoint.BreakpointHit -= new BreakpointEventHandler(OnBreakpointHit); + + breakpoint.Enabled = false; + breakpointCollection.Remove( breakpoint ); + OnBreakpointRemoved( breakpoint); + } + + internal void ResetBreakpoints() + { + foreach (Breakpoint b in breakpointCollection) { + b.ResetBreakpoint(); + } + } + + internal void SetBreakpointsInModule(object sender, ModuleEventArgs e) + { + foreach (Breakpoint b in breakpointCollection) { + b.SetBreakpoint(); + } + } + } +} 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 5fd4e976b0..49d58e78ea 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 @@ -57,7 +57,7 @@ namespace DebuggerLibrary { EnterCallback("StepComplete"); - NDebugger.CurrentThread = NDebugger.Threads[pThread]; + NDebugger.CurrentThread = NDebugger.Instance.GetThread(pThread); if (NDebugger.CurrentThread.CurrentFunction.Module.SymbolsLoaded == false) { NDebugger.TraceMessage(" - stepping out of code without symbols"); @@ -72,11 +72,11 @@ namespace DebuggerLibrary { EnterCallback("Breakpoint"); - NDebugger.CurrentThread = NDebugger.Threads[pThread]; + NDebugger.CurrentThread = NDebugger.Instance.GetThread(pThread); ExitCallback_Paused(PausedReason.Breakpoint); - foreach (Breakpoint b in NDebugger.Breakpoints) { + foreach (Breakpoint b in NDebugger.Instance.Breakpoints) { if (b.Equals(pBreakpoint)) { b.OnBreakpointHit(); } @@ -94,7 +94,7 @@ namespace DebuggerLibrary { EnterCallback("Break"); - NDebugger.CurrentThread = NDebugger.Threads[pThread]; + NDebugger.CurrentThread = NDebugger.Instance.GetThread(pThread); ExitCallback_Paused(PausedReason.Break); } @@ -115,7 +115,7 @@ namespace DebuggerLibrary // return; //} - NDebugger.CurrentThread = NDebugger.Threads[pThread]; + NDebugger.CurrentThread = NDebugger.Instance.GetThread(pThread); NDebugger.CurrentThread.CurrentExceptionIsHandled = (unhandled == 0); ExitCallback_Paused(PausedReason.Exception); @@ -213,7 +213,7 @@ namespace DebuggerLibrary { EnterCallback("LoadModule"); - NDebugger.Modules.Add(pModule); + NDebugger.Instance.AddModule(pModule); ExitCallback_Continue(pAppDomain); } @@ -229,7 +229,7 @@ namespace DebuggerLibrary if (pThread != null) { EnterCallback("NameChange: pThread"); - NDebugger.Threads[pThread].OnThreadStateChanged(); + NDebugger.Instance.GetThread(pThread).OnThreadStateChanged(); ExitCallback_Continue(); return; } @@ -239,10 +239,10 @@ namespace DebuggerLibrary { EnterCallback("CreateThread"); - NDebugger.Threads.Add(pThread); + NDebugger.Instance.AddThread(pThread); if (NDebugger.MainThread == null) { - NDebugger.MainThread = NDebugger.Threads[pThread]; + NDebugger.MainThread = NDebugger.Instance.GetThread(pThread); } ExitCallback_Continue(pAppDomain); @@ -270,7 +270,7 @@ namespace DebuggerLibrary { EnterCallback("UnloadModule"); - NDebugger.Modules.Remove(pModule); + NDebugger.Instance.RemoveModule(pModule); ExitCallback_Continue(pAppDomain); } @@ -286,7 +286,7 @@ namespace DebuggerLibrary { EnterCallback("ExitThread"); - Thread thread = NDebugger.Threads[pThread]; + Thread thread = NDebugger.Instance.GetThread(pThread); if (NDebugger.CurrentThread == thread) NDebugger.CurrentThread = null; @@ -294,7 +294,7 @@ namespace DebuggerLibrary if (NDebugger.MainThread == thread) NDebugger.MainThread = null; - NDebugger.Threads.Remove(thread); + NDebugger.Instance.RemoveThread(thread); try { // TODO ExitCallback_Continue(pAppDomain); @@ -312,7 +312,7 @@ namespace DebuggerLibrary { EnterCallback("ExitProcess"); - NDebugger.ResetEnvironment(); + NDebugger.Instance.ResetEnvironment(); pProcess.Continue(0); //TODO } 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 770f748c02..58c4930561 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 @@ -13,8 +13,20 @@ using DebuggerInterop.MetaData; namespace DebuggerLibrary { - public class NDebugger + public partial class NDebugger { + static NDebugger instance = new NDebugger(); + + public static NDebugger Instance { + get { + return instance; + } + set { + instance = value; + } + } + + // Some variables that are used to get strings // They are used all over the library and // they are here so I don't have to decare them every time I need them @@ -37,33 +49,11 @@ namespace DebuggerLibrary static ICorDebugProcess mainProcess; static Thread mainThread; static Thread currentThread; - - static BreakpointCollection breakpoints; - static ThreadCollection threads; - static ModuleCollection modules; public static bool CatchHandledExceptions = false; #region Public propeties - static public BreakpointCollection Breakpoints { - get{ - return breakpoints; - } - } - - static public ThreadCollection Threads { - get{ - return threads; - } - } - - static public ModuleCollection Modules { - get{ - return modules; - } - } - static public SourcecodeSegment NextStatement { get{ try { @@ -153,10 +143,12 @@ namespace DebuggerLibrary #region Basic functions - static NDebugger() + private NDebugger() { InitDebugger(); ResetEnvironment(); + + this.ModuleLoaded += new ModuleEventHandler(SetBreakpointsInModule); } ~NDebugger() //TODO @@ -164,14 +156,6 @@ namespace DebuggerLibrary corDebug.Terminate(); Marshal.FreeHGlobal(pString); } - - /// - /// It is not possible to implicitly create instance - /// - private NDebugger() - { - - } static internal void InitDebugger() { @@ -190,27 +174,13 @@ namespace DebuggerLibrary corDebug.SetManagedHandler(managedCallbackProxy); } - static internal void ResetEnvironment() + internal void ResetEnvironment() { - if (modules == null) { - modules = new ModuleCollection(); - } else { - modules.Clear(); - } + ClearModules(); - if (breakpoints == null) { - breakpoints = new BreakpointCollection(); - } else { - foreach (Breakpoint b in breakpoints) { - b.ResetBreakpoint(); - } - } + ResetBreakpoints(); - if (threads == null) { - threads = new ThreadCollection(); - } else { - threads.Clear(); - } + ClearThreads(); MainProcess = null; mainThread = null; @@ -476,7 +446,7 @@ namespace DebuggerLibrary #endregion - static public void ToggleBreakpointAt(string fileName, int line, int column) + public void ToggleBreakpointAt(string fileName, int line, int column) { // Check if there is breakpoint on that line foreach (Breakpoint breakpoint in Breakpoints) { @@ -488,15 +458,14 @@ namespace DebuggerLibrary } // Add the breakpoint - int index = Breakpoints.Add(fileName, line, column); - Breakpoint addedBreakpoint = breakpoints[index]; + Breakpoint addedBreakpoint = AddBreakpoint(fileName, line, column); // Check if it wasn't forced to move to different line with breakpoint foreach (Breakpoint breakpoint in Breakpoints) { if (breakpoint != addedBreakpoint) { // Only the old ones if (breakpoint.SourcecodeSegment.StartLine == addedBreakpoint.SourcecodeSegment.StartLine) { // Whops! We have two breakpoint on signle line, delete one - Breakpoints.Remove(addedBreakpoint); + RemoveBreakpoint(addedBreakpoint); return; } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/ModuleCollection.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/ModuleCollection.cs deleted file mode 100644 index 5c42f10b03..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/ModuleCollection.cs +++ /dev/null @@ -1,101 +0,0 @@ -// -// -// - -using System; -using System.Collections; - -using DebuggerInterop.Core; - -namespace DebuggerLibrary -{ - public class ModuleCollection: ReadOnlyCollectionBase - { - int lastAssignedOrderOfLoading= 0; - - public event ModuleEventHandler ModuleAdded; - - private void OnModuleAdded(Module module) - { - if (ModuleAdded != null) - ModuleAdded(this, new ModuleEventArgs(module)); - } - - - public event ModuleEventHandler ModuleRemoved; - - private void OnModuleRemoved(Module module) - { - if (ModuleRemoved != null) - ModuleRemoved(this, new ModuleEventArgs(module)); - } - - - public Module this[int index] { - get { - return (Module) InnerList[index]; - } - } - - public Module this[string filename] { - get { - foreach(Module module in InnerList) - if (module.Filename == filename) - return module; - - throw new UnableToGetPropertyException(this, "this[string]", "Module \"" + filename + "\" is not in collection"); - } - } - - internal Module this[ICorDebugModule corModule] - { - get - { - foreach(Module module in InnerList) - if (module.CorModule == corModule) - return module; - - throw new UnableToGetPropertyException(this, "this[ICorDebugModule]", "Module is not in collection"); - } - } - - internal void Clear() - { - foreach (Module m in InnerList) { - OnModuleRemoved(m); - } - InnerList.Clear(); - lastAssignedOrderOfLoading = 0; - } - - internal void Add(Module module) - { - System.Diagnostics.Trace.Assert(module != null); - if (module != null) - { - module.OrderOfLoading = lastAssignedOrderOfLoading; - lastAssignedOrderOfLoading++; - InnerList.Add(module); - OnModuleAdded(module); - } - } - - internal void Add(ICorDebugModule corModule) - { - System.Diagnostics.Trace.Assert(corModule != null); - if (corModule != null) - Add(new Module(corModule)); - } - - internal void Remove(Module module) - { - InnerList.Remove(module); - OnModuleRemoved (module); - } - - internal void Remove(ICorDebugModule corModule) - { - Remove(this[corModule]); - } - } -} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/NDebugger-Modules.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/NDebugger-Modules.cs new file mode 100644 index 0000000000..45b5600e6c --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Modules/NDebugger-Modules.cs @@ -0,0 +1,96 @@ +// +// +// + +using System; +using System.Collections.Generic; + +using DebuggerInterop.Core; + +namespace DebuggerLibrary +{ + public partial class NDebugger + { + int lastAssignedModuleOrderOfLoading= 0; + + List moduleCollection = new List(); + + public event ModuleEventHandler ModuleLoaded; + public event ModuleEventHandler ModuleUnloaded; + + protected void OnModuleLoaded(Module module) + { + if (ModuleLoaded != null) { + ModuleLoaded(this, new ModuleEventArgs(module)); + } + } + + protected void OnModuleUnloaded(Module module) + { + if (ModuleUnloaded != null) { + ModuleUnloaded(this, new ModuleEventArgs(module)); + } + } + + public IList Modules { + get{ + return moduleCollection.AsReadOnly(); + } + } + + public Module GetModule(string filename) + { + foreach(Module module in moduleCollection) { + if (module.Filename == filename) { + return module; + } + } + + throw new UnableToGetPropertyException(this, "GetModule(string filename)", "Module \"" + filename + "\" is not in collection"); + } + + internal Module GetModule(ICorDebugModule corModule) + { + foreach(Module module in moduleCollection) { + if (module.CorModule == corModule) { + return module; + } + } + + throw new UnableToGetPropertyException(this, "GetModule(ICorDebugModule corModule)", "Module is not in collection"); + } + + internal void AddModule(Module module) + { + module.OrderOfLoading = lastAssignedModuleOrderOfLoading; + lastAssignedModuleOrderOfLoading++; + moduleCollection.Add(module); + OnModuleLoaded(module); + } + + internal void AddModule(ICorDebugModule corModule) + { + AddModule(new Module(corModule)); + } + + internal void RemoveModule(Module module) + { + moduleCollection.Remove(module); + OnModuleUnloaded(module); + } + + internal void RemoveModule(ICorDebugModule corModule) + { + RemoveModule(GetModule(corModule)); + } + + internal void ClearModules() + { + foreach (Module m in moduleCollection) { + OnModuleUnloaded(m); + } + moduleCollection.Clear(); + lastAssignedModuleOrderOfLoading = 0; + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs index 8312402df6..048029cb7b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Function.cs @@ -44,7 +44,7 @@ namespace DebuggerLibrary this.token = new SymbolToken((int)functionToken); ICorDebugModule corModule; corFunction.GetModule(out corModule); - module = NDebugger.Modules[corModule]; + module = NDebugger.Instance.GetModule(corModule); Init(); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/FunctionCollection.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/FunctionCollection.cs deleted file mode 100644 index 7b1443e9cc..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/FunctionCollection.cs +++ /dev/null @@ -1,39 +0,0 @@ -// -// -// - -using System; -using System.Collections; -using System.Diagnostics; - -using DebuggerInterop.Core; - -namespace DebuggerLibrary -{ - public class FunctionCollection: ReadOnlyCollectionBase - { - internal void Add(Function function) - { - System.Diagnostics.Trace.Assert(function != null); - if (function != null) - InnerList.Add(function); - } - - public Function this[int index] { - get { - return (Function) InnerList[index]; - } - } - - public Function this[string functionName] - { - get { - foreach (Function f in InnerList) - if (f.Name == functionName) - return f; - - throw new UnableToGetPropertyException(this, "this[string]", "Function \"" + functionName + "\" is not in collection"); - } - } - } -} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Threads.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Threads.cs new file mode 100644 index 0000000000..f2a59f6546 --- /dev/null +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/NDebugger-Threads.cs @@ -0,0 +1,89 @@ +// +// +// + +using System; +using System.Collections.Generic; + +using DebuggerInterop.Core; + +namespace DebuggerLibrary +{ + public partial class NDebugger + { + List threadCollection = new List(); + + public event ThreadEventHandler ThreadStarted; + public event ThreadEventHandler ThreadExited; + public event ThreadEventHandler ThreadStateChanged; + + protected void OnThreadStarted(Thread thread) + { + if (ThreadStarted != null) { + ThreadStarted(this, new ThreadEventArgs(thread)); + } + } + + protected void OnThreadExited(Thread thread) + { + if (ThreadExited != null) { + ThreadExited(this, new ThreadEventArgs(thread)); + } + } + + protected void OnThreadStateChanged(object sender, ThreadEventArgs e) + { + if (ThreadStateChanged != null) { + ThreadStateChanged(this, new ThreadEventArgs(e.Thread)); + } + } + + public IList Threads { + get { + return threadCollection.AsReadOnly(); + } + } + + internal Thread GetThread(ICorDebugThread corThread) + { + foreach(Thread thread in threadCollection) { + if (thread.CorThread == corThread) { + return thread; + } + } + + throw new UnableToGetPropertyException(this, "this[ICorDebugThread]", "Thread is not in collection"); + } + + internal void AddThread(Thread thread) + { + threadCollection.Add(thread); + thread.ThreadStateChanged += new ThreadEventHandler(OnThreadStateChanged); + OnThreadStarted(thread); + } + + internal void AddThread(ICorDebugThread corThread) + { + AddThread(new Thread(corThread)); + } + + internal void RemoveThread(Thread thread) + { + threadCollection.Remove(thread); + thread.ThreadStateChanged -= new ThreadEventHandler(OnThreadStateChanged); + OnThreadExited(thread); + } + + internal void RemoveThread(ICorDebugThread corThread) + { + RemoveThread(GetThread(corThread)); + } + + internal void ClearThreads() + { + foreach (Thread t in threadCollection) { + RemoveThread(t); + } + } + } +} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs index 2b9990d3a9..792d82a44b 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/Thread.cs @@ -3,6 +3,7 @@ // using System; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Threading; @@ -11,7 +12,7 @@ using DebuggerInterop.MetaData; namespace DebuggerLibrary { - public class Thread + public partial class Thread { internal bool currentExceptionIsHandled; @@ -125,9 +126,9 @@ namespace DebuggerLibrary } } - public unsafe FunctionCollection Callstack { + public unsafe List Callstack { get { - FunctionCollection callstack = new FunctionCollection(); + List callstack = new List(); if (!NDebugger.IsDebugging) return callstack; if (NDebugger.IsProcessRunning) return callstack; @@ -171,7 +172,7 @@ namespace DebuggerLibrary ICorDebugFrame corFrame; corThread.GetActiveFrame(out corFrame); if (corFrame == null) { - FunctionCollection callstack = Callstack; + List callstack = Callstack; if (callstack.Count > 0) { return callstack[0]; } else { diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ThreadCollection.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ThreadCollection.cs deleted file mode 100644 index 3136a9ebca..0000000000 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Threads/ThreadCollection.cs +++ /dev/null @@ -1,103 +0,0 @@ -// -// -// - -using System; -using System.Collections; - -using DebuggerInterop.Core; - -namespace DebuggerLibrary -{ - public class ThreadCollection: ReadOnlyCollectionBase - { - internal ThreadCollection() - { - - } - - public event ThreadEventHandler ThreadAdded; - - private void OnThreadAdded(Thread thread) - { - thread.ThreadStateChanged += new ThreadEventHandler(OnThreadStateChanged); - if (ThreadAdded != null) - ThreadAdded(this, new ThreadEventArgs(thread)); - } - - - public event ThreadEventHandler ThreadRemoved; - - private void OnThreadRemoved(Thread thread) - { - thread.ThreadStateChanged -= new ThreadEventHandler(OnThreadStateChanged); - if (ThreadRemoved != null) - ThreadRemoved(this, new ThreadEventArgs(thread)); - } - - - public event ThreadEventHandler ThreadStateChanged; - - private void OnThreadStateChanged(object sender, ThreadEventArgs e) - { - if (ThreadStateChanged != null) - ThreadStateChanged(this, new ThreadEventArgs(e.Thread)); - } - - - public Thread this[int index] { - get { - return (Thread) InnerList[index]; - } - } - - internal Thread this[ICorDebugThread corThread] - { - get - { - foreach(Thread thread in InnerList) - if (thread.CorThread == corThread) - return thread; - - throw new UnableToGetPropertyException(this, "this[ICorDebugThread]", "Thread is not in collection"); - } - } - - - internal void Clear() - { - foreach (Thread t in InnerList) { - OnThreadRemoved(t); - } - InnerList.Clear(); - } - - internal void Add(Thread thread) - { - System.Diagnostics.Trace.Assert(thread != null); - if (thread != null) - { - InnerList.Add(thread); - OnThreadAdded(thread); - } - } - - internal void Add(ICorDebugThread corThread) - { - System.Diagnostics.Trace.Assert(corThread != null); - if (corThread != null) - Add(new Thread(corThread)); - } - - internal void Remove(Thread thread) - { - InnerList.Remove(thread); - OnThreadRemoved(thread); - } - - internal void Remove(ICorDebugThread corThread) - { - Remove(this[corThread]); - } - } -} diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs index 702ee45892..27ca0a2149 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Variables/ObjectVariable.cs @@ -145,7 +145,7 @@ namespace DebuggerLibrary fullTypeName = NDebugger.pStringAsUnicode; superCallsToken = 0; - foreach (Module m in NDebugger.Modules) + foreach (Module m in NDebugger.Instance.Modules) { // TODO: Does not work for nested // see FindTypeDefByName in dshell.cpp