blob: 5c8465af04a7f3eeee6108c9b21f72904f2f2c7b [file] [log] [blame]
Alexey Samsonov2bc10122013-03-01 07:58:27 +00001llvm-symbolizer - convert addresses into source code locations
2==============================================================
3
James Hendersona0566842019-06-27 13:24:46 +00004.. program:: llvm-symbolizer
5
Alexey Samsonov2bc10122013-03-01 07:58:27 +00006SYNOPSIS
7--------
8
James Henderson512c5252019-06-26 11:42:03 +00009:program:`llvm-symbolizer` [*options*] [*addresses...*]
Alexey Samsonov2bc10122013-03-01 07:58:27 +000010
11DESCRIPTION
12-----------
13
James Henderson512c5252019-06-26 11:42:03 +000014:program:`llvm-symbolizer` reads object file names and addresses from the
15command-line and prints corresponding source code locations to standard output.
Alexey Samsonov2bc10122013-03-01 07:58:27 +000016
James Henderson512c5252019-06-26 11:42:03 +000017If no address is specified on the command-line, it reads the addresses from
18standard input. If no object file is specified on the command-line, but
19addresses are, or if at any time an input value is not recognized, the input is
20simply echoed to the output.
21
22A positional argument or standard input value can be preceded by "DATA" or
23"CODE" to indicate that the address should be symbolized as data or executable
24code respectively. If neither is specified, "CODE" is assumed. DATA is
25symbolized as address and symbol size rather than line number.
26
27Object files can be specified together with the addresses either on standard
28input or as positional arguments on the command-line, following any "DATA" or
29"CODE" prefix.
30
Petr Hosekdedad082019-12-18 10:19:47 -080031:program:`llvm-symbolizer` parses options from the environment variable
32``LLVM_SYMBOLIZER_OPTS`` after parsing options from the command line.
33``LLVM_SYMBOLIZER_OPTS`` is primarily useful for supplementing the command-line
34options when :program:`llvm-symbolizer` is invoked by another program or
35runtime.
36
James Henderson512c5252019-06-26 11:42:03 +000037EXAMPLES
Alexey Samsonov2bc10122013-03-01 07:58:27 +000038--------
39
James Henderson512c5252019-06-26 11:42:03 +000040All of the following examples use the following two source files as input. They
41use a mixture of C-style and C++-style linkage to illustrate how these names are
42printed differently (see :option:`--demangle`).
43
44.. code-block:: c
45
46 // test.h
47 extern "C" inline int foz() {
48 return 1234;
49 }
50
51.. code-block:: c
52
53 // test.cpp
54 #include "test.h"
55 int bar=42;
56
57 int foo() {
58 return bar;
59 }
60
61 int baz() {
62 volatile int k = 42;
63 return foz() + k;
64 }
65
66 int main() {
67 return foo() + baz();
68 }
69
70These files are built as follows:
71
72.. code-block:: console
73
74 $ clang -g test.cpp -o test.elf
75 $ clang -g -O2 test.cpp -o inlined.elf
76
77Example 1 - addresses and object on command-line:
78
79.. code-block:: console
80
81 $ llvm-symbolizer --obj=test.elf 0x4004d0 0x400490
82 foz
83 /tmp/test.h:1:0
84
85 baz()
86 /tmp/test.cpp:11:0
87
88Example 2 - addresses on standard input:
89
Alexey Samsonov2bc10122013-03-01 07:58:27 +000090.. code-block:: console
91
92 $ cat addr.txt
James Henderson512c5252019-06-26 11:42:03 +000093 0x4004a0
94 0x400490
95 0x4004d0
96 $ llvm-symbolizer --obj=test.elf < addr.txt
Alexey Samsonov2bc10122013-03-01 07:58:27 +000097 main
James Henderson512c5252019-06-26 11:42:03 +000098 /tmp/test.cpp:15:0
Alexey Samsonov2bc10122013-03-01 07:58:27 +000099
James Henderson512c5252019-06-26 11:42:03 +0000100 baz()
101 /tmp/test.cpp:11:0
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000102
James Henderson512c5252019-06-26 11:42:03 +0000103 foz
104 /tmp/./test.h:1:0
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000105
James Henderson512c5252019-06-26 11:42:03 +0000106Example 3 - object specified with address:
107
108.. code-block:: console
109
110 $ llvm-symbolizer "test.elf 0x400490" "inlined.elf 0x400480"
111 baz()
112 /tmp/test.cpp:11:0
113
114 foo()
115 /tmp/test.cpp:8:10
116
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000117 $ cat addr2.txt
James Henderson512c5252019-06-26 11:42:03 +0000118 test.elf 0x4004a0
119 inlined.elf 0x400480
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000120
James Henderson512c5252019-06-26 11:42:03 +0000121 $ llvm-symbolizer < addr2.txt
122 main
123 /tmp/test.cpp:15:0
124
125 foo()
126 /tmp/test.cpp:8:10
127
128Example 4 - CODE and DATA prefixes:
129
130.. code-block:: console
131
132 $ llvm-symbolizer --obj=test.elf "CODE 0x400490" "DATA 0x601028"
133 baz()
134 /tmp/test.cpp:11:0
135
136 bar
137 6295592 4
138
139 $ cat addr3.txt
140 CODE test.elf 0x4004a0
141 DATA inlined.elf 0x601028
142
143 $ llvm-symbolizer < addr3.txt
144 main
145 /tmp/test.cpp:15:0
146
147 bar
148 6295592 4
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000149
Sterling Augustine21d9d082020-03-20 13:28:50 -0700150Example 5 - path-style options:
151
152This example uses the same source file as above, but the source file's
153full path is /tmp/foo/test.cpp and is compiled as follows. The first case
154shows the default absolute path, the second --basenames, and the third
155shows --relativenames.
156
157.. code-block:: console
Benjamin Kramerebd52902020-04-13 14:39:25 +0200158
Sterling Augustine21d9d082020-03-20 13:28:50 -0700159 $ pwd
160 /tmp
161 $ clang -g foo/test.cpp -o test.elf
Benjamin Kramerebd52902020-04-13 14:39:25 +0200162 $ llvm-symbolizer --obj=test.elf 0x4004a0
Sterling Augustine21d9d082020-03-20 13:28:50 -0700163 main
164 /tmp/foo/test.cpp:15:0
165 $ llvm-symbolizer --obj=test.elf 0x4004a0 --basenames
166 main
167 test.cpp:15:0
168 $ llvm-symbolizer --obj=test.elf 0x4004a0 --relativenames
169 main
170 foo/test.cpp:15:0
Benjamin Kramerebd52902020-04-13 14:39:25 +0200171
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000172OPTIONS
173-------
174
James Henderson512c5252019-06-26 11:42:03 +0000175.. option:: --adjust-vma <offset>
Alexey Samsonovcd014722014-05-17 00:07:48 +0000176
James Henderson512c5252019-06-26 11:42:03 +0000177 Add the specified offset to object file addresses when performing lookups.
178 This can be used to perform lookups as if the object were relocated by the
179 offset.
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000180
James Henderson512c5252019-06-26 11:42:03 +0000181.. option:: --basenames, -s
Igor Kudrin99f641c2019-04-19 10:17:52 +0000182
Sterling Augustine21d9d082020-03-20 13:28:50 -0700183 Print just the file's name without any directories, instead of the
184 absolute path.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000185
Sterling Augustine21d9d082020-03-20 13:28:50 -0700186.. option:: --relativenames
187
188 Print the file's path relative to the compilation directory, instead
189 of the absolute path. If the command-line to the compiler included
190 the full path, this will be the same as the default.
191
Igor Kudrin99f641c2019-04-19 10:17:52 +0000192.. _llvm-symbolizer-opt-C:
193
James Henderson512c5252019-06-26 11:42:03 +0000194.. option:: --demangle, -C
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000195
James Henderson512c5252019-06-26 11:42:03 +0000196 Print demangled function names, if the names are mangled (e.g. the mangled
197 name `_Z3bazv` becomes `baz()`, whilst the non-mangled name `foz` is printed
198 as is). Defaults to true.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000199
James Henderson512c5252019-06-26 11:42:03 +0000200.. option:: --dwp <path>
Dmitry Venikov119cf662019-01-21 10:00:57 +0000201
James Henderson512c5252019-06-26 11:42:03 +0000202 Use the specified DWP file at ``<path>`` for any CUs that have split DWARF
203 debug data.
204
205.. option:: --fallback-debug-path <path>
206
207 When a separate file contains debug data, and is referenced by a GNU debug
208 link section, use the specified path as a basis for locating the debug data if
209 it cannot be found relative to the object.
210
211.. _llvm-symbolizer-opt-f:
212
James Henderson190707f2020-02-26 10:24:50 +0000213.. option:: --functions [=<none|short|linkage>], -f
James Henderson512c5252019-06-26 11:42:03 +0000214
215 Specify the way function names are printed (omit function name, print short
216 function name, or print full linkage name, respectively). Defaults to
217 ``linkage``.
218
219.. option:: --help, -h
220
221 Show help and usage for this command.
222
223.. option:: --help-list
224
225 Show help and usage for this command without grouping the options into categories.
Dmitry Venikov119cf662019-01-21 10:00:57 +0000226
Igor Kudrin99f641c2019-04-19 10:17:52 +0000227.. _llvm-symbolizer-opt-i:
228
James Henderson512c5252019-06-26 11:42:03 +0000229.. option:: --inlining, --inlines, -i
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000230
James Henderson512c5252019-06-26 11:42:03 +0000231 If a source code location is in an inlined function, prints all the inlined
232 frames. Defaults to true.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000233
James Henderson512c5252019-06-26 11:42:03 +0000234.. option:: --no-demangle
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000235
James Henderson512c5252019-06-26 11:42:03 +0000236 Don't print demangled function names.
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000237
James Henderson512c5252019-06-26 11:42:03 +0000238.. option:: --obj <path>, --exe, -e
Alexander Potapenko7aaf5142014-10-17 00:50:19 +0000239
James Henderson512c5252019-06-26 11:42:03 +0000240 Path to object file to be symbolized. If ``-`` is specified, read the object
241 directly from the standard input stream.
James Henderson759d5e62019-01-25 11:49:21 +0000242
Igor Kudrin99f641c2019-04-19 10:17:52 +0000243.. _llvm-symbolizer-opt-output-style:
244
James Henderson512c5252019-06-26 11:42:03 +0000245.. option:: --output-style <LLVM|GNU>
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000246
247 Specify the preferred output style. Defaults to ``LLVM``. When the output
248 style is set to ``GNU``, the tool follows the style of GNU's **addr2line**.
249 The differences from the ``LLVM`` style are:
250
James Henderson479c2182019-07-10 13:40:45 +0000251 * Does not print the column of a source code location.
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000252
253 * Does not add an empty line after the report for an address.
254
255 * Does not replace the name of an inlined function with the name of the
James Henderson512c5252019-06-26 11:42:03 +0000256 topmost caller when inlined frames are not shown and :option:`--use-symbol-table`
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000257 is on.
258
Sterling Augustinec64b5662020-01-23 17:51:33 -0800259 * Prints an address's debug-data discriminator when it is non-zero. One way to
260 produce discriminators is to compile with clang's -fdebug-info-for-profiling.
261
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000262 .. code-block:: console
263
James Henderson512c5252019-06-26 11:42:03 +0000264 $ llvm-symbolizer --obj=inlined.elf 0x4004be 0x400486 -p
265 baz() at /tmp/test.cpp:11:18
266 (inlined by) main at /tmp/test.cpp:15:0
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000267
James Henderson512c5252019-06-26 11:42:03 +0000268 foo() at /tmp/test.cpp:6:3
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000269
James Henderson512c5252019-06-26 11:42:03 +0000270 $ llvm-symbolizer --output-style=LLVM --obj=inlined.elf 0x4004be 0x400486 -p -i=0
271 main at /tmp/test.cpp:11:18
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000272
James Henderson512c5252019-06-26 11:42:03 +0000273 foo() at /tmp/test.cpp:6:3
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000274
James Henderson512c5252019-06-26 11:42:03 +0000275 $ llvm-symbolizer --output-style=GNU --obj=inlined.elf 0x4004be 0x400486 -p -i=0
276 baz() at /tmp/test.cpp:11
277 foo() at /tmp/test.cpp:6
278
Sterling Augustinec64b5662020-01-23 17:51:33 -0800279 $ clang -g -fdebug-info-for-profiling test.cpp -o profiling.elf
280 $ llvm-symbolizer --output-style=GNU --obj=profiling.elf 0x401167 -p -i=0
281 main at /tmp/test.cpp:15 (discriminator 2)
282
James Henderson512c5252019-06-26 11:42:03 +0000283.. option:: --pretty-print, -p
284
285 Print human readable output. If :option:`--inlining` is specified, the
286 enclosing scope is prefixed by (inlined by).
287
James Henderson6b747452020-02-26 10:29:47 +0000288 .. code-block:: console
James Henderson512c5252019-06-26 11:42:03 +0000289
James Henderson6b747452020-02-26 10:29:47 +0000290 $ llvm-symbolizer --obj=inlined.elf 0x4004be --inlining --pretty-print
291 baz() at /tmp/test.cpp:11:18
292 (inlined by) main at /tmp/test.cpp:15:0
James Henderson512c5252019-06-26 11:42:03 +0000293
294.. option:: --print-address, --addresses, -a
295
296 Print address before the source code location. Defaults to false.
297
James Henderson6b747452020-02-26 10:29:47 +0000298 .. code-block:: console
James Henderson512c5252019-06-26 11:42:03 +0000299
James Henderson6b747452020-02-26 10:29:47 +0000300 $ llvm-symbolizer --obj=inlined.elf --print-address 0x4004be
301 0x4004be
302 baz()
303 /tmp/test.cpp:11:18
304 main
305 /tmp/test.cpp:15:0
James Henderson512c5252019-06-26 11:42:03 +0000306
James Henderson6b747452020-02-26 10:29:47 +0000307 $ llvm-symbolizer --obj=inlined.elf 0x4004be --pretty-print --print-address
308 0x4004be: baz() at /tmp/test.cpp:11:18
309 (inlined by) main at /tmp/test.cpp:15:0
James Henderson512c5252019-06-26 11:42:03 +0000310
311.. option:: --print-source-context-lines <N>
312
313 Print ``N`` lines of source context for each symbolized address.
314
James Henderson6b747452020-02-26 10:29:47 +0000315 .. code-block:: console
James Henderson512c5252019-06-26 11:42:03 +0000316
James Henderson6b747452020-02-26 10:29:47 +0000317 $ llvm-symbolizer --obj=test.elf 0x400490 --print-source-context-lines=2
318 baz()
319 /tmp/test.cpp:11:0
320 10 : volatile int k = 42;
321 11 >: return foz() + k;
322 12 : }
James Henderson512c5252019-06-26 11:42:03 +0000323
324.. _llvm-symbolizer-opt-use-symbol-table:
325
326.. option:: --use-symbol-table
327
328 Prefer function names stored in symbol table to function names in debug info
329 sections. Defaults to true.
330
331.. option:: --verbose
332
333 Print verbose line and column information.
334
James Henderson6b747452020-02-26 10:29:47 +0000335 .. code-block:: console
James Henderson512c5252019-06-26 11:42:03 +0000336
James Henderson6b747452020-02-26 10:29:47 +0000337 $ llvm-symbolizer --obj=inlined.elf --verbose 0x4004be
338 baz()
339 Filename: /tmp/test.cpp
340 Function start line: 9
341 Line: 11
342 Column: 18
343 main
344 Filename: /tmp/test.cpp
345 Function start line: 14
346 Line: 15
347 Column: 0
James Henderson512c5252019-06-26 11:42:03 +0000348
349.. option:: --version
350
351 Print version information for the tool.
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000352
James Henderson9485b262019-06-21 11:49:20 +0000353.. option:: @<FILE>
354
James Henderson512c5252019-06-26 11:42:03 +0000355 Read command-line options from response file `<FILE>`.
356
357MACH-O SPECIFIC OPTIONS
358-----------------------
359
360.. option:: --default-arch <arch>
361
362 If a binary contains object files for multiple architectures (e.g. it is a
363 Mach-O universal binary), symbolize the object file for a given architecture.
364 You can also specify the architecture by writing ``binary_name:arch_name`` in
365 the input (see example below). If the architecture is not specified in either
366 way, the address will not be symbolized. Defaults to empty string.
367
James Henderson6b747452020-02-26 10:29:47 +0000368 .. code-block:: console
James Henderson512c5252019-06-26 11:42:03 +0000369
James Henderson6b747452020-02-26 10:29:47 +0000370 $ cat addr.txt
371 /tmp/mach_universal_binary:i386 0x1f84
372 /tmp/mach_universal_binary:x86_64 0x100000f24
James Henderson512c5252019-06-26 11:42:03 +0000373
James Henderson6b747452020-02-26 10:29:47 +0000374 $ llvm-symbolizer < addr.txt
375 _main
376 /tmp/source_i386.cc:8
James Henderson512c5252019-06-26 11:42:03 +0000377
James Henderson6b747452020-02-26 10:29:47 +0000378 _main
379 /tmp/source_x86_64.cc:8
James Henderson512c5252019-06-26 11:42:03 +0000380
381.. option:: --dsym-hint <path/to/file.dSYM>
382
383 If the debug info for a binary isn't present in the default location, look for
384 the debug info at the .dSYM path provided via this option. This flag can be
385 used multiple times.
James Henderson9485b262019-06-21 11:49:20 +0000386
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000387EXIT STATUS
388-----------
389
James Henderson31908662019-06-12 11:41:43 +0000390:program:`llvm-symbolizer` returns 0. Other exit codes imply an internal program
391error.
James Henderson512c5252019-06-26 11:42:03 +0000392
393SEE ALSO
394--------
395
396:manpage:`llvm-addr2line(1)`