diff --git a/src/coreclr/src/tools/r2rdump/DisassemblingTypeProvider.cs b/src/coreclr/src/tools/r2rdump/DisassemblingTypeProvider.cs
index 75c03265a5a1f618787ffc744b56eec4d2fbec58..19621f16c09e20ca48060503dfdda17a8692f46b 100644
--- a/src/coreclr/src/tools/r2rdump/DisassemblingTypeProvider.cs
+++ b/src/coreclr/src/tools/r2rdump/DisassemblingTypeProvider.cs
@@ -34,51 +34,17 @@ public virtual string GetPrimitiveType(PrimitiveTypeCode typeCode)
public virtual string GetTypeFromDefinition(MetadataReader reader, TypeDefinitionHandle handle, byte rawTypeKind = 0)
{
- TypeDefinition definition = reader.GetTypeDefinition(handle);
-
- string name = definition.Namespace.IsNil
- ? reader.GetString(definition.Name)
- : reader.GetString(definition.Namespace) + "." + reader.GetString(definition.Name);
-
- if ((definition.Attributes & TypeAttributes.NestedPublic) != 0 || (definition.Attributes & TypeAttributes.NestedFamily) != 0)
- {
- TypeDefinitionHandle declaringTypeHandle = definition.GetDeclaringType();
- return GetTypeFromDefinition(reader, declaringTypeHandle, 0) + "." + name;
- }
-
- return name;
+ return MetadataNameFormatter.FormatHandle(reader, handle);
}
public virtual string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind = 0)
{
- TypeReference reference = reader.GetTypeReference(handle);
- Handle scope = reference.ResolutionScope;
-
- string name = reference.Namespace.IsNil
- ? reader.GetString(reference.Name)
- : reader.GetString(reference.Namespace) + "." + reader.GetString(reference.Name);
-
- switch (scope.Kind)
- {
- case HandleKind.ModuleReference:
- return "[.module " + reader.GetString(reader.GetModuleReference((ModuleReferenceHandle)scope).Name) + "]" + name;
-
- case HandleKind.AssemblyReference:
- var assemblyReferenceHandle = (AssemblyReferenceHandle)scope;
- var assemblyReference = reader.GetAssemblyReference(assemblyReferenceHandle);
- return "[" + reader.GetString(assemblyReference.Name) + "]" + name;
-
- case HandleKind.TypeReference:
- return GetTypeFromReference(reader, (TypeReferenceHandle)scope) + "+" + name;
-
- default:
- return name;
- }
+ return MetadataNameFormatter.FormatHandle(reader, handle);
}
public virtual string GetTypeFromSpecification(MetadataReader reader, DisassemblingGenericContext genericContext, TypeSpecificationHandle handle, byte rawTypeKind = 0)
{
- return reader.GetTypeSpecification(handle).DecodeSignature(this, genericContext);
+ return MetadataNameFormatter.FormatHandle(reader, handle);
}
public virtual string GetSZArrayType(string elementType)
@@ -161,20 +127,7 @@ public virtual string GetArrayType(string elementType, ArrayShape shape)
public virtual string GetTypeFromHandle(MetadataReader reader, DisassemblingGenericContext genericContext, EntityHandle handle)
{
- switch (handle.Kind)
- {
- case HandleKind.TypeDefinition:
- return GetTypeFromDefinition(reader, (TypeDefinitionHandle)handle);
-
- case HandleKind.TypeReference:
- return GetTypeFromReference(reader, (TypeReferenceHandle)handle);
-
- case HandleKind.TypeSpecification:
- return GetTypeFromSpecification(reader, genericContext, (TypeSpecificationHandle)handle);
-
- default:
- throw new ArgumentOutOfRangeException(nameof(handle));
- }
+ return MetadataNameFormatter.FormatHandle(reader, handle);
}
public virtual string GetModifiedType(string modifierType, string unmodifiedType, bool isRequired)
diff --git a/src/coreclr/src/tools/r2rdump/R2RDump.cs b/src/coreclr/src/tools/r2rdump/R2RDump.cs
index 1ad800bc7ba48b71404f7dfdaea5a21c96552bc7..07e329880b8e93aa78a7234be4a9029fe3189f4c 100644
--- a/src/coreclr/src/tools/r2rdump/R2RDump.cs
+++ b/src/coreclr/src/tools/r2rdump/R2RDump.cs
@@ -449,7 +449,7 @@ private int Run(string[] args)
foreach (string filename in _inputFilenames)
{
// parse the ReadyToRun image
- R2RReader r2r = new R2RReader(filename);
+ R2RReader r2r = new R2RReader(_options, filename);
if (_options.Disasm)
{
diff --git a/src/coreclr/src/tools/r2rdump/R2RReader.cs b/src/coreclr/src/tools/r2rdump/R2RReader.cs
index 3e38adc7991aa986f7483f0f5f8d07068e07bf73..62bf8a1f7b1e86445f635de5cc27120e9e3befcb 100644
--- a/src/coreclr/src/tools/r2rdump/R2RReader.cs
+++ b/src/coreclr/src/tools/r2rdump/R2RReader.cs
@@ -77,6 +77,11 @@ public InstanceMethod(byte bucket, R2RMethod method)
public class R2RReader
{
+ ///
+ /// Option are used to specify details of signature formatting.
+ ///
+ public readonly DumpOptions Options;
+
///
/// Underlying PE image reader is used to access raw PE structures like header
/// or section list.
@@ -178,8 +183,9 @@ public class R2RReader
///
/// PE image
/// The Cor header flag must be ILLibrary
- public unsafe R2RReader(string filename)
+ public unsafe R2RReader(DumpOptions options, string filename)
{
+ Options = options;
Filename = filename;
Image = File.ReadAllBytes(filename);
@@ -370,7 +376,7 @@ private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint)
NativeParser curParser = allEntriesEnum.GetNext();
while (!curParser.IsNull())
{
- SignatureDecoder decoder = new SignatureDecoder(this, (int)curParser.Offset);
+ SignatureDecoder decoder = new SignatureDecoder(Options, this, (int)curParser.Offset);
string owningType = null;
@@ -634,7 +640,7 @@ private void ParseImportSections()
long section = NativeReader.ReadInt64(Image, ref sectionOffset);
uint sigRva = NativeReader.ReadUInt32(Image, ref signatureOffset);
int sigOffset = GetOffset((int)sigRva);
- string cellName = MetadataNameFormatter.FormatSignature(this, sigOffset);
+ string cellName = MetadataNameFormatter.FormatSignature(Options, this, sigOffset);
entries.Add(new R2RImportSection.ImportSectionEntry(entries.Count, entryOffset, entryOffset + rva, section, sigRva, cellName));
ImportCellNames.Add(rva + entrySize * i, cellName);
}
diff --git a/src/coreclr/src/tools/r2rdump/R2RSignature.cs b/src/coreclr/src/tools/r2rdump/R2RSignature.cs
index f999aca46e109e1a9af099d31ff2f8888f8fc019..60e4c0fd0ab2c25b3440afb68aa6a1010dd9fa63 100644
--- a/src/coreclr/src/tools/r2rdump/R2RSignature.cs
+++ b/src/coreclr/src/tools/r2rdump/R2RSignature.cs
@@ -41,9 +41,9 @@ public static string FormatHandle(MetadataReader metadataReader, Handle handle,
return formatter.EmitHandleName(handle, namespaceQualified, owningTypeOverride);
}
- public static string FormatSignature(R2RReader r2rReader, int imageOffset)
+ public static string FormatSignature(DumpOptions options, R2RReader r2rReader, int imageOffset)
{
- SignatureDecoder decoder = new SignatureDecoder(r2rReader, imageOffset);
+ SignatureDecoder decoder = new SignatureDecoder(options, r2rReader, imageOffset);
string result = decoder.ReadR2RSignature();
return result;
}
@@ -142,7 +142,7 @@ private string EmitMethodDefinitionName(MethodDefinitionHandle methodDefinitionH
builder.Append(" ");
if (owningTypeOverride == null)
{
- owningTypeOverride = EmitHandleName(methodDef.GetDeclaringType(), namespaceQualified: false, owningTypeOverride: null);
+ owningTypeOverride = EmitHandleName(methodDef.GetDeclaringType(), namespaceQualified: true, owningTypeOverride: null);
}
builder.Append(owningTypeOverride);
builder.Append(".");
@@ -295,6 +295,11 @@ public class SignatureDecoder
///
private readonly MetadataReader _metadataReader;
+ ///
+ /// Dump options are used to specify details of signature formatting.
+ ///
+ private readonly DumpOptions _options;
+
///
/// Byte array representing the R2R PE file read from disk.
///
@@ -315,10 +320,12 @@ public class SignatureDecoder
///
/// R2RReader object representing the R2R PE file
/// Signature offset within the array
- public SignatureDecoder(R2RReader reader, int offset)
+ /// Formatting options
+ public SignatureDecoder(DumpOptions options, R2RReader reader, int offset)
{
- _image = reader.Image;
_metadataReader = reader.MetadataReader;
+ _options = options;
+ _image = reader.Image;
_offset = offset;
}
@@ -328,10 +335,11 @@ public SignatureDecoder(R2RReader reader, int offset)
/// Metadata reader for the R2R image
/// Signature to parse
/// Optional signature offset within the signature byte array, 0 by default
- public SignatureDecoder(MetadataReader metadataReader, byte[] signature, int offset = 0)
+ public SignatureDecoder(DumpOptions options, MetadataReader metadataReader, byte[] signature, int offset = 0)
{
- _image = signature;
_metadataReader = metadataReader;
+ _options = options;
+ _image = signature;
_offset = offset;
}
@@ -516,12 +524,14 @@ private void ParseSignature(StringBuilder builder)
{
ParseMethodDefToken(builder, owningTypeOverride: null);
}
- builder.Append(" (METHOD_ENTRY_DEF_TOKEN)");
+ builder.Append(" (METHOD_ENTRY");
+ builder.Append(_options.Naked ? ")" : "_DEF_TOKEN)");
break;
case ReadyToRunFixupKind.READYTORUN_FIXUP_MethodEntry_RefToken:
ParseMethodRefToken(builder, owningTypeOverride: null);
- builder.Append(" (METHOD_ENTRY_REF_TOKEN)");
+ builder.Append(" (METHOD_ENTRY");
+ builder.Append(_options.Naked ? ")" : "_REF_TOKEN)");
break;
@@ -535,12 +545,14 @@ private void ParseSignature(StringBuilder builder)
case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry_DefToken:
ParseMethodDefToken(builder, owningTypeOverride: null);
- builder.Append(" (VIRTUAL_ENTRY_DEF_TOKEN)");
+ builder.Append(" (VIRTUAL_ENTRY");
+ builder.Append(_options.Naked ? ")" : "_DEF_TOKEN)");
break;
case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry_RefToken:
ParseMethodRefToken(builder, owningTypeOverride: null);
- builder.Append(" (VIRTUAL_ENTRY_REF_TOKEN)");
+ builder.Append(" (VIRTUAL_ENTRY");
+ builder.Append(_options.Naked ? ")" : "_REF_TOKEN)");
break;
case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry_Slot:
@@ -622,12 +634,13 @@ private void ParseSignature(StringBuilder builder)
case ReadyToRunFixupKind.READYTORUN_FIXUP_FieldBaseOffset:
- builder.Append("FIELD_BASE_OFFSET");
- // TODO
+ ParseType(builder);
+ builder.Append(" (FIELD_BASE_OFFSET)");
break;
case ReadyToRunFixupKind.READYTORUN_FIXUP_FieldOffset:
- builder.Append("FIELD_OFFSET");
+ ParseField(builder);
+ builder.Append(" (FIELD_OFFSET)");
// TODO
break;
@@ -915,7 +928,7 @@ private void ParseMethod(StringBuilder builder)
string owningTypeOverride = null;
if ((methodFlags & (uint)ReadyToRunMethodSigFlags.READYTORUN_METHOD_SIG_OwnerType) != 0)
{
- SignatureDecoder owningTypeDecoder = new SignatureDecoder(_metadataReader, _image, _offset);
+ SignatureDecoder owningTypeDecoder = new SignatureDecoder(_options, _metadataReader, _image, _offset);
owningTypeOverride = owningTypeDecoder.ReadTypeSignature();
_offset = owningTypeDecoder._offset;
}