コード例 #1
0
 public static void VerifyWindowsPdb(TestResource portable, TestResource windows, string expectedXml, PdbDiagnostic[] expectedDiagnostics = null, PortablePdbConversionOptions options = null)
 {
     VerifyWindowsMatchesExpected(windows, expectedXml);
     // TODO: VerifyPortableReadNativelyMatchesExpected(portable, expectedXml);
     VerifyWindowsConvertedFromPortableMatchesExpected(portable, expectedXml, expectedDiagnostics, options, validateTimeIndifference: false);
 }
コード例 #2
0
        public static void VerifyWindowsConvertedFromPortableMatchesExpected(TestResource portable, string expectedXml, PdbDiagnostic[] expectedDiagnostics, PortablePdbConversionOptions options)
        {
            var portablePEStream          = new MemoryStream(portable.PE);
            var portablePdbStream         = new MemoryStream(portable.Pdb);
            var convertedWindowsPdbStream = new MemoryStream();
            var actualDiagnostics         = new List <PdbDiagnostic>();

            var converter = new PdbConverter(actualDiagnostics.Add);

            converter.ConvertPortableToWindows(portablePEStream, portablePdbStream, convertedWindowsPdbStream, options);

            AssertEx.Equal(expectedDiagnostics ?? Array.Empty <PdbDiagnostic>(), actualDiagnostics, itemInspector: InspectDiagnostic);

            VerifyPdb(convertedWindowsPdbStream, portablePEStream, expectedXml, "Comparing Windows PDB converted from Portable PDB with expected XML");

            portablePdbStream.Position         = 0;
            convertedWindowsPdbStream.Position = 0;
            VerifyMatchingSignatures(portablePdbStream, convertedWindowsPdbStream);
        }
        private void ConvertPortableToWindows(
            ITaskItem file,
            PdbConverter converter,
            PortablePdbConversionOptions parsedConversionOptions)
        {
            string pdbPath = file.GetMetadata(PdbPathMetadata);

            if (string.IsNullOrEmpty(pdbPath))
            {
                Log.LogError($"No '{PdbPathMetadata}' metadata found for '{file}'.");
                return;
            }

            string targetPath = file.GetMetadata(TargetPathMetadata);

            if (string.IsNullOrEmpty(targetPath))
            {
                Log.LogError($"No '{TargetPathMetadata}' metadata found for '{file}'.");
                return;
            }

            using (var sourcePdbStream = new FileStream(pdbPath, FileMode.Open, FileAccess.Read))
            {
                if (PdbConverter.IsPortable(sourcePdbStream))
                {
                    Log.LogMessage(
                        MessageImportance.Low,
                        $"Converting portable PDB '{file.ItemSpec}'...");

                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));

                    using (var peStream = new FileStream(file.ItemSpec, FileMode.Open, FileAccess.Read))
                        using (var peReader = new PEReader(peStream, PEStreamOptions.LeaveOpen))
                        {
                            if (peReader.ReadDebugDirectory().Length > 0)
                            {
                                using (var outPdbStream = new FileStream(targetPath, FileMode.Create, FileAccess.Write))
                                {
                                    converter.ConvertPortableToWindows(
                                        peReader,
                                        sourcePdbStream,
                                        outPdbStream,
                                        parsedConversionOptions);
                                }

                                Log.LogMessage(
                                    MessageImportance.Normal,
                                    $"Portable PDB '{file.ItemSpec}' -> '{targetPath}'");
                            }
                            else
                            {
                                Log.LogWarning($"'{file.ItemSpec}' {NoDebugDirectoryEntriesMessage}");
                            }
                        }
                }
                else
                {
                    Log.LogMessage(
                        MessageImportance.Normal,
                        $"PDB is not portable, skipping: '{file.ItemSpec}'");
                }
            }
        }
コード例 #4
0
 public static void VerifyWindowsPdb(TestResource portable, TestResource windows, string expectedXml, PdbDiagnostic[] expectedDiagnostics = null, PortablePdbConversionOptions options = null)
 {
     VerifyWindowsMatchesExpected(windows, expectedXml);
     VerifyWindowsConvertedFromPortableMatchesExpected(portable, expectedXml, expectedDiagnostics, options);
 }
コード例 #5
0
        public static void VerifyWindowsConvertedFromPortableMatchesExpected(TestResource portable, string expectedXml, PdbDiagnostic[] expectedDiagnostics, PortablePdbConversionOptions options, bool validateTimeIndifference)
        {
            var portablePEStream           = new MemoryStream(portable.PE);
            var portablePdbStream          = new MemoryStream(portable.Pdb);
            var portablePdbStream2         = new MemoryStream(portable.Pdb);
            var convertedWindowsPdbStream1 = new MemoryStream();
            var convertedWindowsPdbStream2 = new MemoryStream();
            var actualDiagnostics          = new List <PdbDiagnostic>();

            var converter = new PdbConverter(actualDiagnostics.Add);

            converter.ConvertPortableToWindows(portablePEStream, portablePdbStream, convertedWindowsPdbStream1, options);
            AssertEx.Equal(expectedDiagnostics ?? Array.Empty <PdbDiagnostic>(), actualDiagnostics, itemInspector: InspectDiagnostic);

            VerifyPdb(convertedWindowsPdbStream1, portablePEStream, expectedXml, "Comparing Windows PDB converted from Portable PDB with expected XML");

            portablePdbStream.Position          = 0;
            convertedWindowsPdbStream1.Position = 0;
            VerifyMatchingSignatures(portablePdbStream, convertedWindowsPdbStream1);

            // validate determinism:
            if (validateTimeIndifference)
            {
                Thread.Sleep(1000);
            }

            portablePEStream.Position  = 0;
            portablePdbStream.Position = 0;
            converter.ConvertPortableToWindows(portablePEStream, portablePdbStream, convertedWindowsPdbStream2, options);
            AssertEx.Equal(convertedWindowsPdbStream1.ToArray(), convertedWindowsPdbStream2.ToArray());
        }