Debugging JVMTI agents

Hi everybody.

I just wrote a really simple agent used to instrument classes at method entries and exits (did it modifying a little the java_crw_demo from jdk6 demo code so that i could change instrumenting methods signatures).

Everything worked perfectly fine until I decided to add some cryptography to the behaviour of the instrumenting methods, and now my agent seems to get stuck (see http://forum.java.sun.com/thread.jspa?threadID=5128421 if you are interested in the details).

My question is: is it possible to debug an agent or the java code called from within it? Maybe I missed something but I cannot use neither jConsole nor Eclipse remote debugger. It says that it can't connect to the JVM. As far as I know Mustang release supports multiple agents...

Any hints?

Vale

[817 byte] By [SpookyValea] at [2007-11-26 16:48:29]
# 1

> My question is: is it possible to debug an agent or

> the java code called from within it? Maybe I missed

> something but I cannot use neither jConsole nor

> Eclipse remote debugger. It says that it can't

> connect to the JVM. As far as I know Mustang release

> supports multiple agents...

> Any hints?

It should be possible. I do not think there is any restriction imposed now

in jvmti. Can you give more information on how we can reproduce this.

Can you paste the exact error msg you see when you try to connect

the jconsole or other debugger.

swamyva at 2007-7-8 23:16:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

OK, I'll try to explain more in detail.

My agent is launched with the option -agentlib: java -agentlib:myAgent -Xbootclasspath/a:myJar.jar someAppl

where myAgent is the agent library (a dll in my case as I'm working with windows) and myJar contains the classes the agent uses to instrument methods.

If I run jConsole, I have a list of active processes I can connect to, but the process associated to my application is dimmed and it is impossible for me to connect to it (a note says that management agent is not enabled in that process). Even if I add the -Dcom.sun.management.jmxremote

option to the launch options, nothing changes.

With Eclipse Debugger, I tried to debug the application in 2 ways:

- launching the application in debug mode from eclipse itself adding the VM options stated above in the VM argument field. It says 揷an抰 connect to the VM?

- launching the application from a cmd shell (adding -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,suspend=y,server=y to let the appl wait for the debugger) and then starting the remote debugger. Result is: 揤M connection refused?(btw, the appl starts anyway even if suspend=y)

Basically I tired anything that came to my mind, it seems that using my agent I prevent other agents to attach to the application, but I don抰 know what to do (eventually how to change the agent) to prevent this.

SpookyValea at 2007-7-8 23:16:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 3

I suspect the code is stuck in your agent and has not returned back to vm.

Try to use -Dcom.sun.management first and the debugger -agentlib:...

then put -agentlib:myagent. See if it makes any difference.

Run jstack and see what is happening? See what is your agent code

executing?

swamyva at 2007-7-8 23:16:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 4

That made the trick!

Now that you make me think about it, it was so simple... but being the first time I have to deal with jvmti, I was so sure it was due to some error in my code! :)

I couldn't attach the agent because I called the "never returning" method from the vmInit callback (still to understand why it behaves that way though... but I'm working on it now!). I moved it to a callback that is called later on and now I can attach other agents (I am about to try with a debugger).

Thanks,

Vale

SpookyValea at 2007-7-8 23:16:01 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...