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.

Advertisements

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. gbenson says:

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: