提交 51f796b0 编写于 作者: T Tomas Matousek

Read hoisted state machine local CDI from Portable PDb

上级 80771ee4
......@@ -52,7 +52,6 @@
<Compile Include="CSharpCompileResult.cs" />
<Compile Include="CSharpInScopeHoistedLocals.cs" />
<Compile Include="CSharpLocalAndMethod.cs" />
<Compile Include="SymUnmanagedReaderExtensions.cs" />
<Compile Include="CompilationContext.cs" />
<Compile Include="CompilationExtensions.cs" />
<Compile Include="CSharpLanguageInstructionDecoder.cs" />
......@@ -101,4 +100,4 @@
<Import Project="..\..\..\..\Tools\Vsdconfig\Vsdconfig.targets" />
<Import Project="..\..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -195,19 +195,10 @@ internal sealed class EvaluationContext : EvaluationContextBase
var inScopeHoistedLocals = InScopeHoistedLocals.Empty;
var methodDebugInfo = default(MethodDebugInfo);
if (typedSymReader != null)
if (typedSymReader != null && MethodDebugInfo.TryReadMethodDebugInfo(typedSymReader, methodToken, methodVersion, allScopes, out methodDebugInfo))
{
try
{
// TODO (https://github.com/dotnet/roslyn/issues/702): switch on the type of typedSymReader and call the appropriate helper.
methodDebugInfo = typedSymReader.GetMethodDebugInfo(methodToken, methodVersion, allScopes);
var inScopeHoistedLocalIndices = methodDebugInfo.GetInScopeHoistedLocalIndices(ilOffset, ref methodContextReuseConstraints);
inScopeHoistedLocals = new CSharpInScopeHoistedLocals(inScopeHoistedLocalIndices);
}
catch (InvalidOperationException)
{
// bad CDI, ignore
}
var inScopeHoistedLocalIndices = methodDebugInfo.GetInScopeHoistedLocalIndices(ilOffset, ref methodContextReuseConstraints);
inScopeHoistedLocals = new CSharpInScopeHoistedLocals(inScopeHoistedLocalIndices);
}
allScopes.Free();
......
......@@ -105,7 +105,7 @@ .maxstack 1
";
var comp = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
EvaluationContext context;
CompilationTestData testData;
......@@ -211,7 +211,7 @@ .maxstack 1
";
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
EvaluationContext context;
CompilationTestData testData;
......@@ -261,7 +261,7 @@ public void AsyncLambda_Instance_CaptureNothing()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "1");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c.<<M>b__1_0>d.MoveNext");
......@@ -302,7 +302,7 @@ public void AsyncLambda_Instance_CaptureLocal()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "x");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -357,7 +357,7 @@ public void AsyncLambda_Instance_CaptureParameter()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "u.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -412,7 +412,7 @@ public void AsyncLambda_Instance_CaptureLambdaParameter()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "ch.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c.<<M>b__1_0>d.MoveNext");
......@@ -453,7 +453,7 @@ public void AsyncLambda_Instance_CaptureThis()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "t.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<<M>b__1_0>d.MoveNext");
......@@ -508,7 +508,7 @@ public void AsyncLambda_Instance_CaptureThisAndLocal()
{
var source = string.Format(asyncLambdaSourceTemplate, "/*instance*/", "x + t.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -578,7 +578,7 @@ public void AsyncLambda_Static_CaptureNothing()
{
var source = string.Format(asyncLambdaSourceTemplate, "static", "1");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c.<<M>b__1_0>d.MoveNext");
......@@ -619,7 +619,7 @@ public void AsyncLambda_Static_CaptureLocal()
{
var source = string.Format(asyncLambdaSourceTemplate, "static", "x");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -674,7 +674,7 @@ public void AsyncLambda_Static_CaptureParameter()
{
var source = string.Format(asyncLambdaSourceTemplate, "static", "u.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -729,7 +729,7 @@ public void AsyncLambda_Static_CaptureLambdaParameter()
{
var source = string.Format(asyncLambdaSourceTemplate, "static", "ch.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c.<<M>b__1_0>d.MoveNext");
......@@ -770,7 +770,7 @@ public void GenericAsyncLambda_Instance_CaptureNothing()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "1");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__1.<<M>b__1_0>d.MoveNext");
......@@ -817,7 +817,7 @@ public void GenericAsyncLambda_Instance_CaptureLocal()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "x");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -878,7 +878,7 @@ public void GenericAsyncLambda_Instance_CaptureParameter()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "u.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -939,7 +939,7 @@ public void GenericAsyncLambda_Instance_CaptureLambdaParameter()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "ch.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__1.<<M>b__1_0>d.MoveNext");
......@@ -986,7 +986,7 @@ public void GenericAsyncLambda_Instance_CaptureThis()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "t.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<<M>b__1_0>d.MoveNext");
......@@ -1047,7 +1047,7 @@ public void GenericAsyncLambda_Instance_CaptureThisAndLocal()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "/*instance*/", "x + t.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -1123,7 +1123,7 @@ public void GenericAsyncLambda_Static_CaptureNothing()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "static", "1");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__1.<<M>b__1_0>d.MoveNext");
......@@ -1170,7 +1170,7 @@ public void GenericAsyncLambda_Static_CaptureLocal()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "static", "x");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -1231,7 +1231,7 @@ public void GenericAsyncLambda_Static_CaptureParameter()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "static", "u.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__DisplayClass1_0.<<M>b__0>d.MoveNext");
......@@ -1292,7 +1292,7 @@ public void GenericAsyncLambda_Static_CaptureLambdaParameter()
{
var source = string.Format(genericAsyncLambdaSourceTemplate, "static", "ch.GetHashCode()");
var comp = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: GetUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var context = CreateMethodContext(runtime, "D.<>c__1.<<M>b__1_0>d.MoveNext");
......@@ -1356,7 +1356,7 @@ static IEnumerable<int> M()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
ImmutableArray<MetadataBlock> blocks;
Guid moduleVersionId;
......
......@@ -912,7 +912,7 @@ static int P
";
var comp = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll, assemblyName: ExpressionCompilerUtilities.GenerateUniqueName());
WithRuntimeInstancePortableBug(comp, runtime =>
WithRuntimeInstance(comp, runtime =>
{
var dummyComp = CreateCompilationWithMscorlib("", new[] { comp.EmitToImageReference() }, options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All));
var typeC = dummyComp.GlobalNamespace.GetMember<NamedTypeSymbol>("C");
......@@ -935,7 +935,7 @@ static int P
private void VerifyHasThis(string source, string methodName, string expectedType, string expectedIL, bool thisCanBeElided = true)
{
var sourceCompilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll, assemblyName: ExpressionCompilerUtilities.GenerateUniqueName());
WithRuntimeInstancePortableBug(sourceCompilation, runtime =>
WithRuntimeInstance(sourceCompilation, runtime =>
{
var context = CreateMethodContext(runtime, methodName);
VerifyHasThis(context, expectedType, expectedIL);
......@@ -943,7 +943,7 @@ private void VerifyHasThis(string source, string methodName, string expectedType
// Now recompile and test CompileExpression with optimized code.
sourceCompilation = sourceCompilation.WithOptions(sourceCompilation.Options.WithOptimizationLevel(OptimizationLevel.Release));
WithRuntimeInstancePortableBug(sourceCompilation, runtime =>
WithRuntimeInstance(sourceCompilation, runtime =>
{
var context = CreateMethodContext(runtime, methodName);
// In C#, "this" may be optimized away.
......@@ -1045,7 +1045,7 @@ System.Collections.IEnumerable F()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<F>d__1.MoveNext");
string error;
......@@ -1081,7 +1081,7 @@ async Task F()
}
}";
var compilation0 = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<F>d__1.MoveNext");
string error;
......@@ -1118,7 +1118,7 @@ void F()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<F>b__1_0");
string error;
......@@ -1154,7 +1154,7 @@ System.Collections.IEnumerable M()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "Derived.<M>d__1.MoveNext");
string error;
......@@ -1195,7 +1195,7 @@ async Task M()
}
}";
var compilation0 = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "Derived.<M>d__1.MoveNext");
string error;
......@@ -1237,7 +1237,7 @@ void F()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "Derived.<F>b__1_0");
string error;
......
......@@ -1251,7 +1251,7 @@ internal IEnumerable F()
}
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<F>d__2.MoveNext", atLineNumber: 999);
var testData = new CompilationTestData();
......@@ -1301,7 +1301,7 @@ static IEnumerable<T> F<T>(T[] o)
}";
var compilation0 = CreateCompilationWithMscorlib(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(
runtime,
......@@ -1371,7 +1371,7 @@ struct S<T> where T : class
options: TestOptions.DebugDll,
references: new[] { SystemRef_v4_0_30319_17929, SystemCoreRef_v4_0_30319_17929, CSharpRef });
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "S.<F>d__1.MoveNext");
......@@ -1442,7 +1442,7 @@ static async Task M(object x)
options: TestOptions.DebugDll,
references: new[] { SystemRef_v4_0_30319_17929, SystemCoreRef_v4_0_30319_17929, CSharpRef });
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<M>d__1.MoveNext");
......@@ -1571,7 +1571,7 @@ static void M()
}
}";
var compilation0 = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, methodName: "C.<>c.<<M>b__0_0>d.MoveNext");
var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
......@@ -2498,7 +2498,7 @@ static async Task M()
}
}";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation, runtime =>
WithRuntimeInstance(compilation, runtime =>
{
var context = CreateMethodContext(runtime, "C.<M>d__1.MoveNext", atLineNumber: 999);
var testData = new CompilationTestData();
......@@ -2558,7 +2558,7 @@ static IEnumerable M()
}
}";
var compilation0 = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation0, runtime =>
WithRuntimeInstance(compilation0, runtime =>
{
var context = CreateMethodContext(runtime, "C.<M>d__1.MoveNext", atLineNumber: 999);
var testData = new CompilationTestData();
......@@ -2710,7 +2710,7 @@ async void M()
}
}";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugDll);
WithRuntimeInstancePortableBug(compilation, runtime =>
WithRuntimeInstance(compilation, runtime =>
{
var context = CreateMethodContext(runtime, "C.<M>d__0.MoveNext()", atLineNumber: 999);
var locals = ArrayBuilder<LocalAndMethod>.GetInstance();
......
......@@ -36,6 +36,8 @@
<Compile Include="DebuggerDiagnosticFormatter.cs" />
<Compile Include="DynamicFlagsCustomTypeInfo.cs" />
<Compile Include="DynamicFlagsCustomTypeInfo_Factory.cs" />
<Compile Include="PDB\MethodDebugInfo.Native.cs" />
<Compile Include="PDB\MethodDebugInfo.Portable.cs" />
<Compile Include="Placeholders.cs" />
<Compile Include="ImmutableArrayExtensions.cs" />
<Compile Include="CompileResult.cs" />
......@@ -106,4 +108,4 @@
<ImportGroup Label="Targets">
<Import Project="..\..\..\..\..\build\Targets\VSL.Imports.targets" />
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
internal struct HoistedLocalScopeRecord
{
public readonly uint StartOffset;
public readonly uint Length;
public readonly int StartOffset;
public readonly int Length;
private HoistedLocalScopeRecord(uint startOffset, uint length)
public HoistedLocalScopeRecord(int startOffset, int length)
{
this.StartOffset = startOffset;
this.Length = length;
}
public static HoistedLocalScopeRecord FromNative(int startOffset, int endOffsetInclusive)
{
return new HoistedLocalScopeRecord((uint)startOffset, (uint)(endOffsetInclusive - startOffset + 1));
}
public static HoistedLocalScopeRecord FromPortable(uint startOffset, uint length)
{
return new HoistedLocalScopeRecord(startOffset, length);
}
}
}
......@@ -3,16 +3,57 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.ExpressionEvaluator;
using System.Reflection.Metadata;
using Microsoft.DiaSymReader;
namespace Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
internal static class SymUnmanagedReaderExtensions
partial struct MethodDebugInfo
{
public static MethodDebugInfo GetMethodDebugInfo(
this ISymUnmanagedReader reader,
public unsafe static bool TryReadMethodDebugInfo(ISymUnmanagedReader symReader, int methodToken, int methodVersion, ArrayBuilder<ISymUnmanagedScope> allScopes, out MethodDebugInfo info)
{
var symReader4 = symReader as ISymUnmanagedReader4;
if (symReader4 != null)
{
byte* metadata;
int size;
// TODO: version
int hr = symReader4.GetPortableDebugMetadata(out metadata, out size);
SymUnmanagedReaderExtensions.ThrowExceptionForHR(hr);
if (metadata != null)
{
var mdReader = new MetadataReader(metadata, size);
try
{
info = ReadFromPortable(mdReader, methodToken);
return true;
}
catch (BadImageFormatException)
{
// bad CDI, ignore
info = default(MethodDebugInfo);
return false;
}
}
}
try
{
info = ReadFromNative(symReader, methodToken, methodVersion, allScopes);
return true;
}
catch (InvalidOperationException)
{
// bad CDI, ignore
info = default(MethodDebugInfo);
return false;
}
}
private static MethodDebugInfo ReadFromNative(
ISymUnmanagedReader reader,
int methodToken,
int methodVersion,
ArrayBuilder<ISymUnmanagedScope> scopes)
......@@ -71,7 +112,7 @@ internal static class SymUnmanagedReaderExtensions
continue;
}
externAliasRecordBuilder.Add(new NativeExternAliasRecord<AssemblySymbol>(alias, targetIdentity));
externAliasRecordBuilder.Add(new NativeExternAliasRecord(alias, targetIdentity));
}
}
}
......@@ -88,7 +129,7 @@ internal static class SymUnmanagedReaderExtensions
if (!customDebugInfoRecord.IsDefault)
{
hoistedLocalScopeRecords = CustomDebugInfoReader.DecodeStateMachineHoistedLocalScopesRecord(customDebugInfoRecord)
.SelectAsArray(s => HoistedLocalScopeRecord.FromNative(s.StartOffset, s.EndOffset));
.SelectAsArray(s => new HoistedLocalScopeRecord(s.StartOffset, s.EndOffset - s.StartOffset + 1));
}
CustomDebugInfoReader.GetCSharpDynamicLocalInfo(
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
partial struct MethodDebugInfo
{
/// <exception cref="BadImageFormatException">Invalid data format.</exception>
public static MethodDebugInfo ReadFromPortable(MetadataReader reader, int methodToken)
{
string defaultNamespace;
ImmutableArray<HoistedLocalScopeRecord> hoistedLocalScopes;
ImmutableDictionary<int, ImmutableArray<bool>> dynamicLocals;
ImmutableDictionary<string, ImmutableArray<bool>> dynamicConstants;
ImmutableArray<ImmutableArray<ImportRecord>> importGroups;
ImmutableArray<ExternAliasRecord> externAliases;
var methodHandle = (MethodDefinitionHandle)MetadataTokens.EntityHandle(methodToken);
ReadImportScopes(reader, methodHandle, out importGroups, out externAliases);
ReadMethodCustomDebugInformation(reader, methodHandle, out hoistedLocalScopes, out dynamicLocals, out dynamicConstants, out defaultNamespace);
return new MethodDebugInfo(hoistedLocalScopes, importGroups, externAliases, dynamicLocals, dynamicConstants, defaultNamespace);
}
/// <exception cref="BadImageFormatException">Invalid data format.</exception>
private static void ReadImportScopes(
MetadataReader reader,
MethodDefinitionHandle methodHandle,
out ImmutableArray<ImmutableArray<ImportRecord>> importGroups,
out ImmutableArray<ExternAliasRecord> externAliases)
{
// TODO:
importGroups = ImmutableArray<ImmutableArray<ImportRecord>>.Empty;
externAliases = ImmutableArray<ExternAliasRecord>.Empty;
}
/// <exception cref="BadImageFormatException">Invalid data format.</exception>
private static void ReadMethodCustomDebugInformation(
MetadataReader reader,
MethodDefinitionHandle methodHandle,
out ImmutableArray<HoistedLocalScopeRecord> hoistedLocalScopes,
out ImmutableDictionary<int, ImmutableArray<bool>> dynamicLocals,
out ImmutableDictionary<string, ImmutableArray<bool>> dynamicConstants,
out string defaultNamespace)
{
hoistedLocalScopes = ImmutableArray<HoistedLocalScopeRecord>.Empty;
defaultNamespace = "";
dynamicLocals = ImmutableDictionary<int, ImmutableArray<bool>>.Empty;
dynamicConstants = ImmutableDictionary<string, ImmutableArray<bool>>.Empty;
foreach (var infoHandle in reader.GetCustomDebugInformation(methodHandle))
{
var info = reader.GetCustomDebugInformation(infoHandle);
var id = reader.GetGuid(info.Kind);
if (id == PortableCustomDebugInfoKinds.StateMachineHoistedLocalScopes)
{
// only single CDI is allowed on a method:
if (!hoistedLocalScopes.IsEmpty)
{
throw new BadImageFormatException();
}
hoistedLocalScopes = DecodeHoistedLocalScopes(reader.GetBlobReader(info.Value));
}
else if (id == PortableCustomDebugInfoKinds.DynamicLocalVariables)
{
// TODO
}
else if (id == PortableCustomDebugInfoKinds.DefaultNamespace)
{
var valueReader = reader.GetBlobReader(info.Value);
defaultNamespace = valueReader.ReadUTF8(valueReader.Length);
}
}
}
/// <exception cref="BadImageFormatException">Invalid data format.</exception>
private static ImmutableArray<HoistedLocalScopeRecord> DecodeHoistedLocalScopes(BlobReader reader)
{
var result = ArrayBuilder<HoistedLocalScopeRecord>.GetInstance();
do
{
int startOffset = reader.ReadInt32();
int length = reader.ReadInt32();
result.Add(new HoistedLocalScopeRecord(startOffset, length));
}
while (reader.RemainingBytes > 0);
return result.ToImmutableAndFree();
}
}
}
......@@ -5,7 +5,7 @@
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
internal struct MethodDebugInfo
internal partial struct MethodDebugInfo
{
public readonly ImmutableArray<HoistedLocalScopeRecord> HoistedLocalScopeRecords;
public readonly ImmutableArray<ImmutableArray<ImportRecord>> ImportRecordGroups;
......@@ -53,7 +53,7 @@ public ImmutableSortedSet<int> GetInScopeHoistedLocalIndices(int ilOffset, ref M
int i = 0;
foreach (var record in this.HoistedLocalScopeRecords)
{
constraintsBuilder.AddRange(record.StartOffset, record.StartOffset + record.Length);
constraintsBuilder.AddRange((uint)record.StartOffset, (uint)(record.StartOffset + record.Length));
var delta = ilOffset - record.StartOffset;
if (0 <= delta && delta < record.Length)
......
......@@ -5,8 +5,7 @@
namespace Microsoft.CodeAnalysis.ExpressionEvaluator
{
internal sealed class NativeExternAliasRecord<TAssemblySymbol> : ExternAliasRecord
where TAssemblySymbol : class, IAssemblySymbol
internal sealed class NativeExternAliasRecord : ExternAliasRecord
{
private readonly AssemblyIdentity _targetAssemblyIdentity;
......@@ -24,7 +23,7 @@ internal sealed class NativeExternAliasRecord<TAssemblySymbol> : ExternAliasReco
{
for (int i = 0; i < assembliesAndModules.Length; i++)
{
var assembly = assembliesAndModules[i] as TAssemblySymbol;
var assembly = assembliesAndModules[i] as IAssemblySymbol;
if (assembly != null && assemblyIdentityComparer.ReferenceMatchesDefinition(_targetAssemblyIdentity, assembly.Identity))
{
return i;
......
......@@ -246,9 +246,6 @@ public static void ValidateDebugDirectory(Stream peStream, Stream portablePdbStr
Assert.True(entries == 1 || entries == 2);
bool hasDebug = entries == 2;
byte[] buffer = new byte[debugDirectory.Size];
peStream.Read(buffer, 0, buffer.Length); // TODO: this is not guaranteed to read buffer.Length of data
peStream.Position = position;
var reader = new BinaryReader(peStream);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册