Skip to content

Commit

Permalink
Fixed table layout for Lua 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
WheretIB committed May 23, 2020
1 parent f166580 commit f25c3f9
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions LuaDkmDebuggerComponent/Bytecode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ public static int StructSize(DkmProcess process)

public void ReadFrom(DkmProcess process, ulong address)
{
// Same in Lua 5.2 and 5.3
// Same in Lua 5.1, 5.2 and 5.3
nameAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += (ulong)DebugHelpers.GetPointerSize(process);

Expand Down Expand Up @@ -792,6 +792,7 @@ public class LuaNodeData

public void ReadFrom(DkmProcess process, ulong address)
{
// Same in Lua 5.1, 5.2 and 5.3
value = LuaHelpers.ReadValue(process, address);
key = LuaHelpers.ReadValue(process, address + LuaHelpers.GetValueSize(process));
}
Expand All @@ -814,32 +815,42 @@ public class LuaTableData

public void ReadFrom(DkmProcess process, ulong address)
{
// Same in Lua 5.2 and 5.3
ulong pointerSize = (ulong)DebugHelpers.GetPointerSize(process);
if (LuaHelpers.luaVersion == 501)
{
// Skip CommonHeader
DebugHelpers.SkipStructPointer(process, ref address); // next
DebugHelpers.SkipStructByte(process, ref address); // typeTag
DebugHelpers.SkipStructByte(process, ref address); // marked

flags = DebugHelpers.ReadStructByte(process, ref address).GetValueOrDefault(0);
nodeArraySizeLog2 = DebugHelpers.ReadStructByte(process, ref address).GetValueOrDefault(0);

address += pointerSize; // Skip CommonHeader
address += 2;
metaTableDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
arrayDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
nodeDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
lastFreeNodeDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
gclistAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);

flags = DebugHelpers.ReadByteVariable(process, address).GetValueOrDefault(0);
address += sizeof(byte);
nodeArraySizeLog2 = DebugHelpers.ReadByteVariable(process, address).GetValueOrDefault(0);
address += sizeof(byte);
arraySize = DebugHelpers.ReadStructInt(process, ref address).GetValueOrDefault(0);
}
else
{
// Same in Lua 5.2 and 5.3
DebugHelpers.SkipStructPointer(process, ref address); // next
DebugHelpers.SkipStructByte(process, ref address); // typeTag
DebugHelpers.SkipStructByte(process, ref address); // marked

Debug.Assert((address & 0x3) == 0);
flags = DebugHelpers.ReadStructByte(process, ref address).GetValueOrDefault(0);
nodeArraySizeLog2 = DebugHelpers.ReadStructByte(process, ref address).GetValueOrDefault(0);

arraySize = DebugHelpers.ReadIntVariable(process, address).GetValueOrDefault(0);
address += sizeof(int);
arraySize = DebugHelpers.ReadStructInt(process, ref address).GetValueOrDefault(0);

arrayDataAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += pointerSize;
nodeDataAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += pointerSize;
lastFreeNodeDataAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += pointerSize;
metaTableDataAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += pointerSize;
gclistAddress = DebugHelpers.ReadPointerVariable(process, address).GetValueOrDefault(0);
address += pointerSize;
arrayDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
nodeDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
lastFreeNodeDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
metaTableDataAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
gclistAddress = DebugHelpers.ReadStructPointer(process, ref address).GetValueOrDefault(0);
}
}

public void LoadValues(DkmProcess process)
Expand Down

0 comments on commit f25c3f9

Please sign in to comment.