Search code examples
visual-studiodebuggingintellij-ideajava-native-interface

How JNI programs can be debugged jointly in IDEA and Visual Studio environments


I am writing a JNI program, but I am having problems with the program and the data is not as expected. Java programs are launched in the IDEA environment. As the program keeps running, when the code executes to a breakpoint, this breakpoint is where java calls the dynamic library. I want visual studio to take over the program so that I can debug and observe the data.

I use google to search for a solution, I don't see the corresponding graphic tutorial, I am not sure if this solution is feasible.

If you can debug, any code can

If you can, I hope that you can provide a graphic tutorial, or suggest some steps, thank you very much.


Solution

  • After starting you Java application in IDEA and stopping at the breakpoint in Java code you need to attach the Visual Studio debugger to the running java process. The general approach is described here.

    You should pay close attention to attach to the correct java process since there are usually several of them (including IDEA's). You can distinguish them by ID which is actually not that easy to find out in IDEA, but I think you can do it directly from your Java code as described here.

    After successfully attaching to your process you can set up whatever breakpoints you need in your native code and then resume the application in both IDEs.