Attaching debugger to JVM created by JNI_CreateJavaVM

675 Views Asked by At

This is on Ubuntu 12.04/ Java 7, 64bit

Working on project to create java bindings for WebkitGtk Version 2. My primary interest in WebkitGTK is DOM access and manipulation as against just displaying web pages. For V2, WebkitGtk team changed architecture which allows DOM access via extensions. Extensions are loaded by WebKitWebProcess which is a separate process fired when webkit is started.

I got most of it under control. My extension is getting loaded and JVM is started and my java classes are getting loaded and mostly working as expected. Right now my debugging technique is basically println statements and/or log statements.

Wondering if I can attach a java debugger so that I can debug java code more easily. If I run jps command, PID of WebKitWebProcess does show up. So someone is aware that this process has JVM. Preferred debugger will be eclipse.

Basically it boils down to how to attach java debugger where VM is stared using JNI_CreateJavaVM and process is already running.

1

There are 1 best solutions below

0
On

Turned out to be very simple. When you create VM, just pass the debugger option as follows. Connect debugger to port 9836 and you in the debugger.

JavaVMOption options[3];
options[0].optionString = <your classpath>;
options[1].optionString = "-Xdebug";
options[2].optionString = "-agentlib:jdwp=transport=dt_socket,server=y,address=9836,suspend=n";