How to find the corresponding code line from the backtrace log

Source: Internet
Author: User
It seems that many people do not know, so write it.

 

In backtrace, there are generally only some addresses. However, with the addr2line tool, you can find the corresponding code line. The precondition is that the-G option is included when the executable program or dynamic link library is compiled.

 

Specifically, there are two situations:

 

If the backtrace line to be followed is located in an executable file, you can directly add addr2line-E <executable> <address> If the followed backtrace is located in a dynamic link library, this 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. In Linux, the 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.

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.