I have a Java Project in which I used Native Library (dll) whose code is written in CPP. I want to debug the java application and as soon as I reach to a point from where the native method compiled in dll called I want to step into the CPP code. How should I do this? Is there Any IDE available that can switch debugging between java and cpp code?
Generate a header file for the native method using javah with the native interface flag -jni . Once you've generated the header file you have the formal signature for your native method. Write the implementation of the native method in the programming language of your choice, such as C or C++.
Don't know of any debugger that can actually switch but you can attach two debuggers to your process. Starting your Java program in your Java IDE in debug mode attaches the Java debugger. Then open the IDE you use for your CPP code and attach its debugger to the running Java process.
In Visual Studio this would be Debug -> Attach to Process...
. You get a dialog with a process list. Choose your Java process here. You might have to switch the field just above the list to "Native code" if Visual Studio can't detect that correctly. Set an appropriate breakpoint in your CPP code and the debugger will stop there. Make sure your Java process loads the debug version of the library for this to work.
This also works for Eclipse: start debugging the "enveloping Java application" that invokes the .dll (or .so, on Linux), set a breakpoint at the accessory native call and start second debugger from the native process that is started there.... Result is: 2 debuggers, one running in Java and the second in the native .dll/.so... when the latter is finished and returns to Java again, it should be possible to resume Java debugging from there. In my environment, this setup works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With