addr2line
Convert addresses to file and line numbers
TLDR
Display the filename and line number of the source code from an instruction address of an executable
Display the function name, filename, and line number
Demangle the function name for C++ code
SYNOPSIS
addr2line [options...] [executable] [{address} ...]
PARAMETERS
-a, --addresses
Display address before function and source info
-b bfdname, --target=bfdname
Set object file format (e.g., elf64-x86-64)
-C, --demangle[=style]
Demangle C++ symbols (styles: gnu-v3, lucid, etc.)
-e file, --exe=file
Specify executable or library file
-f, --functions
Include function names in output
-i, --inlines
Unwind and show inlined function locations
-p, --pretty-print
One address per line with index (stdin support)
-j dirs, --search-dirs=dirs
Colon-separated dirs to search for sources
-s, --basenames
Display only base names of sources
-A arch, --architecture=arch
Set target architecture
DESCRIPTION
addr2line is a utility from the GNU Binutils package that translates memory addresses in executables or libraries into human-readable source code locations, including file names, line numbers, and function names. It is essential for debugging crash dumps, stack traces, or logs containing hexadecimal addresses.
The tool parses debugging information (DWARF or STABS, typically from gcc -g) embedded in ELF, COFF, or other formats via the BFD library. Specify the target binary with -e or positionally, then provide addresses like 0x400123.
Example output for addr2line -e ./program 0x401abc:
/home/user/src/main.c:45 (main+0x1c).
Key features include C++ demangling (-C), function names (-f), inlined frames (-i), and pretty-printing multiple addresses (-p). It supports source path searching (-j) and various architectures. Often scripted or used with GDB for automated symbol resolution in post-mortem analysis.
CAVEATS
Requires unstripped binaries with debug info (-g). Invalid addresses return '?'; no runtime relocation support. Use with static addresses from core dumps.
EXAMPLE USAGE
addr2line -pf -e /bin/ls 0x457891
??:0 (main+0x123)
Reads addresses from stdin if none provided.
INPUT TIPS
Addresses as hex (0x prefix optional). Multiple via args or pipe: echo '0x123 0x456' | addr2line -p -e prog
HISTORY
Developed as part of GNU Binutils (since ~1990s); maintained by GNU Project. Key enhancements in binutils 2.20+ for DWARF4, inlines, and pretty-print.


