In Android development, Java exceptions are intuitive, but dynamic library exceptions print addresses. The following method can be used to lock the faulty function.
Arm-eabi-addr2line-C-F-s-e dynamic library address can parse the address information of the original fault.
For example:
Arm-eabi-addr2line-C-F-s-e libpcmhost. So 0c480
Print:
_ Jnienv: callintmethod (_ jobject *, _ jmethodid *,...)
In backtrace, there are generally only some addresses. However, with the addr2line tool, you can find the correspondingCodeLine. The prerequisite is executable.ProgramOr the-G option is included in the dynamic link library compilation.
Specifically, there are two situations:
1. If the following line of Backtrace is located in an executable file, you can directly add addr2line-E <executable> <address>
2. If the backtrace to be followed is located in a dynamic link library, it is troublesome because the base address of the dynamic link library is not fixed. At this time, we should first find the memory map of the process. InLinuxThe memory map of the process can be obtained in the/proc/<pid>/maps file. Find the base address of the dynamic link library in this file, and then set the address in backtrace to the base address of the dynamic link library to get the offset address, finally, addr2line-E <shared library> <OFFSET address>.
Of course, you can use GDB to find the code line corresponding to the address. However, compared with addr2line, GDB needs to reproduce the bug phenomenon. For bugs that are not easy to reproduce, or bugs that are randomly reproduced, you can use addr2line to directly find the corresponding code line from backtrace, it does not need to be reproduced and is easier to use than GDB.