addr2line command in Linux with Examples
Last Updated :
23 Sep, 2024
‘addr2line’ command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the ‘objdump’ command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with their memory location (address). Using the addr2line command, one can map the address of the machine instruction to the line of the file from which it originated.
Syntax:
addr2line [options] [addr addr ...]
Basic addr2line command Example
For the examples, we will be using the ‘a.out’ file which is obtained after the following C program was compiled using ‘gcc’. 
We will also be using the de-assembled code of the ‘a.out’ executable file. The following command is used to get the ‘main’ part of the de-assembled code.
objdump -D a.out | grep -A20 main.:

Key Options of addr2line command
1. -e[file]:
The name of the executable for which addresses should be translated should be specified. The addresses from this file will be translated to their file name and line. (To exit the addr2line command, press ‘ctrl+c’)
addr2line -e a.out [addr1] [addr2]...
![-e[file]](https://media.geeksforgeeks.org/wp-content/uploads/20190327082941/addr21.png)
From this, we can infer the following:
- Only the code segment which is generated with the debug information could successfully generate a proper output.
- Not all offsets of a program will successfully give the correct filename and line number. Here, even though 651 is an offset present in the main function, it’s line and filename can’t be traced back.
2. -f:
The -f option prints the name of the function associated with each address. This is especially useful when debugging larger programs.
addr2line -e a.out -f [addr1] [addr2] ....
Example 1:

Example 2: C file used:

Note: The obj command is used along with ‘grep -A20 yolo.’ to display the unassembled segment of the yolo function, and the part after it.
From this, we can infer the following:
- If the file name and line can be mapped, then it is printed along with the function name. Here, the address 64a can be mapped both to the function and the file name + line.
- Even if the file name + line can’t be mapped, the name of the function, which the address is a part of, is still printed. Here, even though the address can’t be mapped to the filename and line, the function name is still printed.
3. -a, –addresses:
This option is used to show the address before the function name, file and line number information.
addr2line -e a.out -a [addr1] [addr2]...
4. -s, –basenames:
Displays only the base of the file names instead of the full file path. This can simplify the output if full paths aren’t needed.
addr2line -e a.out -s [addr1] [addr2]...
5. -j, –section:
Specifies a section to read offsets relative to that section, instead of absolute addresses. This can be used when working with relocatable object files.
addr2line -e a.out -j .text [addr1] [addr2]...
6. -p, –pretty-print:
This option formats the output to be more human-readable, often adding indentation or line breaks for clarity.
addr2line -e a.out -p [addr1] [addr2]...
Conclusion
The addr2line command is an essential tool for developers working with compiled code and debugging. It allows the mapping of memory addresses back to the original source code, providing insight into where specific machine instructions came from. With options to display function names, section offsets, and simplified file names, addr2line provides flexibility for debugging and analyzing executables.
Similar Reads
Linux Commands
Linux commands are essential for controlling and managing the system through the terminal. This terminal is similar to the command prompt in Windows. Itâs important to note that Linux/Unix commands are case-sensitive. These commands are used for tasks like file handling, process management, user adm
15+ min read
access command in linux with examples
The 'access' command in Linux is a system call used to determine whether the calling process has access to a specified file or directory. This function is useful for checking file permissions, including whether a file exists, and if it can be read, written, or executed by the process. The check is p
5 min read
accton command in Linux with Examples
'accton' is one of important Linux/Unix command which is used by the administrator to monitor user activities. It is used to turn on or turn off the process for accounting or change the info process accounting file. When the command is run in the terminal without any argument, it stops the process a
2 min read
aclocal command in Linux with Examples
aclocal command in Linux is used to automatically generate 'aclocal.m4' files from configure.in file. automake in Linux contain a lot of autoconf macros that can be used in the different packages. These macros must be defined in the aclocal.m4. If not, then it canât be accessed by the autoconf. The
3 min read
ACPI command in Linux with examples
ACPI is the command in Linux that helps the users in managing power settings. It also helps in monitoring the hardware status efficiently. It facilitates with providing essential information such as battery health, CPU temperatures, and fan speeds, providing support in system maintenance and perform
4 min read
acpi_available command in Linux with examples
acpi_available is a command in Linux that tests whether the ACPI (Advanced Configuration and Power Interface) subsystem is available or not. Syntax$ acpi_availableReturn Statuses of acpi_availableThe command returns one of three possible statuses: Status 0: Indicates that the ACPI subsystem is avail
2 min read
acpid command in Linux with Examples
The acpid daemon provides intelligent power management on a system and allows to query battery and configuration status by supporting the Advanced Configuration and Power Interface (ACPI). The ACPI events are notified to the user-space programs by acpid. The ACPI (Advanced Configuration and Power In
3 min read
addr2line command in Linux with Examples
'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
4 min read
agetty command in Linux with Examples
agetty is a Linux version of getty. getty short for "get tty" is a Unix program running on a host computer that manages physical or virtual terminals to allow multi-user access. Linux provides a virtual terminal(tty) which is similar to the regular Linux terminal. agetty command opens a virtual term
4 min read
How to Create and Use Alias Command in Linux
Imagine you're lost in a maze of complicated Linux commands. You stumble upon a secret doorway marked "Alias," and inside you find shortcuts to all your favorite commands! That's what creating aliases is like. You get to make your own mini-commands for the long ones you use all the time, making thin
6 min read