-
-
Notifications
You must be signed in to change notification settings - Fork 604
Connecting java debugger to JVM inside OSv
Tomasz Grabiec edited this page Oct 10, 2013
·
7 revisions
First you need to start the JVM with debugger interface exposed by passing the following JVM option:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
Where:
-
transport=dt_socket,server=y
means we want to start a debugger server listening on TCP socket. -
suspend=n
means the JVM should not wait for a debugger to connect. You can change toy
if you want to connect a debugger before any java code starts executing. -
address=5005
means the server will listen on port5005
on all interfaces.
To add the JVM option you need to edit the image like this:
$ scripts/imgedit.py setargs build/release/usr.img java.so -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 -jar /usr/mgmt/web-1.0.0.jar app prod
If your image is using default command and you don't know what the default is, you can query it like this:
$ scripts/imgedit.py getargs build/release/usr.img
java.so -jar /usr/mgmt/web-1.0.0.jar app prod
Because the debugger server is using TCP as transport you need to start OSv with networking enabled, eg:
sudo scripts/run.py -n -v
First you need to figure out the IP of your OSv guest. If you don't know what it is, look for the message of the following form in OSv's console:
[I/329 dhcp]: Configuring eth0: ip 192.168.122.89 subnet mask 255.255.255.0 gateway 192.168.122.1
It means the guest was assigned 192.168.122.89.
After that you can use your favorite debugger to connect by pointing it to '192.168.122.89:5005'.
For example, using the JDK's command line debugger:
jdb -attach 192.168.122.89:5005