public bool GetLocation(DecompilerTextView textView, out TextLocation location, out TextLocation endLocation) { var cm = textView == null ? null : textView.CodeMappings; MemberMapping mapping; var key = MethodKey.Create(MemberReference); if (cm == null || key == null || !cm.TryGetValue(key.Value, out mapping)) { location = endLocation = new TextLocation(); return(false); } bool isMatch; SourceCodeMapping map = mapping.GetInstructionByOffset(ilOffset, out isMatch); if (map == null) { location = endLocation = new TextLocation(); return(false); } location = map.StartLocation; endLocation = map.EndLocation; return(true); }
void SyncBookmarks() { if (MainWindow.Instance.ActiveTextView != decompilerTextView) { return; } var storage = decompilerTextView.CodeMappings; if (storage != null && storage.Count != 0) { for (int i = BookmarkManager.Bookmarks.Count - 1; i >= 0; --i) { var breakpoint = BookmarkManager.Bookmarks[i] as BreakpointBookmark; if (breakpoint == null) { continue; } var key = breakpoint.MethodKey; if (!storage.ContainsKey(key)) { continue; } bool isMatch; SourceCodeMapping map = storage[key].GetInstructionByOffset(breakpoint.ILRange.From, out isMatch); if (map == null) { continue; } breakpoint.UpdateLocation(map.StartLocation, map.EndLocation); } } }
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(); }
public void SyncBookmarks() { var storage = DebugInformation.CodeMappings; if (storage == null || storage.Count == 0) { return; } //remove existing bookmarks and create new ones 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.MemberReference.MetadataToken.ToInt32(); if (!storage.ContainsKey(key)) { continue; } var member = DebugInformation.DecompiledMemberReferences[key]; bool isMatch; SourceCodeMapping map = storage[key].GetInstructionByTokenAndOffset( member.MetadataToken.ToInt32(), breakpoint.ILRange.From, out isMatch); if (map != null) { newBookmarks.Add(new BreakpointBookmark( member, new AstLocation(map.SourceCodeLine, 0), map.ILInstructionOffset, BreakpointAction.Break, DebugInformation.Language)); BookmarkManager.RemoveMark(breakpoint); } } newBookmarks.ForEach(m => BookmarkManager.AddMark(m)); SyncCurrentLineBookmark(); }
List <SourceCodeMapping> GetClosest(int line) { var list = new List <SourceCodeMapping>(); foreach (var entry in memberMappings) { SourceCodeMapping map = null; foreach (var m in entry.MemberCodeMappings) { if (line > m.EndPosition.Line) { continue; } if (map == null || m.StartPosition < map.StartPosition) { map = m; } } if (map != null) { if (list.Count == 0) { list.Add(map); } else if (map.StartPosition == list[0].StartPosition) { list.Add(map); } else if (map.StartPosition < list[0].StartPosition) { list.Clear(); list.Add(map); } } } if (list.Count == 0) { return(null); } return(list.Distinct().ToList()); }
static List <SourceCodeMapping> GetClosest(Dictionary <MethodKey, MemberMapping> cm, int line) { List <SourceCodeMapping> list = new List <SourceCodeMapping>(); foreach (var entry in cm.Values) { SourceCodeMapping map = null; foreach (var m in entry.MemberCodeMappings) { if (line > m.EndLocation.Line) { continue; } if (map == null || m.StartLocation < map.StartLocation) { map = m; } } if (map != null) { if (list.Count == 0) { list.Add(map); } else if (map.StartLocation == list[0].StartLocation) { list.Add(map); } else if (map.StartLocation < list[0].StartLocation) { list.Clear(); list.Add(map); } } } if (list.Count == 0) { return(null); } return(list); }
public static bool DebugGetSourceCodeMappingForSetNextStatement(out string errMsg, out SourceCodeMapping mapping) { errMsg = string.Empty; mapping = null; if (DebuggerService.CurrentDebugger == null) { errMsg = "No debugger exists"; return(false); } if (!DebuggerService.CurrentDebugger.IsDebugging) { errMsg = "We're not debugging"; return(false); } if (DebuggerService.CurrentDebugger.IsProcessRunning) { errMsg = "Can't set next statement when the process is running"; return(false); } var textView = MainWindow.Instance.ActiveTextView; if (textView == null) { errMsg = "No tab is available. Decompile the current method!"; return(false); } Tuple <MethodKey, int, IMemberRef> info; MethodKey currentKey; Dictionary <MethodKey, MemberMapping> cm; if (!DebugUtils.VerifyAndGetCurrentDebuggedMethod(textView, out info, out currentKey, out cm)) { errMsg = "No debug information found. Make sure that only the debugged method is selected in the treeview (press 'Alt+Num *' to go to current statement)"; return(false); } var location = textView.TextEditor.TextArea.Caret.Location; var bps = SourceCodeMappingUtils.Find(cm, location.Line, location.Column); if (bps.Count == 0) { errMsg = "It's not possible to set the next statement here"; return(false); } // The method def could be different now if the debugged assembly was reloaded from disk // so use SigComparer and not object references to compare the methods. var flags = SigComparerOptions.CompareDeclaringTypes | SigComparerOptions.CompareAssemblyPublicKeyToken | SigComparerOptions.CompareAssemblyVersion | SigComparerOptions.CompareAssemblyLocale | SigComparerOptions.PrivateScopeIsComparable; foreach (var bp in bps) { if (new SigComparer(flags).Equals(bp.MemberMapping.MethodDefinition, info.Item3)) { mapping = bp; break; } } if (mapping == null) { errMsg = "The next statement cannot be set to another method"; return(false); } return(true); }
static int Sort(SourceCodeMapping a, SourceCodeMapping b) { return(a.StartPosition.CompareTo(b.StartPosition)); }
public RefPos(IList <SourceCodeMapping> sourceCodeMappings) { this.SourceCodeMapping = sourceCodeMappings.Count > 0 ? sourceCodeMappings[0] : null; }