我正在与BCEL一起尝试将System.out.println()调用添加到每个方法的第一行(init和clinit方法除外),以查看调用哪些方法以及当Java:使用BCEL向每个方法添加调试调用
这是我的代码的ATM(有一些伪):
Instruction ins = null;
f (first instruction is ALOAD_0) {
ins = get next instruction
} else {
ins = this instruction;
}
list.insert(ins, new GETSTATIC(cgen.getConstantPool().addFieldref("java/lang/System", "out", "Ljava/io/PrintStream;")));
list.insert(ins, new LDC(cgen.getConstantPool().addUtf8("debug message")));
list.insert(ins, new INVOKEVIRTUAL(cgen.getConstantPool().addMethodref("java/io/PrintStream", "println", "(Ljava/lang/String;)V")));
编辑的类的字节码,但由于某些原因,类将不会在这之后的工作看起来不错。有什么我做错了吗?
为此,只需在代码后面添加对MethodGen类的方法setMaxStack()的调用即可。 – 2011-01-28 21:56:31