Search in sources :

Example 21 with Textifier

use of org.objectweb.asm.util.Textifier in project closure-templates by google.

the class BytecodeProducer method trace.

/**
 * Returns a human readable string for the code that this {@link BytecodeProducer} generates.
 */
public final String trace() {
    // TODO(lukes): textifier has support for custom label names by overriding appendLabel.
    // Consider trying to make use of (using the Label.info field? adding a custom NamedLabel
    // sub type?)
    Textifier textifier = new Textifier(Opcodes.ASM6) {

        {
            // reset tab sizes.  Since we don't care about formatting class names or method
            // signatures (only code). We only need to set the tab2,tab3 and ltab settings (tab is
            // for class members).
            // trigger an error if used.
            this.tab = null;
            // tab setting for instructions
            this.tab2 = "  ";
            // tab setting for switch cases
            this.tab3 = "";
            // tab setting for labels
            this.ltab = "";
        }
    };
    gen(new CodeBuilder(new TraceMethodVisitor(textifier), 0, "trace", "()V"));
    StringWriter writer = new StringWriter();
    textifier.print(new PrintWriter(writer));
    // Note textifier always adds a trailing newline
    return writer.toString();
}
Also used : StringWriter(java.io.StringWriter) Textifier(org.objectweb.asm.util.Textifier) TraceMethodVisitor(org.objectweb.asm.util.TraceMethodVisitor) PrintWriter(java.io.PrintWriter)

Example 22 with Textifier

use of org.objectweb.asm.util.Textifier 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)

Example 23 with Textifier

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

the class AsmVerify method printAnalyzerResult.

static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException {
    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()));
            }
        }
        try {
            // mv.text.get(j));
            pw.printf(format, j, s, buf.get(t));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    for (TryCatchBlockNode tryCatchBlockNode : method.tryCatchBlocks) {
        tryCatchBlockNode.accept(mv);
        try {
            pw.print(" " + buf.get(t));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    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)

Example 24 with Textifier

use of org.objectweb.asm.util.Textifier in project quasar by puniverse.

the class Retransform method dumpClass.

public static void dumpClass(String className, byte[] data) {
    System.err.println("DUMP OF CLASS: " + className);
    ClassReader cr = new ClassReader(data);
    ClassVisitor cv = new TraceClassVisitor(null, new Textifier(), new PrintWriter(System.err));
    cr.accept(cv, ClassReader.SKIP_FRAMES);
    System.out.println("=================");
}
Also used : TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassReader(org.objectweb.asm.ClassReader) TraceClassVisitor(org.objectweb.asm.util.TraceClassVisitor) ClassVisitor(org.objectweb.asm.ClassVisitor) Textifier(org.objectweb.asm.util.Textifier) PrintWriter(java.io.PrintWriter)

Example 25 with Textifier

use of org.objectweb.asm.util.Textifier in project groovy by apache.

the class LoggableTextifier method visitParameterAnnotation.

@Override
public Textifier visitParameterAnnotation(int parameter, String desc, boolean visible) {
    Textifier t = super.visitParameterAnnotation(parameter, desc, visible);
    log();
    return t;
}
Also used : Textifier(org.objectweb.asm.util.Textifier)

Aggregations

Textifier (org.objectweb.asm.util.Textifier)32 PrintWriter (java.io.PrintWriter)15 StringWriter (java.io.StringWriter)10 TraceClassVisitor (org.objectweb.asm.util.TraceClassVisitor)10 ClassReader (org.objectweb.asm.ClassReader)8 TraceMethodVisitor (org.objectweb.asm.util.TraceMethodVisitor)8 IOException (java.io.IOException)5 ClassWriter (org.objectweb.asm.ClassWriter)4 File (java.io.File)3 ClassVisitor (org.objectweb.asm.ClassVisitor)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 DrillConfig (org.apache.drill.common.config.DrillConfig)2 QueryClassLoader (org.apache.drill.exec.compile.QueryClassLoader)2 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)2 LocalPersistentStoreProvider (org.apache.drill.exec.store.sys.store.provider.LocalPersistentStoreProvider)2 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)2