Use GDB to debug JNI code

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.