Addr2line

From LQWiki
Jump to: navigation, search

addr2line shows file names and line numbers for a specified program addresses.

Example

  • Have a file main.cpp:
#include <iostream>
int main()
{
  std::cout << "hello world" << std::endl;
}
g++ main.cpp
  • show it disassembled:
objdump -M intel -d a.out
[...]
00000000004007c0 <_init>:
  4007c0:       48 83 ec 08             sub    rsp,0x8
  4007c4:       e8 47 01 00 00          call   400910 <call_gmon_start>
  4007c9:       e8 d2 01 00 00          call   4009a0 <frame_dummy>    
[...]
  • Now if you ask yourself from which library the call at 0x4007c0 comes, call:
# addr2line -e a.out 4007c0
/usr/src/packages/BUILD/glibc-2.9/cc-nptl/csu/crti.S:25

See also