From 5080d5c8d91c906c70332edcd16ae1d6c1d17031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Srbeck=C3=BD?= Date: Sat, 5 Jul 2008 18:46:50 +0000 Subject: [PATCH] Fixed Breakpoint.Hit event; Checking the MD5 of debugged file with the original MD5 git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3176 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/Service/WindowsDebugger.cs | 52 +++++++++++++++++-- .../Project/Src/Control/Module.cs | 1 - .../Src/Control/NDebugger-Breakpoints.cs | 32 ++++-------- .../Project/Src/Control/Process-Modules.cs | 8 --- .../Project/Src/Debugger/Breakpoint.cs | 13 +++-- .../Project/Src/Internal/ManagedCallback.cs | 14 ++--- .../Src/Internal/ManagedCallbackProxy.cs | 3 +- .../Src/Internal/ManagedCallbackSwitch.cs | 2 +- .../Project/Src/Gui/IconBarMargin.cs | 4 +- .../Services/Debugger/BreakpointBookmark.cs | 16 ++++-- 10 files changed, 87 insertions(+), 58 deletions(-) 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 9c92d875d8..5f707a70d8 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 @@ -37,20 +37,22 @@ // #endregion +using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor; using System; using System.Diagnostics; +using System.IO; +using System.Security.Cryptography; using System.Text; using System.Windows.Forms; -using Bitmap = System.Drawing.Bitmap; - using Debugger; -using Debugger.Expressions; using Debugger.AddIn.TreeModel; using Debugger.Core.Wrappers.CorPub; +using Debugger.Expressions; using ICSharpCode.Core; +using ICSharpCode.SharpDevelop.Debugging; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; -using ICSharpCode.SharpDevelop.Debugging; +using Bitmap = System.Drawing.Bitmap; using BM = ICSharpCode.SharpDevelop.Bookmarks; namespace ICSharpCode.SharpDevelop.Services @@ -440,11 +442,51 @@ namespace ICSharpCode.SharpDevelop.Services } } + bool Compare(byte[] a, byte[] b) + { + if (a.Length != b.Length) return false; + for(int i = 0; i < a.Length; i++) { + if (a[i] != b[i]) return false; + } + return true; + } + void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = debugger.AddBreakpoint(bookmark.FileName, null, bookmark.LineNumber + 1, 0, bookmark.IsEnabled); MethodInvoker setBookmarkColor = delegate { - bookmark.WillBeHit = breakpoint.IsSet || debugger.Processes.Count == 0; + if (debugger.Processes.Count == 0) { + bookmark.IsHealthy = true; + bookmark.Tooltip = null; + } else if (!breakpoint.IsSet) { + bookmark.IsHealthy = false; + bookmark.Tooltip = "Breakpoint was not found in any loaded modules"; + } else if (breakpoint.OriginalLocation.CheckSum == null) { + bookmark.IsHealthy = true; + bookmark.Tooltip = null; + } else { + byte[] fileMD5; + TextEditorDisplayBindingWrapper file = FileService.GetOpenFile(bookmark.FileName) as TextEditorDisplayBindingWrapper; + if (file != null) { + byte[] fileContent = Encoding.UTF8.GetBytes(file.Text); + // Insert UTF-8 BOM + byte[] fileContent2 = new byte[fileContent.Length + 3]; + Array.Copy(fileContent, 0, fileContent2, 3, fileContent.Length); + fileContent2[0] = 0xEF; + fileContent2[1] = 0xBB; + fileContent2[2] = 0xBF; + fileMD5 = new MD5CryptoServiceProvider().ComputeHash(fileContent2); + } else { + fileMD5 = new MD5CryptoServiceProvider().ComputeHash(File.ReadAllBytes(bookmark.FileName)); + } + if (Compare(fileMD5, breakpoint.OriginalLocation.CheckSum)) { + bookmark.IsHealthy = true; + bookmark.Tooltip = null; + } else { + bookmark.IsHealthy = false; + bookmark.Tooltip = "Check sum or file does not match to the original"; + } + } }; // event handlers on bookmark and breakpoint don't need deregistration diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs index 975a758fe4..140f31aab3 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs @@ -178,7 +178,6 @@ namespace Debugger if (symReader == null) { symReader = metaData.GetSymReader(fullPath, string.Join("; ", searchPath ?? new string[0])); if (symReader != null) { - process.OnModuleSymbolsLoaded(new ModuleEventArgs(this)); OnSymbolsLoaded(new ModuleEventArgs(this)); } } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs index e24a140903..7bcdf1e56e 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs @@ -14,40 +14,32 @@ namespace Debugger public partial class NDebugger { List breakpointCollection = new List(); - + public event EventHandler BreakpointAdded; public event EventHandler BreakpointRemoved; - public event EventHandler BreakpointStateChanged; public event EventHandler BreakpointHit; - + protected virtual void OnBreakpointAdded(Breakpoint breakpoint) { if (BreakpointAdded != null) { BreakpointAdded(this, new BreakpointEventArgs(breakpoint)); } } - + protected virtual void OnBreakpointRemoved(Breakpoint breakpoint) { if (BreakpointRemoved != null) { BreakpointRemoved(this, new BreakpointEventArgs(breakpoint)); } } - - protected virtual void OnBreakpointStateChanged(object sender, BreakpointEventArgs e) - { - if (BreakpointStateChanged != null) { - BreakpointStateChanged(this, new BreakpointEventArgs(e.Breakpoint)); - } - } - - protected virtual void OnBreakpointHit(object sender, BreakpointEventArgs e) + + protected internal virtual void OnBreakpointHit(Breakpoint breakpoint) { if (BreakpointHit != null) { - BreakpointHit(this, new BreakpointEventArgs(e.Breakpoint)); + BreakpointHit(this, new BreakpointEventArgs(breakpoint)); } } - + public IList Breakpoints { get { return breakpointCollection.AsReadOnly(); @@ -56,13 +48,12 @@ namespace Debugger internal Breakpoint GetBreakpoint(ICorDebugBreakpoint corBreakpoint) { - foreach(Breakpoint breakpoint in breakpointCollection) { - if (breakpoint.Equals(corBreakpoint)) { + foreach (Breakpoint breakpoint in this.Breakpoints) { + if (breakpoint.IsOwnerOf(corBreakpoint)) { return breakpoint; } } - - throw new DebuggerException("Breakpoint is not in collection"); + return null; } public Breakpoint AddBreakpoint(Breakpoint breakpoint) @@ -74,7 +65,6 @@ namespace Debugger breakpoint.SetBreakpoint(module); } } - breakpoint.Hit += new EventHandler(OnBreakpointHit); OnBreakpointAdded(breakpoint); @@ -93,8 +83,6 @@ namespace Debugger public void RemoveBreakpoint(Breakpoint breakpoint) { - breakpoint.Hit -= new EventHandler(OnBreakpointHit); - breakpoint.Deactivate(); breakpointCollection.Remove(breakpoint); OnBreakpointRemoved(breakpoint); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs index a4b9dbf3e1..95594604a0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs @@ -20,7 +20,6 @@ namespace Debugger public event EventHandler ModuleLoaded; public event EventHandler ModuleUnloaded; - public event EventHandler ModuleSymbolsLoaded; protected void OnModuleLoaded(Module module) { @@ -36,13 +35,6 @@ namespace Debugger } } - internal virtual void OnModuleSymbolsLoaded(ModuleEventArgs e) - { - if (ModuleSymbolsLoaded != null) { - ModuleSymbolsLoaded(this, e); - } - } - public IList Modules { get{ return moduleCollection.AsReadOnly(); diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs index c41aea2cf5..55745762c0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs @@ -48,7 +48,6 @@ namespace Debugger public int Column { get { return column; } - set { column = value; } } public bool Enabled { @@ -78,6 +77,12 @@ namespace Debugger } } + internal void NotifyHit() + { + OnHit(new BreakpointEventArgs(this)); + debugger.OnBreakpointHit(this); + } + protected virtual void OnSet(BreakpointEventArgs e) { if (Set != null) { @@ -95,10 +100,10 @@ namespace Debugger this.enabled = enabled; } - internal bool IsOwnerOf(ICorDebugFunctionBreakpoint breakpoint) + internal bool IsOwnerOf(ICorDebugBreakpoint breakpoint) { - foreach(ICorDebugFunctionBreakpoint corBreakpoint in corBreakpoints) { - if (corBreakpoint == breakpoint) return true; + foreach(ICorDebugFunctionBreakpoint corFunBreakpoint in corBreakpoints) { + if (corFunBreakpoint.CastTo().Equals(breakpoint)) return true; } return false; } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs index 459609030d..b41d64acfc 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs @@ -146,20 +146,16 @@ namespace Debugger ExitCallback(); } - // Do not pass the pBreakpoint parameter as ICorDebugBreakpoint - marshaling of it fails in .NET 1.1 - public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, IntPtr pBreakpoint) + // Warning! Marshaing of ICorBreakpoint fails in .NET 1.1 + public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint corBreakpoint) { EnterCallback(PausedReason.Breakpoint, "Breakpoint", pThread); pauseOnNextExit = true; - ExitCallback(); -// foreach (Breakpoint b in debugger.Breakpoints) { -// if (b.Equals(pBreakpoint)) { -// // TODO: Check that this works -// b.OnHit(); -// } -// } + process.Debugger.GetBreakpoint(corBreakpoint).NotifyHit(); + + ExitCallback(); } public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint, uint dwError) diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs index dc9e6d6877..17691685b0 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs @@ -94,7 +94,8 @@ namespace Debugger callbackSwitch.Breakpoint( MTA2STA.MarshalIntPtrTo(pAppDomain), MTA2STA.MarshalIntPtrTo(pThread), - pBreakpoint // Do not marshal this one - it fails in .NET 1.1 + // This fails in .NET 1.1: + MTA2STA.MarshalIntPtrTo(pBreakpoint) ); }); } diff --git a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs index 47401fda8a..a2d86bebb8 100644 --- a/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs +++ b/src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs @@ -91,7 +91,7 @@ namespace Debugger } // Do not pass the pBreakpoint parameter as ICorDebugBreakpoint - marshaling of it fails in .NET 1.1 - public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, IntPtr pBreakpoint) + public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint) { ManagedCallback managedCallback = GetProcessCallbackInterface(pAppDomain); if (managedCallback != null) { diff --git a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs index 1d42511de2..38b27040ee 100644 --- a/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs +++ b/src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs @@ -98,7 +98,7 @@ namespace ICSharpCode.TextEditor } #region Drawing functions - public void DrawBreakpoint(Graphics g, int y, bool isEnabled, bool willBeHit) + public void DrawBreakpoint(Graphics g, int y, bool isEnabled, bool isHealthy) { int diameter = Math.Min(iconBarWidth - 2, textArea.TextView.FontHeight); Rectangle rect = new Rectangle(1, @@ -112,7 +112,7 @@ namespace ICSharpCode.TextEditor using (PathGradientBrush pthGrBrush = new PathGradientBrush(path)) { pthGrBrush.CenterPoint = new PointF(rect.Left + rect.Width / 3 , rect.Top + rect.Height / 3); pthGrBrush.CenterColor = Color.MistyRose; - Color[] colors = {willBeHit?Color.Firebrick:Color.Olive}; + Color[] colors = {isHealthy ? Color.Firebrick : Color.Olive}; pthGrBrush.SurroundColors = colors; if (isEnabled) { diff --git a/src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs b/src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs index b115a01c39..be9be3ebc7 100644 --- a/src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs +++ b/src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs @@ -15,16 +15,17 @@ namespace ICSharpCode.SharpDevelop.Debugging { public class BreakpointBookmark : SDMarkerBookmark { - bool willBeHit = true; + bool isHealthy = true; + string tooltip; static readonly Color defaultColor = Color.FromArgb(180, 38, 38); - public virtual bool WillBeHit { + public virtual bool IsHealthy { get { - return willBeHit; + return isHealthy; } set { - willBeHit = value; + isHealthy = value; if (Document != null && !Line.IsDeleted) { Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, LineNumber)); Document.CommitUpdate(); @@ -32,13 +33,18 @@ namespace ICSharpCode.SharpDevelop.Debugging } } + public string Tooltip { + get { return tooltip; } + set { tooltip = value; } + } + public BreakpointBookmark(string fileName, IDocument document, int lineNumber) : base(fileName, document, lineNumber) { } public override void Draw(IconBarMargin margin, Graphics g, Point p) { - margin.DrawBreakpoint(g, p.Y, IsEnabled, WillBeHit); + margin.DrawBreakpoint(g, p.Y, IsEnabled, IsHealthy); } protected override TextMarker CreateMarker()