Search code examples
javadebuggingdlljava-native-interfacenative

How to debug native jni c++ code in eclipse with java project


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?


Solution

  • 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.