addr2line: command not found

addr2line is a command-line utility in Linux that is used to convert addresses in an executable or shared object file into line numbers and file names. It is commonly used in combination with tools like gdb (the GNU debugger) and objdump to translate addresses of functions or variables in a program’s binary into their corresponding source code locations.

Here is an example of how addr2line might be used:

$ $ addr2line -e myprogram 0x4005e6
/path/to/myprogram.c:23

In this example, addr2line is used to translate the address 0x4005e6 in the executable file myprogram into a file name and line number. The output indicates that the address corresponds to line 23 in the file /path/to/myprogram.c.

addr2line can be used to translate addresses from both code and data sections of an executable or shared object file. It can also be used to translate addresses from core dumps or other types of memory dumps.

If you encounter the below error while running the addr2line command:

addr2line: command not found

you may try installing the below package as per your choice of distribution:

OS Distribution Command
OS X brew install binutils
Debian apt-get install binutils
Ubuntu apt-get install binutils
Alpine apk add binutils
Arch Linux pacman -S binutils
Kali Linux apt-get install binutils
CentOS yum install binutils
Fedora dnf install binutils
Raspbian apt-get install binutils

addr2line Command Examples

1. Display the filename and line number of the source code from an instruction address of an executable:

# addr2line --exe={{path/to/executable}} {{address}}

2. Display the function name, filename and line number:

# addr2line --exe={{path/to/executable}} --functions {{address}}

3. Demangle the function name for C++ code:

# addr2line --exe={{path/to/executable}} --functions --demangle {{address}}
Related Post