javadebuggingprofilingjvmtiyourkit

How to debug a java app that uses a JVMTI agent to set breakpoint (Unable to get necessary JVMTI capabilities)


I would like to debug java applications that are using a jvmti agent I have written. This seems to only work if the jvmti agent is NOT trying to enable "can_generate_breakpoint_events" capabilities.

Trying to enable the breakpoint capabilities and starting the app in debug mode results in the following error:

ERROR: JVMTI: 98(Unknown): Unable to get necessary JVMTI capabilities. [..\src\agent.cpp:437]

Is there any way to debug an application that is using a jvmti agent that sets breakpoints as well?

I checked Java JVMTI doesn't work alongside -Xdebug -Xrunjdwp but the accepted answer does not seem to be correct as it really seems to depend on the enabled capabilities as well.

I know that profilers (like YourKit, etc) are using jvmti agents as well and still allow you to run your app in debug mode (well, maybe they are just not using the capabilities that lead to these conflicts).


Solution

  • Based on my current understaing the answer is actually the following. From the JVMTI doc:

    The potentially available capabilities of each JVM TI implementation are different. Depending on the implementation, a capability:

    • ...
    • may be possessed by only one environment at a time
    • ...

    Setting breakpoints and watchpoints seem to be the type of capability that can be possessed only by one environement.

    So the problem is that my agent is trying to claim can_generate_breakpoint capabilities but the debugger agent needs them as well. Hence there are two agents requesting these capabilities which leads to the error above.

    As a result to me this means that you can not debug a Java application that is started with a JVM TI agent that needs to be able to set breakpoints.

    The only theoretical solution I can think of is that my JVM TI agent additionally implements support for JDWP and allows a debugger to connect to it (which would be quite a project by itself I suppose)