-
-
Notifications
You must be signed in to change notification settings - Fork 604
Connecting java debugger to JVM inside OSv
First you need to change the command line so that JVM will be started with debugger interface exposed. To do so we need to add 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 you don't know what are the current arguments you can query them 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
Once the JVM starts the debugger server it will print
Listening for transport dt_socket at address: 5005
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