From 8582095cfb49b949e4e6d95ba1fa9f12c2175a44 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Thu, 1 Nov 2012 21:14:17 -0700 Subject: [PATCH] Fix up and improve how parameters are mapped to registers, for local info This additionally adds the local info for the "this" parameter --- .../jf/dexlib2/dexbacked/util/DebugInfo.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugInfo.java b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugInfo.java index 40f4a736..deffc4a0 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugInfo.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/dexbacked/util/DebugInfo.java @@ -106,34 +106,38 @@ public abstract class DebugInfo implements Iterable { VariableSizeList parameters = getParametersWithNames(); final VariableSizeList.Iterator parameterIterator = parameters.listIterator(); - { // local scope for i - int i=0; - while (parameterIterator.hasNext()) { - locals[i++] = parameterIterator.next(); - } + // first, we grab all the parameters and temporarily store them at the beginning of locals, + // disregarding any wide types + int parameterIndex = 0; + if (!AccessFlags.STATIC.isSet(methodImpl.method.getAccessFlags())) { + // add the local info for the "this" parameter + locals[parameterIndex++] = new LocalInfo() { + @Override public String getName() { return "this"; } + @Override public String getType() { return methodImpl.method.classDef.getName(); } + @Override public String getSignature() { return null; } + }; + } + while (parameterIterator.hasNext()) { + locals[parameterIndex++] = parameterIterator.next(); } - if (parameters.size() < registerCount) { - // we need to push the parameter locals back to their appropriate register + if (parameterIndex < registerCount) { + // now, we push the parameter locals back to their appropriate register, starting from the end int localIndex = registerCount-1; - for (int i=parameters.size()-1; i>-1; i--) { - LocalInfo currentLocal = locals[i]; + while(--parameterIndex > -1) { + LocalInfo currentLocal = locals[parameterIndex]; String type = currentLocal.getType(); if (type != null && (type.equals("J") || type.equals("D"))) { localIndex--; + if (localIndex == parameterIndex) { + // there's no more room to push, the remaining registers are already in the correct place + break; + } } locals[localIndex] = currentLocal; - locals[i] = EMPTY_LOCAL_INFO; + locals[parameterIndex] = EMPTY_LOCAL_INFO; localIndex--; } - if (!AccessFlags.STATIC.isSet(methodImpl.method.getAccessFlags())) { - // add the local info for the "this" parameter - locals[localIndex] = new LocalInfo() { - @Override public String getName() { return "this"; } - @Override public String getType() { return methodImpl.method.classDef.getName(); } - @Override public String getSignature() { return null; } - }; - } } return new Iterator() {