Browse Source

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
shortcuts
David Srbecký 17 years ago
parent
commit
5080d5c8d9
  1. 52
      src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs
  2. 1
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs
  3. 32
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs
  4. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs
  5. 13
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs
  6. 14
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs
  7. 3
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs
  8. 2
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackSwitch.cs
  9. 4
      src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs
  10. 16
      src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs

52
src/AddIns/Misc/Debugger/Debugger.AddIn/Project/Src/Service/WindowsDebugger.cs

@ -37,20 +37,22 @@
// //
#endregion #endregion
using ICSharpCode.SharpDevelop.DefaultEditor.Gui.Editor;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Windows.Forms; using System.Windows.Forms;
using Bitmap = System.Drawing.Bitmap;
using Debugger; using Debugger;
using Debugger.Expressions;
using Debugger.AddIn.TreeModel; using Debugger.AddIn.TreeModel;
using Debugger.Core.Wrappers.CorPub; using Debugger.Core.Wrappers.CorPub;
using Debugger.Expressions;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Debugging;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Debugging; using Bitmap = System.Drawing.Bitmap;
using BM = ICSharpCode.SharpDevelop.Bookmarks; using BM = ICSharpCode.SharpDevelop.Bookmarks;
namespace ICSharpCode.SharpDevelop.Services 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) void AddBreakpoint(BreakpointBookmark bookmark)
{ {
Breakpoint breakpoint = debugger.AddBreakpoint(bookmark.FileName, null, bookmark.LineNumber + 1, 0, bookmark.IsEnabled); Breakpoint breakpoint = debugger.AddBreakpoint(bookmark.FileName, null, bookmark.LineNumber + 1, 0, bookmark.IsEnabled);
MethodInvoker setBookmarkColor = delegate { 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 // event handlers on bookmark and breakpoint don't need deregistration

1
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Module.cs

@ -178,7 +178,6 @@ namespace Debugger
if (symReader == null) { if (symReader == null) {
symReader = metaData.GetSymReader(fullPath, string.Join("; ", searchPath ?? new string[0])); symReader = metaData.GetSymReader(fullPath, string.Join("; ", searchPath ?? new string[0]));
if (symReader != null) { if (symReader != null) {
process.OnModuleSymbolsLoaded(new ModuleEventArgs(this));
OnSymbolsLoaded(new ModuleEventArgs(this)); OnSymbolsLoaded(new ModuleEventArgs(this));
} }
} }

32
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/NDebugger-Breakpoints.cs

@ -14,40 +14,32 @@ namespace Debugger
public partial class NDebugger public partial class NDebugger
{ {
List<Breakpoint> breakpointCollection = new List<Breakpoint>(); List<Breakpoint> breakpointCollection = new List<Breakpoint>();
public event EventHandler<BreakpointEventArgs> BreakpointAdded; public event EventHandler<BreakpointEventArgs> BreakpointAdded;
public event EventHandler<BreakpointEventArgs> BreakpointRemoved; public event EventHandler<BreakpointEventArgs> BreakpointRemoved;
public event EventHandler<BreakpointEventArgs> BreakpointStateChanged;
public event EventHandler<BreakpointEventArgs> BreakpointHit; public event EventHandler<BreakpointEventArgs> BreakpointHit;
protected virtual void OnBreakpointAdded(Breakpoint breakpoint) protected virtual void OnBreakpointAdded(Breakpoint breakpoint)
{ {
if (BreakpointAdded != null) { if (BreakpointAdded != null) {
BreakpointAdded(this, new BreakpointEventArgs(breakpoint)); BreakpointAdded(this, new BreakpointEventArgs(breakpoint));
} }
} }
protected virtual void OnBreakpointRemoved(Breakpoint breakpoint) protected virtual void OnBreakpointRemoved(Breakpoint breakpoint)
{ {
if (BreakpointRemoved != null) { if (BreakpointRemoved != null) {
BreakpointRemoved(this, new BreakpointEventArgs(breakpoint)); BreakpointRemoved(this, new BreakpointEventArgs(breakpoint));
} }
} }
protected virtual void OnBreakpointStateChanged(object sender, BreakpointEventArgs e) protected internal virtual void OnBreakpointHit(Breakpoint breakpoint)
{
if (BreakpointStateChanged != null) {
BreakpointStateChanged(this, new BreakpointEventArgs(e.Breakpoint));
}
}
protected virtual void OnBreakpointHit(object sender, BreakpointEventArgs e)
{ {
if (BreakpointHit != null) { if (BreakpointHit != null) {
BreakpointHit(this, new BreakpointEventArgs(e.Breakpoint)); BreakpointHit(this, new BreakpointEventArgs(breakpoint));
} }
} }
public IList<Breakpoint> Breakpoints { public IList<Breakpoint> Breakpoints {
get { get {
return breakpointCollection.AsReadOnly(); return breakpointCollection.AsReadOnly();
@ -56,13 +48,12 @@ namespace Debugger
internal Breakpoint GetBreakpoint(ICorDebugBreakpoint corBreakpoint) internal Breakpoint GetBreakpoint(ICorDebugBreakpoint corBreakpoint)
{ {
foreach(Breakpoint breakpoint in breakpointCollection) { foreach (Breakpoint breakpoint in this.Breakpoints) {
if (breakpoint.Equals(corBreakpoint)) { if (breakpoint.IsOwnerOf(corBreakpoint)) {
return breakpoint; return breakpoint;
} }
} }
return null;
throw new DebuggerException("Breakpoint is not in collection");
} }
public Breakpoint AddBreakpoint(Breakpoint breakpoint) public Breakpoint AddBreakpoint(Breakpoint breakpoint)
@ -74,7 +65,6 @@ namespace Debugger
breakpoint.SetBreakpoint(module); breakpoint.SetBreakpoint(module);
} }
} }
breakpoint.Hit += new EventHandler<BreakpointEventArgs>(OnBreakpointHit);
OnBreakpointAdded(breakpoint); OnBreakpointAdded(breakpoint);
@ -93,8 +83,6 @@ namespace Debugger
public void RemoveBreakpoint(Breakpoint breakpoint) public void RemoveBreakpoint(Breakpoint breakpoint)
{ {
breakpoint.Hit -= new EventHandler<BreakpointEventArgs>(OnBreakpointHit);
breakpoint.Deactivate(); breakpoint.Deactivate();
breakpointCollection.Remove(breakpoint); breakpointCollection.Remove(breakpoint);
OnBreakpointRemoved(breakpoint); OnBreakpointRemoved(breakpoint);

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Control/Process-Modules.cs

@ -20,7 +20,6 @@ namespace Debugger
public event EventHandler<ModuleEventArgs> ModuleLoaded; public event EventHandler<ModuleEventArgs> ModuleLoaded;
public event EventHandler<ModuleEventArgs> ModuleUnloaded; public event EventHandler<ModuleEventArgs> ModuleUnloaded;
public event EventHandler<ModuleEventArgs> ModuleSymbolsLoaded;
protected void OnModuleLoaded(Module module) 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<Module> Modules { public IList<Module> Modules {
get{ get{
return moduleCollection.AsReadOnly(); return moduleCollection.AsReadOnly();

13
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/Breakpoint.cs

@ -48,7 +48,6 @@ namespace Debugger
public int Column { public int Column {
get { return column; } get { return column; }
set { column = value; }
} }
public bool Enabled { 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) protected virtual void OnSet(BreakpointEventArgs e)
{ {
if (Set != null) { if (Set != null) {
@ -95,10 +100,10 @@ namespace Debugger
this.enabled = enabled; this.enabled = enabled;
} }
internal bool IsOwnerOf(ICorDebugFunctionBreakpoint breakpoint) internal bool IsOwnerOf(ICorDebugBreakpoint breakpoint)
{ {
foreach(ICorDebugFunctionBreakpoint corBreakpoint in corBreakpoints) { foreach(ICorDebugFunctionBreakpoint corFunBreakpoint in corBreakpoints) {
if (corBreakpoint == breakpoint) return true; if (corFunBreakpoint.CastTo<ICorDebugBreakpoint>().Equals(breakpoint)) return true;
} }
return false; return false;
} }

14
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallback.cs

@ -146,20 +146,16 @@ namespace Debugger
ExitCallback(); ExitCallback();
} }
// Do not pass the pBreakpoint parameter as ICorDebugBreakpoint - marshaling of it fails in .NET 1.1 // Warning! Marshaing of ICorBreakpoint fails in .NET 1.1
public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, IntPtr pBreakpoint) public void Breakpoint(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint corBreakpoint)
{ {
EnterCallback(PausedReason.Breakpoint, "Breakpoint", pThread); EnterCallback(PausedReason.Breakpoint, "Breakpoint", pThread);
pauseOnNextExit = true; pauseOnNextExit = true;
ExitCallback();
// foreach (Breakpoint b in debugger.Breakpoints) { process.Debugger.GetBreakpoint(corBreakpoint).NotifyHit();
// if (b.Equals(pBreakpoint)) {
// // TODO: Check that this works ExitCallback();
// b.OnHit();
// }
// }
} }
public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint, uint dwError) public void BreakpointSetError(ICorDebugAppDomain pAppDomain, ICorDebugThread pThread, ICorDebugBreakpoint pBreakpoint, uint dwError)

3
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Internal/ManagedCallbackProxy.cs

@ -94,7 +94,8 @@ namespace Debugger
callbackSwitch.Breakpoint( callbackSwitch.Breakpoint(
MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain), MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread), MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
pBreakpoint // Do not marshal this one - it fails in .NET 1.1 // This fails in .NET 1.1:
MTA2STA.MarshalIntPtrTo<ICorDebugBreakpoint>(pBreakpoint)
); );
}); });
} }

2
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 // 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); ManagedCallback managedCallback = GetProcessCallbackInterface(pAppDomain);
if (managedCallback != null) { if (managedCallback != null) {

4
src/Libraries/ICSharpCode.TextEditor/Project/Src/Gui/IconBarMargin.cs

@ -98,7 +98,7 @@ namespace ICSharpCode.TextEditor
} }
#region Drawing functions #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); int diameter = Math.Min(iconBarWidth - 2, textArea.TextView.FontHeight);
Rectangle rect = new Rectangle(1, Rectangle rect = new Rectangle(1,
@ -112,7 +112,7 @@ namespace ICSharpCode.TextEditor
using (PathGradientBrush pthGrBrush = new PathGradientBrush(path)) { using (PathGradientBrush pthGrBrush = new PathGradientBrush(path)) {
pthGrBrush.CenterPoint = new PointF(rect.Left + rect.Width / 3 , rect.Top + rect.Height / 3); pthGrBrush.CenterPoint = new PointF(rect.Left + rect.Width / 3 , rect.Top + rect.Height / 3);
pthGrBrush.CenterColor = Color.MistyRose; pthGrBrush.CenterColor = Color.MistyRose;
Color[] colors = {willBeHit?Color.Firebrick:Color.Olive}; Color[] colors = {isHealthy ? Color.Firebrick : Color.Olive};
pthGrBrush.SurroundColors = colors; pthGrBrush.SurroundColors = colors;
if (isEnabled) { if (isEnabled) {

16
src/Main/Base/Project/Src/Services/Debugger/BreakpointBookmark.cs

@ -15,16 +15,17 @@ namespace ICSharpCode.SharpDevelop.Debugging
{ {
public class BreakpointBookmark : SDMarkerBookmark public class BreakpointBookmark : SDMarkerBookmark
{ {
bool willBeHit = true; bool isHealthy = true;
string tooltip;
static readonly Color defaultColor = Color.FromArgb(180, 38, 38); static readonly Color defaultColor = Color.FromArgb(180, 38, 38);
public virtual bool WillBeHit { public virtual bool IsHealthy {
get { get {
return willBeHit; return isHealthy;
} }
set { set {
willBeHit = value; isHealthy = value;
if (Document != null && !Line.IsDeleted) { if (Document != null && !Line.IsDeleted) {
Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, LineNumber)); Document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, LineNumber));
Document.CommitUpdate(); 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 BreakpointBookmark(string fileName, IDocument document, int lineNumber) : base(fileName, document, lineNumber)
{ {
} }
public override void Draw(IconBarMargin margin, Graphics g, Point p) 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() protected override TextMarker CreateMarker()

Loading…
Cancel
Save