Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove PDB #45

Open
wants to merge 1 commit into
base: metadata-provider
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 4 additions & 48 deletions MetadataProvider/AssemblyExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ public IBasicType ContainingType

private SRPE.PEReader reader;
private SRM.MetadataReader metadata;
private SRM.MetadataReader pdbMetadata;
private GenericContext defGenericContext;
private GenericContext refGenericContext;
private SignatureTypeProvider signatureTypeProvider;
private Assembly assembly;
private Namespace currentNamespace;
private TypeDefinition currentType;
private MethodDefinition currentMethod;
private IDictionary<int, string> currentMethodLocalVariablesNames;

public AssemblyExtractor(Host host, SRPE.PEReader reader, SRM.MetadataReaderProvider pdbProvider = null)
public AssemblyExtractor(Host host, SRPE.PEReader reader)
{
this.Host = host;
this.reader = reader;
Expand All @@ -109,12 +107,7 @@ public AssemblyExtractor(Host host, SRPE.PEReader reader, SRM.MetadataReaderProv
this.defGenericContext = new GenericContext();
this.refGenericContext = new GenericContext();
this.signatureTypeProvider = new SignatureTypeProvider(this);

if (pdbProvider != null)
{
this.pdbMetadata = pdbProvider.GetMetadataReader();
}
}
}

public Host Host { get; private set; }

Expand Down Expand Up @@ -525,7 +518,6 @@ private void ExtractMethod(SRM.MethodDefinitionHandle methoddefHandle)
ExtractParameter(signature, handle);
}

ExtractLocalVariablesNames(methoddefHandle);
ExtractMethodBody(methoddef.RelativeVirtualAddress);

defGenericContext.MethodParameters.Clear();
Expand Down Expand Up @@ -584,27 +576,7 @@ private Constant ExtractParameterDefaultValue(SRM.Parameter parameterdef)

return result;
}

private void ExtractLocalVariablesNames(SRM.MethodDefinitionHandle methoddefHandle)
{
if (pdbMetadata == null)
{
currentMethodLocalVariablesNames = null;
}
else
{
var localVariablesNames = from scopeHandle in pdbMetadata.GetLocalScopes(methoddefHandle)
let localScope = pdbMetadata.GetLocalScope(scopeHandle)
from localHandle in localScope.GetLocalVariables()
let local = pdbMetadata.GetLocalVariable(localHandle)
let name = pdbMetadata.GetString(local.Name)
select new { Name = name, Index = local.Index };

currentMethodLocalVariablesNames = localVariablesNames.ToDictionary(x => x.Index, x => x.Name);
}
}

private void ExtractMethodBody(int relativeVirtualAddress)
private void ExtractMethodBody(int relativeVirtualAddress)
{
if (relativeVirtualAddress == 0) return;
var bodyBlock = SRM.PEReaderExtensions.GetMethodBody(reader, relativeVirtualAddress);
Expand Down Expand Up @@ -655,7 +627,7 @@ private void ExtractLocalVariables(SRM.MethodBodyBlock bodyBlock, IList<IVariabl

for (var i = 0; i < types.Length; ++i)
{
var name = GetLocalSourceName(i);
var name = string.Format("local_{0}", i);
var type = types[i];
var v = new LocalVariable(name)
{
Expand All @@ -665,22 +637,6 @@ private void ExtractLocalVariables(SRM.MethodBodyBlock bodyBlock, IList<IVariabl
variables.Add(v);
}
}

private string GetLocalSourceName(int localVariableIndex)
{
string name = null;

var ok = currentMethodLocalVariablesNames != null &&
currentMethodLocalVariablesNames.TryGetValue(localVariableIndex, out name);

if (!ok)
{
name = string.Format("local_{0}", localVariableIndex);
}

return name;
}

private void ExtractExceptionInformation(SRM.MethodBodyBlock bodyBlock, IList<ProtectedBlock> handlers)
{
foreach (var region in bodyBlock.ExceptionRegions)
Expand Down
9 changes: 3 additions & 6 deletions MetadataProvider/Loader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,16 @@ public Assembly LoadAssembly(string fileName)
return result;
};

var ok = reader.TryOpenAssociatedPortablePdb(fileName, streamProvider,
out SRM.MetadataReaderProvider pdbProvider, out _);

var assembly = ExtractAssembly(reader, pdbProvider);
var assembly = ExtractAssembly(reader);

this.Host.Assemblies.Add(assembly);
return assembly;
}
}

private Assembly ExtractAssembly(SRPE.PEReader reader, SRM.MetadataReaderProvider pdbProvider)
private Assembly ExtractAssembly(SRPE.PEReader reader)
{
var extractor = new AssemblyExtractor(this.Host, reader, pdbProvider);
var extractor = new AssemblyExtractor(this.Host, reader);
var result = extractor.Extract();
return result;
}
Expand Down