0

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.

HuLu
  • 144
  • 1
  • 10
  • You can have both a Java debugger and a native debugger attached to the same process. Keep in mind that breaking in the native debugger will prevent the java debugger from working until you continue. – Botje Jul 12 '19 at 09:41
  • How can I have both a Java debugger and a native debugger attached to the same process. I am completely unfamiliar with this operation. – HuLu Jul 12 '19 at 09:48
  • Take a look here: https://youtu.be/8Cjeq4l5COU There is CLion used, but nothing prevents you from using anything else (e.g. gdb: http://www.owsiak.org/jni-debugging-extreme-way/) – Oo.oO Jul 12 '19 at 12:24

1 Answers1

4

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.

r3mus n0x
  • 5,954
  • 1
  • 13
  • 34
  • I have a question about your answer, what configuration I need to do in IDEA, in order for Java programs to be taken over, – HuLu Jul 12 '19 at 09:55
  • Nothing. Your native debugger can attach to any process in the system. – Botje Jul 12 '19 at 09:55
  • @HuLu, I don't think it actually matters as long as your native library is build in Debug configuration so you can get meaningful debugger output. You'll be able to attach in any case though. – r3mus n0x Jul 12 '19 at 09:58
  • As long as your build generates a PDB you can debug in release mode as well. – Botje Jul 12 '19 at 10:00
  • Take a look here: https://youtu.be/8Cjeq4l5COU There is CLion used, but nothing prevents you from using anything else (e.g. gdb: http://www.owsiak.org/jni-debugging-extreme-way/) – Oo.oO Jul 12 '19 at 12:23