Search in sources :

Example 6 with TraceMethodVisitor

use of org.objectweb.asm.util.TraceMethodVisitor in project dex2jar by pxb1988.

the class TestUtils method printAnalyzerResult.

static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException, IllegalAccessException {
    Frame[] frames = a.getFrames();
    Textifier t = new Textifier();
    TraceMethodVisitor mv = new TraceMethodVisitor(t);
    String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
    for (int j = 0; j < method.instructions.size(); ++j) {
        method.instructions.get(j).accept(mv);
        StringBuffer s = new StringBuffer();
        Frame f = frames[j];
        if (f == null) {
            s.append('?');
        } else {
            for (int k = 0; k < f.getLocals(); ++k) {
                s.append(getShortName(f.getLocal(k).toString()));
            }
            s.append(" : ");
            for (int k = 0; k < f.getStackSize(); ++k) {
                s.append(getShortName(f.getStack(k).toString()));
            }
        }
        // mv.text.get(j));
        pw.printf(format, j, s, buf.get(t));
    }
    for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
        ((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
        pw.print(" " + buf.get(t));
    }
    pw.println();
    pw.flush();
}
Also used : TryCatchBlockNode(org.objectweb.asm.tree.TryCatchBlockNode) Frame(org.objectweb.asm.tree.analysis.Frame) Textifier(org.objectweb.asm.util.Textifier) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor)

Aggregations

TraceMethodVisitor (org.objectweb.asm.util.TraceMethodVisitor)6 Frame (org.objectweb.asm.tree.analysis.Frame)4 Textifier (org.objectweb.asm.util.Textifier)4 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)3 TryCatchBlockNode (org.objectweb.asm.tree.TryCatchBlockNode)3 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 List (java.util.List)2 BuildException (org.apache.tools.ant.BuildException)2 ClassReader (org.objectweb.asm.ClassReader)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 MethodNode (org.objectweb.asm.tree.MethodNode)2 Analyzer (org.objectweb.asm.tree.analysis.Analyzer)2 SimpleVerifier (org.objectweb.asm.tree.analysis.SimpleVerifier)2 CheckClassAdapter (org.objectweb.asm.util.CheckClassAdapter)2 ArrayList (java.util.ArrayList)1