changeset 106:ff944d4bdfb7

Fixed local variable debug info by emitting "this". * dex/ClassData.java: Pass method access flags to code parser. * dex/Code.java (getFlags): The code knows about method access flags now. * dex/DebugInfo.java (interpret): Also emit a local for "this" register.
author Michael Starzinger <michi@complang.tuwien.ac.at>
date Wed, 30 Mar 2011 23:40:28 +0200
parents edb905bf8c29
children 75d12be4d1ea
files src/main/java/org/icedrobot/daneel/dex/ClassData.java src/main/java/org/icedrobot/daneel/dex/Code.java src/main/java/org/icedrobot/daneel/dex/DebugInfo.java
diffstat 3 files changed, 33 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/icedrobot/daneel/dex/ClassData.java	Wed Mar 30 00:04:27 2011 +0200
+++ b/src/main/java/org/icedrobot/daneel/dex/ClassData.java	Wed Mar 30 23:40:28 2011 +0200
@@ -124,12 +124,13 @@
         for (int i = 0; i < directMethodsSize; i++) {
             directMethodsIdx += BufferUtil.getULEB128(buffer);
             MethodId method = dex.getMethodId(directMethodsIdx);
+            int flags = BufferUtil.getULEB128(buffer);
+            int codeOff = BufferUtil.getULEB128(buffer);
             directMethodsIds[i] = method;
-            directMethodsFlags[i] = BufferUtil.getULEB128(buffer);
-            int codeOff = BufferUtil.getULEB128(buffer);
+            directMethodsFlags[i] = flags;
             if (codeOff != 0)
                 directMethodsCode[i] = Code.parse(dex.getDataBuffer(codeOff),
-                        dex, method);
+                        dex, method, flags);
         }
 
         // Parse encoded_method structures in virtual_methods array.
@@ -140,12 +141,13 @@
         for (int i = 0; i < virtualMethodsSize; i++) {
             virtualMethodsIdx += BufferUtil.getULEB128(buffer);
             MethodId method = dex.getMethodId(virtualMethodsIdx);
+            int flags = BufferUtil.getULEB128(buffer);
+            int codeOff = BufferUtil.getULEB128(buffer);
             virtualMethodsIds[i] = method;
-            virtualMethodsFlags[i] = BufferUtil.getULEB128(buffer);
-            int codeOff = BufferUtil.getULEB128(buffer);
+            virtualMethodsFlags[i] = flags;
             if (codeOff != 0)
                 virtualMethodsCode[i] = Code.parse(dex.getDataBuffer(codeOff),
-                        dex, method);
+                        dex, method, flags);
         }
 
         // Parse encoded_array_item and contained encoded_value structures.
--- a/src/main/java/org/icedrobot/daneel/dex/Code.java	Wed Mar 30 00:04:27 2011 +0200
+++ b/src/main/java/org/icedrobot/daneel/dex/Code.java	Wed Mar 30 23:40:28 2011 +0200
@@ -62,16 +62,20 @@
      * @param buffer The byte buffer to read from.
      * @param dex The DEX file currently being parsed.
      * @param method The method identifier this code belongs to.
+     * @param flags The access flags of the method this code belongs to.
      * @return An object representing the parsed data.
      */
-    public static Code parse(ByteBuffer buffer, DexFile dex, MethodId method) {
-        return new Code(buffer, dex, method);
+    public static Code parse(ByteBuffer buffer, DexFile dex, MethodId method,
+            int flags) {
+        return new Code(buffer, dex, method, flags);
     }
 
     private final DexFile dex;
 
     private final MethodId method;
 
+    private final int flags;
+
     private final int registersSize;
 
     private final int insSize;
@@ -88,9 +92,10 @@
 
     private final List<TryCatchInfo> tryCatchInfos;
 
-    private Code(ByteBuffer buffer, DexFile dex, MethodId method) {
+    private Code(ByteBuffer buffer, DexFile dex, MethodId method, int flags) {
         this.dex = dex;
         this.method = method;
+        this.flags = flags;
         registersSize = buffer.getShort();
         insSize = buffer.getShort();
         outsSize = buffer.getShort();
@@ -164,6 +169,15 @@
     }
 
     /**
+     * Returns the access flags of the method this code belongs to.
+     * 
+     * @return The access flags value.
+     */
+    public int getFlags() {
+        return flags;
+    }
+
+    /**
      * Returns the number of registers used by the code as specified in the DEX
      * file.
      * 
--- a/src/main/java/org/icedrobot/daneel/dex/DebugInfo.java	Wed Mar 30 00:04:27 2011 +0200
+++ b/src/main/java/org/icedrobot/daneel/dex/DebugInfo.java	Wed Mar 30 23:40:28 2011 +0200
@@ -166,7 +166,8 @@
         LocalVariable[] regs = new LocalVariable[maxRegs];
 
         // Emit local variables for method parameters.
-        String[] parameterTypes = code.getMethod().getProtoId().getParameters();
+        MethodId method = code.getMethod();
+        String[] parameterTypes = method.getProtoId().getParameters();
         if (parameterTypes != null) {
             if (parametersSize != parameterTypes.length)
                 throw new DexParseException("Parameter count does not match.");
@@ -178,6 +179,12 @@
                     regNum--;
                 regs[regNum] = emitLocalVariable(regNum, 0, name, type, null);
             }
+            // XXX Move the check for ACC_STATIC into "AccessFlags" class.
+            if ((code.getFlags() & 0x8) == 0) {
+                String name = "<this>";
+                String type = method.getClassName();
+                regs[regNum] = emitLocalVariable(regNum, 0, name, type, null);
+            }
         }
 
         // Iterate over all state machine bytecodes.