Example #1
0
        private static void VerifyPdbMatchesExpectedXml(
            Stream peStream,
            Stream pdbStream,
            string qualifiedMethodName,
            PdbToXmlOptions pdbToXmlOptions,
            string expectedPdb,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral,
            bool isPortable)
        {
            peStream.Position  = 0;
            pdbStream.Position = 0;
            var actualPdb = XElement.Parse(PdbToXmlConverter.ToXml(pdbStream, peStream, pdbToXmlOptions, methodName: qualifiedMethodName)).ToString();

            var(actual, expected) = AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: isPortable, actualIsConverted: false);

            AssertEx.AssertLinesEqual(
                expected,
                actual,
                $"PDB format: {(isPortable ? "Portable" : "Windows")}{Environment.NewLine}",
                expectedValueSourcePath,
                expectedValueSourceLine,
                escapeQuotes: !expectedIsXmlLiteral);
        }
Example #2
0
            internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null)
            {
                Dictionary <int, string> markers = null;

                if (sequencePoints != null)
                {
                    var actualPdbXml = PdbToXmlConverter.ToXml(
                        pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
                        peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
                        options: PdbToXmlOptions.ResolveTokens |
                        PdbToXmlOptions.ThrowOnError |
                        PdbToXmlOptions.ExcludeDocuments |
                        PdbToXmlOptions.ExcludeCustomDebugInformation |
                        PdbToXmlOptions.ExcludeScopes,
                        methodName: sequencePoints);

                    markers = PdbValidation.GetMarkers(actualPdbXml);
                }

                if (!realIL)
                {
                    return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers));
                }

                if (_lazyModuleSymbol == null)
                {
                    _lazyModuleSymbol = GetModuleSymbolForEmittedImage(EmittedAssemblyData, MetadataImportOptions.All);
                }

                return(_lazyModuleSymbol != null?_test.VisualizeRealIL(_lazyModuleSymbol, methodData, markers) : null);
            }
Example #3
0
        private static void VerifyPdb(
            this CompilationDifference diff,
            IEnumerable <int> methodTokens,
            string expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral
            )
        {
            Assert.NotEqual(default(DebugInformationFormat), format);
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(
                new ImmutableMemoryStream(diff.PdbDelta),
                methodTokens
                );

            var(actual, expected) = AdjustToPdbFormat(
                actualPdb,
                expectedPdb,
                actualIsPortable: diff.NextGeneration.InitialBaseline.HasPortablePdb,
                actualIsConverted: false
                );

            AssertEx.AssertLinesEqual(
                expected,
                actual,
                $"PDB format: {format}{Environment.NewLine}",
                expectedValueSourcePath,
                expectedValueSourceLine,
                escapeQuotes: !expectedIsXmlLiteral
                );
        }
Example #4
0
        internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null)
        {
            Dictionary <int, string> markers = null;

            if (sequencePoints != null)
            {
                var actualPdbXml = PdbToXmlConverter.ToXml(
                    pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
                    peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
                    options: PdbToXmlOptions.ResolveTokens |
                    PdbToXmlOptions.ThrowOnError |
                    PdbToXmlOptions.ExcludeDocuments |
                    PdbToXmlOptions.ExcludeCustomDebugInformation |
                    PdbToXmlOptions.ExcludeScopes,
                    methodName: sequencePoints);

                markers = ILValidation.GetSequencePointMarkers(actualPdbXml, source);
            }

            if (!realIL)
            {
                return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers));
            }

            if (_lazyModuleSymbol == null)
            {
                var targetReference = LoadTestEmittedExecutableForSymbolValidation(EmittedAssemblyData, _compilation.Options.OutputKind, display: _compilation.AssemblyName);
                _lazyModuleSymbol = GetSymbolFromMetadata(targetReference, MetadataImportOptions.All);
            }

            return(_lazyModuleSymbol != null?_visualizeRealIL(_lazyModuleSymbol, methodData, markers) : null);
        }
Example #5
0
        internal static string GetPdbXml(
            Compilation compilation,
            IMethodSymbol debugEntryPoint = null,
            PdbToXmlOptions options       = 0,
            string qualifiedMethodName    = "",
            bool portable = false)
        {
            string actual = null;

            using (var exebits = new MemoryStream())
            {
                using (var pdbbits = new MemoryStream())
                {
                    var result = compilation.Emit(
                        exebits,
                        pdbbits,
                        debugEntryPoint: debugEntryPoint,
                        options: EmitOptions.Default.WithDebugInformationFormat(portable ? DebugInformationFormat.PortablePdb : DebugInformationFormat.Pdb));

                    result.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).Verify();

                    pdbbits.Position = 0;
                    exebits.Position = 0;

                    options |= PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError;
                    actual   = PdbToXmlConverter.ToXml(pdbbits, exebits, options, methodName: qualifiedMethodName);

                    ValidateDebugDirectory(exebits, portable ? pdbbits : null, compilation.AssemblyName + ".pdb", compilation.IsEmitDeterministic);
                }
            }

            return(actual);
        }
Example #6
0
        internal static string GetPdbXml(
            Compilation compilation,
            PdbToXmlOptions options    = 0,
            string qualifiedMethodName = "",
            bool portable = false)
        {
            string actual = null;

            using (var exebits = new MemoryStream())
            {
                using (var pdbbits = new MemoryStream())
                {
                    compilation.Emit(
                        exebits,
                        pdbbits,
                        options: EmitOptions.Default.WithDebugInformationFormat(portable ? DebugInformationFormat.PortablePdb : DebugInformationFormat.Pdb));

                    pdbbits.Position = 0;
                    exebits.Position = 0;

                    options |= PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError;
                    actual   = PdbToXmlConverter.ToXml(pdbbits, exebits, options, methodName: qualifiedMethodName);
                }

                ValidateDebugDirectory(exebits, compilation.AssemblyName + ".pdb", portable);
            }

            return(actual);
        }
Example #7
0
        private static void VerifyPdb(
            this CompilationDifference diff,
            IEnumerable <int> methodTokens,
            string expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(default(DebugInformationFormat), format);
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            // Include module custom debug info, specifically compilation options and references.
            // These shouldn't be emitted in EnC deltas and we want to validate that.
            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(new ImmutableMemoryStream(diff.PdbDelta), methodTokens, PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.IncludeModuleDebugInfo);

            var(actual, expected) = AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: diff.NextGeneration.InitialBaseline.HasPortablePdb, actualIsConverted: false);

            AssertEx.AssertLinesEqual(
                expected,
                actual,
                $"PDB format: {format}{Environment.NewLine}",
                expectedValueSourcePath,
                expectedValueSourceLine,
                escapeQuotes: !expectedIsXmlLiteral);
        }
        private static void VerifyPdb(Stream pdbStream, Stream peStream, string expectedXml, string message)
        {
            pdbStream.Position = 0;
            peStream.Position  = 0;
            var actualXml = PdbToXmlConverter.ToXml(pdbStream, peStream, Options);

            AssertEx.AssertLinesEqual(expectedXml, actualXml, message);
        }
        public static void GenXmlFromDeltaPdb(string pdbPath, string outPath)
        {
            using var deltaPdb = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);

            // There is no easy way to enumerate all method tokens that are present in the PDB.
            // So dump the first 255 method tokens (the ones that are not present will be skipped):
            File.WriteAllText(outPath, PdbToXmlConverter.DeltaPdbToXml(deltaPdb, Enumerable.Range(0x06000001, 255)));
        }
        private static void VerifyPdb(Stream pdbStream, Stream peStream, string expectedXml, string message)
        {
            pdbStream.Position = 0;
            peStream.Position  = 0;
            var actualXml = PdbToXmlConverter.ToXml(pdbStream, peStream, PdbToXmlOptions.IncludeSourceServerInformation | PdbToXmlOptions.ResolveTokens);

            AssertEx.AssertLinesEqual(expectedXml, actualXml, message);
        }
Example #11
0
        internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null)
        {
            Dictionary <int, string> markers = null;

            if (sequencePoints != null)
            {
                if (EmittedAssemblyPdb == null)
                {
                    throw new InvalidOperationException($"{nameof(EmittedAssemblyPdb)} is not set");
                }

                if (EmittedAssemblyData == null)
                {
                    throw new InvalidOperationException($"{nameof(EmittedAssemblyData)} is not set");
                }

                var actualPdbXml = PdbToXmlConverter.ToXml(
                    pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
                    peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
                    options: PdbToXmlOptions.ResolveTokens |
                    PdbToXmlOptions.ThrowOnError |
                    PdbToXmlOptions.ExcludeDocuments |
                    PdbToXmlOptions.ExcludeCustomDebugInformation |
                    PdbToXmlOptions.ExcludeScopes,
                    methodName: sequencePoints);

                if (actualPdbXml.StartsWith("<error>"))
                {
                    throw new Exception($"Failed to extract PDB information for method '{sequencePoints}'. PdbToXmlConverter returned:\r\n{actualPdbXml}");
                }

                markers = ILValidation.GetSequencePointMarkers(actualPdbXml, source);
            }

            if (!realIL)
            {
                return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers));
            }

            if (_lazyModuleSymbol == null)
            {
                var targetReference = LoadTestEmittedExecutableForSymbolValidation(EmittedAssemblyData, _compilation.Options.OutputKind, display: _compilation.AssemblyName);
                _lazyModuleSymbol = GetSymbolFromMetadata(targetReference, MetadataImportOptions.All);
            }

            if (_lazyModuleSymbol != null)
            {
                if (_visualizeRealIL == null)
                {
                    throw new InvalidOperationException("IL visualization function is not set");
                }


                return(_visualizeRealIL(_lazyModuleSymbol, methodData, markers, _testData.Module.GetMethodBody(methodData.Method).AreLocalsZeroed));
            }

            return(null);
        }
Example #12
0
        public static void GenXmlFromPdb(string exePath, string pdbPath, string outPath, PdbToXmlOptions options)
        {
            using var peStream      = new FileStream(exePath, FileMode.Open, FileAccess.Read);
            using var pdbStream     = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);
            using var dstFileStream = new FileStream(outPath, FileMode.Create, FileAccess.ReadWrite);
            using var sw            = new StreamWriter(dstFileStream, Encoding.UTF8);

            PdbToXmlConverter.ToXml(sw, pdbStream, peStream, options);
        }
        public void VerifyPdb(
            IEnumerable <int> methodTokens,
            XElement expectedPdb,
            [CallerLineNumber] int expectedValueSourceLine  = 0,
            [CallerFilePath] string expectedValueSourcePath = null)
        {
            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(PdbDelta, methodTokens);

            AssertXml.Equal(expectedPdb, XElement.Parse(actualPdb), expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral: true);
        }
 public static string GenXmlFromPdb(string exePath, string pdbPath)
 {
     using (var peStream = new FileStream(exePath, FileMode.Open, FileAccess.Read))
         using (var pdbStream = new FileStream(pdbPath, FileMode.Open, FileAccess.Read))
             using (var ms = new MemoryStream())
                 using (var sw = new StreamWriter(ms, Encoding.UTF8)) {
                     PdbToXmlConverter.ToXml(sw, pdbStream, peStream, PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeTokens);
                     return(Encoding.UTF8.GetString(ms.ToArray()));
                 }
 }
Example #15
0
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            StringBuilder sb  = new StringBuilder();
            var           pdb = (PdbDelta)objectProvider.GetObject();
            string        xml = PdbToXmlConverter.DeltaPdbToXml(pdb.Stream, Enumerable.Range(0x06000001, 0xff));

            var viewer = new TextViewer(xml, "PDB");

            viewer.ShowDialog();
        }
        public override void GetData(object target, Stream outgoingData)
        {
            var pdbDelta = (PdbDelta)target;
            var text     = PdbToXmlConverter.DeltaPdbToXml(pdbDelta.Stream, Enumerable.Range(0x06000001, 0xff));

            var writer = new StreamWriter(outgoingData);

            writer.Write(text);
            writer.Flush();
        }
        public static void VerifyPortablePdb(
            TestResource portable,
            string expectedXml,
            PdbToXmlOptions options = Options)
        {
            var portablePEStream  = new MemoryStream(portable.PE);
            var portablePdbStream = new MemoryStream(portable.Pdb);
            var actualXml         = PdbToXmlConverter.ToXml(portablePdbStream, portablePEStream, options);

            AssertEx.AssertLinesEqual(expectedXml, actualXml, "Comparing Portable PDB with expected XML");
        }
        public static void VerifyWindowsMatchesExpected(TestResource windows, string expectedXml)
        {
            var windowsPEStream  = new MemoryStream(windows.PE);
            var windowsPdbStream = new MemoryStream(windows.Pdb);
            var actualXml        = PdbToXmlConverter.ToXml(windowsPdbStream, windowsPEStream, Options);

            var adjustedExpectedXml = AdjustForInherentDifferences(expectedXml);
            var adjustedActualXml   = AdjustForInherentDifferences(actualXml);

            AssertEx.AssertLinesEqual(adjustedExpectedXml, adjustedActualXml, "Comparing Windows PDB with expected XML");
        }
        public static void VerifyPortableReadNativelyMatchesExpected(TestResource portable, string expectedXml)
        {
            var portablePEStream  = new MemoryStream(portable.PE);
            var portablePdbStream = new MemoryStream(portable.Pdb);
            var actualXml         = PdbToXmlConverter.ToXml(portablePdbStream, portablePEStream, Options | PdbToXmlOptions.UseNativeReader);

            var adjustedActualXml   = RemoveElementsNotSupportedByNativeReader(actualXml);
            var adjustedExpectedXml = RemoveElementsNotSupportedByNativeReader(expectedXml);

            AssertEx.AssertLinesEqual(adjustedExpectedXml, adjustedActualXml, "Comparing Portable PDB read via native reader with expected XML");
        }
Example #20
0
 public static void GenXmlFromPdb(string exePath, string pdbPath, string outPath, PdbToXmlOptions options)
 {
     using (var exebits = new FileStream(exePath, FileMode.Open, FileAccess.Read))
     {
         using (var pdbbits = new FileStream(pdbPath, FileMode.Open, FileAccess.Read))
         {
             using (var sw = new StreamWriter(outPath, append: false, encoding: Encoding.UTF8))
             {
                 PdbToXmlConverter.ToXml(sw, pdbbits, exebits, options);
             }
         }
     }
 }
Example #21
0
        private void VerifyPdb(
            IEnumerable <int> methodTokens,
            string expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(default(DebugInformationFormat), format);
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            string actualPdb = PdbToXmlConverter.DeltaPdbToXml(new ImmutableMemoryStream(PdbDelta), methodTokens);

            var(actualXml, expectedXml) = PdbValidation.AdjustToPdbFormat(actualPdb, expectedPdb, actualIsPortable: NextGeneration.InitialBaseline.HasPortablePdb);

            AssertXml.Equal(expectedXml, actualXml, $"Format: {format}{Environment.NewLine}", expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
        }
Example #22
0
        internal static string GetPdbXml(
            Compilation compilation,
            IEnumerable <EmbeddedText> embeddedTexts = null,
            IMethodSymbol debugEntryPoint            = null,
            PdbValidationOptions options             = PdbValidationOptions.Default,
            string qualifiedMethodName = "",
            bool portable = false)
        {
            var peStream  = new MemoryStream();
            var pdbStream = new MemoryStream();

            EmitWithPdb(peStream, pdbStream, compilation, debugEntryPoint, embeddedTexts, portable);

            pdbStream.Position = 0;
            peStream.Position  = 0;
            return(PdbToXmlConverter.ToXml(pdbStream, peStream, options.ToPdbToXmlOptions(), methodName: qualifiedMethodName));
        }
Example #23
0
        public static string GetPdbXml(Compilation compilation, string methodName = "")
        {
            string actual = null;

            using (var exebits = new MemoryStream())
            {
                using (var pdbbits = new MemoryStream())
                {
                    compilation.Emit(exebits, null, "DontCare", pdbbits, null);

                    pdbbits.Position = 0;
                    exebits.Position = 0;
                    actual           = PdbToXmlConverter.ToXml(pdbbits, exebits, PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError, methodName: methodName);
                }
            }

            return(actual);
        }
        private void TestGeneratePdb([CallerMemberName] string testName = null)
        {
            const PdbToXmlOptions options = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.ThrowOnError | PdbToXmlOptions.IncludeTokens | PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.IncludeMethodSpans;

            string    xmlFile    = Path.Combine(TestCasePath, testName + ".xml");
            string    xmlContent = File.ReadAllText(xmlFile);
            XDocument document   = XDocument.Parse(xmlContent);
            var       files      = document.Descendants("file").ToDictionary(f => f.Attribute("name").Value, f => f.Value);

            Tester.CompileCSharpWithPdb(Path.Combine(TestCasePath, testName + ".expected"), files);

            string peFileName       = Path.Combine(TestCasePath, testName + ".expected.dll");
            string pdbFileName      = Path.Combine(TestCasePath, testName + ".expected.pdb");
            var    moduleDefinition = new PEFile(peFileName);
            var    resolver         = new UniversalAssemblyResolver(peFileName, false, moduleDefinition.Reader.DetectTargetFrameworkId(), PEStreamOptions.PrefetchEntireImage);
            var    decompiler       = new CSharpDecompiler(moduleDefinition, resolver, new DecompilerSettings());

            using (FileStream pdbStream = File.Open(Path.Combine(TestCasePath, testName + ".pdb"), FileMode.OpenOrCreate, FileAccess.ReadWrite))
            {
                pdbStream.SetLength(0);
                PortablePdbWriter.WritePdb(moduleDefinition, decompiler, new DecompilerSettings(), pdbStream, noLogo: true);
                pdbStream.Position = 0;
                using (Stream peStream = File.OpenRead(peFileName))
                    using (Stream expectedPdbStream = File.OpenRead(pdbFileName))
                    {
                        using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(pdbFileName, ".xml"), false, Encoding.UTF8))
                        {
                            PdbToXmlConverter.ToXml(writer, expectedPdbStream, peStream, options);
                        }
                        peStream.Position = 0;
                        using (StreamWriter writer = new StreamWriter(Path.ChangeExtension(xmlFile, ".generated.xml"), false, Encoding.UTF8))
                        {
                            PdbToXmlConverter.ToXml(writer, pdbStream, peStream, options);
                        }
                    }
            }
            string expectedFileName = Path.ChangeExtension(xmlFile, ".expected.xml");

            ProcessXmlFile(expectedFileName);
            string generatedFileName = Path.ChangeExtension(xmlFile, ".generated.xml");

            ProcessXmlFile(generatedFileName);
            Assert.AreEqual(Normalize(expectedFileName), Normalize(generatedFileName));
        }
Example #25
0
        private void VerifyPdb(
            IEnumerable <int> methodTokens,
            XElement expectedPdb,
            DebugInformationFormat format,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            var actualXml = XElement.Parse(PdbToXmlConverter.DeltaPdbToXml(new ImmutableMemoryStream(PdbDelta), methodTokens));

            PdbValidation.AdjustToPdbFormat(
                actualPdb: actualXml,
                actualIsPortable: NextGeneration.InitialBaseline.HasPortablePdb,
                expectedPdb: expectedPdb,
                expectedIsPortable: format != DebugInformationFormat.Pdb);

            AssertXml.Equal(expectedPdb, actualXml, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
        }
Example #26
0
        internal void VerifyIL(
            string qualifiedMethodName,
            string expectedIL,
            Func <Cci.ILocalDefinition, ILVisualizer.LocalInfo> mapLocal = null,
            MethodDefinitionHandle methodToken = default,
            [CallerFilePath] string callerPath = null,
            [CallerLineNumber] int callerLine  = 0
            )
        {
            var ilBuilder = TestData.GetMethodData(qualifiedMethodName).ILBuilder;

            Dictionary <int, string> sequencePointMarkers = null;

            if (!methodToken.IsNil)
            {
                string actualPdb = PdbToXmlConverter.DeltaPdbToXml(
                    new ImmutableMemoryStream(PdbDelta),
                    new[] { MetadataTokens.GetToken(methodToken) }
                    );
                sequencePointMarkers = ILValidation.GetSequencePointMarkers(actualPdb);

                Assert.True(
                    sequencePointMarkers.Count > 0,
                    $"No sequence points found in:{Environment.NewLine}{actualPdb}"
                    );
            }

            string actualIL = ILBuilderVisualizer.ILBuilderToString(
                ilBuilder,
                mapLocal ?? ToLocalInfo,
                sequencePointMarkers
                );

            AssertEx.AssertEqualToleratingWhitespaceDifferences(
                expectedIL,
                actualIL,
                escapeQuotes: true,
                expectedValueSourcePath: callerPath,
                expectedValueSourceLine: callerLine
                );
        }
Example #27
0
        internal static string GetPdbXml(Compilation compilation, string qualifiedMethodName = "")
        {
            string actual = null;

            using (var exebits = new MemoryStream())
            {
                using (var pdbbits = new MemoryStream())
                {
                    compilation.Emit(exebits, pdbbits);

                    pdbbits.Position = 0;
                    exebits.Position = 0;

                    actual = PdbToXmlConverter.ToXml(pdbbits, exebits, PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError, methodName: qualifiedMethodName);
                }

                ValidateDebugDirectory(exebits, compilation.AssemblyName + ".pdb");
            }

            return(actual);
        }
Example #28
0
        private static void VerifyConvertedPdbMatchesExpectedXml(
            Stream peStreamOriginal,
            Stream pdbStreamOriginal,
            string qualifiedMethodName,
            string expectedPdb,
            PdbToXmlOptions pdbToXmlOptions,
            bool expectedIsXmlLiteral,
            bool originalIsPortable)
        {
            var pdbStreamConverted = new MemoryStream();
            var converter          = new PdbConverter(diagnostic => Assert.True(false, diagnostic.ToString()));

            peStreamOriginal.Position  = 0;
            pdbStreamOriginal.Position = 0;

            if (originalIsPortable)
            {
                converter.ConvertPortableToWindows(peStreamOriginal, pdbStreamOriginal, pdbStreamConverted);
            }
            else
            {
                converter.ConvertWindowsToPortable(peStreamOriginal, pdbStreamOriginal, pdbStreamConverted);
            }

            pdbStreamConverted.Position = 0;
            peStreamOriginal.Position   = 0;

            var actualConverted  = AdjustForConversionArtifacts(XElement.Parse(PdbToXmlConverter.ToXml(pdbStreamConverted, peStreamOriginal, pdbToXmlOptions, methodName: qualifiedMethodName)).ToString());
            var adjustedExpected = AdjustForConversionArtifacts(expectedPdb);

            var(actual, expected) = AdjustToPdbFormat(actualConverted, adjustedExpected, actualIsPortable: !originalIsPortable, actualIsConverted: true);

            AssertEx.AssertLinesEqual(
                expected,
                actual,
                $"PDB format: {(originalIsPortable ? "Windows" : "Portable")} converted from {(originalIsPortable ? "Portable" : "Windows")}{Environment.NewLine}",
                expectedValueSourcePath: null,
                expectedValueSourceLine: 0,
                escapeQuotes: !expectedIsXmlLiteral);
        }
        public void VerifyIL(
            string qualifiedMethodName,
            string expectedIL,
            Func <Cci.ILocalDefinition, ILVisualizer.LocalInfo> mapLocal = null,
            MethodDefinitionHandle methodToken = default(MethodDefinitionHandle),
            [CallerFilePath] string callerPath = null,
            [CallerLineNumber] int callerLine  = 0)
        {
            var ilBuilder = TestData.GetMethodData(qualifiedMethodName).ILBuilder;

            Dictionary <int, string> sequencePointMarkers = null;

            if (!methodToken.IsNil)
            {
                string actualPdb = PdbToXmlConverter.DeltaPdbToXml(PdbDelta, new[] { MetadataTokens.GetToken(methodToken) });
                sequencePointMarkers = TestBase.GetMarkers(actualPdb);
            }

            string actualIL = ILBuilderVisualizer.ILBuilderToString(ilBuilder, mapLocal ?? ToLocalInfo, sequencePointMarkers);

            AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedIL, actualIL, escapeQuotes: true, expectedValueSourcePath: callerPath, expectedValueSourceLine: callerLine);
        }
Example #30
0
        internal static void Execute(IEnumerable <AssemblyTreeNode> nodes)
        {
            var highlighting = HighlightingManager.Instance.GetDefinitionByExtension(".xml");
            var options      = PdbToXmlOptions.IncludeEmbeddedSources | PdbToXmlOptions.IncludeMethodSpans | PdbToXmlOptions.IncludeTokens;

            Docking.DockWorkspace.Instance.RunWithCancellation(ct => Task <AvalonEditTextOutput> .Factory.StartNew(() => {
                AvalonEditTextOutput output = new AvalonEditTextOutput();
                var writer = new TextOutputWriter(output);
                foreach (var node in nodes)
                {
                    string pdbFileName = Path.ChangeExtension(node.LoadedAssembly.FileName, ".pdb");
                    if (!File.Exists(pdbFileName))
                    {
                        continue;
                    }
                    using (var pdbStream = File.OpenRead(pdbFileName))
                        using (var peStream = File.OpenRead(node.LoadedAssembly.FileName))
                            PdbToXmlConverter.ToXml(writer, pdbStream, peStream, options);
                }
                return(output);
            }, ct)).Then(output => Docking.DockWorkspace.Instance.ShowNodes(output, null, highlighting)).HandleExceptions();
        }