public static void ToggleBreakpointAt(IDocument document, string fileName, int lineNumber) { foreach (Bookmark m in document.BookmarkManager.Marks) { BreakpointBookmark breakpoint = m as BreakpointBookmark; if (breakpoint != null) { if (breakpoint.LineNumber == lineNumber) { document.BookmarkManager.RemoveMark(m); return; } } } foreach (char ch in document.GetText(document.GetLineSegment(lineNumber))) { if (!char.IsWhiteSpace(ch)) { document.BookmarkManager.AddMark(new BreakpointBookmark(fileName, document, lineNumber)); document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber)); document.CommitUpdate(); break; } } }
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}"); }
public static void ToggleBreakpointAt(IDocument document, string fileName, int lineNumber) { ReadOnlyCollection <Bookmark> bookmarks = document.BookmarkManager.Marks; for (int i = bookmarks.Count - 1; i >= 0; --i) { BreakpointBookmark breakpoint = bookmarks[i] as BreakpointBookmark; if (breakpoint != null) { if (breakpoint.LineNumber == lineNumber) { document.BookmarkManager.RemoveMark(breakpoint); return; } } } int column = 0; foreach (char ch in document.GetText(document.GetLineSegment(lineNumber))) { if (!char.IsWhiteSpace(ch)) { document.BookmarkManager.AddMark(new BreakpointBookmark(fileName, document, new TextLocation(column, lineNumber), BreakpointAction.Break, "", "")); document.RequestUpdate(new TextAreaUpdate(TextAreaUpdateType.SingleLine, lineNumber)); document.CommitUpdate(); break; } column++; } }
/// <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 BookmarkChanged(object sender, EventArgs e) { BreakpointBookmark bb = sender as BreakpointBookmark; if (bb != null) { OnBreakPointChanged(new BreakpointBookmarkEventArgs(bb)); } }
static void BookmarkAdded(object sender, BookmarkEventArgs e) { BreakpointBookmark bb = e.Bookmark as BreakpointBookmark; if (bb != null) { bb.LineNumberChanged += BookmarkChanged; OnBreakPointAdded(new BreakpointBookmarkEventArgs(bb)); } }
static void BookmarkRemoved(object sender, BookmarkEventArgs e) { BreakpointBookmark bb = e.Bookmark as BreakpointBookmark; if (bb != null) { bb.RemoveMarker(); OnBreakPointRemoved(new BreakpointBookmarkEventArgs(bb)); } }
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> /// 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; }); } }
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; }
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 = 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 = 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 = 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> /// 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> /// 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)); } } }
/// <summary> /// Default ctor /// </summary> public DebugLocationBreakpoint(Jdwp.EventKind eventKind, SourceCodePosition sourcePosition, TypeEntry typeEntry, MethodEntry methodEntry, BreakpointBookmark bookmark) : base(eventKind, sourcePosition, typeEntry, methodEntry) { this.bookmark = bookmark; InvalidateBookmark(); }
/// <summary> /// Called when a breakpoint has been reached. /// </summary> internal void OnBreakpointTriggered(BreakpointBookmark bb) { OnDebugProcessIsSuspendedChanged(this, EventArgs.Empty); Dot42Addin.InvokeAsyncAndForget(() => JumpToCurrentLine()); }
public BreakpointBookmarkEventArgs(BreakpointBookmark breakpointBookmark) { this.breakpointBookmark = breakpointBookmark; }
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; }