예제 #1
0
        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;

            InitializeExeFields(dnModule, filename, imageLayout, out var isExe, out var timestamp, out var version);

            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;
                reflectionAssembly = reflectionAppDomain.CreateAssembly(getMetadata, isInMemory, isDynamic, fullyQualifiedName, assemblyLocation);
                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)));
        }
예제 #2
0
 static Func <DmdLazyMetadataBytes> CreateGetMetadataDelegate(DbgEngineImpl engine, DbgRuntime runtime, DnModule dnModule, ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
 {
     if (dnModule.IsDynamic)
     {
         return(CreateDynamicGetMetadataDelegate(engine, dnModule));
     }
     else
     {
         return(CreateNormalGetMetadataDelegate(engine, runtime, dnModule, closedListenerCollection, imageLayout));
     }
 }
예제 #3
0
        static Func <DmdLazyMetadataBytes> CreateNormalGetMetadataDelegate(DbgEngineImpl engine, DbgRuntime runtime, DnModule dnModule, ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
        {
            Debug.Assert(!dnModule.IsDynamic);

            return(() => {
                var rawMd = engine.RawMetadataService.Create(runtime, imageLayout == DbgImageLayout.File, dnModule.Address, (int)dnModule.Size);
                try {
                    closedListenerCollection.Closed += (s, e) => rawMd.Release();
                    return new DmdLazyMetadataBytesPtr(rawMd.Address, (uint)rawMd.Size, rawMd.IsFileLayout);
                }
                catch {
                    rawMd.Release();
                    throw;
                }
            });
        }
예제 #4
0
 public DbgCorDebugInternalModuleImpl(DmdModule reflectionModule, ClosedListenerCollection closedListenerCollection)
 {
     ReflectionModule = reflectionModule ?? throw new ArgumentNullException(nameof(reflectionModule));
     this.closedListenerCollection = closedListenerCollection ?? throw new ArgumentNullException(nameof(closedListenerCollection));
 }