当前位置: 首页>>代码示例>>C#>>正文


C# PEReader.ReadDebugDirectory方法代码示例

本文整理汇总了C#中System.Reflection.PortableExecutable.PEReader.ReadDebugDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# PEReader.ReadDebugDirectory方法的具体用法?C# PEReader.ReadDebugDirectory怎么用?C# PEReader.ReadDebugDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Reflection.PortableExecutable.PEReader的用法示例。


在下文中一共展示了PEReader.ReadDebugDirectory方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmbeddedPortablePdb

        public void EmbeddedPortablePdb()
        {
            string source = @"
            using System;

            class C
            {
            public static void Main()
            {
            Console.WriteLine();
            }
            }
            ";
            var c = CreateCompilationWithMscorlib(Parse(source, "foo.cs"), options: TestOptions.DebugDll);

            var peBlob = c.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Embedded).WithPdbFilePath(@"a/b/c/d.pdb"));

            using (var peReader = new PEReader(peBlob))
            {
                var entries = peReader.ReadDebugDirectory();

                AssertEx.Equal(new[] { DebugDirectoryEntryType.CodeView, DebugDirectoryEntryType.EmbeddedPortablePdb }, entries.Select(e => e.Type));

                var codeView = entries[0];
                var embedded = entries[1];

                // EmbeddedPortablePdb entry:
                Assert.Equal(0x0100, embedded.MajorVersion);
                Assert.Equal(0x0100, embedded.MinorVersion);
                Assert.Equal(0u, embedded.Stamp);

                BlobContentId pdbId;
                using (var embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(embedded))
                {
                    var mdReader = embeddedMetadataProvider.GetMetadataReader();
                    AssertEx.Equal(new[] { "foo.cs" }, mdReader.Documents.Select(doc => mdReader.GetString(mdReader.GetDocument(doc).Name)));

                    pdbId = new BlobContentId(mdReader.DebugMetadataHeader.Id);
                }

                // CodeView entry:
                var codeViewData = peReader.ReadCodeViewDebugDirectoryData(codeView);
                Assert.Equal(0x0100, codeView.MajorVersion);
                Assert.Equal(0x504D, codeView.MinorVersion);
                Assert.Equal(pdbId.Stamp, codeView.Stamp);
                Assert.Equal(pdbId.Guid, codeViewData.Guid);
                Assert.Equal("d.pdb", codeViewData.Path);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:49,代码来源:PortablePdbTests.cs

示例2: GetReaders

 /// <summary>
 /// Returns metadata readers for assembly PE file and portable PDB.
 /// </summary>
 /// <param name="assemblyFileName">file name of the assembly</param>
 /// <param name="peReader">PE metadata reader return</param>
 /// <param name="pdbReader">PDB metadata reader return</param>
 /// <returns>true if debugging information is available</returns>
 private static bool GetReaders(string assemblyFileName, out MetadataReader peReader, out MetadataReader pdbReader)
 {
     peReader = null;
     pdbReader = null;
     
     if (!File.Exists(assemblyFileName))
     {
         return false;
     }
     Stream peStream = File.OpenRead(assemblyFileName);
     PEReader reader = new PEReader(peStream);
     string pdbPath = null;
     
     foreach (DebugDirectoryEntry entry in reader.ReadDebugDirectory())
     {
         if (entry.Type == DebugDirectoryEntryType.CodeView)
         {
             CodeViewDebugDirectoryData codeViewData = reader.ReadCodeViewDebugDirectoryData(entry);
             pdbPath = codeViewData.Path;
             break;
         }
     }
     if (pdbPath == null)
     {
         return false;
     }
     if (!File.Exists(pdbPath))
     {
         pdbPath = Path.GetFileName(pdbPath);
         if (!File.Exists(pdbPath))
         {
             return false;
         }
     }
     
     peReader = reader.GetMetadataReader();
     Stream pdbStream = File.OpenRead(pdbPath);
     MetadataReaderProvider provider = MetadataReaderProvider.FromPortablePdbStream(pdbStream);
     pdbReader = provider.GetMetadataReader();
     
     return true;
     
 }
开发者ID:AndreGleichner,项目名称:corefx,代码行数:50,代码来源:SymbolReader.cs

示例3: ReadPortableDebugTableEntries

        private static void ReadPortableDebugTableEntries(PEReader peReader, out DebugDirectoryEntry codeViewEntry, out DebugDirectoryEntry embeddedPdbEntry)
        {
            // See spec: https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PE-COFF.md

            codeViewEntry = default(DebugDirectoryEntry);
            embeddedPdbEntry = default(DebugDirectoryEntry);

            foreach (DebugDirectoryEntry entry in peReader.ReadDebugDirectory())
            {
                if (entry.Type == DebugDirectoryEntryType.CodeView)
                {
                    const ushort PortableCodeViewVersionMagic = 0x504d;
                    if (entry.MinorVersion != PortableCodeViewVersionMagic)
                    {
                        continue;
                    }

                    codeViewEntry = entry;
                }
                else if (entry.Type == DebugDirectoryEntryType.EmbeddedPortablePdb)
                {
                    embeddedPdbEntry = entry;
                }
            }
        }
开发者ID:bartdesmet,项目名称:coreclr,代码行数:25,代码来源:SymbolReader.cs

示例4: EmbeddedSource_InEmbeddedPdb

        public void EmbeddedSource_InEmbeddedPdb()
        {
            string source = @"
using System;

class C
{
    public static void Main()
    {
        Console.WriteLine();
    }
}
";
            var tree = Parse(source, "f:/build/foo.cs");
            var c = CreateCompilationWithMscorlib(tree, options: TestOptions.DebugDll);

            var pdbStream = new MemoryStream();
            var peBlob = c.EmitToArray(
                EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Embedded),
                embeddedTexts: new[] { EmbeddedText.FromSource(tree.FilePath, tree.GetText()) });
            pdbStream.Position = 0;

            using (var peReader = new PEReader(peBlob))
            {
                var embeddedEntry = peReader.ReadDebugDirectory().Single(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb);

                using (var embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(embeddedEntry))
                {
                    var pdbReader = embeddedMetadataProvider.GetMetadataReader();

                    var embeddedSource =
                        (from documentHandle in pdbReader.Documents
                         let document = pdbReader.GetDocument(documentHandle)
                         select new
                         {
                             FilePath = pdbReader.GetString(document.Name),
                             Text = pdbReader.GetEmbeddedSource(documentHandle)
                         }).Single();

                    Assert.Equal(embeddedSource.FilePath, "f:/build/foo.cs");
                    Assert.Equal(source, embeddedSource.Text.ToString());
                }
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:44,代码来源:PortablePdbTests.cs

示例5: SourceLink_Embedded

        public void SourceLink_Embedded()
        {
            string source = @"
using System;

class C
{
    public static void Main()
    {
        Console.WriteLine();
    }
}
";
            var sourceLinkBlob = Encoding.UTF8.GetBytes(@"
{
  ""documents"": {
     ""f:/build/*"" : ""https://raw.githubusercontent.com/my-org/my-project/1111111111111111111111111111111111111111/*""
  }
}
");
            var c = CreateCompilationWithMscorlib(Parse(source, "f:/build/foo.cs"), options: TestOptions.DebugDll);

            var peBlob = c.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Embedded), sourceLinkStream: new MemoryStream(sourceLinkBlob));

            using (var peReader = new PEReader(peBlob))
            {
                var embeddedEntry = peReader.ReadDebugDirectory().Single(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb);

                using (var embeddedMetadataProvider = peReader.ReadEmbeddedPortablePdbDebugDirectoryData(embeddedEntry))
                {
                    var pdbReader = embeddedMetadataProvider.GetMetadataReader();

                    var actualBlob =
                        (from cdiHandle in pdbReader.GetCustomDebugInformation(EntityHandle.ModuleDefinition)
                         let cdi = pdbReader.GetCustomDebugInformation(cdiHandle)
                         where pdbReader.GetGuid(cdi.Kind) == PortableCustomDebugInfoKinds.SourceLink
                         select pdbReader.GetBlobBytes(cdi.Value)).Single();

                    AssertEx.Equal(sourceLinkBlob, actualBlob);
                }
            }
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:42,代码来源:PortablePdbTests.cs

示例6: TryReadCodeViewData

        private bool TryReadCodeViewData(string peFilePath, out CodeViewDebugDirectoryData codeViewData, out uint stamp)
        {
            try
            {
                var peStream = PortableShim.File.OpenRead(peFilePath);
                using (var peReader = new PEReader(peStream))
                {
                    foreach (var entry in peReader.ReadDebugDirectory())
                    {
                        if (entry.Type == DebugDirectoryEntryType.CodeView)
                        {
                            codeViewData = peReader.ReadCodeViewDebugDirectoryData(entry);
                            stamp = entry.Stamp;
                            return true;
                        }
                    }
                }
            }
            catch
            {
            }

            codeViewData = default(CodeViewDebugDirectoryData);
            stamp = 0;
            return false;
        }
开发者ID:xier2012,项目名称:roslyn,代码行数:26,代码来源:SymBinder.cs


注:本文中的System.Reflection.PortableExecutable.PEReader.ReadDebugDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。