Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javassist';在错误的字节码位置插入(行,src)仪器代码_Java_Instrumentation_Javassist_Javaagents - Fatal编程技术网

Javassist';在错误的字节码位置插入(行,src)仪器代码

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

我的目标是在每个基本代码块的开头插入一点插装代码。使用Javaassist的ControlFlow.Block和CtMethod.insertAt()似乎是一项相当简单的任务。以下是到目前为止相关的代码块(位于transform函数中):

请注意,
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