From 0812d49aeb7ae83bf04a6799f47594ad8a47cfdd Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Mon, 13 Jan 2020 13:08:08 -0800 Subject: [PATCH] Make parsing of debug info lazy (#1657) --- .../DebugInfo.cs | 90 ++++++-- .../EHInfo.cs | 4 +- .../GCRefMap.cs | 4 +- .../{R2RHeader.cs => ReadyToRunHeader.cs} | 16 +- ...tSection.cs => ReadyToRunImportSection.cs} | 6 +- .../{R2RMethod.cs => ReadyToRunMethod.cs} | 33 ++- .../{R2RReader.cs => ReadyToRunReader.cs} | 217 +++++++++++------- .../{R2RSection.cs => ReadyToRunSection.cs} | 4 +- ...R2RSignature.cs => ReadyToRunSignature.cs} | 8 +- .../TransitionBlock.cs | 6 +- src/coreclr/src/tools/r2rdump/CoreDisTools.cs | 4 +- src/coreclr/src/tools/r2rdump/Extensions.cs | 8 +- src/coreclr/src/tools/r2rdump/R2RDiff.cs | 16 +- src/coreclr/src/tools/r2rdump/R2RDump.cs | 62 ++--- src/coreclr/src/tools/r2rdump/TextDumper.cs | 48 ++-- 15 files changed, 313 insertions(+), 213 deletions(-) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RHeader.cs => ReadyToRunHeader.cs} (88%) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RImportSection.cs => ReadyToRunImportSection.cs} (97%) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RMethod.cs => ReadyToRunMethod.cs} (93%) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RReader.cs => ReadyToRunReader.cs} (81%) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RSection.cs => ReadyToRunSection.cs} (94%) rename src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/{R2RSignature.cs => ReadyToRunSignature.cs} (99%) diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs index 490f4053a9bb46..fe0872c1b39863 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/DebugInfo.cs @@ -18,45 +18,45 @@ namespace ILCompiler.Reflection.ReadyToRun /// public class DebugInfo { - private List _boundsList = new List(); - private List _variablesList = new List(); + private readonly ReadyToRunReader _readyToRunReader; + private readonly int _offset; + private List _boundsList; + private List _variablesList; private Machine _machine; - public DebugInfo(byte[] image, int offset, Machine machine) + public DebugInfo(ReadyToRunReader readyToRunReader, int offset) { - _machine = machine; - - // Get the id of the runtime function from the NativeArray - uint lookback = 0; - uint debugInfoOffset = NativeReader.DecodeUnsigned(image, (uint)offset, ref lookback); + this._readyToRunReader = readyToRunReader; + this._offset = offset; + } - if (lookback != 0) + public List BoundsList + { + get { - System.Diagnostics.Debug.Assert(0 < lookback && lookback < offset); - debugInfoOffset = (uint)offset - lookback; + EnsureInitialized(); + return _boundsList; } + } - NibbleReader reader = new NibbleReader(image, (int)debugInfoOffset); - uint boundsByteCount = reader.ReadUInt(); - uint variablesByteCount = reader.ReadUInt(); - int boundsOffset = reader.GetNextByteOffset(); - int variablesOffset = (int)(boundsOffset + boundsByteCount); - - if (boundsByteCount > 0) + public List VariablesList + { + get { - ParseBounds(image, boundsOffset); + EnsureInitialized(); + return _variablesList; } + } - if (variablesByteCount > 0) + public Machine Machine + { + get { - ParseNativeVarInfo(image, variablesOffset); + EnsureInitialized(); + return _machine; } } - public List BoundsList => _boundsList; - public List VariablesList => _variablesList; - public Machine Machine => _machine; - /// /// Convert a register number in debug info into a machine-specific register /// @@ -77,6 +77,46 @@ public static string GetPlatformSpecificRegister(Machine machine, int regnum) } } + private void EnsureInitialized() + { + if (_boundsList != null) + { + return; + } + int offset = _offset; + _boundsList = new List(); + _variablesList = new List(); + Machine machine = _readyToRunReader.Machine; + byte[] image = _readyToRunReader.Image; + _machine = machine; + + // Get the id of the runtime function from the NativeArray + uint lookback = 0; + uint debugInfoOffset = NativeReader.DecodeUnsigned(image, (uint)offset, ref lookback); + + if (lookback != 0) + { + System.Diagnostics.Debug.Assert(0 < lookback && lookback < offset); + debugInfoOffset = (uint)offset - lookback; + } + + NibbleReader reader = new NibbleReader(image, (int)debugInfoOffset); + uint boundsByteCount = reader.ReadUInt(); + uint variablesByteCount = reader.ReadUInt(); + int boundsOffset = reader.GetNextByteOffset(); + int variablesOffset = (int)(boundsOffset + boundsByteCount); + + if (boundsByteCount > 0) + { + ParseBounds(image, boundsOffset); + } + + if (variablesByteCount > 0) + { + ParseNativeVarInfo(image, variablesOffset); + } + } + private void ParseBounds(byte[] image, int offset) { // Bounds info contains (Native Offset, IL Offset, flags) diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/EHInfo.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/EHInfo.cs index e4e02ebc0cb0f6..45a8772891a04b 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/EHInfo.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/EHInfo.cs @@ -84,7 +84,7 @@ public class EHClause /// /// R2R image reader /// Offset of the EH clause in the image - public EHClause(R2RReader reader, int offset) + public EHClause(ReadyToRunReader reader, int offset) { Flags = (CorExceptionFlag)BitConverter.ToUInt32(reader.Image, offset + 0 * sizeof(uint)); TryOffset = BitConverter.ToUInt32(reader.Image, offset + 1 * sizeof(uint)); @@ -175,7 +175,7 @@ public class EHInfo /// Starting RVA of the runtime function /// File offset of the EH info /// Number of EH info clauses - public EHInfo(R2RReader reader, int ehInfoRva, int methodRva, int offset, int clauseCount) + public EHInfo(ReadyToRunReader reader, int ehInfoRva, int methodRva, int offset, int clauseCount) { EHInfoRVA = ehInfoRva; MethodRVA = methodRva; diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/GCRefMap.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/GCRefMap.cs index e1d19bdc1040ea..2dd598aedfb91d 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/GCRefMap.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/GCRefMap.cs @@ -57,12 +57,12 @@ public GCRefMap(uint stackPop, GCRefMapEntry[] entries) /// public class GCRefMapDecoder { - private readonly R2RReader _reader; + private readonly ReadyToRunReader _reader; private int _offset; private int _pendingByte; private int _pos; - public GCRefMapDecoder(R2RReader reader, int offset) + public GCRefMapDecoder(ReadyToRunReader reader, int offset) { _reader = reader; _offset = offset; diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RHeader.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs similarity index 88% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RHeader.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs index 7b73cc6c148b4e..35829230007e56 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RHeader.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs @@ -13,7 +13,7 @@ namespace ILCompiler.Reflection.ReadyToRun /// /// based on src/inc/readytorun.h READYTORUN_HEADER /// - public class R2RHeader + public class ReadyToRunHeader { /// /// The expected signature of a ReadyToRun header @@ -51,9 +51,9 @@ public class R2RHeader /// /// The ReadyToRun section RVAs and sizes /// - public IDictionary Sections { get; } + public IDictionary Sections { get; } - public R2RHeader() { } + public ReadyToRunHeader() { } /// /// Initializes the fields of the R2RHeader @@ -62,7 +62,7 @@ public R2RHeader() { } /// Relative virtual address of the ReadyToRun header /// Index in the image byte array to the start of the ReadyToRun header /// The signature must be 0x00525452 - public R2RHeader(byte[] image, int rva, int curOffset) + public ReadyToRunHeader(byte[] image, int rva, int curOffset) { RelativeVirtualAddress = rva; int startOffset = curOffset; @@ -80,18 +80,18 @@ public R2RHeader(byte[] image, int rva, int curOffset) MinorVersion = NativeReader.ReadUInt16(image, ref curOffset); Flags = NativeReader.ReadUInt32(image, ref curOffset); int nSections = NativeReader.ReadInt32(image, ref curOffset); - Sections = new Dictionary(); + Sections = new Dictionary(); for (int i = 0; i < nSections; i++) { int type = NativeReader.ReadInt32(image, ref curOffset); - var sectionType = (R2RSection.SectionType)type; - if (!Enum.IsDefined(typeof(R2RSection.SectionType), type)) + var sectionType = (ReadyToRunSection.SectionType)type; + if (!Enum.IsDefined(typeof(ReadyToRunSection.SectionType), type)) { // TODO (refactoring) - what should we do? // R2RDump.WriteWarning("Invalid ReadyToRun section type"); } - Sections[sectionType] = new R2RSection(sectionType, + Sections[sectionType] = new ReadyToRunSection(sectionType, NativeReader.ReadInt32(image, ref curOffset), NativeReader.ReadInt32(image, ref curOffset)); } diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RImportSection.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunImportSection.cs similarity index 97% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RImportSection.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunImportSection.cs index 165cbc0049f4ed..7bdd3dd748d633 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RImportSection.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunImportSection.cs @@ -13,7 +13,7 @@ namespace ILCompiler.Reflection.ReadyToRun /// /// based on src/inc/readytorun.h READYTORUN_IMPORT_SECTION /// - public struct R2RImportSection + public struct ReadyToRunImportSection { public class ImportSectionEntry { @@ -76,9 +76,9 @@ public ImportSectionEntry(int index, int startOffset, int startRVA, long section public int AuxiliaryDataSize { get; set; } - public R2RImportSection( + public ReadyToRunImportSection( int index, - R2RReader reader, + ReadyToRunReader reader, int rva, int size, CorCompileImportFlags flags, diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RMethod.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs similarity index 93% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RMethod.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs index 0d75d6df89c015..933186588c3f40 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RMethod.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunMethod.cs @@ -50,6 +50,9 @@ public abstract class BaseGcInfo /// public class RuntimeFunction { + private ReadyToRunReader _readyToRunReader; + private DebugInfo _debugInfo; + /// /// The index of the runtime function /// @@ -82,34 +85,42 @@ public class RuntimeFunction /// /// The method that this runtime function belongs to /// - public R2RMethod Method { get; } + public ReadyToRunMethod Method { get; } public BaseUnwindInfo UnwindInfo { get; } public EHInfo EHInfo { get; } - public DebugInfo DebugInfo { get; } - - public RuntimeFunction() { } + public DebugInfo DebugInfo + { + get + { + if (_debugInfo == null) + { + _readyToRunReader.RuntimeFunctionToDebugInfo.TryGetValue(Id, out _debugInfo); + } + return _debugInfo; + } + } public RuntimeFunction( + ReadyToRunReader readyToRunReader, int id, int startRva, int endRva, int unwindRva, int codeOffset, - R2RMethod method, + ReadyToRunMethod method, BaseUnwindInfo unwindInfo, BaseGcInfo gcInfo, - EHInfo ehInfo, - DebugInfo debugInfo) + EHInfo ehInfo) { + _readyToRunReader = readyToRunReader; Id = id; StartAddress = startRva; UnwindRVA = unwindRva; Method = method; UnwindInfo = unwindInfo; - DebugInfo = debugInfo; if (endRva != -1) { @@ -141,7 +152,7 @@ public RuntimeFunction( } } - public class R2RMethod + public class ReadyToRunMethod { private const int _mdtMethodDef = 0x06000000; @@ -196,12 +207,10 @@ public class R2RMethod public FixupCell[] Fixups { get; set; } - public R2RMethod() { } - /// /// Extracts the method signature from the metadata by rid /// - public R2RMethod( + public ReadyToRunMethod( int index, MetadataReader metadataReader, EntityHandle methodHandle, diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RReader.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs similarity index 81% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RReader.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index cedbfcffd9fcbe..d0d5831046f6e1 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RReader.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -69,23 +69,30 @@ public enum OperatingSystem public struct InstanceMethod { public byte Bucket; - public R2RMethod Method; + public ReadyToRunMethod Method; - public InstanceMethod(byte bucket, R2RMethod method) + public InstanceMethod(byte bucket, ReadyToRunMethod method) { Bucket = bucket; Method = method; } } - public sealed class R2RReader + public sealed class ReadyToRunReader { - private IAssemblyResolver _assemblyResolver; + private readonly IAssemblyResolver _assemblyResolver; private Dictionary _assemblyCache; private Dictionary _runtimeFunctionToDebugInfo; private MetadataReader _manifestReader; private List _manifestReferences; + // Header + private OperatingSystem _operatingSystem; + private Machine _machine; + private Architecture _architecture; + private ulong _imageBase; + private ReadyToRunHeader _readyToRunHeader; + /// /// Underlying PE image reader is used to access raw PE structures like header /// or section list. @@ -131,38 +138,68 @@ public IEnumerable ManifestReferenceAssemblies /// /// The type of target machine /// - public Machine Machine { get; set; } + public Machine Machine + { + get + { + EnsureHeader(); + return _machine; + } + } /// /// Targeting operating system for the R2R executable /// - public OperatingSystem OS { get; set; } + public OperatingSystem OperatingSystem + { + get + { + EnsureHeader(); + return _operatingSystem; + } + } /// /// Targeting processor architecture of the R2R executable /// - public Architecture Architecture { get; set; } - - /// - /// Pointer size in bytes for the target architecture - /// - public int PointerSize { get; set; } + public Architecture Architecture + { + get + { + EnsureHeader(); + return _architecture; + } + } /// /// The preferred address of the first byte of image when loaded into memory; /// must be a multiple of 64K. /// - public ulong ImageBase { get; set; } + public ulong ImageBase + { + get + { + EnsureHeader(); + return _imageBase; + } + } /// /// The ReadyToRun header /// - public R2RHeader R2RHeader { get; private set; } + public ReadyToRunHeader ReadyToRunHeader + { + get + { + EnsureHeader(); + return _readyToRunHeader; + } + } /// /// The runtime functions and method signatures of each method /// - public IList R2RMethods { get; private set; } + public IList R2RMethods { get; private set; } /// /// Parsed instance entrypoint table entries. @@ -187,23 +224,33 @@ public IEnumerable ManifestReferenceAssemblies /// /// List of import sections present in the R2R executable. /// - public IList ImportSections { get; private set; } + public IList ImportSections { get; private set; } /// /// Map from import cell addresses to their symbolic names. /// public Dictionary ImportCellNames { get; private set; } + internal Dictionary RuntimeFunctionToDebugInfo + { + get + { + EnsureRuntimeFunctionToDebugInfo(); + + return _runtimeFunctionToDebugInfo; + } + } + /// /// Initializes the fields of the R2RHeader and R2RMethods /// /// PE image /// The Cor header flag must be ILLibrary - public R2RReader(IAssemblyResolver assemblyResolver, MetadataReader metadata, PEReader peReader, string filename) + public ReadyToRunReader(IAssemblyResolver assemblyResolver, MetadataReader metadata, PEReader peReader, string filename) { _assemblyResolver = assemblyResolver; MetadataReader = metadata; - PEReader = peReader; + PEReader = peReader; Filename = filename; Initialize(); } @@ -213,7 +260,7 @@ public R2RReader(IAssemblyResolver assemblyResolver, MetadataReader metadata, PE /// /// PE image /// The Cor header flag must be ILLibrary - public unsafe R2RReader(IAssemblyResolver assemblyResolver, string filename) + public unsafe ReadyToRunReader(IAssemblyResolver assemblyResolver, string filename) { _assemblyResolver = assemblyResolver; Filename = filename; @@ -246,13 +293,21 @@ private unsafe void Initialize() Image = Unsafe.As, byte[]>(ref content); } - ParseHeader(); + if ((PEReader.PEHeaders.CorHeader.Flags & CorFlags.ILLibrary) == 0) + { + throw new BadImageFormatException("The file is not a ReadyToRun image"); + } + + // This is a work in progress toward lazy initialization. + // Ideally, here should be the end of the Initialize() method + + EnsureHeader(); - ParseDebugInfo(); + EnsureRuntimeFunctionToDebugInfo(); - if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA)) + if (ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA)) { - R2RSection manifestMetadata = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA]; + ReadyToRunSection manifestMetadata = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA]; fixed (byte* image = Image) { _manifestReader = new MetadataReader(image + GetOffset(manifestMetadata.RelativeVirtualAddress), manifestMetadata.Size); @@ -265,23 +320,23 @@ private unsafe void Initialize() } } - if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO)) + if (ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO)) { - R2RSection exceptionInfoSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO]; + ReadyToRunSection exceptionInfoSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_EXCEPTION_INFO]; EHLookupTable = new EHLookupTable(Image, GetOffset(exceptionInfoSection.RelativeVirtualAddress), exceptionInfoSection.Size); } - ImportSections = new List(); + ImportSections = new List(); ImportCellNames = new Dictionary(); ParseImportSections(); - R2RMethods = new List(); + R2RMethods = new List(); InstanceMethods = new List(); - if (R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS)) + if (ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS)) { int runtimeFunctionSize = CalculateRuntimeFunctionSize(); - R2RSection runtimeFunctionSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS]; + ReadyToRunSection runtimeFunctionSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS]; uint nRuntimeFunctions = (uint)(runtimeFunctionSection.Size / runtimeFunctionSize); int runtimeFunctionOffset = GetOffset(runtimeFunctionSection.RelativeVirtualAddress); @@ -299,51 +354,46 @@ private unsafe void Initialize() CompilerIdentifier = ParseCompilerIdentifier(); } - private unsafe void ParseHeader() + private unsafe void EnsureHeader() { - if ((PEReader.PEHeaders.CorHeader.Flags & CorFlags.ILLibrary) == 0) + if (_readyToRunHeader != null) { - throw new BadImageFormatException("The file is not a ReadyToRun image"); + return; } - uint machine = (uint)PEReader.PEHeaders.CoffHeader.Machine; - OS = OperatingSystem.Unknown; + _operatingSystem = OperatingSystem.Unknown; foreach (OperatingSystem os in Enum.GetValues(typeof(OperatingSystem))) { - Machine = (Machine)(machine ^ (uint)os); - if (Enum.IsDefined(typeof(Machine), Machine)) + _machine = (Machine)(machine ^ (uint)os); + if (Enum.IsDefined(typeof(Machine), _machine)) { - OS = os; + _operatingSystem = os; break; } } - if (OS == OperatingSystem.Unknown) + if (_operatingSystem == OperatingSystem.Unknown) { throw new BadImageFormatException($"Invalid Machine: {machine}"); } - switch (Machine) + switch (_machine) { case Machine.I386: - Architecture = Architecture.X86; - PointerSize = 4; + _architecture = Architecture.X86; break; case Machine.Amd64: - Architecture = Architecture.X64; - PointerSize = 8; + _architecture = Architecture.X64; break; case Machine.Arm: case Machine.Thumb: case Machine.ArmThumb2: - Architecture = Architecture.Arm; - PointerSize = 4; + _architecture = Architecture.Arm; break; case Machine.Arm64: - Architecture = Architecture.Arm64; - PointerSize = 8; + _architecture = Architecture.Arm64; break; default: @@ -351,13 +401,13 @@ private unsafe void ParseHeader() } - ImageBase = PEReader.PEHeaders.PEHeader.ImageBase; + _imageBase = PEReader.PEHeaders.PEHeader.ImageBase; - // initialize R2RHeader + // Initialize R2RHeader DirectoryEntry r2rHeaderDirectory = PEReader.PEHeaders.CorHeader.ManagedNativeHeaderDirectory; int r2rHeaderOffset = GetOffset(r2rHeaderDirectory.RelativeVirtualAddress); - R2RHeader = new R2RHeader(Image, r2rHeaderDirectory.RelativeVirtualAddress, r2rHeaderOffset); - if (r2rHeaderDirectory.Size != R2RHeader.Size) + _readyToRunHeader = new ReadyToRunHeader(Image, r2rHeaderDirectory.RelativeVirtualAddress, r2rHeaderOffset); + if (r2rHeaderDirectory.Size != ReadyToRunHeader.Size) { throw new BadImageFormatException("The calculated size of the R2RHeader doesn't match the size saved in the ManagedNativeHeaderDirectory"); } @@ -394,11 +444,11 @@ private int CalculateRuntimeFunctionSize() /// private void ParseMethodDefEntrypoints(bool[] isEntryPoint) { - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS)) { return; } - int methodDefEntryPointsRVA = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS].RelativeVirtualAddress; + int methodDefEntryPointsRVA = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS].RelativeVirtualAddress; int methodDefEntryPointsOffset = GetOffset(methodDefEntryPointsRVA); NativeArray methodEntryPoints = new NativeArray(Image, (uint)methodDefEntryPointsOffset); uint nMethodEntryPoints = methodEntryPoints.GetCount(); @@ -412,7 +462,7 @@ private void ParseMethodDefEntrypoints(bool[] isEntryPoint) int runtimeFunctionId; FixupCell[] fixups; GetRuntimeFunctionIndexFromOffset(offset, out runtimeFunctionId, out fixups); - R2RMethod method = new R2RMethod(R2RMethods.Count, this.MetadataReader, methodHandle, runtimeFunctionId, owningType: null, constrainedType: null, instanceArgs: null, fixups: fixups); + ReadyToRunMethod method = new ReadyToRunMethod(R2RMethods.Count, this.MetadataReader, methodHandle, runtimeFunctionId, owningType: null, constrainedType: null, instanceArgs: null, fixups: fixups); if (method.EntryPointRuntimeFunctionId < 0 || method.EntryPointRuntimeFunctionId >= isEntryPoint.Length) { @@ -429,11 +479,11 @@ private void ParseMethodDefEntrypoints(bool[] isEntryPoint) /// private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint) { - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS)) { return; } - R2RSection instMethodEntryPointSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS]; + ReadyToRunSection instMethodEntryPointSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS]; int instMethodEntryPointsOffset = GetOffset(instMethodEntryPointSection.RelativeVirtualAddress); NativeParser parser = new NativeParser(Image, (uint)instMethodEntryPointsOffset); NativeHashtable instMethodEntryPoints = new NativeHashtable(Image, parser, (uint)(instMethodEntryPointsOffset + instMethodEntryPointSection.Size)); @@ -486,7 +536,7 @@ private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint) int runtimeFunctionId; FixupCell[] fixups; GetRuntimeFunctionIndexFromOffset((int)decoder.Offset, out runtimeFunctionId, out fixups); - R2RMethod method = new R2RMethod( + ReadyToRunMethod method = new ReadyToRunMethod( R2RMethods.Count, mdReader == null ? MetadataReader : mdReader, methodHandle, @@ -512,7 +562,7 @@ private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint) private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffset, int runtimeFunctionSize) { int curOffset = 0; - foreach (R2RMethod method in R2RMethods) + foreach (ReadyToRunMethod method in R2RMethods) { int runtimeFunctionId = method.EntryPointRuntimeFunctionId; if (runtimeFunctionId == -1) @@ -537,7 +587,7 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse unwindInfo = new Amd64.UnwindInfo(Image, unwindOffset); if (isEntryPoint[runtimeFunctionId]) { - gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion); + gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, ReadyToRunHeader.MajorVersion); } } else if (Machine == Machine.I386) @@ -545,7 +595,7 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse unwindInfo = new x86.UnwindInfo(Image, unwindOffset); if (isEntryPoint[runtimeFunctionId]) { - gcInfo = new x86.GcInfo(Image, unwindOffset, Machine, R2RHeader.MajorVersion); + gcInfo = new x86.GcInfo(Image, unwindOffset, Machine, ReadyToRunHeader.MajorVersion); } } else if (Machine == Machine.ArmThumb2) @@ -553,7 +603,7 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse unwindInfo = new Arm.UnwindInfo(Image, unwindOffset); if (isEntryPoint[runtimeFunctionId]) { - gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion); // Arm and Arm64 use the same GcInfo format as x64 + gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, ReadyToRunHeader.MajorVersion); // Arm and Arm64 use the same GcInfo format as x64 } } else if (Machine == Machine.Arm64) @@ -561,7 +611,7 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse unwindInfo = new Arm64.UnwindInfo(Image, unwindOffset); if (isEntryPoint[runtimeFunctionId]) { - gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, R2RHeader.MajorVersion); + gcInfo = new Amd64.GcInfo(Image, unwindOffset + unwindInfo.Size, Machine, ReadyToRunHeader.MajorVersion); } } @@ -572,10 +622,8 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse ehInfo = new EHInfo(this, ehInfoLocation.EHInfoRVA, startRva, GetOffset(ehInfoLocation.EHInfoRVA), ehInfoLocation.ClauseCount); } - DebugInfo debugInfo; - _runtimeFunctionToDebugInfo.TryGetValue(runtimeFunctionId, out debugInfo); - RuntimeFunction rtf = new RuntimeFunction( + this, runtimeFunctionId, startRva, endRva, @@ -584,8 +632,7 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse method, unwindInfo, gcInfo, - ehInfo, - debugInfo); + ehInfo); method.RuntimeFunctions.Add(rtf); runtimeFunctionId++; @@ -600,12 +647,12 @@ private void ParseRuntimeFunctions(bool[] isEntryPoint, int runtimeFunctionOffse /// private void ParseAvailableTypes() { - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES)) { return; } - R2RSection availableTypesSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES]; + ReadyToRunSection availableTypesSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES]; int availableTypesOffset = GetOffset(availableTypesSection.RelativeVirtualAddress); NativeParser parser = new NativeParser(Image, (uint)availableTypesOffset); NativeHashtable availableTypes = new NativeHashtable(Image, parser, (uint)(availableTypesOffset + availableTypesSection.Size)); @@ -640,11 +687,11 @@ private void ParseAvailableTypes() /// private string ParseCompilerIdentifier() { - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER)) { return ""; } - R2RSection compilerIdentifierSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER]; + ReadyToRunSection compilerIdentifierSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER]; byte[] identifier = new byte[compilerIdentifierSection.Size - 1]; int identifierOffset = GetOffset(compilerIdentifierSection.RelativeVirtualAddress); Array.Copy(Image, identifierOffset, identifier, 0, compilerIdentifierSection.Size - 1); @@ -656,11 +703,11 @@ private string ParseCompilerIdentifier() /// private void ParseImportSections() { - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS)) { return; } - R2RSection importSectionsSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS]; + ReadyToRunSection importSectionsSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS]; int offset = GetOffset(importSectionsSection.RelativeVirtualAddress); int endOffset = offset + importSectionsSection.Size; while (offset < endOffset) @@ -702,7 +749,7 @@ private void ParseImportSections() { signatureOffset = GetOffset(signatureRVA); } - List entries = new List(); + List entries = new List(); for (int i = 0; i < entryCount; i++) { int entryOffset = sectionOffset - startOffset; @@ -710,7 +757,7 @@ private void ParseImportSections() uint sigRva = NativeReader.ReadUInt32(Image, ref signatureOffset); int sigOffset = GetOffset((int)sigRva); string cellName = MetadataNameFormatter.FormatSignature(_assemblyResolver, this, sigOffset); - entries.Add(new R2RImportSection.ImportSectionEntry(entries.Count, entryOffset, entryOffset + rva, section, sigRva, cellName)); + entries.Add(new ReadyToRunImportSection.ImportSectionEntry(entries.Count, entryOffset, entryOffset + rva, section, sigRva, cellName)); ImportCellNames.Add(rva + entrySize * i, cellName); } @@ -720,19 +767,23 @@ private void ParseImportSections() { auxDataOffset = GetOffset(auxDataRVA); } - ImportSections.Add(new R2RImportSection(ImportSections.Count, this, rva, size, flags, type, entrySize, signatureRVA, entries, auxDataRVA, auxDataOffset, Machine, R2RHeader.MajorVersion)); + ImportSections.Add(new ReadyToRunImportSection(ImportSections.Count, this, rva, size, flags, type, entrySize, signatureRVA, entries, auxDataRVA, auxDataOffset, Machine, ReadyToRunHeader.MajorVersion)); } } - private void ParseDebugInfo() + private void EnsureRuntimeFunctionToDebugInfo() { + if (_runtimeFunctionToDebugInfo != null) + { + return; + } _runtimeFunctionToDebugInfo = new Dictionary(); - if (!R2RHeader.Sections.ContainsKey(R2RSection.SectionType.READYTORUN_SECTION_DEBUG_INFO)) + if (!ReadyToRunHeader.Sections.ContainsKey(ReadyToRunSection.SectionType.READYTORUN_SECTION_DEBUG_INFO)) { return; } - R2RSection debugInfoSection = R2RHeader.Sections[R2RSection.SectionType.READYTORUN_SECTION_DEBUG_INFO]; + ReadyToRunSection debugInfoSection = ReadyToRunHeader.Sections[ReadyToRunSection.SectionType.READYTORUN_SECTION_DEBUG_INFO]; int debugInfoSectionOffset = GetOffset(debugInfoSection.RelativeVirtualAddress); NativeArray debugInfoArray = new NativeArray(Image, (uint)debugInfoSectionOffset); @@ -744,7 +795,7 @@ private void ParseDebugInfo() continue; } - var debugInfo = new DebugInfo(Image, offset, Machine); + var debugInfo = new DebugInfo(this, offset); _runtimeFunctionToDebugInfo.Add((int)i, debugInfo); } } @@ -831,8 +882,8 @@ private FixupCell[] DecodeFixupCells(int offset) while (true) { - R2RImportSection importSection = ImportSections[(int)curTableIndex]; - R2RImportSection.ImportSectionEntry entry = importSection.Entries[(int)fixupIndex]; + ReadyToRunImportSection importSection = ImportSections[(int)curTableIndex]; + ReadyToRunImportSection.ImportSectionEntry entry = importSection.Entries[(int)fixupIndex]; cells.Add(new FixupCell(cells.Count, curTableIndex, fixupIndex, entry.Signature)); uint delta = reader.ReadUInt(); @@ -881,7 +932,7 @@ internal MetadataReader OpenReferenceAssembly(int refAsmIndex) metadataReader = _manifestReader; assemblyReferenceHandle = _manifestReferences[refAsmIndex - assemblyRefCount - 2]; } - + MetadataReader result; if (!_assemblyCache.TryGetValue(refAsmIndex, out result)) diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSection.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSection.cs similarity index 94% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSection.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSection.cs index 5e03f7e7966d0c..910cbed122b2bf 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSection.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSection.cs @@ -9,7 +9,7 @@ namespace ILCompiler.Reflection.ReadyToRun { - public struct R2RSection + public struct ReadyToRunSection { /// /// based on src/inc/readytorun.h ReadyToRunSectionType @@ -46,7 +46,7 @@ public enum SectionType /// public int Size { get; set; } - public R2RSection(SectionType type, int rva, int size) + public ReadyToRunSection(SectionType type, int rva, int size) { Type = type; RelativeVirtualAddress = rva; diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSignature.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs similarity index 99% rename from src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSignature.cs rename to src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs index 989c5cbfea97cc..93097c0ea765d9 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/R2RSignature.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunSignature.cs @@ -39,7 +39,7 @@ public static string FormatHandle(MetadataReader metadataReader, Handle handle, return formatter.EmitHandleName(handle, namespaceQualified, owningTypeOverride, signaturePrefix); } - public static string FormatSignature(IAssemblyResolver assemblyResolver, R2RReader r2rReader, int imageOffset) + public static string FormatSignature(IAssemblyResolver assemblyResolver, ReadyToRunReader r2rReader, int imageOffset) { SignatureDecoder decoder = new SignatureDecoder(assemblyResolver, r2rReader, imageOffset); string result = decoder.ReadR2RSignature(); @@ -353,7 +353,7 @@ public class SignatureDecoder /// /// ECMA reader representing the top-level signature context. /// - private readonly R2RReader _contextReader; + private readonly ReadyToRunReader _contextReader; /// /// Dump options are used to specify details of signature formatting. @@ -381,7 +381,7 @@ public class SignatureDecoder /// Dump options and paths /// R2RReader object representing the PE file containing the ECMA metadata /// Signature offset within the PE file byte array - public SignatureDecoder(IAssemblyResolver options, R2RReader r2rReader, int offset) + public SignatureDecoder(IAssemblyResolver options, ReadyToRunReader r2rReader, int offset) { _metadataReader = r2rReader.MetadataReader; _options = options; @@ -398,7 +398,7 @@ public SignatureDecoder(IAssemblyResolver options, R2RReader r2rReader, int offs /// Signature to parse /// Signature offset within the signature byte array /// Top-level signature context reader - private SignatureDecoder(IAssemblyResolver options, MetadataReader metadataReader, byte[] signature, int offset, R2RReader contextReader) + private SignatureDecoder(IAssemblyResolver options, MetadataReader metadataReader, byte[] signature, int offset, ReadyToRunReader contextReader) { _metadataReader = metadataReader; _options = options; diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs index 28deb28d0d0e83..2b8892d518a224 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/TransitionBlock.cs @@ -12,9 +12,9 @@ namespace ILCompiler.Reflection.ReadyToRun { public abstract class TransitionBlock { - public R2RReader _reader; + public ReadyToRunReader _reader; - public static TransitionBlock FromReader(R2RReader reader) + public static TransitionBlock FromReader(ReadyToRunReader reader) { switch (reader.Architecture) { @@ -22,7 +22,7 @@ public static TransitionBlock FromReader(R2RReader reader) return X86TransitionBlock.Instance; case Architecture.X64: - return reader.OS == OperatingSystem.Windows ? X64WindowsTransitionBlock.Instance : X64UnixTransitionBlock.Instance; + return reader.OperatingSystem == OperatingSystem.Windows ? X64WindowsTransitionBlock.Instance : X64UnixTransitionBlock.Instance; case Architecture.Arm: return ArmTransitionBlock.Instance; diff --git a/src/coreclr/src/tools/r2rdump/CoreDisTools.cs b/src/coreclr/src/tools/r2rdump/CoreDisTools.cs index 69ae7f60486eb9..6f3678a7831480 100644 --- a/src/coreclr/src/tools/r2rdump/CoreDisTools.cs +++ b/src/coreclr/src/tools/r2rdump/CoreDisTools.cs @@ -89,7 +89,7 @@ public class Disassembler : IDisposable /// /// R2R reader is used to access architecture info, the PE image data and symbol table. /// - private readonly R2RReader _reader; + private readonly ReadyToRunReader _reader; /// /// Dump options @@ -105,7 +105,7 @@ public class Disassembler : IDisposable /// Store the R2R reader and construct the disassembler for the appropriate architecture. /// /// - public Disassembler(R2RReader reader, DumpOptions options) + public Disassembler(ReadyToRunReader reader, DumpOptions options) { _reader = reader; _options = options; diff --git a/src/coreclr/src/tools/r2rdump/Extensions.cs b/src/coreclr/src/tools/r2rdump/Extensions.cs index 9e66d5cf2c7785..e2895fcd26fe88 100644 --- a/src/coreclr/src/tools/r2rdump/Extensions.cs +++ b/src/coreclr/src/tools/r2rdump/Extensions.cs @@ -92,7 +92,7 @@ public static void WriteTo(this DebugInfo theThis, TextWriter writer, DumpOption } } - public static void WriteTo(this R2RImportSection.ImportSectionEntry theThis, TextWriter writer, DumpOptions options) + public static void WriteTo(this ReadyToRunImportSection.ImportSectionEntry theThis, TextWriter writer, DumpOptions options) { if (!options.Naked) { @@ -110,9 +110,9 @@ public static void WriteTo(this R2RImportSection.ImportSectionEntry theThis, Tex } } - public static void WriteTo(this R2RSection theThis, TextWriter writer, DumpOptions options) + public static void WriteTo(this ReadyToRunSection theThis, TextWriter writer, DumpOptions options) { - writer.WriteLine($"Type: {Enum.GetName(typeof(R2RSection.SectionType), theThis.Type)} ({theThis.Type:D})"); + writer.WriteLine($"Type: {Enum.GetName(typeof(ReadyToRunSection.SectionType), theThis.Type)} ({theThis.Type:D})"); if (!options.Naked) { writer.WriteLine($"RelativeVirtualAddress: 0x{theThis.RelativeVirtualAddress:X8}"); @@ -120,7 +120,7 @@ public static void WriteTo(this R2RSection theThis, TextWriter writer, DumpOptio writer.WriteLine($"Size: {theThis.Size} bytes"); } - public static void WriteTo(this R2RMethod theThis, TextWriter writer, DumpOptions options) + public static void WriteTo(this ReadyToRunMethod theThis, TextWriter writer, DumpOptions options) { writer.WriteLine(theThis.SignatureString); diff --git a/src/coreclr/src/tools/r2rdump/R2RDiff.cs b/src/coreclr/src/tools/r2rdump/R2RDiff.cs index 27684ace7af26c..525d92f578bc1e 100644 --- a/src/coreclr/src/tools/r2rdump/R2RDiff.cs +++ b/src/coreclr/src/tools/r2rdump/R2RDiff.cs @@ -20,12 +20,12 @@ class R2RDiff /// /// Left R2R image for the diff. /// - private readonly R2RReader _leftFile; + private readonly ReadyToRunReader _leftFile; /// /// Right R2R image for the diff. /// - private readonly R2RReader _rightFile; + private readonly ReadyToRunReader _rightFile; /// /// Text writer to receive diff output. @@ -38,7 +38,7 @@ class R2RDiff /// Left R2R file /// Right R2R file /// Output writer to receive the diff - public R2RDiff(R2RReader leftFile, R2RReader rightFile, TextWriter writer) + public R2RDiff(ReadyToRunReader leftFile, ReadyToRunReader rightFile, TextWriter writer) { _leftFile = leftFile; _rightFile = rightFile; @@ -157,7 +157,7 @@ private void ShowDiff(Dictionary leftObjects, Dictionary /// R2R image to scan /// - private Dictionary GetPESectionMap(R2RReader reader) + private Dictionary GetPESectionMap(ReadyToRunReader reader) { Dictionary sectionMap = new Dictionary(); @@ -174,11 +174,11 @@ private Dictionary GetPESectionMap(R2RReader reader) /// /// R2R image to scan /// - private Dictionary GetR2RSectionMap(R2RReader reader) + private Dictionary GetR2RSectionMap(ReadyToRunReader reader) { Dictionary sectionMap = new Dictionary(); - foreach (KeyValuePair typeAndSection in reader.R2RHeader.Sections) + foreach (KeyValuePair typeAndSection in reader.ReadyToRunHeader.Sections) { string name = typeAndSection.Key.ToString(); sectionMap.Add(name, typeAndSection.Value.Size); @@ -192,11 +192,11 @@ private Dictionary GetR2RSectionMap(R2RReader reader) /// /// R2R image to scan /// - private Dictionary GetR2RMethodMap(R2RReader reader) + private Dictionary GetR2RMethodMap(ReadyToRunReader reader) { Dictionary methodMap = new Dictionary(); - foreach (R2RMethod method in reader.R2RMethods) + foreach (ReadyToRunMethod method in reader.R2RMethods) { int size = method.RuntimeFunctions.Sum(rf => rf.Size); methodMap.Add(method.SignatureString, size); diff --git a/src/coreclr/src/tools/r2rdump/R2RDump.cs b/src/coreclr/src/tools/r2rdump/R2RDump.cs index 5f8a330be5aeaa..74a763f9e2fecb 100644 --- a/src/coreclr/src/tools/r2rdump/R2RDump.cs +++ b/src/coreclr/src/tools/r2rdump/R2RDump.cs @@ -109,12 +109,12 @@ private static unsafe MetadataReader Open(string filename) public abstract class Dumper { - protected readonly R2RReader _r2r; + protected readonly ReadyToRunReader _r2r; protected TextWriter _writer; protected readonly Disassembler _disassembler; protected readonly DumpOptions _options; - public Dumper(R2RReader r2r, TextWriter writer, Disassembler disassembler, DumpOptions options) + public Dumper(ReadyToRunReader r2r, TextWriter writer, Disassembler disassembler, DumpOptions options) { _r2r = r2r; _writer = writer; @@ -122,9 +122,9 @@ public Dumper(R2RReader r2r, TextWriter writer, Disassembler disassembler, DumpO _options = options; } - public IEnumerable NormalizedSections() + public IEnumerable NormalizedSections() { - IEnumerable sections = _r2r.R2RHeader.Sections.Values; + IEnumerable sections = _r2r.ReadyToRunHeader.Sections.Values; if (_options.Normalize) { sections = sections.OrderBy((s) => s.Type); @@ -132,9 +132,9 @@ public IEnumerable NormalizedSections() return sections; } - public IEnumerable NormalizedMethods() + public IEnumerable NormalizedMethods() { - IEnumerable methods = _r2r.R2RMethods; + IEnumerable methods = _r2r.R2RMethods; if (_options.Normalize) { methods = methods.OrderBy((m) => m.SignatureString); @@ -155,14 +155,14 @@ public IEnumerable NormalizedMethods() abstract internal void WriteSubDivider(); abstract internal void SkipLine(); abstract internal void DumpHeader(bool dumpSections); - abstract internal void DumpSection(R2RSection section); + abstract internal void DumpSection(ReadyToRunSection section); abstract internal void DumpEntryPoints(); abstract internal void DumpAllMethods(); - abstract internal void DumpMethod(R2RMethod method); + abstract internal void DumpMethod(ReadyToRunMethod method); abstract internal void DumpRuntimeFunction(RuntimeFunction rtf); abstract internal void DumpDisasm(RuntimeFunction rtf, int imageOffset); abstract internal void DumpBytes(int rva, uint size, string name = "Raw", bool convertToOffset = true); - abstract internal void DumpSectionContents(R2RSection section); + abstract internal void DumpSectionContents(ReadyToRunSection section); abstract internal void DumpQueryCount(string q, string title, int count); } @@ -170,7 +170,7 @@ class R2RDump { private readonly DumpOptions _options; private readonly TextWriter _writer; - private readonly Dictionary _selectedSections = new Dictionary(); + private readonly Dictionary _selectedSections = new Dictionary(); private Dumper _dumper; private R2RDump(DumpOptions options) @@ -237,7 +237,7 @@ public static void WriteWarning(string warning) /// The title to print, "R2R Methods by Query" or "R2R Methods by Keyword" /// The keywords/ids to search for /// Specifies whether to look for methods with names/signatures/ids matching the method exactly or partially - private void QueryMethod(R2RReader r2r, string title, IReadOnlyList queries, bool exact) + private void QueryMethod(ReadyToRunReader r2r, string title, IReadOnlyList queries, bool exact) { if (queries.Count > 0) { @@ -245,9 +245,9 @@ private void QueryMethod(R2RReader r2r, string title, IReadOnlyList quer } foreach (string q in queries) { - IList res = FindMethod(r2r, q, exact); + IList res = FindMethod(r2r, q, exact); _dumper.DumpQueryCount(q, "Methods", res.Count); - foreach (R2RMethod method in res) + foreach (ReadyToRunMethod method in res) { _dumper.DumpMethod(method); } @@ -259,7 +259,7 @@ private void QueryMethod(R2RReader r2r, string title, IReadOnlyList quer /// /// Contains all the extracted info about the ReadyToRun image /// The names/values to search for - private void QuerySection(R2RReader r2r, IReadOnlyList queries) + private void QuerySection(ReadyToRunReader r2r, IReadOnlyList queries) { if (queries.Count > 0) { @@ -267,9 +267,9 @@ private void QuerySection(R2RReader r2r, IReadOnlyList queries) } foreach (string q in queries) { - IList res = FindSection(r2r, q); + IList res = FindSection(r2r, q); _dumper.DumpQueryCount(q, "Sections", res.Count); - foreach (R2RSection section in res) + foreach (ReadyToRunSection section in res) { _dumper.DumpSection(section); } @@ -282,7 +282,7 @@ private void QuerySection(R2RReader r2r, IReadOnlyList queries) /// /// Contains all the extracted info about the ReadyToRun image /// The ids to search for - private void QueryRuntimeFunction(R2RReader r2r, IEnumerable queries) + private void QueryRuntimeFunction(ReadyToRunReader r2r, IEnumerable queries) { if (queries.Any()) { @@ -306,7 +306,7 @@ private void QueryRuntimeFunction(R2RReader r2r, IEnumerable queries) /// Outputs specified headers, sections, methods or runtime functions for one ReadyToRun image /// /// The structure containing the info of the ReadyToRun image - public void Dump(R2RReader r2r) + public void Dump(ReadyToRunReader r2r) { _dumper.Begin(); @@ -363,7 +363,7 @@ public void Dump(R2RReader r2r) /// /// Specifies exact or partial match /// Case-insensitive and ignores whitespace - private bool Match(R2RMethod method, string query, bool exact) + private bool Match(ReadyToRunMethod method, string query, bool exact) { int id; bool isNum = ArgStringToInt(query, out id); @@ -394,11 +394,11 @@ private bool Match(R2RMethod method, string query, bool exact) /// Returns true if the name or value of the ReadyToRunSectionType of section matches query /// /// Case-insensitive - private bool Match(R2RSection section, string query) + private bool Match(ReadyToRunSection section, string query) { int queryInt; bool isNum = ArgStringToInt(query, out queryInt); - string typeName = Enum.GetName(typeof(R2RSection.SectionType), section.Type); + string typeName = Enum.GetName(typeof(ReadyToRunSection.SectionType), section.Type); return (isNum && (int)section.Type == queryInt) || typeName.IndexOf(query, StringComparison.OrdinalIgnoreCase) >= 0; } @@ -411,10 +411,10 @@ private bool Match(R2RSection section, string query) /// Specifies exact or partial match /// List of all matching methods /// Case-insensitive and ignores whitespace - public IList FindMethod(R2RReader r2r, string query, bool exact) + public IList FindMethod(ReadyToRunReader r2r, string query, bool exact) { - List res = new List(); - foreach (R2RMethod method in r2r.R2RMethods) + List res = new List(); + foreach (ReadyToRunMethod method in r2r.R2RMethods) { if (Match(method, query, exact)) { @@ -431,10 +431,10 @@ public IList FindMethod(R2RReader r2r, string query, bool exact) /// The name or value to search for /// List of all matching sections /// Case-insensitive - public IList FindSection(R2RReader r2r, string query) + public IList FindSection(ReadyToRunReader r2r, string query) { - List res = new List(); - foreach (R2RSection section in r2r.R2RHeader.Sections.Values) + List res = new List(); + foreach (ReadyToRunSection section in r2r.ReadyToRunHeader.Sections.Values) { if (Match(section, query)) { @@ -449,9 +449,9 @@ public IList FindSection(R2RReader r2r, string query) /// /// Contains all extracted info about the ReadyToRun image /// The name or value to search for - public RuntimeFunction FindRuntimeFunction(R2RReader r2r, int rtfQuery) + public RuntimeFunction FindRuntimeFunction(ReadyToRunReader r2r, int rtfQuery) { - foreach (R2RMethod m in r2r.R2RMethods) + foreach (ReadyToRunMethod m in r2r.R2RMethods) { foreach (RuntimeFunction rtf in m.RuntimeFunctions) { @@ -481,12 +481,12 @@ private int Run() throw new ArgumentException("The option '--naked' is incompatible with '--raw'"); } - R2RReader previousReader = null; + ReadyToRunReader previousReader = null; foreach (FileInfo filename in _options.In) { // parse the ReadyToRun image - R2RReader r2r = new R2RReader(_options, filename.FullName); + ReadyToRunReader r2r = new ReadyToRunReader(_options, filename.FullName); if (_options.Disasm) { diff --git a/src/coreclr/src/tools/r2rdump/TextDumper.cs b/src/coreclr/src/tools/r2rdump/TextDumper.cs index 4a4e338c2e9567..e2ec51cc63fc68 100644 --- a/src/coreclr/src/tools/r2rdump/TextDumper.cs +++ b/src/coreclr/src/tools/r2rdump/TextDumper.cs @@ -17,7 +17,7 @@ namespace R2RDump { class TextDumper : Dumper { - public TextDumper(R2RReader r2r, TextWriter writer, Disassembler disassembler, DumpOptions options) + public TextDumper(ReadyToRunReader r2r, TextWriter writer, Disassembler disassembler, DumpOptions options) : base(r2r, writer, disassembler, options) { } @@ -27,7 +27,7 @@ internal override void Begin() if (!_options.Normalize) { _writer.WriteLine($"Filename: {_r2r.Filename}"); - _writer.WriteLine($"OS: {_r2r.OS}"); + _writer.WriteLine($"OS: {_r2r.OperatingSystem}"); _writer.WriteLine($"Machine: {_r2r.Machine}"); _writer.WriteLine($"ImageBase: 0x{_r2r.ImageBase:X8}"); SkipLine(); @@ -63,20 +63,20 @@ internal override void SkipLine() /// internal override void DumpHeader(bool dumpSections) { - _writer.WriteLine(_r2r.R2RHeader.ToString()); + _writer.WriteLine(_r2r.ReadyToRunHeader.ToString()); if (_options.Raw) { - DumpBytes(_r2r.R2RHeader.RelativeVirtualAddress, (uint)_r2r.R2RHeader.Size); + DumpBytes(_r2r.ReadyToRunHeader.RelativeVirtualAddress, (uint)_r2r.ReadyToRunHeader.Size); } SkipLine(); if (dumpSections) { WriteDivider("R2R Sections"); - _writer.WriteLine($"{_r2r.R2RHeader.Sections.Count} sections"); + _writer.WriteLine($"{_r2r.ReadyToRunHeader.Sections.Count} sections"); SkipLine(); - foreach (R2RSection section in NormalizedSections()) + foreach (ReadyToRunSection section in NormalizedSections()) { DumpSection(section); } @@ -87,7 +87,7 @@ internal override void DumpHeader(bool dumpSections) /// /// Dumps one R2RSection /// - internal override void DumpSection(R2RSection section) + internal override void DumpSection(ReadyToRunSection section) { WriteSubDivider(); section.WriteTo(_writer, _options); @@ -107,7 +107,7 @@ internal override void DumpSection(R2RSection section) internal override void DumpEntryPoints() { WriteDivider($@"R2R Entry Points"); - foreach (R2RMethod method in NormalizedMethods()) + foreach (ReadyToRunMethod method in NormalizedMethods()) { _writer.WriteLine(method.SignatureString); } @@ -118,7 +118,7 @@ internal override void DumpAllMethods() WriteDivider("R2R Methods"); _writer.WriteLine($"{_r2r.R2RMethods.Count} methods"); SkipLine(); - foreach (R2RMethod method in NormalizedMethods()) + foreach (ReadyToRunMethod method in NormalizedMethods()) { TextWriter temp = _writer; _writer = new StringWriter(); @@ -131,7 +131,7 @@ internal override void DumpAllMethods() /// /// Dumps one R2RMethod. /// - internal override void DumpMethod(R2RMethod method) + internal override void DumpMethod(ReadyToRunMethod method) { WriteSubDivider(); method.WriteTo(_writer, _options); @@ -267,11 +267,11 @@ internal override void DumpBytes(int rva, uint size, string name = "Raw", bool c SkipLine(); } - internal override void DumpSectionContents(R2RSection section) + internal override void DumpSectionContents(ReadyToRunSection section) { switch (section.Type) { - case R2RSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_AVAILABLE_TYPES: if (!_options.Naked) { uint availableTypesSectionOffset = (uint)_r2r.GetOffset(section.RelativeVirtualAddress); @@ -285,14 +285,14 @@ internal override void DumpSectionContents(R2RSection section) _writer.WriteLine(name); } break; - case R2RSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_METHODDEF_ENTRYPOINTS: if (!_options.Naked) { NativeArray methodEntryPoints = new NativeArray(_r2r.Image, (uint)_r2r.GetOffset(section.RelativeVirtualAddress)); _writer.Write(methodEntryPoints.ToString()); } break; - case R2RSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_INSTANCE_METHOD_ENTRYPOINTS: if (!_options.Naked) { uint instanceSectionOffset = (uint)_r2r.GetOffset(section.RelativeVirtualAddress); @@ -306,7 +306,7 @@ internal override void DumpSectionContents(R2RSection section) _writer.WriteLine($@"0x{instanceMethod.Bucket:X2} -> {instanceMethod.Method.SignatureString}"); } break; - case R2RSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_RUNTIME_FUNCTIONS: int rtfOffset = _r2r.GetOffset(section.RelativeVirtualAddress); int rtfEndOffset = rtfOffset + section.Size; int rtfIndex = 0; @@ -327,17 +327,17 @@ internal override void DumpSectionContents(R2RSection section) rtfIndex++; } break; - case R2RSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_COMPILER_IDENTIFIER: _writer.WriteLine(_r2r.CompilerIdentifier); break; - case R2RSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_IMPORT_SECTIONS: if (_options.Naked) { DumpNakedImportSections(); } else { - foreach (R2RImportSection importSection in _r2r.ImportSections) + foreach (ReadyToRunImportSection importSection in _r2r.ImportSections) { importSection.WriteTo(_writer); if (_options.Raw && importSection.Entries.Count != 0) @@ -358,7 +358,7 @@ internal override void DumpSectionContents(R2RSection section) DumpBytes(importSection.AuxiliaryDataRVA, (uint)importSection.AuxiliaryDataSize); } } - foreach (R2RImportSection.ImportSectionEntry entry in importSection.Entries) + foreach (ReadyToRunImportSection.ImportSectionEntry entry in importSection.Entries) { entry.WriteTo(_writer, _options); _writer.WriteLine(); @@ -367,7 +367,7 @@ internal override void DumpSectionContents(R2RSection section) } } break; - case R2RSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_MANIFEST_METADATA: int assemblyRefCount = _r2r.MetadataReader.GetTableRowCount(TableIndex.AssemblyRef); _writer.WriteLine($"MSIL AssemblyRef's ({assemblyRefCount} entries):"); for (int assemblyRefIndex = 1; assemblyRefIndex <= assemblyRefCount; assemblyRefIndex++) @@ -385,7 +385,7 @@ internal override void DumpSectionContents(R2RSection section) manifestAsmIndex++; } break; - case R2RSection.SectionType.READYTORUN_SECTION_ATTRIBUTEPRESENCE: + case ReadyToRunSection.SectionType.READYTORUN_SECTION_ATTRIBUTEPRESENCE: int attributesStartOffset = _r2r.GetOffset(section.RelativeVirtualAddress); int attributesEndOffset = attributesStartOffset + section.Size; NativeCuckooFilter attributes = new NativeCuckooFilter(_r2r.Image, attributesStartOffset, attributesEndOffset); @@ -397,13 +397,13 @@ internal override void DumpSectionContents(R2RSection section) private void DumpNakedImportSections() { - List entries = new List(); - foreach (R2RImportSection importSection in _r2r.ImportSections) + List entries = new List(); + foreach (ReadyToRunImportSection importSection in _r2r.ImportSections) { entries.AddRange(importSection.Entries); } entries.Sort((e1, e2) => e1.Signature.CompareTo(e2.Signature)); - foreach (R2RImportSection.ImportSectionEntry entry in entries) + foreach (ReadyToRunImportSection.ImportSectionEntry entry in entries) { entry.WriteTo(_writer, _options); _writer.WriteLine();