Debugging native code with Hotspot and GDB

The last couple of hours I struggled to debug a segfault some JNI code of OpenJDK. I could not get GDB doing anything useful with Hotspot. Until I discovered the following very useful command line option:

java -XX:OnError="gdb - %p" MyApplication

This fires up gdb whenever an error occurs, and sets up all the libraries etc for debugging. Very nice. Ideally you do this using a debug build of OpenJDK, so get get as much useful information as possible.

2 Responses to “Debugging native code with Hotspot and GDB”

    -->
  1. Mario Torre Says:

    Yeah, that’s useful, I had same troubles with hotspot and java-gnome few weeks ago, and debugging it the “usual” way was not really the best option.

  2. -->
  3. gbenson Says:

    Oh, nice! I usually set LD_LIBRARY_PATH but this way is much simpler.

Leave a Reply