本文整理汇总了Java中org.objectweb.asm.util.TraceMethodVisitor类的典型用法代码示例。如果您正苦于以下问题:Java TraceMethodVisitor类的具体用法?Java TraceMethodVisitor怎么用?Java TraceMethodVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TraceMethodVisitor类属于org.objectweb.asm.util包,在下文中一共展示了TraceMethodVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dump
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
private static void dump(MethodNode method) {
Textifier textifier = new Textifier();
method.accept(new TraceMethodVisitor(textifier));
StringWriter writer = new StringWriter();
try (PrintWriter pw = new PrintWriter(writer)) {
textifier.print(pw);
}
System.out.println(writer.toString());
}
示例2: visitEnd
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public void visitEnd() {
try {
accept(inner);
super.visitEnd();
} catch(Exception e){
Textifier t = new Textifier();
accept(new TraceMethodVisitor(t));
StringBuilderWriter sw = new StringBuilderWriter();
PrintWriter pw = new PrintWriter(sw);
t.print(pw);
pw.flush();
String bytecode = sw.getBuilder().toString();
logger.error(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
}
}
示例3: viewByteCode
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
/**
* 格式化输出字节码
* @param bytecode
*/
public static void viewByteCode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
final List<MethodNode> mns = cn.methods;
Printer printer = new Textifier();
TraceMethodVisitor mp = new TraceMethodVisitor(printer);
for (MethodNode mn : mns) {
InsnList inList = mn.instructions;
System.out.println(mn.name);
for (int i = 0; i < inList.size(); i++) {
inList.get(i).accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
System.out.print(sw.toString());
}
}
}
示例4: visitEnd
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public void visitEnd() {
super.visitEnd();
if (!found && errorNoMatch) {
StringWriter output = new StringWriter();
PrintWriter writer = new PrintWriter(output);
writer.append("Cannot find nodes");
if (methods.size() > 0) {
writer.append(" for methods ").append(methods.toString());
}
writer.println();
Printer printer = new Textifier();
TraceMethodVisitor visitor = new TraceMethodVisitor(printer);
for (AbstractInsnNode node : nodes) {
node.accept(visitor);
}
printer.print(writer);
throw new IllegalStateException(output.toString());
}
}
示例5: viewByteCode
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static void viewByteCode(byte[] bytecode) {
ClassReader cr = new ClassReader(bytecode);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
final List<MethodNode> mns = cn.methods;
Printer printer = new Textifier();
TraceMethodVisitor mp = new TraceMethodVisitor(printer);
for (MethodNode mn : mns) {
InsnList inList = mn.instructions;
System.out.println(mn.name);
for (int i = 0; i < inList.size(); i++) {
inList.get(i).accept(mp);
StringWriter sw = new StringWriter();
printer.print(new PrintWriter(sw));
printer.getText().clear();
System.out.print(sw.toString());
}
}
}
示例6: trace
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
/** 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).
this.tab = null; // trigger an error if used.
this.tab2 = " "; // tab setting for instructions
this.tab3 = ""; // tab setting for switch cases
this.ltab = ""; // tab setting for labels
}
};
gen(new CodeBuilder(new TraceMethodVisitor(textifier), 0, "trace", "()V"));
StringWriter writer = new StringWriter();
textifier.print(new PrintWriter(writer));
return writer.toString(); // Note textifier always adds a trailing newline
}
示例7: getMethodInstructionList
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static String getMethodInstructionList(final MethodNode methodNode) {
Preconditions.checkNotNull(methodNode, "methodNode");
final Printer printer = new NonMaxTextifier();
final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
methodNode.accept(traceMethodVisitor);
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
printer.print(printWriter);
printWriter.flush();
final String[] lines = PATTERN.split(stringWriter.toString());
int lineNr = 0;
for (int i = 0; i < lines.length; i++) {
if (!lines[i].startsWith(" @")) {
lines[i] = String.format("%2d %s", lineNr++, lines[i]);
}
}
return "Method '" + methodNode.name + "':\n"
+ NEWLINE.join(lines) + '\n';
}
示例8: setUp
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
jsr = new JSRInlinerAdapter(Opcodes.ASM5, null, 0, "m", "()V", null,
null) {
@Override
public void visitEnd() {
System.err.println("started w/ method:" + name);
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
for (int i = 0; i < instructions.size(); ++i) {
instructions.get(i).accept(mv);
System.err.print(Integer.toString(i + 100000).substring(1));
System.err.print(" : " + t.text.get(i));
}
super.visitEnd();
System.err.println("finished w/ method:" + name);
}
};
exp = new MethodNode(0, "m", "()V", null, null);
}
示例9: printMethod
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static void printMethod(PrintStream out, MethodNode method) {
final Textifier textifier = new Textifier();
final TraceMethodVisitor mv = new TraceMethodVisitor(textifier);
out.println(method.name + method.desc);
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
final StringBuffer s = new StringBuffer();
while (s.length() < method.maxStack + method.maxLocals + 1) {
s.append(' ');
}
out.print(Integer.toString(j + 100000).substring(1));
out.print(" " + s + " : " + textifier.text.get(j));
}
for (int j = 0; j < method.tryCatchBlocks.size(); ++j) {
((TryCatchBlockNode) method.tryCatchBlocks.get(j)).accept(mv);
out.print(" " + textifier.text.get(method.instructions.size()+j));
}
out.println(" MAXSTACK " + method.maxStack);
out.println(" MAXLOCALS " + method.maxLocals);
out.println();
}
示例10: setUp
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
protected void setUp() throws Exception {
super.setUp();
jsr = new JSRInlinerAdapter(null, 0, "m", "()V", null, null) {
@Override
public void visitEnd() {
System.err.println("started w/ method:" + name);
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
for (int i = 0; i < instructions.size(); ++i) {
instructions.get(i).accept(mv);
System.err.print(Integer.toString(i + 100000).substring(1));
System.err.print(" : " + t.text.get(i));
}
super.visitEnd();
System.err.println("finished w/ method:" + name);
}
};
exp = new MethodNode(0, "m", "()V", null, null);
}
示例11: toString
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public String toString() {
triggerDelayedParsingIfNeccessary();
TraceMethodVisitor visitor = new TraceMethodVisitor(new Textifier());
node.accept(visitor);
StringWriter writer = new StringWriter();
visitor.p.print(new PrintWriter(writer));
return writer.toString();
}
示例12: traceMethod
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public void traceMethod(String className, final String method) {
new ClassReader(inMemoryClassFileManager.classBytes(className)).accept(
new ClassVisitor(Opcodes.ASM5) {
PrintWriter pw = new PrintWriter(System.out);
Textifier p = new Textifier();
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if(name.equals(method)) {
p.visitMethod(access, name, desc, signature, exceptions);
return new TraceMethodVisitor(p);
}
return null;
}
@Override
public void visitEnd() {
p.visitClassEnd();
if (pw != null) {
p.print(pw);
pw.flush();
}
}
},
ClassReader.SKIP_FRAMES
);
}
示例13: toString
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public String toString() {
Textifier t = new Textifier();
accept(new TraceMethodVisitor(t));
StringWriter sw = new StringWriter();
t.print(new PrintWriter(sw));
return sw.toString();
}
示例14: visitMethod
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (method.matches(name, desc)) {
Printer localPrinter = asmifier.visitMethod(access, name, desc, signature, exceptions);
return new TraceMethodVisitor(null, localPrinter);
}
return null;
}
示例15: toString
import org.objectweb.asm.util.TraceMethodVisitor; //导入依赖的package包/类
public static String toString(MethodNode mn) {
TraceMethodVisitor tcv = new TraceMethodVisitor(null, new Textifier());
mn.accept(tcv);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println(mn.name + " " + mn.desc);
tcv.p.print(pw);
pw.flush();
return sw.toString();
}