public static bool JumpTo(DecompilerTextView textView, IMemberRef mr, MethodKey key, int ilOffset) { return(MainWindow.Instance.JumpToReference(textView, mr, (success, hasMovedCaret) => { if (success) { return MoveCaretTo(textView, key, ilOffset); } return false; })); }
static bool MoveCaretTo(DecompilerTextView textView, MethodKey key, int ilOffset) { if (textView == null) { return(false); } TextLocation location, endLocation; var cm = textView.CodeMappings; if (cm == null || !cm.ContainsKey(key)) { return(false); } if (!cm[key].GetInstructionByTokenAndOffset(unchecked ((uint)ilOffset), out location, out endLocation)) { //TODO: Missing IL ranges return(false); } else { textView.ScrollAndMoveCaretTo(location.Line, location.Column); return(true); } }
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); } }
/// <summary> /// Gets the current debugged method /// </summary> /// <param name="info"></param> /// <param name="currentKey"></param> /// <param name="codeMappings"></param> /// <returns></returns> public static bool VerifyAndGetCurrentDebuggedMethod(DecompilerTextView textView, out Tuple <MethodKey, int, IMemberRef> info, out MethodKey currentKey, out Dictionary <MethodKey, MemberMapping> codeMappings) { currentKey = default(MethodKey); codeMappings = textView == null ? null : textView.CodeMappings; info = DebugInformation.DebugStepInformation; if (info == null) { return(false); } currentKey = info.Item1; if (codeMappings == null || !codeMappings.ContainsKey(currentKey)) { return(false); } return(true); }