Beispiel #1
0
        void DefineAsyncCustomMetadata(MethodDebugInformation info)
        {
            if (!info.HasCustomDebugInformations)
            {
                return;
            }

            foreach (var custom_info in info.CustomDebugInformations)
            {
                var async_debug_info = custom_info as AsyncMethodBodyDebugInformation;
                if (async_debug_info == null)
                {
                    continue;
                }

                using (var stream = new MemoryStream()) {
                    var async_metadata = new BinaryStreamWriter(stream);
                    async_metadata.WriteUInt32(info.StateMachineKickOffMethod != null ? info.StateMachineKickOffMethod.MetadataToken.ToUInt32() : 0);
                    async_metadata.WriteUInt32((uint)async_debug_info.CatchHandler.Offset);
                    async_metadata.WriteUInt32((uint)async_debug_info.Resumes.Count);
                    for (int i = 0; i < async_debug_info.Resumes.Count; ++i)
                    {
                        async_metadata.WriteUInt32((uint)async_debug_info.Yields [i].Offset);
                        async_metadata.WriteUInt32(async_debug_info.resume_methods [i].MetadataToken.ToUInt32());
                        async_metadata.WriteUInt32((uint)async_debug_info.Resumes [i].Offset);
                    }

                    writer.DefineCustomMetadata("asyncMethodInfo", stream.ToArray());
                }
            }
        }
Beispiel #2
0
        public void WriteCustomMetadata()
        {
            if (count == 0)
            {
                return;
            }

            writer.BaseStream.Position = 1;
            writer.WriteByte((byte)count);
            writer.Flush();

            sym_writer.DefineCustomMetadata("MD2", stream.ToArray());
        }
Beispiel #3
0
        private void DefineCustomMetadata(PdbMethodSymbols pdbSymbols)
        {
            // Custom PDB metadata
            if (pdbSymbols != null)
            {
                using (var memoryStream = new MemoryStream()) {
                    var metadata = new BinaryStreamWriter(memoryStream);
                    metadata.WriteByte(4);                      // version
                    metadata.WriteByte((byte)1);                // count
                    metadata.WriteInt16(0);                     // padding

                    var metadataStartPosition = metadata.BaseStream.Position;
                    var customMetadataCount   = 0;

                    if (pdbSymbols.IteratorClass != null)
                    {
                        customMetadataCount++;
                        metadata.WriteByte(4);                          // version
                        metadata.WriteByte(4);                          // forward iterator
                        metadata.Align(4);
                        using (new PdbBinaryStreamWriterSizeHelper(metadata)) {
                            metadata.WriteString(pdbSymbols.IteratorClass);
                            metadata.WriteInt16(0);
                            metadata.Align(4);
                        }
                    }

                    if (pdbSymbols.UsingCounts != null)
                    {
                        customMetadataCount++;
                        metadata.WriteByte(4);                          // version
                        metadata.WriteByte(0);                          // using info
                        metadata.Align(4);
                        using (new PdbBinaryStreamWriterSizeHelper(metadata)) {
                            metadata.WriteUInt16((ushort)pdbSymbols.UsingCounts.Count);
                            foreach (var uc in pdbSymbols.UsingCounts)
                            {
                                metadata.WriteUInt16(uc);
                            }
                            metadata.Align(4);
                        }
                    }

                    if (pdbSymbols.MethodWhoseUsingInfoAppliesToThisMethod != null)
                    {
                        customMetadataCount++;
                        metadata.WriteByte(4);                          // version
                        metadata.WriteByte(1);                          // forward info
                        metadata.Align(4);
                        using (new PdbBinaryStreamWriterSizeHelper(metadata)) {
                            metadata.WriteUInt32(pdbSymbols.MethodWhoseUsingInfoAppliesToThisMethod.MetadataToken.ToUInt32());
                        }
                    }

                    if (pdbSymbols.IteratorScopes != null)
                    {
                        customMetadataCount++;
                        metadata.WriteByte(4);                          // version
                        metadata.WriteByte(3);                          // iterator scopes
                        metadata.Align(4);
                        using (new PdbBinaryStreamWriterSizeHelper(metadata)) {
                            metadata.WriteInt32(pdbSymbols.IteratorScopes.Count);
                            foreach (var scope in pdbSymbols.IteratorScopes)
                            {
                                metadata.WriteInt32(scope.Start.Offset);
                                metadata.WriteInt32(scope.End.Offset);
                            }
                        }
                    }

                    if (metadata.BaseStream.Position != metadataStartPosition)
                    {
                        // Update number of entries
                        metadata.Flush();
                        metadata.BaseStream.Position = 1;
                        metadata.WriteByte((byte)customMetadataCount);
                        metadata.Flush();

                        writer.DefineCustomMetadata("MD2", memoryStream.ToArray());
                    }
                }

                // Save back asyncMethodInfo
                if (pdbSymbols.SynchronizationInformation != null)
                {
                    using (var memoryStream = new MemoryStream()) {
                        var metadata = new BinaryStreamWriter(memoryStream);
                        metadata.WriteUInt32(pdbSymbols.SynchronizationInformation.KickoffMethod != null ? pdbSymbols.SynchronizationInformation.KickoffMethod.MetadataToken.ToUInt32() : 0);
                        metadata.WriteUInt32(pdbSymbols.SynchronizationInformation.GeneratedCatchHandlerIlOffset);
                        metadata.WriteUInt32((uint)pdbSymbols.SynchronizationInformation.SynchronizationPoints.Count);
                        foreach (var syncPoint in pdbSymbols.SynchronizationInformation.SynchronizationPoints)
                        {
                            metadata.WriteUInt32(syncPoint.SynchronizeOffset);
                            metadata.WriteUInt32(syncPoint.ContinuationMethod != null ? syncPoint.ContinuationMethod.MetadataToken.ToUInt32() : 0);
                            metadata.WriteUInt32(syncPoint.ContinuationOffset);
                        }

                        writer.DefineCustomMetadata("asyncMethodInfo", memoryStream.ToArray());
                    }
                }
            }
        }