Пример #1
0
        /// <summary>
        /// Maps global method token to a handle local to the current delta PDB.
        /// Debug tables referring to methods currently use local handles, not global handles.
        /// See https://github.com/dotnet/roslyn/issues/16286
        /// </summary>
        private static MethodDefinitionHandle GetDeltaRelativeMethodDefinitionHandle(
            MetadataReader reader,
            int methodToken
            )
        {
            var globalHandle = (MethodDefinitionHandle)MetadataTokens.EntityHandle(methodToken);

            if (reader.GetTableRowCount(TableIndex.EncMap) == 0)
            {
                return(globalHandle);
            }

            var globalDebugHandle = globalHandle.ToDebugInformationHandle();

            int rowId = 1;

            foreach (var handle in reader.GetEditAndContinueMapEntries())
            {
                if (handle.Kind == HandleKind.MethodDebugInformation)
                {
                    if (handle == globalDebugHandle)
                    {
                        return(MetadataTokens.MethodDefinitionHandle(rowId));
                    }

                    rowId++;
                }
            }

            // compiler generated invalid EncMap table:
            throw new BadImageFormatException();
        }
Пример #2
0
        private static ImmutableArray <MethodId> CreateHandleToIdMap(MetadataReader reader, List <MethodInfo> infos, int version)
        {
            var handleToIdMapBuilder = ImmutableArray.CreateBuilder <MethodId>(reader.MethodDebugInformation.Count);

            // Consider: Ideally MetadataReader would expose GetEditAndContinueMapEntries(TableIndex) and do binary search.
            // However, the only records in the table for Portable PDBs are currently MethodDebugInformation handles.
            foreach (EntityHandle encMapHandle in reader.GetEditAndContinueMapEntries())
            {
                if (encMapHandle.Kind == HandleKind.MethodDebugInformation)
                {
                    var id = new MethodId(MetadataTokens.GetRowNumber(encMapHandle));
                    handleToIdMapBuilder.Add(id);
                    var methodHandle = MetadataTokens.MethodDebugInformationHandle(handleToIdMapBuilder.Count);

                    int index = id.Value - 1;
                    while (infos.Count <= index)
                    {
                        infos.Add(default(MethodInfo));
                    }

                    // an existing info is overwritten with new version:
                    infos[index] = new MethodInfo(methodHandle, version);
                }
            }

            return(handleToIdMapBuilder.MoveToImmutable());
        }
Пример #3
0
 internal static void CheckEncMap(MetadataReader reader, params EntityHandle[] handles)
 {
     AssertEx.Equal(
         handles,
         reader.GetEditAndContinueMapEntries(),
         itemInspector: EncMapRowToString
         );
 }
Пример #4
0
        private void PopulateEnC(MetadataReader asmMetadataReaderParm, MetadataReader pdbMetadataReaderParm)
        {
            int i = 1;

            foreach (EntityHandle encMapHandle in asmMetadataReaderParm.GetEditAndContinueMapEntries())
            {
                if (encMapHandle.Kind == HandleKind.MethodDebugInformation)
                {
                    var method = methods[asmMetadataReader.GetRowNumber(encMapHandle)];
                    method.UpdateEnC(asmMetadataReaderParm, pdbMetadataReaderParm, i);
                    i++;
                }
            }
        }
Пример #5
0
        private void WriteEnCMap()
        {
            if (aggregateReader != null)
            {
                AddHeader("Entity", "Gen", "Row", "Edit");
            }
            else
            {
                AddHeader("Entity");
            }


            foreach (var entry in reader.GetEditAndContinueMapEntries())
            {
                if (aggregateReader != null)
                {
                    int    generation;
                    Handle primary  = aggregateReader.GetGenerationHandle(entry, out generation);
                    bool   isUpdate = readers[generation] != reader;

                    var primaryModule = readers[generation].GetModuleDefinition();

                    AddRow(
                        Token(entry),
                        primaryModule.Generation.ToString(),
                        "0x" + MetadataTokens.GetRowNumber(primary).ToString("x6"),
                        isUpdate ? "update" : "add");
                }
                else
                {
                    AddRow(Token(entry));
                }
            }

            WriteRows("EnC Map (0x1f):");
        }
Пример #6
0
 internal void VerifyEncMap(IEnumerable <EntityHandle> expected)
 {
     AssertEx.Equal(expected, _metadataReader.GetEditAndContinueMapEntries(), itemInspector: EncMapRowToString, message: GetAssertMessage("EncMap doesn't match"));
 }