Exemplo n.º 1
0
        internal unsafe static ImmutableArray <MetadataBlock> GetMetadataBlocks(this DkmClrRuntimeInstance runtime, DkmClrAppDomain appDomain)
        {
            var builder = ArrayBuilder <MetadataBlock> .GetInstance();

            IntPtr ptr;
            uint   size;

            foreach (DkmClrModuleInstance module in runtime.GetModulesInAppDomain(appDomain))
            {
                MetadataBlock block;
                try
                {
                    ptr = module.GetMetaDataBytesPtr(out size);
                    Debug.Assert(size > 0);
                    block = GetMetadataBlock(ptr, size);
                }
                catch (NotImplementedException e) when(module is DkmClrNcModuleInstance)
                {
                    // DkmClrNcModuleInstance.GetMetaDataBytesPtr not implemented in Dev14.
                    throw new NotImplementedMetadataException(e);
                }
                catch (Exception e) when(MetadataUtilities.IsBadOrMissingMetadataException(e, module.FullName))
                {
                    continue;
                }
                Debug.Assert(block.ModuleVersionId == module.Mvid);
                builder.Add(block);
            }
            // Include "intrinsic method" assembly.
            ptr = runtime.GetIntrinsicAssemblyMetaDataBytesPtr(out size);
            builder.Add(GetMetadataBlock(ptr, size));
            return(builder.ToImmutableAndFree());
        }
Exemplo n.º 2
0
        internal static ImmutableArray <MetadataBlock> GetMetadataBlocks(
            this DkmClrRuntimeInstance runtime,
            DkmClrAppDomain appDomain,
            ImmutableArray <MetadataBlock> previousMetadataBlocks)
        {
            // Add a dummy data item to the appdomain to add it to the disposal queue when the debugged process is shutting down.
            // This should prevent from attempts to use the Metadata pointer for dead debugged processes.
            if (appDomain.GetDataItem <AppDomainLifetimeDataItem>() == null)
            {
                appDomain.SetDataItem(DkmDataCreationDisposition.CreateNew, new AppDomainLifetimeDataItem());
            }

            var builder = ArrayBuilder <MetadataBlock> .GetInstance();

            IntPtr ptr;
            uint   size;
            int    index = 0;

            foreach (DkmClrModuleInstance module in runtime.GetModulesInAppDomain(appDomain))
            {
                try
                {
                    ptr = module.GetMetaDataBytesPtr(out size);
                    Debug.Assert(size > 0);
                }
                catch (NotImplementedException e) when(module is DkmClrNcModuleInstance)
                {
                    // DkmClrNcModuleInstance.GetMetaDataBytesPtr not implemented in Dev14.
                    throw new NotImplementedMetadataException(e);
                }
                catch (Exception e) when(DkmExceptionUtilities.IsBadOrMissingMetadataException(e))
                {
                    continue;
                }

                if (!TryGetMetadataBlock(previousMetadataBlocks, index, ptr, size, out var block))
                {
                    // ignore modules with bad metadata headers
                    continue;
                }

                Debug.Assert(block.ModuleVersionId == module.Mvid);
                builder.Add(block);
                index++;
            }

            // Include "intrinsic method" assembly.
            ptr = runtime.GetIntrinsicAssemblyMetaDataBytesPtr(out size);
            if (!TryGetMetadataBlock(previousMetadataBlocks, index, ptr, size, out var intrinsicsBlock))
            {
                throw ExceptionUtilities.Unreachable;
            }

            builder.Add(intrinsicsBlock);
            return(builder.ToImmutableAndFree());
        }