internal static void VerifyPdb(
     this Compilation compilation,
     string expectedPdb,
     DebugInformationFormat format = 0,
     [CallerLineNumber]int expectedValueSourceLine = 0,
     [CallerFilePath]string expectedValueSourcePath = null)
 {
     VerifyPdb(compilation, "", expectedPdb, format, expectedValueSourceLine, expectedValueSourcePath);
 }
 internal RuntimeInstance CreateRuntimeInstance(
     Compilation compilation,
     IEnumerable<MetadataReference> references = null,
     DebugInformationFormat debugFormat = DebugInformationFormat.Pdb,
     bool includeLocalSignatures = true)
 {
     var instance = RuntimeInstance.Create(compilation, references, debugFormat, includeLocalSignatures);
     _runtimeInstances.Add(instance);
     return instance;
 }
Beispiel #3
0
 internal static void VerifyPdb(
     this Compilation compilation,
     XElement expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdb(compilation, "", expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
 }
Beispiel #4
0
        internal static ModuleInstance ToModuleInstance(
            this Compilation compilation,
            DebugInformationFormat debugFormat = DebugInformationFormat.Pdb,
            bool includeLocalSignatures        = true)
        {
            var pdbStream = (debugFormat != 0) ? new MemoryStream() : null;
            var peImage   = compilation.EmitToArray(new EmitOptions(debugInformationFormat: debugFormat), pdbStream: pdbStream);
            var symReader = (debugFormat != 0) ? SymReaderFactory.CreateReader(pdbStream, new PEReader(peImage)) : null;

            return(ModuleInstance.Create(peImage, symReader, includeLocalSignatures));
        }
        internal RuntimeInstance CreateRuntimeInstance(
            Compilation compilation,
            IEnumerable <MetadataReference> references = null,
            DebugInformationFormat debugFormat         = DebugInformationFormat.Pdb,
            bool includeLocalSignatures = true)
        {
            var instance = RuntimeInstance.Create(compilation, references, debugFormat, includeLocalSignatures, includeIntrinsicAssembly: true);

            _runtimeInstances.Add(instance);
            return(instance);
        }
Beispiel #6
0
 public CompilationVerifier VerifyPdb(
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     _compilation.VerifyPdb(qualifiedMethodName, expectedPdb, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return(this);
 }
 public CompilationVerifier VerifyPdb(
     string expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     _compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return(this);
 }
Beispiel #8
0
        public EmitOptions WithDebugInformationFormat(DebugInformationFormat format)
        {
            if (DebugInformationFormat == format)
            {
                return(this);
            }

            return(new EmitOptions(this)
            {
                DebugInformationFormat = format
            });
        }
Beispiel #9
0
 public static void VerifyPdb(
     this Compilation compilation,
     XElement expectedPdb,
     IEnumerable <EmbeddedText> embeddedTexts        = null,
     IMethodSymbol debugEntryPoint                   = null,
     DebugInformationFormat format                   = 0,
     PdbValidationOptions options                    = PdbValidationOptions.Default,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdb(compilation, "", expectedPdb, embeddedTexts, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
 }
Beispiel #10
0
        internal static RuntimeInstance Create(
            ModuleInstance module,
            IEnumerable<MetadataReference> references,
            DebugInformationFormat debugFormat)
        {
            // Create modules for the references and the program
            var modules = ImmutableArray.CreateRange(
                references.Select(r => r.ToModuleInstance()).
                Concat(new[] { module }));

            VerifyAllModules(modules);
            return new RuntimeInstance(modules, debugFormat);
        }
Beispiel #11
0
        internal static RuntimeInstance Create(
            ModuleInstance module,
            IEnumerable <MetadataReference> references,
            DebugInformationFormat debugFormat)
        {
            // Create modules for the references and the program
            var modules = ImmutableArray.CreateRange(
                references.Select(r => r.ToModuleInstance()).
                Concat(new[] { module }));

            VerifyAllModules(modules);
            return(new RuntimeInstance(modules, debugFormat));
        }
Beispiel #12
0
 public static CompilationVerifier VerifyPdb(
     this CompilationVerifier verifier,
     string qualifiedMethodName,
     XElement expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     verifier.Compilation.VerifyPdb(qualifiedMethodName, expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return(verifier);
 }
Beispiel #13
0
 public static CompilationVerifier VerifyPdb(
     this CompilationVerifier verifier,
     string expectedPdb,
     IEnumerable <EmbeddedText> embeddedTexts        = null,
     IMethodSymbol debugEntryPoint                   = null,
     DebugInformationFormat format                   = 0,
     PdbValidationOptions options                    = PdbValidationOptions.Default,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     verifier.Compilation.VerifyPdb(expectedPdb, embeddedTexts, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return(verifier);
 }
Beispiel #14
0
        internal void ValidateOptions(DiagnosticBag diagnostics, CommonMessageProvider messageProvider, bool isDeterministic)
        {
            if (!DebugInformationFormat.IsValid())
            {
                diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidDebugInformationFormat, Location.None, (int)DebugInformationFormat));
            }

            foreach (var instrumentationKind in InstrumentationKinds)
            {
                if (!instrumentationKind.IsValid())
                {
                    diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidInstrumentationKind, Location.None, (int)instrumentationKind));
                }
            }

            if (OutputNameOverride != null)
            {
                MetadataHelpers.CheckAssemblyOrModuleName(OutputNameOverride, messageProvider, messageProvider.ERR_InvalidOutputName, diagnostics);
            }

            if (FileAlignment != 0 && !IsValidFileAlignment(FileAlignment))
            {
                diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidFileAlignment, Location.None, FileAlignment));
            }

            if (!SubsystemVersion.Equals(SubsystemVersion.None) && !SubsystemVersion.IsValid)
            {
                diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidSubsystemVersion, Location.None, SubsystemVersion.ToString()));
            }

            if (PdbChecksumAlgorithm.Name != null)
            {
                try
                {
                    IncrementalHash.CreateHash(PdbChecksumAlgorithm).Dispose();
                }
                catch
                {
                    diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidHashAlgorithmName, Location.None, PdbChecksumAlgorithm.ToString()));
                }
            }
            else if (isDeterministic)
            {
                diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.ERR_InvalidHashAlgorithmName, Location.None, ""));
            }

            if (PdbFilePath != null && !PathUtilities.IsValidFilePath(PdbFilePath))
            {
                diagnostics.Add(messageProvider.CreateDiagnostic(messageProvider.FTL_InvalidInputFileName, Location.None, PdbFilePath));
            }
        }
        public void AssemblyAndPdb(DebugInformationFormat pdbFormat, bool exactPdbPath)
        {
            var dir     = Temp.CreateDirectory();
            var dllFile = dir.CreateFile("lib.dll");
            var pdbFile =
                (pdbFormat == DebugInformationFormat.Embedded) ? null : dir.CreateFile("lib.pdb");

            var source = @"class C { public static void Main() { int x = 1; } }";

            var compilation = CSharpTestBase.CreateCompilationWithMscorlib40AndSystemCore(
                source,
                options: TestOptions.DebugDll,
                assemblyName: "lib"
                );
            var pdbStream       = (pdbFile != null) ? new MemoryStream() : null;
            var debugDirPdbPath = exactPdbPath ? pdbFile.Path : "a/y/z/lib.pdb";
            var peImage         = compilation.EmitToArray(
                new EmitOptions(debugInformationFormat: pdbFormat, pdbFilePath: debugDirPdbPath),
                pdbStream: pdbStream
                );

            dllFile.WriteAllBytes(peImage);

            if (pdbFile != null)
            {
                pdbStream.Position = 0;
                pdbFile.WriteAllBytes(pdbStream.ToArray());
            }

            var outputs = new CompilationOutputFilesWithImplicitPdbPath(dllFile.Path);

            using (var pdb = outputs.OpenPdb())
            {
                var encReader = pdb.CreateEditAndContinueMethodDebugInfoReader();
                Assert.True(encReader.IsPortable);
                var localSig = encReader.GetLocalSignature(
                    MetadataTokens.MethodDefinitionHandle(1)
                    );
                Assert.Equal(MetadataTokens.StandaloneSignatureHandle(1), localSig);
            }

            using (var metadata = outputs.OpenAssemblyMetadata(prefetch: false))
            {
                var mdReader = metadata.GetMetadataReader();
                Assert.Equal("lib", mdReader.GetString(mdReader.GetAssemblyDefinition().Name));
            }

            // make sure all files are closed and can be deleted
            Directory.Delete(dir.Path, recursive: true);
        }
        private ImmutableArray<byte> EmitDeterministic(string source, Platform platform, DebugInformationFormat pdbFormat, bool optimize)
        {
            var options = (optimize ? TestOptions.ReleaseExe : TestOptions.DebugExe).WithPlatform(platform).WithDeterminism(true);

            var compilation = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef }, options: options);

            // The resolution of the PE header time date stamp is seconds, and we want to make sure that has an opportunity to change
            // between calls to Emit.
            if (pdbFormat == DebugInformationFormat.Pdb)
            {
                Thread.Sleep(TimeSpan.FromSeconds(1));
            }

            return compilation.EmitToArray(EmitOptions.Default.WithDebugInformationFormat(pdbFormat), pdbStream: new MemoryStream());
        }
Beispiel #17
0
        public static DebugFileFormat ToDebugFileFormat(this DebugInformationFormat format)
        {
            switch (format)
            {
            case 0:                                                                         return(DebugFileFormat.None);

            case DebugInformationFormat.Pdb:                        return(DebugFileFormat.Pdb);

            case DebugInformationFormat.PortablePdb:        return(DebugFileFormat.PortablePdb);

            case DebugInformationFormat.Embedded:           return(DebugFileFormat.Embedded);

            default:
                Debug.Fail($"Unknown debug info format: {format}");
                return(DebugFileFormat.None);
            }
        }
        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);
        }
Beispiel #19
0
 internal static void VerifyPdb(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdbImpl(
         compilation,
         qualifiedMethodName,
         expectedPdb,
         format,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: true);
 }
Beispiel #20
0
        internal static RuntimeInstance Create(
            Compilation compilation,
            IEnumerable<MetadataReference> references = null,
            DebugInformationFormat debugFormat = 0,
            bool includeLocalSignatures = true)
        {
            var module = compilation.ToModuleInstance(debugFormat, includeLocalSignatures);

            if (references == null)
            {
                references = ExpressionCompilerTestHelpers.GetEmittedReferences(compilation, module.GetMetadataReader());
            }

            references = references.Concat(new[] { ExpressionCompilerTestHelpers.IntrinsicAssemblyReference });

            return Create(module, references, debugFormat);
        }
Beispiel #21
0
        internal static RuntimeInstance Create(
            Compilation compilation,
            IEnumerable <MetadataReference> references = null,
            DebugInformationFormat debugFormat         = 0,
            bool includeLocalSignatures = true)
        {
            var module = compilation.ToModuleInstance(debugFormat, includeLocalSignatures);

            if (references == null)
            {
                references = ExpressionCompilerTestHelpers.GetEmittedReferences(compilation, module.GetMetadataReader());
            }

            references = references.Concat(new[] { ExpressionCompilerTestHelpers.IntrinsicAssemblyReference });

            return(Create(module, references));
        }
Beispiel #22
0
        private static void VerifyPdbImpl(
            this Compilation compilation,
            IMethodSymbol debugEntryPoint,
            string qualifiedMethodName,
            XElement expectedPdb,
            DebugInformationFormat format,
            PdbToXmlOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            if (format == 0 || format == DebugInformationFormat.Pdb)
            {
                XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: false));
                AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }

            if (format == 0 || format == DebugInformationFormat.PortablePdb)
            {
                XElement actualPortablePdb = XElement.Parse(GetPdbXml(compilation, debugEntryPoint, options, qualifiedMethodName, portable: true));

                // SymWriter doesn't create empty scopes. When the C# compiler uses forwarding CDI instead of a NamespaceScope
                // the scope is actually not empty - it logically contains the imports. Portable PDB does not used forwarding and thus
                // creates the scope. When generating PDB XML for testing the Portable DiaSymReader returns empty namespaces.
                RemoveEmptyScopes(actualPortablePdb);

                // sharing the same expected output with native PDB
                if (format == 0)
                {
                    RemoveNonPortablePdb(expectedPdb);

                    // TODO: remove
                    RemoveEmptySequencePoints(expectedPdb);

                    // remove scopes that only contained non-portable elements (namespace scopes)
                    RemoveEmptyScopes(expectedPdb);
                    RemoveMethodsWithNoSequencePoints(expectedPdb);
                    RemoveEmptyMethods(expectedPdb);
                }

                AssertXml.Equal(expectedPdb, actualPortablePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }
        }
Beispiel #23
0
        private void TestEmit(DebugInformationFormat format)
        {
            var script      = CSharpScript.Create("1 + 2", options: ScriptOptions.Default.WithEmitDebugInformation(true));
            var compilation = script.GetCompilation();
            var emitOptions = ScriptBuilder.GetEmitOptions(emitDebugInformation: true).WithDebugInformationFormat(format);

            var peStream   = new MemoryStream();
            var pdbStream  = new MemoryStream();
            var emitResult = ScriptBuilder.Emit(peStream, pdbStream, compilation, emitOptions, cancellationToken: default);

            peStream.Position  = 0;
            pdbStream.Position = 0;

            PdbValidation.ValidateDebugDirectory(
                peStream,
                portablePdbStreamOpt: (format == DebugInformationFormat.PortablePdb) ? pdbStream : null,
                pdbPath: compilation.AssemblyName + ".pdb",
                hashAlgorithm: default,
Beispiel #24
0
        public CommonPEModuleBuilder(
            IEnumerable <ResourceDescription> manifestResources,
            EmitOptions emitOptions,
            OutputKind outputKind,
            Cci.ModulePropertiesForSerialization serializationProperties,
            Compilation compilation)
        {
            Debug.Assert(manifestResources != null);
            Debug.Assert(serializationProperties != null);
            Debug.Assert(compilation != null);

            ManifestResources       = manifestResources;
            DebugDocumentsBuilder   = new DebugDocumentsBuilder(compilation.Options.SourceReferenceResolver, compilation.IsCaseSensitive);
            OutputKind              = outputKind;
            SerializationProperties = serializationProperties;
            _methodBodyMap          = new ConcurrentDictionary <IMethodSymbol, Cci.IMethodBody>(ReferenceEqualityComparer.Instance);
            DebugInformationFormat  = emitOptions.DebugInformationFormat;
        }
Beispiel #25
0
        private static void VerifyPdbImpl(
            this Compilation compilation,
            IEnumerable <EmbeddedText> embeddedTexts,
            IMethodSymbol debugEntryPoint,
            string qualifiedMethodName,
            string expectedPdb,
            DebugInformationFormat format,
            PdbValidationOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            bool testWindowsPdb  = format == 0 || format == DebugInformationFormat.Pdb;
            bool testPortablePdb = format == 0 || format == DebugInformationFormat.PortablePdb;
            bool testConversion  = (options & PdbValidationOptions.SkipConversionValidation) == 0;
            var  pdbToXmlOptions = options.ToPdbToXmlOptions();

            if (testWindowsPdb)
            {
                Verify(isPortable: false, testOtherFormat: testPortablePdb);
            }

            if (testPortablePdb)
            {
                Verify(isPortable: true, testOtherFormat: testWindowsPdb);
            }

            void Verify(bool isPortable, bool testOtherFormat)
            {
                var peStream  = new MemoryStream();
                var pdbStream = new MemoryStream();

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

                VerifyPdbMatchesExpectedXml(peStream, pdbStream, qualifiedMethodName, pdbToXmlOptions, expectedPdb, expectedValueSourceLine, expectedValueSourcePath, expectedIsXmlLiteral, isPortable);

                if (testConversion && testOtherFormat)
                {
                    VerifyConvertedPdbMatchesExpectedXml(peStream, pdbStream, qualifiedMethodName, expectedPdb, pdbToXmlOptions, expectedIsXmlLiteral, isPortable);
                }
            }
        }
Beispiel #26
0
 public static void VerifyPdb(
     this CompilationDifference diff,
     IEnumerable <int> methodTokens,
     XElement expectedPdb,
     DebugInformationFormat format = DebugInformationFormat.Pdb,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null
     )
 {
     VerifyPdb(
         diff,
         methodTokens,
         expectedPdb.ToString(),
         format,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: true
         );
 }
Beispiel #27
0
        internal static void VerifyPdb(
            this Compilation compilation,
            string qualifiedMethodName,
            string expectedPdb,
            DebugInformationFormat format = 0,
            [CallerLineNumber] int expectedValueSourceLine  = 0,
            [CallerFilePath] string expectedValueSourcePath = null)
        {
            var expectedPdbXml = XElement.Parse(string.IsNullOrWhiteSpace(expectedPdb) ? "<symbols></symbols>" : expectedPdb);

            VerifyPdbImpl(
                compilation,
                qualifiedMethodName,
                expectedPdbXml,
                format,
                expectedValueSourceLine,
                expectedValueSourcePath,
                expectedIsXmlLiteral: false);
        }
Beispiel #28
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);
        }
Beispiel #29
0
        public void CompareAllBytesEmitted_Debug(DebugInformationFormat pdbFormat)
        {
            var result1 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.AnyCpu32BitPreferred, pdbFormat, optimize: false);
            var result2 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.AnyCpu32BitPreferred, pdbFormat, optimize: false);

            AssertEx.Equal(result1.pe, result2.pe);
            AssertEx.Equal(result1.pdb, result2.pdb);

            var result3 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.X64, pdbFormat, optimize: false);
            var result4 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.X64, pdbFormat, optimize: false);

            AssertEx.Equal(result3.pe, result4.pe);
            AssertEx.Equal(result3.pdb, result4.pdb);

            var result5 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.Arm64, pdbFormat, optimize: false);
            var result6 = EmitDeterministic(CompareAllBytesEmitted_Source, Platform.Arm64, pdbFormat, optimize: false);

            AssertEx.Equal(result5.pe, result6.pe);
            AssertEx.Equal(result5.pdb, result6.pdb);
        }
 private static void VerifyPdbImpl(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format,
     int expectedValueSourceLine,
     string expectedValueSourcePath,
     bool expectedIsXmlLiteral)
 {
     if (format == 0 || format == DebugInformationFormat.Pdb)
     {
         XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, qualifiedMethodName));
         AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
     }
     else
     {
         // Portable PDBs not supported yet
         throw ExceptionUtilities.Unreachable;
     }
 }
Beispiel #31
0
        public void SourceLink(DebugInformationFormat format)
        {
            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 = CreateCompilation(
                Parse(source, "f:/build/goo.cs"),
                options: TestOptions.DebugDll
                );

            var pdbStream = new MemoryStream();

            c.EmitToArray(
                EmitOptions.Default.WithDebugInformationFormat(format),
                pdbStream: pdbStream,
                sourceLinkStream: new MemoryStream(sourceLinkBlob)
                );

            var actualData = PdbValidation.GetSourceLinkData(pdbStream);

            AssertEx.Equal(sourceLinkBlob, actualData);
        }
Beispiel #32
0
        public void SourceLink_Errors(DebugInformationFormat format)
        {
            string source =
                @"
using System;

class C
{
    public static void Main()
    {
        Console.WriteLine();
    }
}
";
            var sourceLinkStream = new TestStream(
                canRead: true,
                readFunc: (_, __, ___) =>
            {
                throw new Exception("Error!");
            }
                );

            var c = CreateCompilation(
                Parse(source, "f:/build/goo.cs"),
                options: TestOptions.DebugDll
                );
            var pdbStream = format != DebugInformationFormat.Embedded ? new MemoryStream() : null;
            var result    = c.Emit(
                new MemoryStream(),
                pdbStream,
                options: EmitOptions.Default.WithDebugInformationFormat(format),
                sourceLinkStream: sourceLinkStream
                );

            result.Diagnostics.Verify(
                // error CS0041: Unexpected error writing debug information -- 'Error!'
                Diagnostic(ErrorCode.FTL_DebugEmitFailure)
                .WithArguments("Error!")
                .WithLocation(1, 1)
                );
        }
Beispiel #33
0
 internal static void VerifyPdb(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdbImpl(
         compilation,
         debugEntryPoint,
         qualifiedMethodName,
         expectedPdb,
         format,
         options,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: true);
 }
Beispiel #34
0
 public static void VerifyPdb(
     this Compilation compilation,
     string qualifiedMethodName,
     string expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options       = 0,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdbImpl(
         compilation,
         debugEntryPoint,
         qualifiedMethodName,
         string.IsNullOrWhiteSpace(expectedPdb) ? "<symbols></symbols>" : expectedPdb,
         format,
         options,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: false);
 }
Beispiel #35
0
 public static void VerifyPdb(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     IEnumerable <EmbeddedText> embeddedTexts        = null,
     IMethodSymbol debugEntryPoint                   = null,
     DebugInformationFormat format                   = 0,
     PdbValidationOptions options                    = PdbValidationOptions.Default,
     [CallerLineNumber] int expectedValueSourceLine  = 0,
     [CallerFilePath] string expectedValueSourcePath = null)
 {
     VerifyPdbImpl(
         compilation,
         embeddedTexts,
         debugEntryPoint,
         qualifiedMethodName,
         expectedPdb.ToString(),
         format,
         options,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: true);
 }
 public CompilationVerifier VerifyPdb(
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options = 0,
     [CallerLineNumber]int expectedValueSourceLine = 0,
     [CallerFilePath]string expectedValueSourcePath = null)
 {
     _compilation.VerifyPdb(qualifiedMethodName, expectedPdb, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return this;
 }
        private static void VerifyPdbImpl(
            this Compilation compilation,
            string qualifiedMethodName,
            XElement expectedPdb,
            DebugInformationFormat format,
            PdbToXmlOptions options,
            int expectedValueSourceLine,
            string expectedValueSourcePath,
            bool expectedIsXmlLiteral)
        {
            Assert.NotEqual(DebugInformationFormat.Embedded, format);

            if (format == 0 || format == DebugInformationFormat.Pdb)
            {
                XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, options, qualifiedMethodName, portable: false));
                AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }

            if (format == 0 || format == DebugInformationFormat.PortablePdb)
            {
                XElement actualPortablePdb = XElement.Parse(GetPdbXml(compilation, options, qualifiedMethodName, portable: true));

                // SymWriter doesn't create empty scopes. When the C# compiler uses forwarding CDI instead of a NamespaceScope
                // the scope is actually not empty - it logically contains the imports. Portable PDB does not used forwarding and thus
                // creates the scope. When generating PDB XML for testing the Portable DiaSymReader returns empty namespaces.
                RemoveEmptyScopes(actualPortablePdb);

                // sharing the same expected output with native PDB
                if (format == 0)
                {
                    RemoveNonPortablePdb(expectedPdb);

                    // TODO: remove
                    RemoveEmptySequencePoints(expectedPdb);

                    // remove scopes that only contained non-portable elements (namespace scopes)
                    RemoveEmptyScopes(expectedPdb);

                    RemoveEmptyMethods(expectedPdb);
                }

                AssertXml.Equal(expectedPdb, actualPortablePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
            }
        }
 public CompilationVerifier VerifyPdb(
     string expectedPdb,
     DebugInformationFormat format = 0,
     [CallerLineNumber]int expectedValueSourceLine = 0,
     [CallerFilePath]string expectedValueSourcePath = null)
 {
     _compilation.VerifyPdb(expectedPdb, format, expectedValueSourceLine, expectedValueSourcePath);
     return this;
 }
 public CompilationVerifier VerifyPdb(
     string expectedPdb,
     IMethodSymbol debugEntryPoint = null,
     DebugInformationFormat format = 0,
     PdbToXmlOptions options = 0,
     [CallerLineNumber]int expectedValueSourceLine = 0,
     [CallerFilePath]string expectedValueSourcePath = null)
 {
     _compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
     return this;
 }
Beispiel #40
0
 internal RuntimeInstance(ImmutableArray<ModuleInstance> modules, DebugInformationFormat debugFormat)
 {
     Modules = modules;
     DebugFormat = debugFormat;
 }
 internal static void VerifyPdb(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format = 0,
     [CallerLineNumber]int expectedValueSourceLine = 0,
     [CallerFilePath]string expectedValueSourcePath = null)
 {
     VerifyPdbImpl(
         compilation,
         qualifiedMethodName,
         expectedPdb,
         format,
         expectedValueSourceLine,
         expectedValueSourcePath,
         expectedIsXmlLiteral: true);
 }
 private static void VerifyPdbImpl(
     this Compilation compilation,
     string qualifiedMethodName,
     XElement expectedPdb,
     DebugInformationFormat format,
     int expectedValueSourceLine,
     string expectedValueSourcePath,
     bool expectedIsXmlLiteral)
 {
     if (format == 0 || format == DebugInformationFormat.Pdb)
     {
         XElement actualNativePdb = XElement.Parse(GetPdbXml(compilation, qualifiedMethodName));
         AssertXml.Equal(expectedPdb, actualNativePdb, expectedValueSourcePath, expectedValueSourceLine, expectedIsXmlLiteral);
     }
     else
     {
         // Portable PDBs not supported yet
         throw ExceptionUtilities.Unreachable;
     }
 }
        internal static void VerifyPdb(
            this Compilation compilation,
            string qualifiedMethodName,
            string expectedPdb,
            DebugInformationFormat format = 0,
            [CallerLineNumber]int expectedValueSourceLine = 0,
            [CallerFilePath]string expectedValueSourcePath = null)
        {
            var expectedPdbXml = XElement.Parse(string.IsNullOrWhiteSpace(expectedPdb) ? "<symbols></symbols>" : expectedPdb);

            VerifyPdbImpl(
                compilation,
                qualifiedMethodName,
                expectedPdbXml,
                format,
                expectedValueSourceLine,
                expectedValueSourcePath,
                expectedIsXmlLiteral: false);
        }