DbgAppDomainImpl VerifyOptionalAppDomain(DbgAppDomain appDomain) { if (appDomain == null) { return(null); } var appDomainImpl = appDomain as DbgAppDomainImpl; if (appDomainImpl == null) { throw new ArgumentOutOfRangeException(nameof(appDomain)); } if (appDomainImpl.Runtime != runtime) { throw new ArgumentException(); } return(appDomainImpl); }
public override DbgEngineModule CreateModule <T>(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineModule> onCreated) { if (disposed) { throw new ObjectDisposedException(nameof(DbgObjectFactoryImpl)); } var module = new DbgModuleImpl(runtime, VerifyOptionalAppDomain(appDomain), internalModule, isExe, address, size, imageLayout, name, filename, isDynamic, isInMemory, isOptimized, order, timestamp, version); if (data != null) { module.GetOrCreateData(() => data); } var engineModule = new DbgEngineModuleImpl(module); onCreated?.Invoke(engineModule); owner.Dispatcher.BeginInvoke(() => owner.AddModule_DbgThread(runtime, module, messageFlags)); return(engineModule); }
ulong?GetManagedId(DnThread thread, DbgAppDomain appDomain) { var res = ReadField_CorDebug(TryGetThreadObject(thread), appDomain, "m_ManagedThreadId"); if (res == null || !res.HasValue) { return(null); } if (res.Value.ValueType == DbgSimpleValueType.Int32) { return((uint)(int)res.Value.RawValue); } if (res.Value.ValueType == DbgSimpleValueType.UInt32) { return((uint)res.Value.RawValue); } return(null); }
public override DbgEngineThread CreateThread <T>(DbgAppDomain appDomain, string kind, ulong id, ulong?managedId, string name, int suspendedCount, ReadOnlyCollection <DbgStateInfo> state, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineThread> onCreated) { if (disposed) { throw new ObjectDisposedException(nameof(DbgObjectFactoryImpl)); } var thread = new DbgThreadImpl(runtime, VerifyOptionalAppDomain(appDomain), kind, id, managedId, name, suspendedCount, state); if (data != null) { thread.GetOrCreateData(() => data); } var engineThread = new DbgEngineThreadImpl(thread); onCreated?.Invoke(engineThread); owner.Dispatcher.BeginInvoke(() => owner.AddThread_DbgThread(runtime, thread, messageFlags)); return(engineThread); }
public static DbgEngineModule CreateModule <T>(DbgEngineImpl engine, DbgObjectFactory objectFactory, DbgAppDomain appDomain, DnModule dnModule, T data) where T : class { ulong address = dnModule.Address; uint size = dnModule.Size; var imageLayout = CalculateImageLayout(dnModule); string name = GetFilename(dnModule.Name); string filename = dnModule.Name; bool isDynamic = dnModule.IsDynamic; bool isInMemory = dnModule.IsInMemory; bool? isOptimized = CalculateIsOptimized(dnModule); int order = dnModule.UniqueId + 1; // 0-based to 1-based InitializeExeFields(dnModule, filename, imageLayout, out var isExe, out var isDll, out var timestamp, out var version, out var assemblySimpleName); var reflectionAppDomain = ((DbgCorDebugInternalAppDomainImpl)appDomain.InternalAppDomain).ReflectionAppDomain; var closedListenerCollection = new ClosedListenerCollection(); var modules = dnModule.Assembly.Modules; bool isManifestModule = modules[0] == dnModule; var getMetadata = CreateGetMetadataDelegate(engine, objectFactory.Runtime, dnModule, closedListenerCollection, imageLayout); var fullyQualifiedName = DmdModule.GetFullyQualifiedName(isInMemory, isDynamic, dnModule.Name); DmdAssembly reflectionAssembly; DmdModule reflectionModule; if (isManifestModule) { var assemblyLocation = isInMemory || isDynamic ? string.Empty : dnModule.Name; var asmOptions = DmdCreateAssemblyOptions.None; if (isInMemory) { asmOptions |= DmdCreateAssemblyOptions.InMemory; } if (isDynamic) { asmOptions |= DmdCreateAssemblyOptions.Dynamic; } if (isExe) { asmOptions |= DmdCreateAssemblyOptions.IsEXE; } else if (isDll) { asmOptions |= DmdCreateAssemblyOptions.IsDLL; } var asmInfo = new DmdCreateAssemblyInfo(asmOptions, fullyQualifiedName, assemblyLocation, assemblySimpleName); reflectionAssembly = reflectionAppDomain.CreateAssembly(getMetadata, asmInfo); reflectionModule = reflectionAssembly.ManifestModule; } else { var manifestModule = engine.TryGetModule(modules[0].CorModule); if (manifestModule == null) { throw new InvalidOperationException(); } reflectionAssembly = ((DbgCorDebugInternalModuleImpl)manifestModule.InternalModule).ReflectionModule.Assembly; reflectionModule = reflectionAppDomain.CreateModule(reflectionAssembly, getMetadata, isInMemory, isDynamic, fullyQualifiedName); } var internalModule = new DbgCorDebugInternalModuleImpl(reflectionModule, closedListenerCollection); return(objectFactory.CreateModule(appDomain, internalModule, isExe, address, size, imageLayout, name, filename, isDynamic, isInMemory, isOptimized, order, timestamp, version, engine.GetMessageFlags(), data: data, onCreated: engineModule => internalModule.SetModule(engineModule.Module))); }
/// <summary> /// Updates <see cref="DbgThread.AppDomain"/> /// </summary> /// <param name="appDomain">New value</param> public void UpdateAppDomain(DbgAppDomain appDomain) => Update(UpdateOptions.AppDomain, appDomain: appDomain);
/// <summary> /// Creates a module. The engine has paused the program. /// </summary> /// <param name="appDomain">New <see cref="DbgModule.AppDomain"/> value</param> /// <param name="internalModule">Module object created by the debug engine</param> /// <param name="isExe">New <see cref="DbgModule.IsExe"/> value</param> /// <param name="address">New <see cref="DbgModule.Address"/> value</param> /// <param name="size">New <see cref="DbgModule.Size"/> value</param> /// <param name="imageLayout">New <see cref="DbgModule.ImageLayout"/> value</param> /// <param name="name">New <see cref="DbgModule.Name"/> value</param> /// <param name="filename">New <see cref="DbgModule.Filename"/> value</param> /// <param name="isDynamic">New <see cref="DbgModule.IsDynamic"/> value</param> /// <param name="isInMemory">New <see cref="DbgModule.IsInMemory"/> value</param> /// <param name="isOptimized">New <see cref="DbgModule.IsOptimized"/> value</param> /// <param name="order">New <see cref="DbgModule.Order"/> value</param> /// <param name="timestamp">New <see cref="DbgModule.Timestamp"/> value</param> /// <param name="version">New <see cref="DbgModule.Version"/> value</param> /// <param name="messageFlags">Message flags</param> /// <returns></returns> public DbgEngineModule CreateModule(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags) => CreateModule <object>(appDomain, internalModule, isExe, address, size, imageLayout, name, filename, isDynamic, isInMemory, isOptimized, order, timestamp, version, messageFlags, null, null);
/// <summary> /// Creates a thread. The engine has paused the program. /// </summary> /// <typeparam name="T">Type of data</typeparam> /// <param name="appDomain">New <see cref="DbgThread.AppDomain"/> value</param> /// <param name="kind">New <see cref="DbgThread.Kind"/> value</param> /// <param name="id">New <see cref="DbgThread.Id"/> value</param> /// <param name="managedId">New <see cref="DbgThread.ManagedId"/> value</param> /// <param name="name">New <see cref="DbgThread.Name"/> value</param> /// <param name="suspendedCount">New <see cref="DbgThread.SuspendedCount"/> value</param> /// <param name="state">New <see cref="DbgThread.State"/> value</param> /// <param name="messageFlags">Message flags</param> /// <param name="data">Data to add to the <see cref="DbgThread"/> or null if nothing gets added</param> /// <param name="onCreated">Called right after creating the thread but before adding it to internal data structures. This can be null.</param> /// <returns></returns> public abstract DbgEngineThread CreateThread <T>(DbgAppDomain appDomain, string kind, ulong id, ulong?managedId, string name, int suspendedCount, ReadOnlyCollection <DbgStateInfo> state, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineThread> onCreated = null) where T : class;
/// <summary> /// Creates a thread. The engine has paused the program. /// </summary> /// <param name="appDomain">New <see cref="DbgThread.AppDomain"/> value</param> /// <param name="kind">New <see cref="DbgThread.Kind"/> value</param> /// <param name="id">New <see cref="DbgThread.Id"/> value</param> /// <param name="managedId">New <see cref="DbgThread.ManagedId"/> value</param> /// <param name="name">New <see cref="DbgThread.Name"/> value</param> /// <param name="suspendedCount">New <see cref="DbgThread.SuspendedCount"/> value</param> /// <param name="state">New <see cref="DbgThread.State"/> value</param> /// <param name="messageFlags">Message flags</param> /// <returns></returns> public DbgEngineThread CreateThread(DbgAppDomain appDomain, string kind, ulong id, ulong?managedId, string name, int suspendedCount, ReadOnlyCollection <DbgStateInfo> state, DbgEngineMessageFlags messageFlags) => CreateThread <object>(appDomain, kind, id, managedId, name, suspendedCount, state, messageFlags, null, null);
/// <summary> /// Creates a module. The engine has paused the program. /// </summary> /// <typeparam name="T">Type of data</typeparam> /// <param name="appDomain">New <see cref="DbgModule.AppDomain"/> value</param> /// <param name="internalModule">Module object created by the debug engine</param> /// <param name="isExe">New <see cref="DbgModule.IsExe"/> value</param> /// <param name="address">New <see cref="DbgModule.Address"/> value</param> /// <param name="size">New <see cref="DbgModule.Size"/> value</param> /// <param name="imageLayout">New <see cref="DbgModule.ImageLayout"/> value</param> /// <param name="name">New <see cref="DbgModule.Name"/> value</param> /// <param name="filename">New <see cref="DbgModule.Filename"/> value</param> /// <param name="isDynamic">New <see cref="DbgModule.IsDynamic"/> value</param> /// <param name="isInMemory">New <see cref="DbgModule.IsInMemory"/> value</param> /// <param name="isOptimized">New <see cref="DbgModule.IsOptimized"/> value</param> /// <param name="order">New <see cref="DbgModule.Order"/> value</param> /// <param name="timestamp">New <see cref="DbgModule.Timestamp"/> value</param> /// <param name="version">New <see cref="DbgModule.Version"/> value</param> /// <param name="messageFlags">Message flags</param> /// <param name="data">Data to add to the <see cref="DbgModule"/> or null if nothing gets added</param> /// <param name="onCreated">Called right after creating the module but before adding it to internal data structures. This can be null.</param> /// <returns></returns> public abstract DbgEngineModule CreateModule <T>(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineModule> onCreated = null) where T : class;
internal void SetAppDomain(DbgAppDomain appDomain) { this.appDomain = appDomain ?? throw new ArgumentNullException(nameof(appDomain)); ReflectionAppDomain.GetOrCreateData(() => appDomain); }
public static DbgEngineModule CreateModule <T>(DbgEngineImpl engine, DbgObjectFactory objectFactory, DbgAppDomain appDomain, ModuleMirror monoModule, int moduleOrder, T data) where T : class => new ModuleCreator(engine, objectFactory, appDomain, monoModule, moduleOrder).CreateModuleCore(data);
/// <summary> /// Updates <see cref="DbgThread"/> properties /// </summary> /// <param name="options">Options</param> /// <param name="appDomain">New <see cref="DbgThread.AppDomain"/> value</param> /// <param name="kind">New <see cref="DbgThread.Kind"/> value</param> /// <param name="id">New <see cref="DbgThread.Id"/> value</param> /// <param name="managedId">New <see cref="DbgThread.ManagedId"/> value</param> /// <param name="name">New <see cref="DbgThread.Name"/> value</param> /// <param name="suspendedCount">New <see cref="DbgThread.SuspendedCount"/> value</param> /// <param name="state">New <see cref="DbgThread.State"/> value</param> public abstract void Update(UpdateOptions options, DbgAppDomain appDomain = null, string kind = null, ulong id = 0, ulong?managedId = null, string name = null, int suspendedCount = 0, ReadOnlyCollection <DbgStateInfo> state = null);