public void GetSymAttributeByVersion()
        {
            var source1 = @"
public class C
{
    public static void M()
    {
        int x = 1;
    }
}";

            var source2 = @"
public class C
{
    public static void M()
    {
        int x = 1;
        string y = ""a"";
    }
}";
            var comp1 = CreateCompilationWithMscorlib(source1, options: TestOptions.DebugDll);
            var comp2 = CreateCompilationWithMscorlib(source2, options: TestOptions.DebugDll);

            using (MemoryStream
                peStream1Unused = new MemoryStream(),
                peStream2 = new MemoryStream(),
                pdbStream1 = new MemoryStream(),
                pdbStream2 = new MemoryStream())
            {
                Assert.True(comp1.Emit(peStream1Unused, pdbStream1).Success);
                Assert.True(comp2.Emit(peStream2, pdbStream2).Success);

                pdbStream1.Position = 0;
                pdbStream2.Position = 0;
                peStream2.Position = 0;

                // Note: This SymReader will behave differently from the ISymUnmanagedReader
                // we receive during real debugging.  We're just using it as a rough
                // approximation of ISymUnmanagedReader3, which is unavailable here.
                var symReader = new SymReader(new[] { pdbStream1, pdbStream2 }, peStream2, null);

                var runtime = CreateRuntimeInstance(
                    GetUniqueName(),
                    ImmutableArray.Create(MscorlibRef, ExpressionCompilerTestHelpers.IntrinsicAssemblyReference),
                    peStream2.ToArray(),
                    symReader);

                ImmutableArray<MetadataBlock> blocks;
                Guid moduleVersionId;
                ISymUnmanagedReader symReader2;
                int methodToken;
                int localSignatureToken;
                GetContextState(runtime, "C.M", out blocks, out moduleVersionId, out symReader2, out methodToken, out localSignatureToken);

                Assert.Same(symReader, symReader2);

                AssertEx.SetEqual(symReader.GetLocalNames(methodToken, methodVersion: 1), "x");
                AssertEx.SetEqual(symReader.GetLocalNames(methodToken, methodVersion: 2), "x", "y");

                var context1 = EvaluationContext.CreateMethodContext(
                    default(CSharpMetadataContext),
                    blocks,
                    symReader,
                    moduleVersionId,
                    methodToken: methodToken,
                    methodVersion: 1,
                    ilOffset: 0,
                    localSignatureToken: localSignatureToken);

                var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
                string typeName;
                context1.CompileGetLocals(
                    locals,
                    argumentsOnly: false,
                    typeName: out typeName,
                    testData: null);
                AssertEx.SetEqual(locals.Select(l => l.LocalName), "x");

                var context2 = EvaluationContext.CreateMethodContext(
                    default(CSharpMetadataContext),
                    blocks,
                    symReader,
                    moduleVersionId,
                    methodToken: methodToken,
                    methodVersion: 2,
                    ilOffset: 0,
                    localSignatureToken: localSignatureToken);

                locals.Clear();
                context2.CompileGetLocals(
                    locals,
                    argumentsOnly: false,
                    typeName: out typeName,
                    testData: null);
                AssertEx.SetEqual(locals.Select(l => l.LocalName), "x", "y");
            }
        }
Beispiel #2
0
 internal SymScope(SymReader reader, ISymUnmanagedScope scope)
 {
     _reader = reader;
     _scope  = scope;
 }
        private static ImmutableArray<ImmutableArray<string>> GetGroupedImportStrings(Compilation compilation, string methodName, out ImmutableArray<string> externAliasStrings)
        {
            Assert.NotNull(compilation);
            Assert.NotNull(methodName);

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

                    exebits.Position = 0;
                    using (var module = new PEModule(new PEReader(exebits, PEStreamOptions.LeaveOpen), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0))
                    {
                        var metadataReader = module.MetadataReader;
                        MethodDefinitionHandle methodHandle = metadataReader.MethodDefinitions.Single(mh => metadataReader.GetString(metadataReader.GetMethodDefinition(mh).Name) == methodName);
                        int methodToken = metadataReader.GetToken(methodHandle);

                        // Create a SymReader, rather than a raw COM object, because
                        // SymReader implements ISymUnmanagedReader3 and the COM object
                        // might not.
                        pdbbits.Position = 0;
                        using (var reader = new SymReader(pdbbits.ToArray()))
                        {
                            return reader.GetCSharpGroupedImportStrings(methodToken, methodVersion: 1, externAliasStrings: out externAliasStrings);
                        }
                    }
                }
            }
        }
Beispiel #4
0
 internal SymMethod(SymReader reader, ISymUnmanagedMethod method)
 {
     _reader = reader;
     _method = method;
 }