void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = null; breakpoint = new ILBreakpoint( debugger, bookmark.MemberReference.DeclaringType.FullName, bookmark.LineNumber, bookmark.MemberReference.MetadataToken.ToInt32(), bookmark.ILRange.From, bookmark.IsEnabled); debugger.Breakpoints.Add(breakpoint); // Action setBookmarkColor = delegate { // 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; // IEditable file = FileService.GetOpenFile(bookmark.FileName) as IEditable; // if (file != null) { // byte[] fileContent = Encoding.UTF8.GetBytesWithPreamble(file.Text); // fileMD5 = new MD5CryptoServiceProvider().ComputeHash(fileContent); // } 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 bookmark.IsEnabledChanged += delegate { breakpoint.Enabled = bookmark.IsEnabled; }; breakpoint.Set += delegate { //setBookmarkColor(); }; //setBookmarkColor(); EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessStarted = (sender, e) => { //setBookmarkColor(); // User can change line number by inserting or deleting lines breakpoint.Line = bookmark.LineNumber; }; EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessExited = (sender, e) => { //setBookmarkColor(); }; EventHandler<BreakpointEventArgs> bp_debugger_BreakpointHit = new EventHandler<BreakpointEventArgs>( delegate(object sender, BreakpointEventArgs e) { //LoggingService.Debug(bookmark.Action + " " + bookmark.ScriptLanguage + " " + bookmark.Condition); switch (bookmark.Action) { case BreakpointAction.Break: break; case BreakpointAction.Condition: // if (Evaluate(bookmark.Condition, bookmark.ScriptLanguage)) // DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAtBecause}") + "\n", bookmark.LineNumber, bookmark.FileName, bookmark.Condition)); // else // this.debuggedProcess.AsyncContinue(); break; case BreakpointAction.Trace: //DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAt}") + "\n", bookmark.LineNumber, bookmark.FileName)); break; } }); BookmarkEventHandler bp_bookmarkManager_Removed = null; bp_bookmarkManager_Removed = (sender, e) => { if (bookmark == e.Bookmark) { debugger.Breakpoints.Remove(breakpoint); // unregister the events debugger.Processes.Added -= bp_debugger_ProcessStarted; debugger.Processes.Removed -= bp_debugger_ProcessExited; breakpoint.Hit -= bp_debugger_BreakpointHit; BookmarkManager.Removed -= bp_bookmarkManager_Removed; } }; // register the events debugger.Processes.Added += bp_debugger_ProcessStarted; debugger.Processes.Removed += bp_debugger_ProcessExited; breakpoint.Hit += bp_debugger_BreakpointHit; BookmarkManager.Removed += bp_bookmarkManager_Removed; }
void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = null; if (bookmark is DecompiledBreakpointBookmark) { var dbb = (DecompiledBreakpointBookmark)bookmark; var memberReference = dbb.MemberReference; var decompilerService = GetDecompilerService(); int token = memberReference.MetadataToken.ToInt32(); if (!decompilerService.CheckMappings(token)) decompilerService.DecompileOnDemand(memberReference as TypeDefinition); int[] ilRanges; int methodToken; if (decompilerService.GetILAndTokenByLineNumber(token, dbb.LineNumber, out ilRanges, out methodToken)) { dbb.ILFrom = ilRanges[0]; dbb.ILTo = ilRanges[1]; // create BP breakpoint = new ILBreakpoint( debugger, dbb.MemberReference.FullName, dbb.LineNumber, memberReference.MetadataToken.ToInt32(), methodToken, dbb.ILFrom, dbb.IsEnabled); debugger.Breakpoints.Add(breakpoint); } } else { breakpoint = debugger.Breakpoints.Add(bookmark.FileName, null, bookmark.LineNumber, 0, bookmark.IsEnabled); } if (breakpoint == null) { LoggingService.Warn(string.Format("unable to create breakpoint: {0}", bookmark.ToString())); return; } MethodInvoker setBookmarkColor = delegate { 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 == null || breakpoint.OriginalLocation.CheckSum == null) { bookmark.IsHealthy = true; bookmark.Tooltip = null; } else { if (!File.Exists(bookmark.FileName)) return; byte[] fileMD5; IEditable file = FileService.GetOpenFile(bookmark.FileName) as IEditable; if (file != null) { byte[] fileContent = Encoding.UTF8.GetBytesWithPreamble(file.Text); fileMD5 = new MD5CryptoServiceProvider().ComputeHash(fileContent); } 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 bookmark.IsEnabledChanged += delegate { breakpoint.Enabled = bookmark.IsEnabled; }; breakpoint.Set += delegate { setBookmarkColor(); }; setBookmarkColor(); EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessStarted = (sender, e) => { setBookmarkColor(); // User can change line number by inserting or deleting lines breakpoint.Line = bookmark.LineNumber; }; EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessExited = (sender, e) => { setBookmarkColor(); }; EventHandler<BreakpointEventArgs> bp_debugger_BreakpointHit = new EventHandler<BreakpointEventArgs>( delegate(object sender, BreakpointEventArgs e) { LoggingService.Debug(bookmark.Action + " " + bookmark.ScriptLanguage + " " + bookmark.Condition); switch (bookmark.Action) { case BreakpointAction.Break: break; case BreakpointAction.Condition: if (Evaluate(bookmark.Condition, bookmark.ScriptLanguage)) DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAtBecause}") + "\n", bookmark.LineNumber, bookmark.FileName, bookmark.Condition)); else this.debuggedProcess.AsyncContinue(); break; case BreakpointAction.Trace: DebuggerService.PrintDebugMessage(string.Format(StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.BreakpointHitAt}") + "\n", bookmark.LineNumber, bookmark.FileName)); break; } }); BookmarkEventHandler bp_bookmarkManager_Removed = null; bp_bookmarkManager_Removed = (sender, e) => { if (bookmark == e.Bookmark) { debugger.Breakpoints.Remove(breakpoint); // unregister the events debugger.Processes.Added -= bp_debugger_ProcessStarted; debugger.Processes.Removed -= bp_debugger_ProcessExited; breakpoint.Hit -= bp_debugger_BreakpointHit; BookmarkManager.Removed -= bp_bookmarkManager_Removed; } }; // register the events debugger.Processes.Added += bp_debugger_ProcessStarted; debugger.Processes.Removed += bp_debugger_ProcessExited; breakpoint.Hit += bp_debugger_BreakpointHit; BookmarkManager.Removed += bp_bookmarkManager_Removed; }
void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = null; breakpoint = new ILBreakpoint( debugger, bookmark.Location, bookmark.EndLocation, bookmark.MethodKey, bookmark.ILRange.From, bookmark.IsEnabled); debugger.Breakpoints.Add(breakpoint); // event handlers on bookmark and breakpoint don't need deregistration bookmark.IsEnabledChanged += delegate { breakpoint.Enabled = bookmark.IsEnabled; }; EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessStarted = (sender, e) => { // User can change line number by inserting or deleting lines breakpoint.Location = bookmark.Location; breakpoint.EndLocation = bookmark.EndLocation; }; EventHandler<CollectionItemEventArgs<Process>> bp_debugger_ProcessExited = (sender, e) => { }; BookmarkEventHandler bp_bookmarkManager_Removed = null; bp_bookmarkManager_Removed = (sender, e) => { if (bookmark == e.Bookmark) { debugger.Breakpoints.Remove(breakpoint); // unregister the events debugger.Processes.Added -= bp_debugger_ProcessStarted; debugger.Processes.Removed -= bp_debugger_ProcessExited; BookmarkManager.Removed -= bp_bookmarkManager_Removed; } }; // register the events debugger.Processes.Added += bp_debugger_ProcessStarted; debugger.Processes.Removed += bp_debugger_ProcessExited; BookmarkManager.Removed += bp_bookmarkManager_Removed; }