Java中类仪器化后断点不触发?

huangapple go评论72阅读模式
英文:

Java Breakpoints not firing after instrumenting class?

问题

在我使用自定义的Java代理对一些类进行了仪器化之后,在Intellij IDEA中断点不再触发。我知道当类被仪器化时,断点会被移除(至少在Hotspot JVM中是这样)。但是我尝试在仪器化完成后的代码中插入新的断点,它们也不会触发。如何解决这个问题?

更新:方法断点可以正常触发,所以我认为在仪器化之后,行号可能不匹配,这就是为什么断点设置在错误的位置(?)并且它们不会触发的原因。但是我尝试在我的类的每一行上设置行断点,但没有一个触发。

英文:

After I instrument some classes with my custom Java agent, breakpoints are not firing inside Intellij IDEA anymore. I know that when classes are instrumented, breakpoints are removed(Hotspot JVM at least)...But I tried to insert new breakpoints in the code after instrumentation is done and they won't fire either. How to overcome this issue?

UPDATE: Method breakpoints fire just fine, so I think that after instrumentation, lines are mismatching that's why breakpoints are set at wrong locations(?) and that's why they are not firing. But I tried setting line breakpoints on every single line of my class and none of them is fired.

答案1

得分: 1

有几个导致断点无法命中的原因,比如运行时 JVM 的版本错误或者生成的类中移除了调试信息。

然而,更常见的情况是断点无法命中是因为 .java.class 不同步。换句话说,编译后的代码与源代码不完全相同。

断点是按行号设置的,因此如果源代码和编译后的代码不同步,行号不匹配,断点可能会指向一个在远程系统上不是有效断点候选项的行号,例如一个不可执行的行。在这种情况下,断点不会被设置,并且似乎被跳过。

在编译/构建之前,您可以尝试首先清理项目。

英文:

There are several reasons for breakpoints not being hit such as a wrong version of the runtime JVM or debug information being removed from the generated class.

However, more often than not, failure to hit a breakpoint means that the .java and the .class are out of sync. In other words, the compiled code is not exactly the same as the source code.

Breakpoints are set by line number thus if the source and the compiled code is out of sync and line numbers don't match, the breakpoints could point to a line number that is not a valid candidate for a breakpoint on the remote system e.g one that is not executable. In such a case the breakpoint would not be set and appears to be skipped.

You can try cleaning the project first before compiling/building

huangapple
  • 本文由 发表于 2020年8月2日 02:53:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/63208942.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定