addr2line
addr2line is a command line tool used in various operating systems, including Linux, to convert memory addresses into file names and line numbers of the corresponding program's source code. It is typically used for debugging purposes.
The tool takes two main arguments: the memory address and the name of the executable file. With this information, addr2line retrieves the program's debug information, which includes mappings of memory addresses to source code locations.
When provided with a memory address, addr2line uses the debug information to determine the file name and line number of the corresponding source code location where the address refers to. It can work with both statically and dynamically linked executables.
The tool is particularly useful when analyzing core dumps or crash logs, as it helps developers pinpoint the exact location in the code where an error occurred. It aids in diagnosing and fixing bugs more efficiently.
addr2line supports several options to specify the output format, such as displaying function names, source file names, or line numbers. These options make the tool adaptable to various debugging scenarios.
While primarily used for C and C++ programs, addr2line can also work with other languages that produce compatible debugging information, such as Rust or Ada.
The debug information that addr2line relies upon is generated during the compiling and linking process. It requires the inclusion of debug symbols in the executable, which can be enabled with compiler flags such as -g.
addr2line can be used both interactively in a terminal session and programmatically within scripts or other debugging tools. Its simplicity and effectiveness make it a handy tool for software developers and system administrators.
List of commands for addr2line:
-
addr2line:tldr:27dd0 addr2line: Demangle the function name for C++ code.$ addr2line --exe=${path-to-executable} --functions --demangle ${address}try on your machineexplain this command
-
addr2line:tldr:40afc addr2line: Display the function name, filename and line number.$ addr2line --exe=${path-to-executable} --functions ${address}try on your machineexplain this command
-
addr2line:tldr:b9170 addr2line: Display the filename and line number of the source code from an instruction address of an executable.$ addr2line --exe=${path-to-executable} ${address}try on your machineexplain this command