recipe № 024

Calling JNI methods from Threads and how to debug them using gdb

In this sample, I want to take a closer look at Threads and how to attach gdb to running JVM to debug the code.

Situation looks like this. We have a Java code that runs multiple Threads, and each Thread is calling some JNI code. To simplify things, I have one JNI method that calls different native functions depending on parameter’s value.

recipeno024

As you can see, in order to debug the code, we need to attach to running JVM process. Then, we can set breakpoints at locations inside native code.

You can download and run full sample code following way