Link: http://blog.csdn.net/kongxx/article/details/7329515
Recently, I encountered a piece of JNICodeThe core dump keeps appearing. I used GDB to check the core file, and the information was not very clear. So I thought that the run was the debug JNI code.
For JNI code, it is still a little bit of work to do dynamic debug, as follows:
1. first, modify the Java parameter and add-xdebug-xrunjdwp: Transport = dt_socket, address = 8888, Server = Y, suspend = N as the Java parameter, where 8888 is the port number, suspend = n indicates that when Java is started, it does not wait for the client debug connection.ProgramJNI needs to be called as soon as it is started. Here we can set its value to suspend = N, so that the Java Process will start and wait for the client such as eclipse to perform remote debugging, java will continue after the remote debugging connection is equal to that of eclipse. Therefore, the modified running command is similar to the following statement.
$ Java-xms64m-xmx512m-xdebug-xrunjdwp: Transport = dt_socket, address = 8888, Server = Y, suspend = n myclass
2. Set the breakpoint where JNI code needs to be called in Java, and then use eclipse to remotely debug and connect to the machine and port on which the Java program runs;
3. Wait until eclipse is connected, and check the PID of the Java program process started above on the command line;
4. Use GDB to connect to the above process. The command is as follows:
$ GDB-P <pid> 5. set the position of the breakpoint in the JNI method to be debugged as follows:
(GDB) break <method_name> 6. then you can use various gdb commands to debug and print various variables.