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; }
void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = null; breakpoint = new ILBreakpoint( debugger, bookmark.MemberReference.DeclaringType.FullName, bookmark.LineNumber, bookmark.FunctionToken, 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; }
private void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = debugger.Breakpoints.Add(bookmark.FileName, null, bookmark.LineNumber, 0, bookmark.IsEnabled); 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.CheckSum == null) { bookmark.IsHealthy = true; bookmark.Tooltip = null; } else { byte[] fileMD5; IEditable file = null;// = FileService.GetOpenFile(bookmark.FileName) as IEditable; if (file != null) { byte[] fileContent = VelerSoftware.SZC.Debugger.Base.ExtensionMethods.GetBytesWithPreamble(System.Text.Encoding.UTF8, 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)) { if (Variables.Langue == "en") { this.DebuggedProcess.OnLogMessage(new Debugger.MessageEventArgs(this.DebuggedProcess, string.Format(StringParser.Parse(VelerSoftware.SZC.Properties.Resources.MainWindow_Windows_Debug_Conditional_Breakpoints_BreakpointHitAtBecause_EN) + "\n", bookmark.LineNumber, bookmark.FileName, bookmark.Condition))); } else { this.DebuggedProcess.OnLogMessage(new Debugger.MessageEventArgs(this.DebuggedProcess, string.Format(StringParser.Parse(VelerSoftware.SZC.Properties.Resources.MainWindow_Windows_Debug_Conditional_Breakpoints_BreakpointHitAtBecause) + "\n", bookmark.LineNumber, bookmark.FileName, bookmark.Condition))); } } else { this.debuggedProcess.AsyncContinue(); } break; case BreakpointAction.Trace: if (Variables.Langue == "en") { this.DebuggedProcess.OnLogMessage(new Debugger.MessageEventArgs(this.DebuggedProcess, string.Format(StringParser.Parse(VelerSoftware.SZC.Properties.Resources.MainWindow_Windows_Debug_Conditional_Breakpoints_BreakpointHitAt_EN) + "\n", bookmark.LineNumber, bookmark.FileName))); } else { this.DebuggedProcess.OnLogMessage(new Debugger.MessageEventArgs(this.DebuggedProcess, string.Format(StringParser.Parse(VelerSoftware.SZC.Properties.Resources.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) { try { if (debuggerDecompilerService == null) { LoggingService.Warn("No IDebuggerDecompilerService found!"); return; } var dbb = (DecompiledBreakpointBookmark)bookmark; MemberReference memberReference = null; string assemblyFile, typeName; if (DecompiledBreakpointBookmark.GetAssemblyAndType(dbb.FileName, out assemblyFile, out typeName)) { memberReference = dbb.GetMemberReference(debuggerDecompilerService.GetAssemblyResolver(assemblyFile)); } int token = memberReference.MetadataToken.ToInt32(); if (!debuggerDecompilerService.CheckMappings(token)) { debuggerDecompilerService.DecompileOnDemand(memberReference as TypeDefinition); } int[] ilRanges; int methodToken; if (debuggerDecompilerService.GetILAndTokenByLineNumber(token, dbb.LineNumber, out ilRanges, out methodToken)) { // create BP breakpoint = new ILBreakpoint( debugger, memberReference.FullName, dbb.LineNumber, memberReference.MetadataToken.ToInt32(), methodToken, ilRanges[0], dbb.IsEnabled); debugger.Breakpoints.Add(breakpoint); } } catch (System.Exception ex) { LoggingService.Error("Error on DecompiledBreakpointBookmark: " + ex.Message); } } 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 = debugger.AddBreakpoint(bookmark.FileName, null, bookmark.LineNumber + 1, 0, bookmark.IsEnabled); 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.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.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 <ProcessEventArgs> bp_debugger_ProcessStarted = (sender, e) => { setBookmarkColor(); // User can change line number by inserting or deleting lines breakpoint.Line = bookmark.LineNumber + 1; }; EventHandler <ProcessEventArgs> 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 + 1, 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 + 1, bookmark.FileName)); break; } }); BookmarkEventHandler bp_bookmarkManager_Removed = null; bp_bookmarkManager_Removed = (sender, e) => { if (bookmark == e.Bookmark) { debugger.RemoveBreakpoint(breakpoint); // unregister the events debugger.ProcessStarted -= bp_debugger_ProcessStarted; debugger.ProcessExited -= bp_debugger_ProcessExited; breakpoint.Hit -= bp_debugger_BreakpointHit; BookmarkManager.Removed -= bp_bookmarkManager_Removed; } }; // register the events debugger.ProcessStarted += bp_debugger_ProcessStarted; debugger.ProcessExited += bp_debugger_ProcessExited; breakpoint.Hit += bp_debugger_BreakpointHit; BookmarkManager.Removed += bp_bookmarkManager_Removed; }