LinuxCommandLibrary

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

$ addr2line --exe=[path/to/executable] [address]
copy

Display the function name, filename and line number
$ addr2line --exe=[path/to/executable] --functions [address]
copy

Demangle the function name for C++ code
$ addr2line --exe=[path/to/executable] --functions --demangle [address]
copy

SYNOPSIS

addr2line [options] [address ...]

PARAMETERS

-a | --address
    Display the address before the file and line number information.

-b | --target=
    Specify the binary file format (BFD name) of the input file.

-C | --demangle[=style]
    Demangle low-level symbol names into user-level names. Optional 'style' argument selects a demangling style.

-e | --exe=
    Specify the executable file to use for debugging information. Defaults to 'a.out' if not provided.

-f | --functions
    Display function names as well as file and line number information.

-i | --inlines
    If the address belongs to an inlined function, the source information for all enclosing scopes back to the first non-inlined function will also be printed.

-j

| --section=

    Read offsets relative to the specified section.

-p | --pretty-print
    Make the output more human friendly: each location are printed on one line.

-s | --basenames
    Display only the base of each file name.

-S | --source-locations
    Display source code for debugging.

-v | --version
    Display the version number of addr2line.

-w | --wide
    Format the output to fit on a single line (may be truncated by some terminals).

-h | --help
    Display this help message.


    The memory address to look up.

DESCRIPTION

The addr2line command translates program addresses into file names and line numbers. Given an address and an executable, addr2line uses the debugging information in the executable to determine the source file and line number corresponding to that address. This is particularly useful when debugging crash dumps or stack traces, allowing developers to pinpoint the exact location in the source code where a problem occurred.
addr2line can accept multiple addresses at once, or read addresses from standard input. It's a crucial tool in the debugging workflow, bridging the gap between low-level memory addresses and human-readable code. The command is part of the GNU Binutils package. Its core function is to improve code debugging and understanding.

CAVEATS

addr2line relies on debugging information being present in the executable file. If the executable was stripped of debugging symbols (e.g., using `strip`), addr2line will be unable to provide accurate file and line number information.

USAGE EXAMPLES

Example: addr2line -e myprogram 0x400564
This will attempt to find source and line number information for address 0x400564 within the 'myprogram' executable.
Example with demangling: addr2line -C -e myprogram 0x400564
This attempt to demangle low-level symbol names into user-level names for C++ code. This is frequently required.

HISTORY

addr2line is part of the GNU Binutils, a package of binary utilities commonly used for software development on Unix-like systems. The development of Binutils and addr2line began in the early 1990s as part of the GNU project. Over the years, addr2line has become an essential tool for debugging and reverse engineering, finding its use in a wide range of software development environments and toolchains.

SEE ALSO

objdump(1), gdb(1)

Copied to clipboard