This article link: http://blog.csdn.net/kongxx/article/details/7329515
Recently encountered a JNI code constantly appear core dump, with GDB looked at the core file, the information is not very clear, so think of the run is debug JNI code
, there is a little work to do with the JNI code for dynamic Debug, as follows:
1. First modify the Java parameters, add-xdebug-xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=n as Java parameters, where 8888 is the port number, suspend =n means that Java starts without waiting for a client to debug the connection, and if its own program calls JNI when it starts, you can set its value to Suspend=n so that the Java process starts and waits for clients like Eclipse to debug remotely, After the remote debugging connection to Eclipse, Java continues to go down, so the modified Run command resembles the following statement
$ java-xms64m-xmx512m-xdebug-xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=n MyClass
2. Set breakpoints in Java where the JNI code needs to be invoked, and then use Eclipse Remote Debugging to connect to the machine and port where the Java program is running;
3. Wait until eclipse connects, at the command line, look at the process PID of the Java program started above;
4. Using GDB to connect the above process, the commands are as follows
$ gdb-p <pid>
5. Set breakpoints in the JNI method location that needs to be debugged as follows:
(GDB) Break <method_name>
6. You can then use the various GDB commands to debug and print each variable.