Javassist';在错误的字节码位置插入(行,src)仪器代码
我的目标是在每个基本代码块的开头插入一点插装代码。使用Javaassist的ControlFlow.Block和CtMethod.insertAt()似乎是一项相当简单的任务。以下是到目前为止相关的代码块(位于transform函数中): 请注意,Javassist';在错误的字节码位置插入(行,src)仪器代码,java,instrumentation,javassist,javaagents,Java,Instrumentation,Javassist,Javaagents,我的目标是在每个基本代码块的开头插入一点插装代码。使用Javaassist的ControlFlow.Block和CtMethod.insertAt()似乎是一项相当简单的任务。以下是到目前为止相关的代码块(位于transform函数中): 请注意,CtMethod.insertAt(line,srcCode)中的“line”参数是源代码行位置,而不是字节码行位置。在源代码中,一些基本块报告相同的行号!以下是输出: At 6: { _JDA_mse.setBlockIndex(0); } -&g
CtMethod.insertAt(line,srcCode)
中的“line”参数是源代码行位置,而不是字节码行位置。在源代码中,一些基本块报告相同的行号!以下是输出:
At 6: { _JDA_mse.setBlockIndex(0); } -> 6
At 8: { _JDA_mse.setBlockIndex(1); } -> 8
At 8: { _JDA_mse.setBlockIndex(2); } -> 8
At 8: { _JDA_mse.setBlockIndex(3); } -> 8
At 8: { _JDA_mse.setBlockIndex(4); } -> 8
At 8: { _JDA_mse.setBlockIndex(5); } -> 8
At 8: { _JDA_mse.setBlockIndex(6); } -> 8
At#
表示我请求代码放置的位置,->#
表示它在源代码中实际插入的位置(如果一切正常,它们应该是相同的)。{…}
中的所有内容都是我想要放置的代码(\u JDA\u mse
是我用Javassist方法添加到函数中的局部变量,因此使用它没有问题)
问题在于,如果需要使用Javaassist插入的变量在字节码级别插入指令,请参见解决方法
At 6: { _JDA_mse.setBlockIndex(0); } -> 6
At 8: { _JDA_mse.setBlockIndex(1); } -> 8
At 8: { _JDA_mse.setBlockIndex(2); } -> 8
At 8: { _JDA_mse.setBlockIndex(3); } -> 8
At 8: { _JDA_mse.setBlockIndex(4); } -> 8
At 8: { _JDA_mse.setBlockIndex(5); } -> 8
At 8: { _JDA_mse.setBlockIndex(6); } -> 8