我正在與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