public bool TrySetBreakpoint(BreakpointBookmark breakpoint) { SymbolToken token; Session.ProgressReporter.Report("Trying to set breakpoint {0}:{1} in module {2}", breakpoint.Location.FilePath, breakpoint.Location.Line, Name); if (Symbols.TryGetFunctionByLocation(breakpoint.Location, out token)) { Session.ProgressReporter.Report("Method token found."); var function = GetFunction((uint)token.GetToken()); if (function == null) { return(false); } Session.ProgressReporter.Report("Method found. Finding IL offset"); var sequencePoint = function.Symbols.GetSequencePointByLine(breakpoint.Location.Line); if (sequencePoint == null) { return(false); } Session.ProgressReporter.Report("Setting breakpoint at offset {0}", sequencePoint.Offset); function.IlCode.CreateBreakpoint(sequencePoint.Offset); return(true); } return(false); }
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) { List <ToolStripItem> items = new List <ToolStripItem>(); ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as ITextEditorControlProvider; BreakpointBookmark point = null; foreach (BreakpointBookmark breakpoint in DebuggerService.Breakpoints) { if ((breakpoint.FileName == provider.TextEditorControl.FileName) && (breakpoint.LineNumber == provider.TextEditorControl.ActiveTextAreaControl.Caret.Line)) { point = breakpoint; break; } } if (point != null) { foreach (string item in BreakpointAction.GetNames(typeof(BreakpointAction))) { items.Add(MakeItem("${res:MainWindow.Windows.Debug.Conditional.Breakpoints." + item + "}", item, point, point.Action.ToString(), delegate(object sender, EventArgs e) { HandleItem(sender); })); } } return(items.ToArray()); }
private void AddBreakpointBookmark(DebugLocator item) { var location = new TextLocation((item.LinePos >= 0 ? item.LinePos - 1 : 0), item.Line - 1); var newBookmark = new BreakpointBookmark(_textEdit.Document, location, item); AddBookmark(newBookmark); }
public EditBreakpointScriptForm(BreakpointBookmark data) { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); this.data = data; this.data.Action = BreakpointAction.Condition; this.txtCode.Document.TextContent = data.Condition; this.cmbLanguage.Items.AddRange(new string[] { "C#", "VBNET" }); this.cmbLanguage.SelectedIndex = (!string.IsNullOrEmpty(data.ScriptLanguage)) ? this.cmbLanguage.Items.IndexOf(data.ScriptLanguage.ToUpper()) : this.cmbLanguage.Items.IndexOf(ProjectService.CurrentProject.Language.ToUpper()); this.txtCode.SetHighlighting(data.ScriptLanguage.ToUpper()); // Setup translation text this.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.ScriptingWindow.Title}"); this.btnCancel.Text = StringParser.Parse("${res:Global.CancelButtonText}"); this.btnOK.Text = StringParser.Parse("${res:Global.OKButtonText}"); this.label1.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.ScriptingWindow.ScriptingLanguage}") + ":"; this.btnCheckSyntax.Text = StringParser.Parse("${res:MainWindow.Windows.Debug.Conditional.Breakpoints.ScriptingWindow.CheckSyntax}"); }
void HandleItem(object sender) { ToolStripMenuItem item = null; if (sender is ToolStripMenuItem) { item = (ToolStripMenuItem)sender; } if (item != null) { BreakpointBookmark bookmark = (BreakpointBookmark)item.Tag; switch (item.Name) { case "Break": bookmark.Action = BreakpointAction.Break; break; case "Condition": EditBreakpointScriptForm form = new EditBreakpointScriptForm(bookmark); if (form.ShowDialog() == DialogResult.OK) { bookmark = form.Data; } break; case "Trace": bookmark.Action = BreakpointAction.Trace; break; } } }
public EditBreakpointScriptWindow(BreakpointBookmark data) { InitializeComponent(); this.data = data; this.data.Action = BreakpointAction.Condition; foreach (var name in Enum.GetNames(typeof(SupportedLanguage))) { cmbLanguage.Items.Add(name); } string language = "CSharp"; if (ProjectService.CurrentProject != null) { language = ProjectService.CurrentProject.Language.Replace("#", "Sharp"); } this.cmbLanguage.SelectedIndex = (!string.IsNullOrEmpty(data.ScriptLanguage)) ? this.cmbLanguage.Items.IndexOf(data.ScriptLanguage) : this.cmbLanguage.Items.IndexOf(language); this.codeEditor.Document.Text = data.Condition; UpdateHighlighting(); }
void AddBreakpoint(BreakpointBookmark bookmark) { Breakpoint breakpoint = CurrentDebugger.AddBreakpoint(bookmark.FileName, bookmark.LineNumber, 0, bookmark.IsEnabled); bookmark.InternalBreakpointObject = breakpoint; bookmark.IsHealthy = (CurrentProcess == null) || breakpoint.IsSet; bookmark.IsEnabledChanged += delegate { breakpoint.IsEnabled = bookmark.IsEnabled; }; }
/// <summary> /// Remove a breakpoint for the given bookmark. /// </summary> internal void RemoveBreakpoint(BreakpointBookmark bb) { var breakpoint = FirstOrDefault <DebugLocationBreakpoint>(x => x.Bookmark == bb); if (breakpoint != null) { ResetAsync(breakpoint); } }
static void BookmarkRemoved(object sender, BookmarkEventArgs e) { BreakpointBookmark bb = e.Bookmark as BreakpointBookmark; if (bb != null) { OnBreakPointRemoved(new BreakpointBookmarkEventArgs(bb)); } }
static void BookmarkChanged(object sender, EventArgs e) { BreakpointBookmark bb = sender as BreakpointBookmark; if (bb != null) { OnBreakPointChanged(new BreakpointBookmarkEventArgs(bb)); } }
public void RemoveBreakpoint(BreakpointBookmark breakpoint) { Breakpoint debuggerBreakpoint = Breakpoints.GetBreakpointByBookmark(breakpoint); if (debuggerBreakpoint != null) { debuggerBreakpoint.Enabled = false; } }
public EditBreakpointScriptWindow(BreakpointBookmark data) { InitializeComponent(); this.data = data; string language = ProjectService.CurrentProject != null ? ProjectService.CurrentProject.Language : "C#"; this.codeEditor.Document.Text = data.Condition ?? string.Empty; this.codeEditor.SyntaxHighlighting = HighlightingManager.Instance.GetDefinition(language); }
/// <summary> /// Find TextEditor for bookmark. /// </summary> /// <param name="mark">Bookmark</param> /// <returns>TextEditor</returns> private ITextEditor findEditor(BreakpointBookmark mark) { foreach (IViewContent cont in WorkbenchSingleton.Workbench.ViewContentCollection) { foreach (OpenedFile file in cont.Files) { if (FileUtility.IsEqualFileName(file.FileName, mark.FileName) && cont is ITextEditorProvider) { return(((ITextEditorProvider)cont).TextEditor); } } } return(null); }
/// <summary> /// Add a breakpoint for the given bookmark. /// </summary> internal void AddBreakpoint(BreakpointBookmark bb) { try { if (bb.IsEnabled) { this.SetAtLocation(bb.FileName, bb.LineNumber, bb.ColumnNumber, bb.LineNumber, int.MaxValue, bb); } } catch (Exception ex) { Dot42Addin.InvokeAsyncAndForget(() => { bb.IsHealthy = false; bb.Tooltip = ex.Message; }); } }
/// <summary> /// Recreates breakpoints after change of source code. /// </summary> private void updateBreakpoints() { BreakpointBookmark[] markers = new BreakpointBookmark[DebuggerService.Breakpoints.Count]; DebuggerService.Breakpoints.CopyTo(markers, 0); foreach (BreakpointBookmark item in markers) { ITextEditor editor = findEditor(item); if (editor != null) { DebuggerService.ToggleBreakpointAt(editor, item.LineNumber, typeof(BreakpointBookmark)); DebuggerService.ToggleBreakpointAt(editor, item.LineNumber, typeof(BreakpointBookmark)); } } }
public void SyncBookmarks() { var storage = DebugInformation.CodeMappings; if (storage == null || storage.Count == 0) { return; } // TODO: handle other types of bookmarks // remove existing bookmarks and create new ones // update of existing bookmarks for new position does not update TextMarker // this is only done in TextMarkerService handlers for BookmarkManager.Added/Removed List <BreakpointBookmark> newBookmarks = new List <BreakpointBookmark>(); for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i) { var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark; if (breakpoint == null) { continue; } var key = breakpoint.FunctionToken; if (!storage.ContainsKey(key)) { continue; } bool isMatch; SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset(breakpoint.ILRange.From, out isMatch); if (map != null) { BreakpointBookmark newBookmark = new BreakpointBookmark(breakpoint.MemberReference, new TextLocation(map.StartLocation.Line, 0), breakpoint.FunctionToken, map.ILInstructionOffset, BreakpointAction.Break); newBookmark.IsEnabled = breakpoint.IsEnabled; newBookmarks.Add(newBookmark); BookmarkManager.RemoveMark(breakpoint); } } newBookmarks.ForEach(m => BookmarkManager.AddMark(m)); SyncCurrentLineBookmark(); }
ToolStripMenuItem MakeItem(string title, string name, BreakpointBookmark tag, string data, EventHandler onClick) { ToolStripMenuItem menuItem = new ToolStripMenuItem(StringParser.Parse(title)); menuItem.Click += onClick; menuItem.Name = name; menuItem.Tag = tag; if (name == tag.Action.ToString()) { menuItem.Checked = true; } return(menuItem); }
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; }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (dragDropBookmark != null) { dragDropCurrentPoint = e.GetPosition(this).Y; if (Math.Abs(dragDropCurrentPoint - dragDropStartPoint) > SystemParameters.MinimumVerticalDragDistance) { dragStarted = true; } InvalidateVisual(); } BreakpointBookmark bm = BookmarkManager.Bookmarks.Find( b => DebugData.CodeMappings != null && DebugData.CodeMappings.ContainsKey(b.MemberReference.MetadataToken.ToInt32()) && b.LineNumber == GetLineFromMousePosition(e) && b is BreakpointBookmark) as BreakpointBookmark; this.ToolTip = (bm != null) ? bm.Tooltip : null; }
public override void Run() { ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as ITextEditorControlProvider; BreakpointBookmark point = null; foreach (BreakpointBookmark breakpoint in DebuggerService.Breakpoints) { if ((breakpoint.FileName == provider.TextEditorControl.FileName) && (breakpoint.LineNumber == provider.TextEditorControl.ActiveTextAreaControl.Caret.Line)) { point = breakpoint; break; } } if (point != null) { point.IsEnabled = false; } }
public void AddBreakpoint(BreakpointBookmark breakpoint) { Breakpoint debuggerBreakpoint = Breakpoints.GetBreakpointByBookmark(breakpoint); if (debuggerBreakpoint == null) { var module = FindModule(x => x.Symbols != null); if (module == null) { PendingBreakpoints.Add(breakpoint); } else { module.TrySetBreakpoint(breakpoint); } } if (debuggerBreakpoint != null) { debuggerBreakpoint.Enabled = true; } }
public void InitializeService() { List <ISymbolSource> symbolSources = new List <ISymbolSource>(); symbolSources.Add(PdbSymbolSource); symbolSources.AddRange(AddInTree.BuildItems <ISymbolSource>("/SharpDevelop/Services/DebuggerService/SymbolSource", null, false)); // init NDebugger CurrentDebugger = new NDebugger(); CurrentDebugger.Options = DebuggingOptions.Instance; CurrentDebugger.SymbolSources = symbolSources; foreach (BreakpointBookmark b in SD.BookmarkManager.Bookmarks.OfType <BreakpointBookmark>()) { AddBreakpoint(b); } SD.BookmarkManager.BookmarkAdded += (sender, e) => { BreakpointBookmark bm = e.Bookmark as BreakpointBookmark; if (bm != null) { AddBreakpoint(bm); } }; SD.BookmarkManager.BookmarkRemoved += (sender, e) => { BreakpointBookmark bm = e.Bookmark as BreakpointBookmark; if (bm != null) { Breakpoint bp = bm.InternalBreakpointObject as Breakpoint; CurrentDebugger.RemoveBreakpoint(bp); } }; if (Initialize != null) { Initialize(this, null); } }
void HandleItem(object sender) { ToolStripMenuItem item = null; if (sender is ToolStripMenuItem) { item = (ToolStripMenuItem)sender; } if (item != null) { BreakpointBookmark bookmark = (BreakpointBookmark)item.Tag; switch (item.Name) { case "Break": bookmark.Action = BreakpointAction.Break; break; case "Condition": EditBreakpointScriptWindow window = new EditBreakpointScriptWindow(bookmark) { Owner = WorkbenchSingleton.MainWindow }; if (window.ShowDialog() ?? false) { bookmark = window.Data; } break; case "Trace": bookmark.Action = BreakpointAction.Trace; break; } } }
public bool IsValid(object caller, Condition condition) { if (WorkbenchSingleton.Workbench == null || WorkbenchSingleton.Workbench.ActiveWorkbenchWindow == null) { return(false); } ITextEditorControlProvider provider = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow.ActiveViewContent as ITextEditorControlProvider; if (provider == null) { return(false); } if (string.IsNullOrEmpty(provider.TextEditorControl.FileName)) { return(false); } BreakpointBookmark point = null; foreach (BreakpointBookmark breakpoint in DebuggerService.Breakpoints) { if ((breakpoint.FileName == provider.TextEditorControl.FileName) && (breakpoint.LineNumber == provider.TextEditorControl.ActiveTextAreaControl.Caret.Line)) { point = breakpoint; break; } } if (point != null) { return(point.IsEnabled); } return(false); }
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; }
public BreakpointBookmarkVM(BreakpointBookmark bpm) { this.bpm = bpm; }
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; }
/// <summary> /// Called when a breakpoint has been reached. /// </summary> internal void OnBreakpointTriggered(BreakpointBookmark bb) { OnDebugProcessIsSuspendedChanged(this, EventArgs.Empty); Dot42Addin.InvokeAsyncAndForget(() => JumpToCurrentLine()); }
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; }
public void LoadInternal() { ILSpySettings settings = ILSpySettings.Load(); var bpsx = settings["Breakpoints"]; BookmarkManager.RemoveMarks <BreakpointBookmark>(); foreach (var bpx in bpsx.Elements("Breakpoint")) { int? token = (int?)bpx.Attribute("Token"); string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath")); string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath")); uint? from = (uint?)bpx.Attribute("From"); uint? to = (uint?)bpx.Attribute("To"); bool? isEnabled = (bool?)bpx.Attribute("IsEnabled"); int? locationLine = (int?)bpx.Attribute("LocationLine"); int? locationColumn = (int?)bpx.Attribute("LocationColumn"); int? endLocationLine = (int?)bpx.Attribute("EndLocationLine"); int? endLocationColumn = (int?)bpx.Attribute("EndLocationColumn"); string methodFullName = SessionSettings.Unescape((string)bpx.Attribute("MethodFullName")); if (token == null) { continue; } if (string.IsNullOrEmpty(moduleFullPath)) { continue; } if (assemblyFullPath == null) { continue; } if (from == null || to == null || from.Value >= to.Value) { continue; } if (isEnabled == null) { continue; } if (locationLine == null || locationLine.Value < 1) { continue; } if (locationColumn == null || locationColumn.Value < 1) { continue; } if (endLocationLine == null || endLocationLine.Value < 1) { continue; } if (endLocationColumn == null || endLocationColumn.Value < 1) { continue; } var location = new TextLocation(locationLine.Value, locationColumn.Value); var endLocation = new TextLocation(endLocationLine.Value, endLocationColumn.Value); if (location >= endLocation) { continue; } ModuleDefMD loadedMod; try { loadedMod = MainWindow.Instance.LoadAssembly(assemblyFullPath, moduleFullPath).ModuleDefinition as ModuleDefMD; } catch { continue; } if (loadedMod == null) { continue; } var method = loadedMod.ResolveToken(token.Value) as MethodDef; if (method == null) { continue; } // Add an extra check to make sure that the file hasn't been re-created. This check // isn't perfect but should work most of the time unless the file was re-compiled // with the same tools and no methods were added or removed. if (method.FullName != methodFullName) { continue; } if (MethodKey.Create(method) == null) { continue; } var bpm = new BreakpointBookmark(method, location, endLocation, new ILRange(from.Value, to.Value), isEnabled.Value); BookmarkManager.AddMark(bpm); } }
private void RemoveBookmark(BreakpointBookmark bookmark) { _textEdit.Document.BookmarkManager.RemoveMark(bookmark); bookmark.RemoveMarker(); _textEdit.ActiveTextAreaControl.TextArea.Refresh(_textEdit.ActiveTextAreaControl.TextArea.IconBarMargin); }