예제 #1
0
        public void EndToEnd_PortableToWindows_ImplicitPath_SuppressSourceLinkConversion()
        {
            var dir = _temp.CreateDirectory();
            var pe  = dir.CreateFile("SourceLink.dll").WriteAllBytes(TestResources.SourceLink.PortableDll);

            dir.CreateFile("SourceLink.pdb").WriteAllBytes(TestResources.SourceLink.PortablePdb);
            var outPdb = dir.CreateFile("SourceLink.converted.pdb").WriteAllText("dummy");

            Assert.True(Pdb2Pdb.Convert(new Pdb2Pdb.Args(
                                            peFilePath: pe.Path,
                                            pdbFilePathOpt: null,
                                            outPdbFilePathOpt: outPdb.Path,
                                            options: new PortablePdbConversionOptions(suppressSourceLinkConversion: true),
                                            suppressedWarnings: ImmutableArray <PdbDiagnosticId> .Empty,
                                            suppressAllWarnings: false,
                                            extract: false)));

            using (var peStream = File.OpenRead(pe.Path))
                using (var pdbStream = File.OpenRead(outPdb.Path))
                {
                    var symReader = SymReaderHelpers.CreateWindowsPdbReader(pdbStream);
                    AssertEx.Equal(TestResources.SourceLink.SourceLinkJson, symReader.GetRawSourceLinkData());
                    Assert.Null(symReader.GetSourceServerData());
                }
        }
예제 #2
0
        public void EndToEnd_PortableToWindows_ExplicitPath_SourceLinkConversion()
        {
            var dir        = _temp.CreateDirectory();
            var pe         = dir.CreateFile("SourceLink.dll").WriteAllBytes(TestResources.SourceLink.PortableDll);
            var pdb        = dir.CreateFile("SourceLink.x.pdb").WriteAllBytes(TestResources.SourceLink.PortablePdb);
            var outPdbPath = Path.Combine(dir.Path, "SourceLink.pdb2");

            Assert.True(Pdb2Pdb.Convert(new Pdb2Pdb.Args(
                                            peFilePath: pe.Path,
                                            pdbFilePathOpt: pdb.Path,
                                            outPdbFilePathOpt: outPdbPath,
                                            options: PortablePdbConversionOptions.Default,
                                            suppressedWarnings: ImmutableArray.Create(PdbDiagnosticId.UnmappedDocumentName),
                                            suppressAllWarnings: false,
                                            extract: false)));

            using (var peStream = File.OpenRead(pe.Path))
                using (var pdbStream = File.OpenRead(outPdbPath))
                {
                    var symReader = SymReaderHelpers.CreateWindowsPdbReader(pdbStream);

                    string sourceLink = symReader.GetSourceLinkData();
                    AssertEx.AssertLinesEqual(
                        @"{
  ""documents"": {
    ""C:\\a*"": ""http://server/1/a*"",
    ""C:\\A*"": ""http://server/2/A*"",
    ""C:\\*"": ""http://server/3/*.g"",
    "":*"": ""http://server/4/*""
  }
}", sourceLink);

                    string srcsvr = symReader.GetSourceServerData();
                    AssertEx.AssertLinesEqual(
                        @"SRCSRV: ini ------------------------------------------------
VERSION=2
SRCSRV: variables ------------------------------------------
RAWURL=http://server/%var2%
SRCSRVVERCTRL=http
SRCSRVTRG=%RAWURL%
SRCSRV: source files ---------------------------------------
C:\Documents.cs*3/Documents.cs.g
C:\a\b\c\d\1.cs*1/a/b/c/d/1.cs
C:\a\b\c\D\2.cs*1/a/b/c/D/2.cs
C:\a\b\C\d\3.cs*1/a/b/C/d/3.cs
C:\a\b\c\d\x.cs*1/a/b/c/d/x.cs
C:\A\b\c\x.cs*1/a/b/c/x.cs
C:\a\b\x.cs*1/a/b/x.cs
C:\a\B\3.cs*1/a/B/3.cs
C:\a\B\c\4.cs*1/a/B/c/4.cs
:6.cs*4/6.cs
C:\a\b\X.cs*1/a/b/X.cs
C:\a\B\x.cs*1/a/B/x.cs
SRCSRV: end ------------------------------------------------", srcsvr);
                }
        }
예제 #3
0
 public void TryReadPdbId_CrossGen_Windows()
 {
     using (var peStream = TestResources.CrossGen.WindowsDll)
     {
         using (var peReader = new PEReader(peStream, PEStreamOptions.LeaveOpen))
         {
             Assert.True(SymReaderHelpers.TryReadPdbId(peReader, out var pePdbId, out int peAge));
             Assert.True(pePdbId.Guid == TestResources.CrossGen.WindowsDllDebugDirectoryEntryGuid);
             Assert.True(peAge == 1);
         }
     }
 }
예제 #4
0
        public void EndToEnd_PortableToWindows_ExplicitPath_SourceLinkConversion()
        {
            var dir        = _temp.CreateDirectory();
            var pe         = dir.CreateFile("SourceLink.dll").WriteAllBytes(TestResources.SourceLink.PortableDll);
            var pdb        = dir.CreateFile("SourceLink.x.pdb").WriteAllBytes(TestResources.SourceLink.PortablePdb);
            var outPdbPath = Path.Combine(dir.Path, "SourceLink.pdb2");

            Assert.True(Pdb2Pdb.Convert(new Pdb2Pdb.Args(
                                            peFilePath: pe.Path,
                                            pdbFilePathOpt: pdb.Path,
                                            outPdbFilePathOpt: outPdbPath,
                                            options: PortablePdbConversionOptions.Default,
                                            extract: false,
                                            verbose: false)));

            using (var peStream = File.OpenRead(pe.Path))
                using (var pdbStream = File.OpenRead(outPdbPath))
                {
                    var symReader = SymReaderHelpers.CreateWindowsPdbReader(pdbStream);
                    Assert.Null(symReader.GetSourceLinkData());

                    string actual = symReader.GetSourceServerData();
                    AssertEx.AssertLinesEqual(
                        @"SRCSRV: ini ------------------------------------------------
VERSION=2
SRCSRV: variables ------------------------------------------
RAWURL=http://server/%var2%
SRCSRVVERCTRL=http
SRCSRVTRG=%RAWURL%
SRCSRV: source files ---------------------------------------
C:\Documents.cs*3/Documents.cs.g
C:\a\b\c\d\1.cs*1/a/b/c/d/1.cs
C:\a\b\c\D\2.cs*1/a/b/c/D/2.cs
C:\a\b\C\d\3.cs*1/a/b/C/d/3.cs
C:\a\b\c\d\x.cs*1/a/b/c/d/x.cs
C:\A\b\c\x.cs*1/a/b/c/x.cs
C:\a\b\x.cs*1/a/b/x.cs
C:\a\B\3.cs*1/a/B/3.cs
C:\a\B\c\4.cs*1/a/B/c/4.cs
:6.cs*4/:6.cs
C:\a\b\X.cs*1/a/b/X.cs
C:\a\B\x.cs*1/a/B/x.cs
SRCSRV: end ------------------------------------------------", actual);
                }
        }
예제 #5
0
        public void EndToEnd_EmbeddedToWindows_SuppressSourceLinkConversion()
        {
            var dir    = _temp.CreateDirectory();
            var pe     = dir.CreateFile("SourceLink.Embedded.dll").WriteAllBytes(TestResources.SourceLink.EmbeddedDll);
            var outPdb = dir.CreateFile("SourceLink.converted.pdb").WriteAllText("dummy");

            Assert.True(Pdb2Pdb.Convert(new Pdb2Pdb.Args(
                                            peFilePath: pe.Path,
                                            pdbFilePathOpt: null,
                                            outPdbFilePathOpt: outPdb.Path,
                                            options: PdbConversionOptions.SuppressSourceLinkConversion,
                                            extract: false,
                                            verbose: false)));

            using (var peStream = File.OpenRead(pe.Path))
                using (var pdbStream = File.OpenRead(outPdb.Path))
                {
                    var symReader = SymReaderHelpers.CreateWindowsPdbReader(pdbStream);
                    AssertEx.Equal(TestResources.SourceLink.SourceLinkJson, symReader.GetRawSourceLinkData());
                    Assert.Null(symReader.GetSourceServerData());
                }
        }
        private static void VerifyMatchingSignatures(Stream portablePdbStream, Stream windowsPdbStream)
        {
            Guid guid;
            uint stamp;
            int  age;

            using (var provider = MetadataReaderProvider.FromPortablePdbStream(portablePdbStream, MetadataStreamOptions.LeaveOpen))
            {
                SymReaderHelpers.GetWindowsPdbSignature(provider.GetMetadataReader().DebugMetadataHeader !.Id, out guid, out stamp, out age);
            }

            var symReader = SymReaderHelpers.CreateWindowsPdbReader(windowsPdbStream);

            try
            {
                Marshal.ThrowExceptionForHR(symReader.MatchesModule(guid, stamp, age, out bool result));
                Assert.True(result);
            }
            finally
            {
                ((ISymUnmanagedDispose)symReader).Destroy();
            }
        }