mirror of
https://github.com/LegacyModdingMC/UniMix.git
synced 2026-11-21 03:22:17 +00:00
Clean up debugging code in Locals ready for merge
This commit is contained in:
1 parent
2955e1a359
commit
c9f6d04f84
1 file changed
+8
-52
@@ -76,7 +76,7 @@ public class Locals {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <p>Attempts to identify available locals at an arbitrary point in the
|
||||
* bytecode specified by node.</p>
|
||||
@@ -120,8 +120,6 @@ public class Locals {
|
||||
* specified location
|
||||
*/
|
||||
public static LocalVariableNode[] getLocalsAt(ClassNode classNode, MethodNode method, AbstractInsnNode node) {
|
||||
System.err.printf("----------------------------------------------------\n");
|
||||
|
||||
List<FrameData> frames = ClassInfo.forName(classNode.name).findMethod(method).getFrames();
|
||||
|
||||
LocalVariableNode[] frame = new LocalVariableNode[method.maxLocals];
|
||||
@@ -139,16 +137,16 @@ public class Locals {
|
||||
}
|
||||
|
||||
int initialFrameSize = local;
|
||||
int opcode = 0, frameIndex = 0, numLocals = 0;
|
||||
int frameIndex = -1, locals = 0;
|
||||
|
||||
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext(); opcode++) {
|
||||
for (Iterator<AbstractInsnNode> iter = method.instructions.iterator(); iter.hasNext();) {
|
||||
AbstractInsnNode insn = iter.next();
|
||||
if (insn instanceof FrameNode) {
|
||||
frameIndex++;
|
||||
FrameNode frameNode = (FrameNode)insn;
|
||||
FrameData frameData = frames.get(frameIndex++);
|
||||
FrameData frameData = frameIndex < frames.size() ? frames.get(frameIndex) : null;
|
||||
|
||||
numLocals = frameData.type == Opcodes.F_FULL ? Math.max(numLocals, frameNode.local.size()) : frameNode.local.size();
|
||||
System.err.printf("FRAME: Type=%s Size=%d FD=%s TOTAL=%d\n", frameNode.type, frameNode.local.size(), frameData, numLocals);
|
||||
locals = frameData != null && frameData.type == Opcodes.F_FULL ? Math.max(locals, frameNode.local.size()) : frameNode.local.size();
|
||||
|
||||
// localPos tracks the location in the frame node's locals list, which doesn't leave space for TOP entries
|
||||
for (int localPos = 0, framePos = 0; framePos < frame.length; framePos++, localPos++) {
|
||||
@@ -157,22 +155,16 @@ public class Locals {
|
||||
|
||||
if (localType instanceof String) { // String refers to a reference type
|
||||
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
|
||||
Locals.print(method.name, opcode, "F REF " + framePos, frame);
|
||||
} else if (localType instanceof Integer) { // Integer refers to a primitive type or other marker
|
||||
boolean isMarkerType = localType == Opcodes.UNINITIALIZED_THIS || localType == Opcodes.NULL;
|
||||
boolean is32bitValue = localType == Opcodes.INTEGER || localType == Opcodes.FLOAT;
|
||||
boolean is64bitValue = localType == Opcodes.DOUBLE || localType == Opcodes.LONG;
|
||||
if (localType == Opcodes.TOP) {
|
||||
if (framePos >= initialFrameSize) {
|
||||
// frame[framePos] = null;
|
||||
Locals.print(method.name, opcode, "F TOP " + framePos, frame);
|
||||
}
|
||||
// Do nothing, explicit TOP entries are pretty much always bogus, and real ones are handled below
|
||||
} else if (isMarkerType) {
|
||||
frame[framePos] = null;
|
||||
Locals.print(method.name, opcode, "F MRK[" + localType + "] " + framePos, frame);
|
||||
} else if (is32bitValue || is64bitValue) {
|
||||
frame[framePos] = Locals.getLocalVariableAt(classNode, method, node, framePos);
|
||||
Locals.print(method.name, opcode, "F PRIMITIVE " + framePos, frame);
|
||||
|
||||
if (is64bitValue) {
|
||||
framePos++;
|
||||
@@ -183,20 +175,17 @@ public class Locals {
|
||||
+ " in " + classNode.name + "." + method.name + method.desc);
|
||||
}
|
||||
} else if (localType == null) {
|
||||
if (framePos >= initialFrameSize && framePos >= numLocals && numLocals > 0) {
|
||||
if (framePos >= initialFrameSize && framePos >= locals && locals > 0) {
|
||||
frame[framePos] = null;
|
||||
}
|
||||
Locals.print(method.name, opcode, "NULL " + framePos, frame);
|
||||
} else {
|
||||
throw new RuntimeException("Invalid value " + localType + " in locals array at position " + localPos
|
||||
+ " in " + classNode.name + "." + method.name + method.desc);
|
||||
}
|
||||
}
|
||||
System.err.printf("ENDFRAME\n");
|
||||
} else if (insn instanceof VarInsnNode) {
|
||||
VarInsnNode varNode = (VarInsnNode) insn;
|
||||
frame[varNode.var] = Locals.getLocalVariableAt(classNode, method, node, varNode.var);
|
||||
Locals.print(method.name, opcode, "VAR " + varNode.var, frame);
|
||||
} else if (insn == node) {
|
||||
break;
|
||||
}
|
||||
@@ -205,36 +194,6 @@ public class Locals {
|
||||
return frame;
|
||||
}
|
||||
|
||||
private static void print(String name, int opcode, String string, LocalVariableNode[] frame) {
|
||||
System.err.printf("%-30s #%-4d %-20s [ ", name, opcode, string);
|
||||
for (LocalVariableNode node : frame) {
|
||||
String desc = node != null ? node.desc : "-";
|
||||
if (desc == null) {
|
||||
desc = "?";
|
||||
} else {
|
||||
desc = desc.substring(desc.lastIndexOf('/') + 1).replace(';', ' ').trim();
|
||||
desc = desc.replace("ServerConfigurationManager", "SCM");
|
||||
desc = desc.replace("NetworkManager", "NM");
|
||||
desc = desc.replace("EntityPlayerMP", "EPMP");
|
||||
desc = desc.replace("GameProfile", "GP");
|
||||
desc = desc.replace("PlayerProfileCache", "PPC");
|
||||
desc = desc.replace("NBTTagCompound", "NBTTC");
|
||||
desc = desc.replace("WorldServer", "WS");
|
||||
desc = desc.replace("WorldInfo", "WI");
|
||||
desc = desc.replace("BlockPos", "BP");
|
||||
desc = desc.replace("NetHandlerPlayServer", "NHPS");
|
||||
desc = desc.replace("ChatComponentTranslation", "CCT");
|
||||
desc = desc.replace("Iterator", "IT");
|
||||
desc = desc.replace("PotionEffect", "PE");
|
||||
desc = desc.replace("World", "W");
|
||||
desc = desc.replace("EntityPlayer", "EP");
|
||||
desc = desc.replace("Entity", "E");
|
||||
}
|
||||
System.err.printf("%s ", desc);
|
||||
}
|
||||
System.err.printf("]\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to locate the appropriate entry in the local variable table for
|
||||
* the specified local variable index at the location specified by node.
|
||||
@@ -340,8 +299,6 @@ public class Locals {
|
||||
LabelNode[] labels = new LabelNode[methodSize]; // Labels to add to the method, for the markers
|
||||
String[] lastKnownType = new String[method.maxLocals];
|
||||
|
||||
System.err.printf(" -------->>\n");
|
||||
|
||||
// Traverse the frames and work out when locals begin and end
|
||||
for (int i = 0; i < methodSize; i++) {
|
||||
Frame<BasicValue> f = frames[i];
|
||||
@@ -376,7 +333,6 @@ public class Locals {
|
||||
}
|
||||
|
||||
String desc = (local.getType() != null) ? local.getType().getDescriptor() : lastKnownType[j];
|
||||
System.err.printf(" -------->> Generating %d with %s (%s)\n", j, desc, lastKnownType[j]);
|
||||
localNodes[j] = new LocalVariableNode("var" + j, desc, null, label, null, j);
|
||||
if (desc != null) {
|
||||
lastKnownType[j] = desc;
|
||||
|
||||
Reference in new issue
Block a user