public void LoadInternal() { ILSpySettings settings = ILSpySettings.Load(); var bpsx = settings["Breakpoints"]; BreakpointManager.Instance.Clear(); foreach (var bpx in bpsx.Elements("Breakpoint")) { uint? token = (uint?)bpx.Attribute("Token"); string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath")); string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath")); bool isDynamic = (bool?)bpx.Attribute("IsDynamic") ?? false; bool isInMemory = (bool?)bpx.Attribute("IsInMemory") ?? false; uint? ilOffset = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From");//TODO: Remove "From" some time after this commit bool? isEnabled = (bool?)bpx.Attribute("IsEnabled"); if (token == null) continue; if (string.IsNullOrEmpty(moduleFullPath)) continue; if (ilOffset == null) continue; if (isEnabled == null) continue; var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory); var key = MethodKey.Create(token.Value, snModule); var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value); BreakpointManager.Instance.Add(bp); } }
internal void RefreshIfNameError(SerializedDnModule serMod) { if (!NameError) { return; } var dnbp = Breakpoint.DnBreakpoint as DnILCodeBreakpoint; if (dnbp == null) { return; } if (dnbp.Module != serMod) { return; } // If we still can't resolve the method, there's no need to refresh the name field if (GetMethodDef(true) == null) { return; } RefreshNameField(); }
internal DnCodeBreakpoint(SerializedDnModule module, uint token, uint offset) { this.module = module; this.token = token; this.offset = offset; this.code = null; }
internal DnILCodeBreakpoint(SerializedDnModule module, uint token, uint ilOffset, IBreakpointCondition bpCond) : base(bpCond) { this.module = module; this.token = token; this.ilOffset = ilOffset; }
internal DnModule(DnAssembly ownerAssembly, ICorDebugModule module, int incrementedId, int moduleOrder) { this.ownerAssembly = ownerAssembly; this.module = new CorModule(module); this.incrementedId = incrementedId; this.moduleOrder = moduleOrder; this.serializedDnModule = this.module.SerializedDnModule; }
internal DnCodeBreakpoint(CorCode code, uint offset) { this.module = GetModule(code); var func = code.Function; this.token = func == null ? 0 : func.Token; this.offset = offset; this.code = code; }
MethodKey(uint token, ModuleDef module) { this.token = token; if (string.IsNullOrEmpty(module.Location)) { throw new ArgumentException("Module has no path"); } this.module = new SerializedDnModule(Path.GetFullPath(module.Location)); }
void LoadInternal() { var section = settingsManager.GetOrCreateSection(SETTINGS_GUID); breakpointManager.Clear(); foreach (var bpx in section.SectionsWithName("Breakpoint")) { uint? token = bpx.Attribute <uint?>("Token"); string asmFullName = bpx.Attribute <string>("AssemblyFullName"); string moduleName = bpx.Attribute <string>("ModuleName"); bool? isDynamic = bpx.Attribute <bool?>("IsDynamic"); bool? isInMemory = bpx.Attribute <bool?>("IsInMemory"); bool moduleNameOnly = bpx.Attribute <bool?>("ModuleNameOnly") ?? false; uint? ilOffset = bpx.Attribute <uint?>("ILOffset"); bool? isEnabled = bpx.Attribute <bool?>("IsEnabled"); if (token == null) { continue; } if (isDynamic == null || isInMemory == null) { continue; } if (string.IsNullOrEmpty(asmFullName) && !moduleNameOnly) { continue; } if (string.IsNullOrEmpty(moduleName)) { continue; } if (ilOffset == null) { continue; } if (isEnabled == null) { continue; } var snModule = SerializedDnModule.Create(asmFullName, moduleName, isDynamic.Value, isInMemory.Value, moduleNameOnly); var key = new SerializedDnToken(snModule, token.Value); if (!isInMemory.Value && !isDynamic.Value) { var s = bpx.Attribute <string>("Method"); if (s == null || s != GetMethodAsString(key)) { continue; } } var bp = new ILCodeBreakpoint(key, ilOffset.Value, isEnabled.Value); breakpointManager.Add(bp); } }
DnModule GetDnModule(SerializedDnModule serMod) { var dbg = theDebugger.Value.Debugger; if (dbg == null) return null; //TODO: This method should have an AppDomain parameter. foreach (var m in dbg.Modules) { if (m.SerializedDnModule.Equals(serMod)) return m; } return null; }
IDnSpyFile LoadNonDiskFile(SerializedDnModule serMod, bool canLoadDynFile) { if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory) { var dnModule = GetDnModule(serMod); if (dnModule != null) { return(inMemoryModuleManager.Value.LoadFile(dnModule, canLoadDynFile)); } } return(null); }
internal static SerializedDnModule Create(IFileTreeView fileTreeView, ModuleDef module) { if (module == null) { return(new SerializedDnModule()); } var modNode = fileTreeView.FindNode(module); if (modNode == null) { return(SerializedDnModule.CreateFromFile(module)); } return(modNode.DnSpyFile.ToSerializedDnModule()); }
void LoadInternal() { DNSpySettings settings = DNSpySettings.Load(); var bpsx = settings[SETTINGS_NAME]; BreakpointManager.Instance.Clear(); foreach (var bpx in bpsx.Elements("Breakpoint")) { uint? token = (uint?)bpx.Attribute("Token"); string assemblyFullPath = SessionSettings.Unescape((string)bpx.Attribute("AssemblyFullPath")); string moduleFullPath = SessionSettings.Unescape((string)bpx.Attribute("ModuleFullPath")); bool isDynamic = (bool?)bpx.Attribute("IsDynamic") ?? false; bool isInMemory = (bool?)bpx.Attribute("IsInMemory") ?? false; uint? ilOffset = (uint?)bpx.Attribute("ILOffset") ?? (uint?)bpx.Attribute("From"); //TODO: Remove "From" some time after this commit bool? isEnabled = (bool?)bpx.Attribute("IsEnabled"); if (token == null) { continue; } if (string.IsNullOrEmpty(moduleFullPath)) { continue; } if (ilOffset == null) { continue; } if (isEnabled == null) { continue; } var snModule = new SerializedDnModule(moduleFullPath, isDynamic, isInMemory); var key = MethodKey.Create(token.Value, snModule); if (!isInMemory) { var s = SessionSettings.Unescape((string)bpx.Attribute("Method")); if (s == null || s != GetMethodAsString(assemblyFullPath, key)) { continue; } } var bp = new ILCodeBreakpoint(assemblyFullPath, key, ilOffset.Value, isEnabled.Value); BreakpointManager.Instance.Add(bp); } }
internal void RefreshIfNameError(SerializedDnModule serMod) { if (!NameError) return; var dnbp = Breakpoint.DnBreakpoint as DnILCodeBreakpoint; if (dnbp == null) return; if (dnbp.Module != serMod) return; // If we still can't resolve the method, there's no need to refresh the name field if (GetMethodDef(true) == null) return; RefreshNameField(); }
public static SerializedDnModule ToSerializedDnModule(this IDnSpyFile file) { var sdm = file as ISerializedDnModule; if (sdm != null) { return(sdm.SerializedDnModule ?? new SerializedDnModule()); } var mod = file.ModuleDef; if (mod == null) { return(new SerializedDnModule()); } return(SerializedDnModule.CreateFromFile(mod)); }
DnModule GetDnModule(SerializedDnModule serMod) { var dbg = theDebugger.Value.Debugger; if (dbg == null) { return(null); } //TODO: This method should have an AppDomain parameter. foreach (var m in dbg.Modules) { if (m.SerializedDnModule.Equals(serMod)) { return(m); } } return(null); }
IDnSpyFile LoadExisting(SerializedDnModule serMod) { foreach (var file in AllActiveDnSpyFiles) { var serModFile = file.ToSerializedDnModule(); if (serModFile.Equals(serMod)) { return(file); } } foreach (var file in AllDnSpyFiles) { var serModFile = file.ToSerializedDnModule(); if (serModFile.Equals(serMod)) { return(file); } } return(null); }
IEnumerable<DnModule> GetLoadedDnModules(SerializedDnModule module) { foreach (var process in processes.GetAll()) { foreach (var appDomain in process.AppDomains) { foreach (var assembly in appDomain.Assemblies) { foreach (var dnMod in assembly.Modules) { if (dnMod.SerializedDnModule.Equals(module)) yield return dnMod; } } } } }
public static void GoToIL(IFileTabManager fileTabManager, IModuleLoader moduleLoader, SerializedDnModule serAsm, uint token, uint ilOffset, bool newTab) { var file = moduleLoader.LoadModule(serAsm, true); GoToIL(fileTabManager, file, token, ilOffset, newTab); }
public static MethodKey Create(uint token, SerializedDnModule module) { return(new MethodKey(token, module)); }
void SetILBreakpoint(SerializedDnModule serMod, uint token) { Debug.Assert(token != 0 && breakpoint == null); DnBreakpoint bp = null; bp = debugger.CreateBreakpoint(serMod, token, 0, ctx2 => { debugger.RemoveBreakpoint(bp); return true; }); }
MethodKey(uint token, SerializedDnModule module) { this.module = module; this.token = token; }
public static SerializedDnSpyModule ToSerializedDnSpyModule(this SerializedDnModule self) { return(SerializedDnSpyModule.Create(self.AssemblyFullName, self.ModuleName, self.IsDynamic, self.IsInMemory)); }
IDnSpyFile LoadExisting(SerializedDnModule serMod) { foreach (var file in AllActiveDnSpyFiles) { var serModFile = file.ToSerializedDnModule(); if (serModFile.Equals(serMod)) return file; } foreach (var file in AllDnSpyFiles) { var serModFile = file.ToSerializedDnModule(); if (serModFile.Equals(serMod)) return file; } return null; }
IDnSpyFile LoadNonDiskFile(SerializedDnModule serMod, bool canLoadDynFile) { if (UseMemoryModules || serMod.IsDynamic || serMod.IsInMemory) { var dnModule = GetDnModule(serMod); if (dnModule != null) return inMemoryModuleManager.Value.LoadFile(dnModule, canLoadDynFile); } return null; }
internal DnNativeCodeBreakpoint(SerializedDnModule module, uint token, uint offset, Func<NativeCodeBreakpointConditionContext, bool> cond) : base(module, token, offset) { this.cond = cond ?? defaultCond; }
public IDnSpyFile LoadModule(SerializedDnModule serMod, bool canLoadDynFile, bool diskFileOk = false) { const bool isAutoLoaded = true; IDnSpyFile file; if (diskFileOk) { file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile); if (file != null) return file; } else { file = LoadNonDiskFile(serMod, canLoadDynFile) ?? LoadExisting(serMod); if (file != null) return file; } if (serMod.IsDynamic || serMod.IsInMemory) return null; string moduleFilename = serMod.ModuleName; if (!File.Exists(moduleFilename)) return null; string asmFilename = GetAssemblyFilename(moduleFilename, serMod.AssemblyFullName, serMod.ModuleNameOnly); if (!string.IsNullOrEmpty(asmFilename)) { file = fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(asmFilename), isAutoLoaded); if (file == null) file = fileManager.Resolve(new AssemblyNameInfo(serMod.AssemblyFullName), null); if (file != null) { // Common case is a one-file assembly or first module of a multifile assembly if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase)) return file; foreach (var child in file.Children) { if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase)) return child; } } } return fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(moduleFilename), isAutoLoaded); }
LoadedAssembly LoadAssembly(string asmName, SerializedDnModule module, bool open) { if (module.IsInMemory) return null;//TODO: Support in-memory modules string moduleFilename = module.Name; lock (assemblyList.GetLockObj()) { var loadedAsm = open ? assemblyList.OpenAssemblyDelay(asmName, true) : assemblyList.FindAssemblyByFileName(asmName); if (loadedAsm == null) return null; // Common case is a one-file assembly or first module of a multifile assembly if (asmName.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase)) return loadedAsm; var loadedMod = assemblyListTreeNode.FindModule(loadedAsm, moduleFilename); if (loadedMod != null) return loadedMod; Debug.Fail("Shouldn't be here."); return open ? assemblyList.OpenAssemblyDelay(moduleFilename, true) : null; } }
public LoadedAssembly TryLoadAssembly(string asmName, SerializedDnModule module) { return LoadAssembly(asmName, module, false); }
public IDnSpyFile LoadModule(SerializedDnModule serMod, bool canLoadDynFile, bool diskFileOk = false) { const bool isAutoLoaded = true; IDnSpyFile file; if (diskFileOk) { file = LoadExisting(serMod) ?? LoadNonDiskFile(serMod, canLoadDynFile); if (file != null) { return(file); } } else { file = LoadNonDiskFile(serMod, canLoadDynFile) ?? LoadExisting(serMod); if (file != null) { return(file); } } if (serMod.IsDynamic || serMod.IsInMemory) { return(null); } string moduleFilename = serMod.ModuleName; if (!File.Exists(moduleFilename)) { return(null); } string asmFilename = GetAssemblyFilename(moduleFilename, serMod.AssemblyFullName); if (!string.IsNullOrEmpty(asmFilename)) { file = fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(asmFilename), isAutoLoaded); if (file == null) { file = fileManager.Resolve(new AssemblyNameInfo(serMod.AssemblyFullName), null); } if (file != null) { // Common case is a one-file assembly or first module of a multifile assembly if (asmFilename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase)) { return(file); } foreach (var child in file.Children) { if (child.Filename.Equals(moduleFilename, StringComparison.OrdinalIgnoreCase)) { return(child); } } } } return(fileManager.TryGetOrCreate(DnSpyFileInfo.CreateFile(moduleFilename), isAutoLoaded)); }
public SerializedDnToken(SerializedDnModule module, uint token) { this.module = module; this.token = token; }
/// <summary> /// Creates an IL instruction breakpoint /// </summary> /// <param name="module">Module</param> /// <param name="token">Method token</param> /// <param name="ilOffset">IL offset</param> /// <param name="cond">Condition</param> /// <returns></returns> public DnILCodeBreakpoint CreateBreakpoint(SerializedDnModule module, uint token, uint ilOffset, Predicate<BreakpointConditionContext> cond) { DebugVerifyThread(); return CreateBreakpoint(module, token, ilOffset, new DelegateBreakpointCondition(cond)); }
/// <summary> /// Creates an IL instruction breakpoint /// </summary> /// <param name="module">Module</param> /// <param name="token">Method token</param> /// <param name="ilOffset">IL offset</param> /// <param name="bpCond">Condition or null</param> /// <returns></returns> public DnILCodeBreakpoint CreateBreakpoint(SerializedDnModule module, uint token, uint ilOffset, IBreakpointCondition bpCond = null) { DebugVerifyThread(); var bp = new DnILCodeBreakpoint(module, token, ilOffset, bpCond); ilCodeBreakpointList.Add(module, bp); foreach (var dnMod in GetLoadedDnModules(module)) bp.AddBreakpoint(dnMod); return bp; }
public SerializedDnToken(SerializedDnModule module, MDToken mdToken) : this(module, mdToken.Raw) { }