Debugging JNI Eclipse plug-ins
Previously I explained how to create a JNI plug-in for Eclipse, from Eclipse.
Here’s a basic recipe for how to debug such a plug-in.
- Launch one of your Java-side plug-ins as an Eclipse application.
- Go to Help -> About Carbide.c++ (or equivalent)
- Select Configuration Details
- Find eclipse.commands
- Copy the command line shown. Mine was -name Eclipse -showsplash 600 -product com.nokia.carbide.cpp.product -data P:\runtime-EclipseApplication -configuration "file:P:/carbide-ws/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/" -dev "file:P:/carbide-ws/.metadata/.plugins/org.eclipse.pde.core/Eclipse Application/dev.properties" -pdelaunch -os win32 -ws win32 -arch x86
- Put it into an editor and edit it. First make it into a single line, and insert quotes round multi-word arguments (as I have done above).
- Prepend this: -Xms40m -Xmx512m -jar "c:\program files\nokia\carbide.c++ v1.1\startup.jar". You may need to adjust slightly… use the startup.jar in the path of your Eclipse launcher binary. The bits before that are memory arguments to the VM. Get them out of the .ini file in the same directory. There may be other arguments there.
- You should now have all the arguments required for a javaw process to launch Eclipse.
- So, shut down the runtime Eclipse workspace.
- Find your native JNI project. Go to Debug. Choose Local C/C++ Application. In the name of the program to run, put the appropriate Java VM (in my case, "c:\Program Files\Nokia\Carbide.c++ v1.1\jre\bin\javaw.exe"). Under Program Arguments, put the complex arguments string you came up with.
- Now, you can click Debug and the runtime Eclipse workspace will launch, but running within GDB and the CDT debugger.
I have no idea whether you can actually set breakpoints. I don’t even know if you can debug crashes. Unfortunately I need to debug a debugging session, and gdb gets a bit stroppy about that. So the above recipe hasn’t actually proven useful to me yet, but I thought I’d post it in case anyone else did. (For all I know there’s a much simpler way anyway).
Note that it doesn’t allow stepping from Java to C code or anything fancy like that – this appears to be one of the Holy Grails of CDT/JDT interoperability…

January 16th, 2007 at 11:52 am
Hi,
Great blog entry. I’m into devloping stuff using JNI, but currently for Win32 and Unix. I.e. developing the platform depenent code using VC++ and Eclispe for the Java-portion.
Anyhow, you mention it is not possible to step from Java to native (C/C++) code. That is tru for most envrionemnts, but one I have come across. That is the Sun Studio C/C++ product from Sun Microsystems. I had a demo a few years back for Kongsberg (AWACS) where one of the features I showed them was the ability to step from Java code ‘into’ the native method. Very nice! Wonder when we will this in CDT?
See you at the plug-in fest next week…
January 16th, 2007 at 11:57 am
Yes, that would be terrific. I’m sure it will come one day. Thanks for the comment, and see you next week!
January 10th, 2008 at 12:30 pm
For the interested, Vivek Unune (http://serialize.blogspot.com/search/label/Eclipse) provides an excellent short video and explanation of how he was able to perform JNI debugging using Eclipse and VS2005, *including* setting breakpoints in *both* Java and C++ code!
Hope this is as useful for others as it was for me!
John