From a1c04b25428b2c800f281ad2a4b7241199612bac Mon Sep 17 00:00:00 2001 From: Amy Yu Date: Thu, 14 Jun 2018 17:34:47 -0700 Subject: [PATCH] Fixed some bugs with gc transitions --- src/tools/r2rdump/GCInfo.cs | 15 ++++++++++++--- src/tools/r2rdump/GCSlotTable.cs | 4 ++-- src/tools/r2rdump/NativeReader.cs | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/tools/r2rdump/GCInfo.cs b/src/tools/r2rdump/GCInfo.cs index 2b8c1f1..a39a85a 100644 --- a/src/tools/r2rdump/GCInfo.cs +++ b/src/tools/r2rdump/GCInfo.cs @@ -385,12 +385,21 @@ namespace R2RDump { chunkPointers[i] = NativeReader.ReadBits(image, numBitsPerPointer, ref bitOffset); } - bitOffset = (int)Math.Ceiling(bitOffset / 8.0) * 8; + int info2Offset = (int)Math.Ceiling(bitOffset / 8.0) * 8; List transitions = new List(); bool[] liveAtEnd = new bool[slots.Count]; for (int currentChunk = 0; currentChunk < numChunks; currentChunk++) { + if (chunkPointers[currentChunk] == 0) + { + continue; + } + else + { + bitOffset = info2Offset + chunkPointers[currentChunk] - 1; + } + int couldBeLiveOffset = bitOffset; int slotId = 0; bool fSimple = (NativeReader.ReadBits(image, 1, ref couldBeLiveOffset) == 0); @@ -410,7 +419,7 @@ namespace R2RDump int normChunkBaseCodeOffset = currentChunk * gcInfoTypes.NUM_NORM_CODE_OFFSETS_PER_CHUNK; for (int i = 0; i < numCouldBeLiveSlots; i++) { - slotId = GetSlotId(image, gcInfoTypes, fSimple, fSkipFirst, slotId, ref couldBeLiveCnt, ref couldBeLiveOffset); + slotId = GetNextSlotId(image, gcInfoTypes, fSimple, fSkipFirst, slotId, ref couldBeLiveCnt, ref couldBeLiveOffset); bool isLive = !liveAtEnd[slotId]; liveAtEnd[slotId] = (NativeReader.ReadBits(image, 1, ref finalStateOffset) != 0); @@ -469,7 +478,7 @@ namespace R2RDump return numCouldBeLiveSlots; } - private int GetSlotId(byte[] image, GcInfoTypes gcInfoTypes, bool fSimple, bool fSkipFirst, int slotId, ref int couldBeLiveCnt, ref int couldBeLiveOffset) + private int GetNextSlotId(byte[] image, GcInfoTypes gcInfoTypes, bool fSimple, bool fSkipFirst, int slotId, ref int couldBeLiveCnt, ref int couldBeLiveOffset) { if (fSimple) { diff --git a/src/tools/r2rdump/GCSlotTable.cs b/src/tools/r2rdump/GCSlotTable.cs index 5828b95..750c65d 100644 --- a/src/tools/r2rdump/GCSlotTable.cs +++ b/src/tools/r2rdump/GCSlotTable.cs @@ -103,7 +103,7 @@ namespace R2RDump GcSlotFlags flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset); GcSlots.Add(new GcSlot((int)regNum, null, flags)); - for (int i = 1; i < NumRegisters && i < gcInfoTypes.MAX_PREDECODED_SLOTS; i++) + for (int i = 1; i < NumRegisters; i++) { if ((uint)flags != 0) { @@ -128,7 +128,7 @@ namespace R2RDump GcSlotFlags flags = (GcSlotFlags)NativeReader.ReadBits(image, 2, ref bitOffset); GcSlots.Add(new GcSlot(-1, new GcStackSlot(spOffset, spBase), flags)); - for (int i = 1; i < nSlots && GcSlots.Count < gcInfoTypes.MAX_PREDECODED_SLOTS; i++) + for (int i = 1; i < nSlots; i++) { spBase = (GcStackSlotBase)NativeReader.ReadBits(image, 2, ref bitOffset); if ((uint)flags != 0) diff --git a/src/tools/r2rdump/NativeReader.cs b/src/tools/r2rdump/NativeReader.cs index cfc9a68..9871c2e 100644 --- a/src/tools/r2rdump/NativeReader.cs +++ b/src/tools/r2rdump/NativeReader.cs @@ -107,7 +107,7 @@ namespace R2RDump int bits = bitOffset % BITS_PER_BYTE; int val = image[start] >> bits; bits += numBits; - if (bits > BITS_PER_BYTE) + while (bits > BITS_PER_BYTE) { start++; bits -= BITS_PER_BYTE; -- 2.7.4