• Post Reply Bookmark Topic Watch Topic
  • New Topic

Debugging JNI in HotSpot  RSS feed

 
Chase Bonham
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Debugging JNI in HotSpot. Is there a HotSpot option to do this?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think HotSpot (the Java just-in-time compiler) has much to do with debugging of JNI code.

To debug JNI code, the first thing to do is to ensure that your native libraries are built with full debug information. That's an option in the C++ (or whatever) compiler and linker used to build them.

Next, you need to find a suitable native debugger for your platform. For instance, gdb on Unix and Mac OS X, or Microsoft Visual Studio on Windows.

It may be possible to launch your Java application from the debugger, but I find it easier to launch the Java application in the normal way, then attach the debugger to it.

Note that native libraries typically only get loaded when the associated Java class gets loaded. You can't do things with the native libraries in the debugger until they are loaded. Once, they are loaded, you can set native breakpoints, examine data, look at native code call stacks etc.

If the problem with your native code manifests itself quickly after the Java program is started, you might have trouble attaching the native debugger soon enough. In this situation, you may like to run your Java program in a Java debugger (jdb), so you can set a breakpoint just after the native library loads. While it's stopped at that Java breakpoint, you can attach the native debugger. Sounds nasty, but actually not too difficult.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!