Debugging JNI code with GDB

Source: Internet
Author: User

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.

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.