我正在使用 BCEL 尝试将 System.out.println() 调用添加到每个方法的第一行(init 和 clinit 方法除外),以查看调用了哪些方法以及何时调用
这是我的代码 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")));
编辑后的类在字节码中看起来不错,但由于某种原因,该类在此之后将无法工作。有什么我做错了吗?