llvm-symbolizer.rst 9.9 KB

llvm-symbolizer - convert addresses into source code locations

SYNOPSIS

:program:`llvm-symbolizer` [options] [addresses...]

DESCRIPTION

:program:`llvm-symbolizer` reads object file names and addresses from the command-line and prints corresponding source code locations to standard output.

If no address is specified on the command-line, it reads the addresses from standard input. If no object file is specified on the command-line, but addresses are, or if at any time an input value is not recognized, the input is simply echoed to the output.

A positional argument or standard input value can be preceded by "DATA" or "CODE" to indicate that the address should be symbolized as data or executable code respectively. If neither is specified, "CODE" is assumed. DATA is symbolized as address and symbol size rather than line number.

Object files can be specified together with the addresses either on standard input or as positional arguments on the command-line, following any "DATA" or "CODE" prefix.

:program:`llvm-symbolizer` parses options from the environment variable LLVM_SYMBOLIZER_OPTS after parsing options from the command line. LLVM_SYMBOLIZER_OPTS is primarily useful for supplementing the command-line options when :program:`llvm-symbolizer` is invoked by another program or runtime.

EXAMPLES

All of the following examples use the following two source files as input. They use a mixture of C-style and C++-style linkage to illustrate how these names are printed differently (see :option:`--demangle`).

// test.h
extern "C" inline int foz() {
  return 1234;
}
// test.cpp
#include "test.h"
int bar=42;

int foo() {
  return bar;
}

int baz() {
  volatile int k = 42;
  return foz() + k;
}

int main() {
  return foo() + baz();
}

These files are built as follows:

$ clang -g test.cpp -o test.elf
$ clang -g -O2 test.cpp -o inlined.elf

Example 1 - addresses and object on command-line:

$ llvm-symbolizer --obj=test.elf 0x4004d0 0x400490
foz
/tmp/test.h:1:0

baz()
/tmp/test.cpp:11:0

Example 2 - addresses on standard input:

$ cat addr.txt
0x4004a0
0x400490
0x4004d0
$ llvm-symbolizer --obj=test.elf < addr.txt
main
/tmp/test.cpp:15:0

baz()
/tmp/test.cpp:11:0

foz
/tmp/./test.h:1:0

Example 3 - object specified with address:

$ llvm-symbolizer "test.elf 0x400490" "inlined.elf 0x400480"
baz()
/tmp/test.cpp:11:0

foo()
/tmp/test.cpp:8:10

$ cat addr2.txt
test.elf 0x4004a0
inlined.elf 0x400480

$ llvm-symbolizer < addr2.txt
main
/tmp/test.cpp:15:0

foo()
/tmp/test.cpp:8:10

Example 4 - CODE and DATA prefixes:

$ llvm-symbolizer --obj=test.elf "CODE 0x400490" "DATA 0x601028"
baz()
/tmp/test.cpp:11:0

bar
6295592 4

$ cat addr3.txt
CODE test.elf 0x4004a0
DATA inlined.elf 0x601028

$ llvm-symbolizer < addr3.txt
main
/tmp/test.cpp:15:0

bar
6295592 4

Example 5 - path-style options:

This example uses the same source file as above, but the source file's full path is /tmp/foo/test.cpp and is compiled as follows. The first case shows the default absolute path, the second --basenames, and the third shows --relativenames.

$ pwd
/tmp
$ clang -g foo/test.cpp -o test.elf
$ llvm-symbolizer --obj=test.elf 0x4004a0
main
/tmp/foo/test.cpp:15:0
$ llvm-symbolizer --obj=test.elf 0x4004a0 --basenames
main
test.cpp:15:0
$ llvm-symbolizer --obj=test.elf 0x4004a0 --relativenames
main
foo/test.cpp:15:0

OPTIONS

MACH-O SPECIFIC OPTIONS

EXIT STATUS

:program:`llvm-symbolizer` returns 0. Other exit codes imply an internal program error.

SEE ALSO

:manpage:`llvm-addr2line(1)`