# HG changeset patch # User Michael Starzinger # Date 1301521228 -7200 # Node ID ff944d4bdfb7dfc369dd4c64414df782ea1e4922 # Parent edb905bf8c291884d4a896aa32cd05b9901329ae 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. diff -r edb905bf8c29 -r ff944d4bdfb7 src/main/java/org/icedrobot/daneel/dex/ClassData.java --- 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. diff -r edb905bf8c29 -r ff944d4bdfb7 src/main/java/org/icedrobot/daneel/dex/Code.java --- 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 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. * diff -r edb905bf8c29 -r ff944d4bdfb7 src/main/java/org/icedrobot/daneel/dex/DebugInfo.java --- 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 = ""; + String type = method.getClassName(); + regs[regNum] = emitLocalVariable(regNum, 0, name, type, null); + } } // Iterate over all state machine bytecodes.