addr2line Command Examples in Linux

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.

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