Ejemplo n.º 1
0
        public static ISymUnmanagedReader5 OpenDummySymReader(ImmutableArray <byte> pdbImage)
        {
            var symBinder = new SymBinder();
            var metadataImportProvider = new DummyMetadataImportProvider();

            var pdbStream = new MemoryStream();

            pdbImage.WriteToStream(pdbStream);

            var pdbStreamCom = SymUnmanagedStreamFactory.CreateStream(pdbStream);

            if (
                pdbImage.Length > 4 &&
                pdbImage[0] == 'B' &&
                pdbImage[1] == 'S' &&
                pdbImage[2] == 'J' &&
                pdbImage[3] == 'B'
                )
            {
                var hr = symBinder.GetReaderFromPdbStream(
                    metadataImportProvider,
                    pdbStreamCom,
                    out var symReader
                    );
                Assert.Equal(0, hr);
                return((ISymUnmanagedReader5)symReader);
            }
            else
            {
                return(SymUnmanagedReaderFactory.CreateReader <ISymUnmanagedReader5>(
                           pdbStream,
                           new DummySymReaderMetadataProvider()
                           ));
            }
        }
Ejemplo n.º 2
0
        public static (ImmutableArray <byte> PEImage, ISymUnmanagedReader5 SymReader) EmitAndOpenDummySymReader(Compilation compilation, DebugInformationFormat pdbFormat)
        {
            var symBinder = new SymBinder();
            var metadataImportProvider = new DummyMetadataImportProvider();

            var pdbStream = new MemoryStream();
            var peImage   = compilation.EmitToArray(new EmitOptions(debugInformationFormat: pdbFormat), pdbStream: pdbStream);

            pdbStream.Position = 0;

            var pdbStreamCom = SymUnmanagedStreamFactory.CreateStream(pdbStream);

            ISymUnmanagedReader5 symReader5;

            if (pdbFormat == DebugInformationFormat.PortablePdb)
            {
                int hr = symBinder.GetReaderFromPdbStream(metadataImportProvider, pdbStreamCom, out var symReader);
                Assert.Equal(0, hr);
                symReader5 = (ISymUnmanagedReader5)symReader;
            }
            else
            {
                symReader5 = SymUnmanagedReaderFactory.CreateReader <ISymUnmanagedReader5>(pdbStream, new DummySymReaderMetadataProvider());
            }

            return(peImage, symReader5);
        }
Ejemplo n.º 3
0
        public void DebugInfo(DebugInformationFormat format, bool useSymReader)
        {
            var source      = @"
using System;
delegate void D();
class C
{
    public static void Main()
    {
        int x = 1;
        D d = () => Console.Write(x);
        d();
    }
}
";
            var compilation = CSharpTestBase.CreateCompilationWithMscorlib40AndSystemCore(source, options: TestOptions.DebugDll, sourceFileName: "/a/c.cs");

            var pdbStream = new MemoryStream();

            compilation.EmitToArray(new EmitOptions(debugInformationFormat: format), pdbStream: pdbStream);
            pdbStream.Position = 0;

            DebugInformationReaderProvider       provider;
            EditAndContinueMethodDebugInfoReader reader;

            if (format == DebugInformationFormat.PortablePdb && useSymReader)
            {
                var pdbStreamCom           = SymUnmanagedStreamFactory.CreateStream(pdbStream);
                var metadataImportProvider = new DummyMetadataImportProvider();
                Assert.Equal(0, new SymBinder().GetReaderFromPdbStream(metadataImportProvider, pdbStreamCom, out var symReader));
                reader = EditAndContinueMethodDebugInfoReader.Create((ISymUnmanagedReader5)symReader, version: 1);
            }
            else
            {
                provider = DebugInformationReaderProvider.CreateFromStream(pdbStream);
                reader   = provider.CreateEditAndContinueMethodDebugInfoReader();
            }

            // Main method
            var debugInfo = reader.GetDebugInfo(MetadataTokens.MethodDefinitionHandle(5));

            Assert.Equal(0, debugInfo.GetMethodOrdinal());
            AssertEx.Equal(new[] { "Offset=0 Ordinal=0 Kind=LambdaDisplayClass", "Offset=33 Ordinal=0 Kind=UserDefined" }, debugInfo.InspectLocalSlots());
            AssertEx.Equal(new[] { "Offset=43 Id=0#0 Closure=0" }, debugInfo.InspectLambdas());
            AssertEx.Equal(new[] { "Offset=0 Id=0#0" }, debugInfo.InspectClosures());

            var localSig = reader.GetLocalSignature(MetadataTokens.MethodDefinitionHandle(5));

            Assert.Equal(MetadataTokens.StandaloneSignatureHandle(1), localSig);

            // method without debug information:
            debugInfo = reader.GetDebugInfo(MetadataTokens.MethodDefinitionHandle(1));
            Assert.Equal(-1, debugInfo.GetMethodOrdinal());
            Assert.Null(debugInfo.InspectLocalSlots());
            Assert.Null(debugInfo.InspectLambdas());
            Assert.Null(debugInfo.InspectClosures());

            localSig = reader.GetLocalSignature(MetadataTokens.MethodDefinitionHandle(1));
            Assert.Equal(default, localSig);
Ejemplo n.º 4
0
        public static void UpdateSymReaderFromResource(ISymUnmanagedReader symReader, TestResource artifacts, SymUnmanagedLineDelta[] lineDeltas = null)
        {
            lineDeltas = lineDeltas ?? Array.Empty <SymUnmanagedLineDelta>();

            var symUpdate = (ISymUnmanagedEncUpdate)symReader;
            var deltaPdb  = SymUnmanagedStreamFactory.CreateStream(new MemoryStream(artifacts.Pdb));

            Assert.Equal(HResult.S_OK, symUpdate.UpdateSymbolStore2(deltaPdb, lineDeltas, lineDeltas.Length));
        }
 public void Errors()
 {
     Assert.Throws<ArgumentNullException>(() => SymUnmanagedStreamFactory.CreateStream(null));
 }