Here is the situation:
I have a client’s java project open in eclipse. It uses a JNI library created by an Xcode Objective C project. Is there any good way for me to debug the C code from eclipse when I execute the Java code? Obviously eclipse’s default debugger cannot step into the jni library file and we lose the thread (thread meaning investigative thread here, not programming thread).
Any advice or input is appreciated as the code base is large enough that following the client’s code will be radically faster than other options.
Thanks.
EDIT:
It should be noted that the reason that the jni library is written in Objective-C is because it is integrating with Mac OSX. It is using the Cocoa framework to integrate with the Apple speech api.
I am not sure that I have fully understood your setup and if you require this to be done from eclipse or not. Anyhow I was interested in doing a little test program using JNI and a Cocoa library doing nothing just to try the debugging of the obj-c/c code.
I succeeded to do this setup and also to debug the code. I use IntelliJ for Java and Xcode for the objc/c part but doing the java part in eclipse is a no-brainer.
So you should be able to set up exactly my project structure and get going with the debugging. And from there you should be able to apply this knowledge to your own more complex code.
This is how I started off:
libnativeand make it of Type Dynamic.Choose a place for your new project. I use
~/Development/and skip theCreate local git...part.This will create a new project called
lib native.xcodeprojin your selected folder. Two files have been automatically created:libnative.handlibnative.m.First you must change the Project Settings.
Executable Extensionin thePackagingsection must be changed fromdynlibtojnilib.Framework Search Pathsin theSearch Pathssection must be updated to point to the JNI framework:/System/Library/Frameworks/JavaVM.framework/Frameworks/JavaNativeFoundation.framework/<JavaVM/jni.h>. Update thelibnative.mto look like the following code:Build the code by pressing ⌘+B.
And now it is time to create the Java code. I simply created a class called Main in package
com.stackoverflow.com.stackoverflow.Main.javaMain.print();. Start the debugger with the following JVM option:This line is a little long and also user specific. You will have to look for yourself what the directory names are but they will be more or less the same as mine except for the generated
libnative-cquleqohzyhghnercyqdwpnznjdfpath.The program should be running and waiting at the breakpoint. Time to attach the Xcode debugger to the running application.
Choose menu
Product->Attach to Process >and point to the runningjavaprocess in theSystempart of the drop down. If there are severaljavaprocesses then it is most likely the one with the highest PID but not always. You’ll have to try.Create a breakpoint in the c code on the line
printf("Hello from C");.Go back to the Java IDE and continue the execution from where it was halting.
Go back to Xcode and see that it is waiting at the breakpoint!
As I stated earlier this is a very simple approach to the obj-c/JNI and your project is probably quite large but with this small test project you can at least see how it works and then continue to your own project setup.