Skip to content
Search

Addr2line

lastmod 2020-04-06created 2017-04-292 edits

addr2line uses debug information to obtain file names and line numbers.

How to use

The program must be compiled in advance to include debug information. In GCC, use the -g option.

#include <stdio.h>

void func(void)
{
    printf("func call\n");
}

int main(void)
{
    printf(" func addr %p\n", func);
}

Compile as follows.

$ gcc -g main.c

Run it.

$ ./a.out
func addr 0x8048414

Let's look at the simplest example.

$ addr2line -e a.out 0x8048414
/root/tmp/addr2line.c:4

Given the input file and an address, it prints the exact line being executed.

It can also print the function name.

$ addr2line -f -e a.out 0x8048414
func
/root/tmp/addr2line.c:4

addr2line also uses the BFD library to obtain debug information. addr2line can obtain the file name and line number from an address.

See also

author Zer0 sitemap