changeset 63:cf225eeae6ee

Adapted parser interface for debug information. * dex/Code.java (accept, acceptInsns): Call new interface methods. * dex/DexMethodVisitor.java (visitLineNumber, visitLocalVariable): Added. * rewriter/DexRewriter.java: Adapted to above change.
author Michael Starzinger <michi@complang.tuwien.ac.at>
date Tue, 22 Mar 2011 02:22:23 +0100
parents 387a3d5f9695
children 7687468aed66
files src/main/java/org/icedrobot/daneel/dex/Code.java src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java
diffstat 3 files changed, 57 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/org/icedrobot/daneel/dex/Code.java	Tue Mar 22 02:11:59 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/Code.java	Tue Mar 22 02:22:23 2011 +0100
@@ -169,13 +169,19 @@
     public void accept(DexMethodVisitor visitor) {
         visitor.visitCode(registersSize, insSize, outsSize);
         acceptInsns(visitor);
+
+        // Visit local variable information if available.
         if (debugInfo != null)
-            for (LocalVariable local : debugInfo.getLocalVariables())
-                // XXX Define method in DexMethodVisitor for that.
-                System.out.printf("LOCAL: r%02x : %s %s (%s-%s)\n",
-                        local.regNum, dex.getTypeDescriptor(local.typeIdx),
-                        dex.getString(local.nameIdx), local.startLabel,
-                        local.endLabel);
+            for (LocalVariable local : debugInfo.getLocalVariables()) {
+                String name = (local.nameIdx != DexFile.NO_INDEX) ? dex
+                        .getString(local.nameIdx) : null;
+                String desc = (local.typeIdx != DexFile.NO_INDEX) ? dex
+                        .getTypeDescriptor(local.typeIdx) : null;
+                visitor.visitLocalVariable(name, desc, local.startLabel,
+                        local.endLabel, local.regNum);
+            }
+
+        // Visit try-catch block information if available.
         for (TryCatchInfo tryCatch : tryCatchInfos)
             visitor.visitTryCatch(tryCatch.startLabel, tryCatch.endLabel,
                     tryCatch.handlerLabel, tryCatch.type);
@@ -221,8 +227,11 @@
                 v.visitLabel(label);
 
             // Visit a line number entry at the current position.
-            if (label instanceof LineNumberLabel)
-                /* XXX Define method in DexMethodVisitor for that. */;
+            if (label instanceof LineNumberLabel) {
+                LineNumberLabel line = (LineNumberLabel) label;
+                // XXX Correctly pass source file as well.
+                v.visitLineNumber(null, line.line, label);
+            }
 
             // Switch over all possible opcodes.
             switch (op) {
--- a/src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java	Tue Mar 22 02:11:59 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/dex/DexMethodVisitor.java	Tue Mar 22 02:22:23 2011 +0100
@@ -90,6 +90,35 @@
     void visitLabel(Label label);
 
     /**
+     * Visits a line number entry as stored in debug information. Note that
+     * methods can contain several source entities, that's why the source file
+     * name is passed as well.
+     * 
+     * @param source The name of the file containing the original source or
+     *        {@code null} in case value is unknown.
+     * @param line The line number referring to the source file, is never less
+     *        than {@code 1}.
+     * @param start The start of instructions corresponding to the line number.
+     */
+    void visitLineNumber(String source, int line, Label start);
+
+    /**
+     * Visits a local variable scope as stored in debug information. Note that
+     * the same variable might have different scopes, in which case this method
+     * is called more than once for the same variable.
+     * 
+     * @param name The name of the local variable or {@code null} in case value
+     *        is unknown.
+     * @param desc The type of the local variable as type descriptor or {@code
+     *        null} in case value is unknown.
+     * @param start The start of the local variable scope.
+     * @param end Then end (exclusive) of the local variable scope.
+     * @param reg The register which holds the local variable value.
+     */
+    void visitLocalVariable(String name, String desc, Label start, Label end,
+            int reg);
+
+    /**
      * Visits an instruction with a {@code 10x} format id.
      * 
      * @param opcode An opcode among NOP, RETURN_VOID.
--- a/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java	Tue Mar 22 02:11:59 2011 +0100
+++ b/src/main/java/org/icedrobot/daneel/rewriter/DexRewriter.java	Tue Mar 22 02:22:23 2011 +0100
@@ -248,6 +248,17 @@
         }
 
         @Override
+        public void visitLineNumber(String source, int line, Label start) {
+            // XXX Ignore debug information for now.
+        }
+
+        @Override
+        public void visitLocalVariable(String name, String desc, Label start,
+                Label end, int reg) {
+            // XXX Ignore debug information for now.
+        }
+
+        @Override
         public void visitCode(int registerSize, int insSize, int outSize) {
             mv.visitCode();
             this.locals = registerSize - insSize;