From 7a20f8a0c3873bb7d984a4704421651d93bd3cbf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tom=C3=A1=C5=A1=20Rylek?= Date: Tue, 16 Oct 2018 20:08:11 -0700 Subject: [PATCH] Structured dump of instance entrypoints and decoding generic lookups (dotnet/coreclr#20433) 1) Dump method signatures in the INSTANCE_METHOD_ENTRYPOINTS section; 2) Add logic for decoding generic lookups; 3) Add previously missing support for dumping MVAR index. Thanks Tomas Commit migrated from https://github.com/dotnet/coreclr/commit/57d101bf25c31973ec01872506f9c7e12933f2b3 --- src/coreclr/src/tools/r2rdump/R2RReader.cs | 20 +++++++++++++++++ src/coreclr/src/tools/r2rdump/R2RSignature.cs | 32 ++++++++++++++++----------- src/coreclr/src/tools/r2rdump/TextDumper.cs | 5 +++++ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/coreclr/src/tools/r2rdump/R2RReader.cs b/src/coreclr/src/tools/r2rdump/R2RReader.cs index 01705e6..63aa679 100644 --- a/src/coreclr/src/tools/r2rdump/R2RReader.cs +++ b/src/coreclr/src/tools/r2rdump/R2RReader.cs @@ -56,6 +56,18 @@ namespace R2RDump Unknown = -1 } + public struct InstanceMethod + { + public byte Bucket; + public R2RMethod Method; + + public InstanceMethod(byte bucket, R2RMethod method) + { + Bucket = bucket; + Method = method; + } + } + public class R2RReader { /// @@ -108,6 +120,11 @@ namespace R2RDump public IList R2RMethods { get; } /// + /// Parsed instance entrypoint table entries. + /// + public IList InstanceMethods { get; } + + /// /// The available types from READYTORUN_SECTION_AVAILABLE_TYPES /// public IList AvailableTypes { get; } @@ -196,6 +213,8 @@ namespace R2RDump } R2RMethods = new List(); + InstanceMethods = new List(); + if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS)) { int runtimeFunctionSize = CalculateRuntimeFunctionSize(); @@ -350,6 +369,7 @@ namespace R2RDump isEntryPoint[method.EntryPointRuntimeFunctionId] = true; } R2RMethods.Add(method); + InstanceMethods.Add(new InstanceMethod(curParser.LowHashcode, method)); curParser = allEntriesEnum.GetNext(); } } diff --git a/src/coreclr/src/tools/r2rdump/R2RSignature.cs b/src/coreclr/src/tools/r2rdump/R2RSignature.cs index 7cf81bd..488b55c 100644 --- a/src/coreclr/src/tools/r2rdump/R2RSignature.cs +++ b/src/coreclr/src/tools/r2rdump/R2RSignature.cs @@ -444,29 +444,30 @@ namespace R2RDump switch ((ReadyToRunFixupKind)fixupType) { case ReadyToRunFixupKind.READYTORUN_FIXUP_ThisObjDictionaryLookup: - builder.Append("THIS_OBJ_DICTIONARY_LOOKUP"); - // TODO + builder.Append("THISOBJ_DICTIONARY_LOOKUP @ "); + ParseType(builder); + builder.Append(": "); + ParseSignature(builder); break; case ReadyToRunFixupKind.READYTORUN_FIXUP_TypeDictionaryLookup: - builder.Append("TYPE_DICTIONARY_LOOKUP"); - // TODO + builder.Append("TYPE_DICTIONARY_LOOKUP: "); + ParseSignature(builder); break; case ReadyToRunFixupKind.READYTORUN_FIXUP_MethodDictionaryLookup: - builder.Append("METHOD_DICTIONARY_LOOKUP"); - // TODO + builder.Append("METHOD_DICTIONARY_LOOKUP: "); + ParseSignature(builder); break; - case ReadyToRunFixupKind.READYTORUN_FIXUP_TypeHandle: ParseType(builder); builder.Append(" (TYPE_HANDLE)"); break; case ReadyToRunFixupKind.READYTORUN_FIXUP_MethodHandle: - builder.Append("METHOD_HANDLE"); - // TODO + ParseMethod(builder); + builder.Append(" (METHOD_HANDLE)"); break; case ReadyToRunFixupKind.READYTORUN_FIXUP_FieldHandle: @@ -507,8 +508,11 @@ namespace R2RDump break; case ReadyToRunFixupKind.READYTORUN_FIXUP_VirtualEntry_Slot: - builder.Append("VIRTUAL_ENTRY_SLOT"); - // TODO + { + uint slot = ReadUInt(); + ParseType(builder); + builder.Append($@" #{slot} (VIRTUAL_ENTRY_SLOT)"); + } break; @@ -708,7 +712,8 @@ namespace R2RDump break; case CorElementType.ELEMENT_TYPE_VAR: - builder.Append("var"); + builder.Append("var #"); + builder.Append(ReadUInt()); break; case CorElementType.ELEMENT_TYPE_ARRAY: @@ -744,7 +749,8 @@ namespace R2RDump break; case CorElementType.ELEMENT_TYPE_MVAR: - builder.Append("mvar"); + builder.Append("mvar #"); + builder.Append(ReadUInt()); break; case CorElementType.ELEMENT_TYPE_CMOD_REQD: diff --git a/src/coreclr/src/tools/r2rdump/TextDumper.cs b/src/coreclr/src/tools/r2rdump/TextDumper.cs index 3fa444c..67a40a8 100644 --- a/src/coreclr/src/tools/r2rdump/TextDumper.cs +++ b/src/coreclr/src/tools/r2rdump/TextDumper.cs @@ -266,6 +266,11 @@ namespace R2RDump NativeParser instanceParser = new NativeParser(_r2r.Image, instanceSectionOffset); NativeHashtable instMethodEntryPoints = new NativeHashtable(_r2r.Image, instanceParser, (uint)(instanceSectionOffset + section.Size)); _writer.Write(instMethodEntryPoints.ToString()); + _writer.WriteLine(); + foreach (InstanceMethod instanceMethod in _r2r.InstanceMethods) + { + _writer.WriteLine($@"0x{instanceMethod.Bucket:X2} -> {instanceMethod.Method.SignatureString}"); + } break; case R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS: int rtfOffset = _r2r.GetOffset(section.RelativeVirtualAddress); -- 2.7.4