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.