Add the local info for the implicit "this" param

This also fixes some minor issues with using the correct register
for parameter info
This commit is contained in:
Ben Gruver
2012-11-01 00:16:30 -07:00
parent 476e704c86
commit 269c15688b
3 changed files with 20 additions and 8 deletions

View File

@ -206,8 +206,8 @@ public class DexBackedClassDef implements ClassDef {
methodAnnotationIterator.reset();
parameterAnnotationIterator.reset();
}
DexBackedMethod item = new DexBackedMethod(reader, previousMethodIndex,
methodAnnotationIterator, parameterAnnotationIterator);
DexBackedMethod item = new DexBackedMethod(reader, DexBackedClassDef.this,
previousMethodIndex, methodAnnotationIterator, parameterAnnotationIterator);
previousMethodIndex = item.methodIndex;
return item;
}

View File

@ -44,6 +44,7 @@ import java.util.List;
public class DexBackedMethod implements Method {
@Nonnull public final DexBuffer dexBuf;
@Nonnull public final DexBackedClassDef classDef;
@Nonnull public final String name;
public final int accessFlags;
@ -65,10 +66,12 @@ public class DexBackedMethod implements Method {
private static final int PARAMETERS_OFFSET = 8;
public DexBackedMethod(@Nonnull DexReader reader,
int previousMethodIndex,
@Nonnull AnnotationsDirectory.AnnotationIterator methodAnnotationIterator,
@Nonnull AnnotationsDirectory.AnnotationIterator paramaterAnnotationIterator) {
@Nonnull DexBackedClassDef classDef,
int previousMethodIndex,
@Nonnull AnnotationsDirectory.AnnotationIterator methodAnnotationIterator,
@Nonnull AnnotationsDirectory.AnnotationIterator paramaterAnnotationIterator) {
this.dexBuf = reader.getDexBuffer();
this.classDef = classDef;
int methodIndexDiff = reader.readSmallUleb128();
this.methodIndex = methodIndexDiff + previousMethodIndex;

View File

@ -32,6 +32,7 @@
package org.jf.dexlib2.dexbacked.util;
import com.google.common.collect.Iterators;
import org.jf.dexlib2.AccessFlags;
import org.jf.dexlib2.DebugItemType;
import org.jf.dexlib2.dexbacked.DexBackedMethod;
import org.jf.dexlib2.dexbacked.DexBackedMethodImplementation;
@ -117,13 +118,21 @@ public abstract class DebugInfo implements Iterable<DebugItem> {
int localIndex = registerCount-1;
for (int i=parameters.size()-1; i>-1; i--) {
LocalInfo currentLocal = locals[i];
locals[localIndex] = currentLocal;
locals[i] = EMPTY_LOCAL_INFO;
String type = currentLocal.getType();
localIndex--;
if (type != null && (type.equals("J") || type.equals("D"))) {
localIndex--;
}
locals[localIndex] = currentLocal;
locals[i] = 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; }
};
}
}