Posts

Showing posts from October, 2011

Linux - GDB to debug JNI with Tomcat

To debug native code in JNI with GDB, you can do the following


1. Get process ID - first you must know the Java process id for your application


ps -ef | grep java


2. Connect GDB to Java


gdb -p


or


(gdb) attach prog_port


3. If your .so is built with debug information, you should see the following when gdb load the process. To get debug information into your .so, you can use gcc or g++ with -g



Reading symbols from your_debug.so...done.

Loaded symbols for your_debug.so


4. Add your source directory for debugging


(gdb) dir /your/src/path


Below are some abstract from GNU


directory dirname ... dir dirname ...

Add directory dirname to the front of the source path. Several directory names may be given to this command, separated by `:' (`;' on MS-DOS and MS-Windows, where `:' usually appears as part of absolute file names) or whitespace. You may specify a directory that is already in the source path; this moves it forward, so GDB searches it sooner. You can use the string `$cdir' to refer t…