From 3d273df9063da9b506715cccd926b7505e73c928 Mon Sep 17 00:00:00 2001 From: Amy Yu Date: Mon, 11 Jun 2018 16:01:39 -0700 Subject: [PATCH] Add public to classes and set accessor to properties needed for serialization Commit migrated from https://github.com/dotnet/coreclr/commit/600dc1b49623d96e9b950756c229af637a6a7187 --- src/coreclr/src/tools/r2rdump/GCInfo.cs | 10 +++---- src/coreclr/src/tools/r2rdump/GCInfoTypes.cs | 9 ++++--- src/coreclr/src/tools/r2rdump/GCSlotTable.cs | 20 +++++++------- src/coreclr/src/tools/r2rdump/R2RHeader.cs | 22 +++++++++------- src/coreclr/src/tools/r2rdump/R2RImportSection.cs | 2 +- src/coreclr/src/tools/r2rdump/R2RMethod.cs | 32 ++++++++++++++--------- src/coreclr/src/tools/r2rdump/R2RReader.cs | 14 +++++----- src/coreclr/src/tools/r2rdump/R2RSection.cs | 8 +++--- 8 files changed, 66 insertions(+), 51 deletions(-) diff --git a/src/coreclr/src/tools/r2rdump/GCInfo.cs b/src/coreclr/src/tools/r2rdump/GCInfo.cs index cf57db6..de2ce66 100644 --- a/src/coreclr/src/tools/r2rdump/GCInfo.cs +++ b/src/coreclr/src/tools/r2rdump/GCInfo.cs @@ -9,7 +9,7 @@ using System.Text; namespace R2RDump { - class GcInfo + public class GcInfo { private enum GcInfoHeaderFlags { @@ -33,8 +33,8 @@ namespace R2RDump public struct InterruptibleRange { - public uint StartOffset { get; } - public uint StopOffset { get; } + public uint StartOffset { get; set; } + public uint StopOffset { get; set; } public InterruptibleRange(uint start, uint stop) { StartOffset = start; @@ -335,7 +335,7 @@ namespace R2RDump _wantsReportOnlyLeaf = ((headerFlags & GcInfoHeaderFlags.GC_INFO_WANTS_REPORT_ONLY_LEAF) != 0); } - private IEnumerable EnumerateSafePoints(byte[] image, ref int bitOffset) + private List EnumerateSafePoints(byte[] image, ref int bitOffset) { List safePoints = new List(); uint numBitsPerOffset = GcInfoTypes.CeilOfLog2(CodeLength); @@ -347,7 +347,7 @@ namespace R2RDump return safePoints; } - private IEnumerable EnumerateInterruptibleRanges(byte[] image, int interruptibleRangeDelta1EncBase, int interruptibleRangeDelta2EncBase, ref int bitOffset) + private List EnumerateInterruptibleRanges(byte[] image, int interruptibleRangeDelta1EncBase, int interruptibleRangeDelta2EncBase, ref int bitOffset) { List ranges = new List(); uint lastinterruptibleRangeStopOffset = 0; diff --git a/src/coreclr/src/tools/r2rdump/GCInfoTypes.cs b/src/coreclr/src/tools/r2rdump/GCInfoTypes.cs index 9b44a59..a285ebb 100644 --- a/src/coreclr/src/tools/r2rdump/GCInfoTypes.cs +++ b/src/coreclr/src/tools/r2rdump/GCInfoTypes.cs @@ -8,7 +8,7 @@ using System.Text; namespace R2RDump { - class GcInfoTypes + public class GcInfoTypes { private Machine _target; @@ -196,8 +196,11 @@ namespace R2RDump public class GcStackSlot { - public int SpOffset { get; } - public GcStackSlotBase Base { get; } + public int SpOffset { get; set; } + public GcStackSlotBase Base { get; set; } + + public GcStackSlot() { } + public GcStackSlot(int spOffset, GcStackSlotBase stackSlotBase) { SpOffset = spOffset; diff --git a/src/coreclr/src/tools/r2rdump/GCSlotTable.cs b/src/coreclr/src/tools/r2rdump/GCSlotTable.cs index f2ebf41..d788f4d 100644 --- a/src/coreclr/src/tools/r2rdump/GCSlotTable.cs +++ b/src/coreclr/src/tools/r2rdump/GCSlotTable.cs @@ -9,13 +9,13 @@ using System.Text; namespace R2RDump { - class GcSlotTable + public class GcSlotTable { public struct GcSlot { - public int RegisterNumber { get; } - public GcStackSlot StackSlot { get; } - public GcSlotFlags Flags { get; } + public int RegisterNumber { get; set; } + public GcStackSlot StackSlot { get; set; } + public GcSlotFlags Flags { get; set; } public GcSlot(int registerNumber, GcStackSlot stack, GcSlotFlags flags, bool isUntracked = false) { @@ -50,11 +50,13 @@ namespace R2RDump } } - public uint NumRegisters { get; } - public uint NumStackSlots { get; } - public uint NumUntracked { get; } - public uint NumSlots { get; } - public List GcSlots { get; } + public uint NumRegisters { get; set; } + public uint NumStackSlots { get; set; } + public uint NumUntracked { get; set; } + public uint NumSlots { get; set; } + public List GcSlots { get; set; } + + public GcSlotTable() { } public GcSlotTable(byte[] image, Machine machine, GcInfoTypes gcInfoTypes, ref int bitOffset) { diff --git a/src/coreclr/src/tools/r2rdump/R2RHeader.cs b/src/coreclr/src/tools/r2rdump/R2RHeader.cs index 96eacd5..cf7e65a 100644 --- a/src/coreclr/src/tools/r2rdump/R2RHeader.cs +++ b/src/coreclr/src/tools/r2rdump/R2RHeader.cs @@ -8,7 +8,7 @@ using System.Text; namespace R2RDump { - class R2RHeader + public class R2RHeader { [Flags] public enum ReadyToRunFlag @@ -26,35 +26,37 @@ namespace R2RDump /// /// RVA to the begining of the ReadyToRun header /// - public int RelativeVirtualAddress { get; } + public int RelativeVirtualAddress { get; set; } /// /// Size of the ReadyToRun header /// - public int Size { get; } + public int Size { get; set; } /// /// Signature of the header in string and hex formats /// - public string SignatureString { get; } - public uint Signature { get; } + public string SignatureString { get; set; } + public uint Signature { get; set; } /// /// The ReadyToRun version /// - public ushort MajorVersion { get; } - public ushort MinorVersion { get; } + public ushort MajorVersion { get; set; } + public ushort MinorVersion { get; set; } /// /// Flags in the header /// eg. PLATFORM_NEUTRAL_SOURCE, SKIP_TYPE_VALIDATION /// - public uint Flags { get; } + public uint Flags { get; set; } /// /// The ReadyToRun section RVAs and sizes /// - public Dictionary Sections { get; } + public IDictionary Sections { get; } + + public R2RHeader() { } /// /// Initializes the fields of the R2RHeader @@ -70,7 +72,7 @@ namespace R2RDump byte[] signature = new byte[sizeof(uint)]; Array.Copy(image, curOffset, signature, 0, sizeof(uint)); - SignatureString = System.Text.Encoding.UTF8.GetString(signature); + SignatureString = Encoding.UTF8.GetString(signature).Replace("\0", string.Empty); ; Signature = NativeReader.ReadUInt32(image, ref curOffset); if (Signature != READYTORUN_SIGNATURE) { diff --git a/src/coreclr/src/tools/r2rdump/R2RImportSection.cs b/src/coreclr/src/tools/r2rdump/R2RImportSection.cs index aa567d5..e91ef34 100644 --- a/src/coreclr/src/tools/r2rdump/R2RImportSection.cs +++ b/src/coreclr/src/tools/r2rdump/R2RImportSection.cs @@ -9,7 +9,7 @@ using System.Text; namespace R2RDump { - struct R2RImportSection + public struct R2RImportSection { public enum CorCompileImportType { diff --git a/src/coreclr/src/tools/r2rdump/R2RMethod.cs b/src/coreclr/src/tools/r2rdump/R2RMethod.cs index 448b5b7..3851085 100644 --- a/src/coreclr/src/tools/r2rdump/R2RMethod.cs +++ b/src/coreclr/src/tools/r2rdump/R2RMethod.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; using System.Text; +using System.Xml.Serialization; namespace R2RDump { @@ -17,17 +18,17 @@ namespace R2RDump } - class RuntimeFunction + public class RuntimeFunction { /// /// The index of the runtime function /// - public int Id { get; } + public int Id { get; set; } /// /// The relative virtual address to the start of the code block /// - public int StartAddress { get; } + public int StartAddress { get; set; } /// /// The size of the code block in bytes @@ -36,12 +37,12 @@ namespace R2RDump /// The EndAddress field in the runtime functions section is conditional on machine type /// Size is -1 for images without the EndAddress field /// - public int Size { get; } + public int Size { get; set; } /// /// The relative virtual address to the unwind info /// - public int UnwindRVA { get; } + public int UnwindRVA { get; set; } public int CodeOffset { get; set; } @@ -52,6 +53,8 @@ namespace R2RDump public BaseUnwindInfo UnwindInfo { get; } + public RuntimeFunction() { } + public RuntimeFunction(int id, int startRva, int endRva, int unwindRva, int codeOffset, R2RMethod method, BaseUnwindInfo unwindInfo, GcInfo gcInfo) { Id = id; @@ -91,7 +94,7 @@ namespace R2RDump } } - class R2RMethod + public class R2RMethod { private const int _mdtMethodDef = 0x06000000; @@ -101,31 +104,31 @@ namespace R2RDump /// /// The name of the method /// - public string Name { get; } + public string Name { get; set; } /// /// The signature with format: namespace.class.methodName(S, T, ...) /// - public string SignatureString { get; } + public string SignatureString { get; set; } - public bool IsGeneric { get; } + public bool IsGeneric { get; set; } public MethodSignature Signature { get; } /// /// The type that the method belongs to /// - public string DeclaringType { get; } + public string DeclaringType { get; set; } /// /// The token of the method consisting of the table code (0x06) and row id /// - public uint Token { get; } + public uint Token { get; set; } /// /// The row id of the method /// - public uint Rid { get; } + public uint Rid { get; set; } /// /// All the runtime functions of this method @@ -135,8 +138,9 @@ namespace R2RDump /// /// The id of the entrypoint runtime function /// - public int EntryPointRuntimeFunctionId { get; } + public int EntryPointRuntimeFunctionId { get; set; } + [XmlIgnore] public GcInfo GcInfo { get; set; } /// @@ -179,6 +183,8 @@ namespace R2RDump Array = 0x1d, }; + public R2RMethod() { } + /// /// Extracts the method signature from the metadata by rid /// diff --git a/src/coreclr/src/tools/r2rdump/R2RReader.cs b/src/coreclr/src/tools/r2rdump/R2RReader.cs index b5d150b..56539da 100644 --- a/src/coreclr/src/tools/r2rdump/R2RReader.cs +++ b/src/coreclr/src/tools/r2rdump/R2RReader.cs @@ -32,7 +32,7 @@ namespace R2RDump E15 = 15, } - class R2RReader + public class R2RReader { private readonly PEReader _peReader; private readonly MetadataReader _mdReader; @@ -45,23 +45,23 @@ namespace R2RDump /// /// Name of the image file /// - public string Filename { get; } + public string Filename { get; set; } /// /// True if the image is ReadyToRun /// - public bool IsR2R { get; } + public bool IsR2R { get; set; } /// /// The type of target machine /// - public Machine Machine { get; } + public Machine Machine { get; set; } /// /// The preferred address of the first byte of image when loaded into memory; /// must be a multiple of 64K. /// - public ulong ImageBase { get; } + public ulong ImageBase { get; set; } /// /// The ReadyToRun header @@ -85,6 +85,8 @@ namespace R2RDump public IList ImportSections { get; } + public unsafe R2RReader() { } + /// /// Initializes the fields of the R2RHeader and R2RMethods /// @@ -313,7 +315,7 @@ namespace R2RDump byte[] identifier = new byte[compilerIdentifierSection.Size]; int identifierOffset = GetOffset(compilerIdentifierSection.RelativeVirtualAddress); Array.Copy(Image, identifierOffset, identifier, 0, compilerIdentifierSection.Size); - return Encoding.UTF8.GetString(identifier); + return Encoding.UTF8.GetString(identifier).Replace("\0", string.Empty); } private void ParseImportSections() diff --git a/src/coreclr/src/tools/r2rdump/R2RSection.cs b/src/coreclr/src/tools/r2rdump/R2RSection.cs index 8d6d7cf..77cf24d 100644 --- a/src/coreclr/src/tools/r2rdump/R2RSection.cs +++ b/src/coreclr/src/tools/r2rdump/R2RSection.cs @@ -8,7 +8,7 @@ using System.Text; namespace R2RDump { - struct R2RSection + public struct R2RSection { public enum SectionType { @@ -28,17 +28,17 @@ namespace R2RDump /// /// The ReadyToRun section type /// - public SectionType Type { get; } + public SectionType Type { get; set; } /// /// The RVA to the section /// - public int RelativeVirtualAddress { get; } + public int RelativeVirtualAddress { get; set; } /// /// The size of the section /// - public int Size { get; } + public int Size { get; set; } public R2RSection(SectionType type, int rva, int size) { -- 2.7.4