blob: 7f3a8a4e27ecf9c1be76f6ff03d661a412c401cb [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
31EXAMPLES
Alexey Samsonov2bc10122013-03-01 07:58:27 +000032--------
33
James Henderson512c5252019-06-26 11:42:03 +000034All of the following examples use the following two source files as input. They
35use a mixture of C-style and C++-style linkage to illustrate how these names are
36printed differently (see :option:`--demangle`).
37
38.. code-block:: c
39
40 // test.h
41 extern "C" inline int foz() {
42 return 1234;
43 }
44
45.. code-block:: c
46
47 // test.cpp
48 #include "test.h"
49 int bar=42;
50
51 int foo() {
52 return bar;
53 }
54
55 int baz() {
56 volatile int k = 42;
57 return foz() + k;
58 }
59
60 int main() {
61 return foo() + baz();
62 }
63
64These files are built as follows:
65
66.. code-block:: console
67
68 $ clang -g test.cpp -o test.elf
69 $ clang -g -O2 test.cpp -o inlined.elf
70
71Example 1 - addresses and object on command-line:
72
73.. code-block:: console
74
75 $ llvm-symbolizer --obj=test.elf 0x4004d0 0x400490
76 foz
77 /tmp/test.h:1:0
78
79 baz()
80 /tmp/test.cpp:11:0
81
82Example 2 - addresses on standard input:
83
Alexey Samsonov2bc10122013-03-01 07:58:27 +000084.. code-block:: console
85
86 $ cat addr.txt
James Henderson512c5252019-06-26 11:42:03 +000087 0x4004a0
88 0x400490
89 0x4004d0
90 $ llvm-symbolizer --obj=test.elf < addr.txt
Alexey Samsonov2bc10122013-03-01 07:58:27 +000091 main
James Henderson512c5252019-06-26 11:42:03 +000092 /tmp/test.cpp:15:0
Alexey Samsonov2bc10122013-03-01 07:58:27 +000093
James Henderson512c5252019-06-26 11:42:03 +000094 baz()
95 /tmp/test.cpp:11:0
Alexey Samsonov2bc10122013-03-01 07:58:27 +000096
James Henderson512c5252019-06-26 11:42:03 +000097 foz
98 /tmp/./test.h:1:0
Alexey Samsonov2ca65362013-06-28 08:15:40 +000099
James Henderson512c5252019-06-26 11:42:03 +0000100Example 3 - object specified with address:
101
102.. code-block:: console
103
104 $ llvm-symbolizer "test.elf 0x400490" "inlined.elf 0x400480"
105 baz()
106 /tmp/test.cpp:11:0
107
108 foo()
109 /tmp/test.cpp:8:10
110
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000111 $ cat addr2.txt
James Henderson512c5252019-06-26 11:42:03 +0000112 test.elf 0x4004a0
113 inlined.elf 0x400480
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000114
James Henderson512c5252019-06-26 11:42:03 +0000115 $ llvm-symbolizer < addr2.txt
116 main
117 /tmp/test.cpp:15:0
118
119 foo()
120 /tmp/test.cpp:8:10
121
122Example 4 - CODE and DATA prefixes:
123
124.. code-block:: console
125
126 $ llvm-symbolizer --obj=test.elf "CODE 0x400490" "DATA 0x601028"
127 baz()
128 /tmp/test.cpp:11:0
129
130 bar
131 6295592 4
132
133 $ cat addr3.txt
134 CODE test.elf 0x4004a0
135 DATA inlined.elf 0x601028
136
137 $ llvm-symbolizer < addr3.txt
138 main
139 /tmp/test.cpp:15:0
140
141 bar
142 6295592 4
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000143
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000144OPTIONS
145-------
146
James Henderson512c5252019-06-26 11:42:03 +0000147.. option:: --adjust-vma <offset>
Alexey Samsonovcd014722014-05-17 00:07:48 +0000148
James Henderson512c5252019-06-26 11:42:03 +0000149 Add the specified offset to object file addresses when performing lookups.
150 This can be used to perform lookups as if the object were relocated by the
151 offset.
Alexey Samsonov60e59e22013-12-24 19:33:22 +0000152
James Henderson512c5252019-06-26 11:42:03 +0000153.. option:: --basenames, -s
Igor Kudrin99f641c2019-04-19 10:17:52 +0000154
James Henderson512c5252019-06-26 11:42:03 +0000155 Strip directories when printing the file path.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000156
Igor Kudrin99f641c2019-04-19 10:17:52 +0000157.. _llvm-symbolizer-opt-C:
158
James Henderson512c5252019-06-26 11:42:03 +0000159.. option:: --demangle, -C
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000160
James Henderson512c5252019-06-26 11:42:03 +0000161 Print demangled function names, if the names are mangled (e.g. the mangled
162 name `_Z3bazv` becomes `baz()`, whilst the non-mangled name `foz` is printed
163 as is). Defaults to true.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000164
James Henderson512c5252019-06-26 11:42:03 +0000165.. option:: --dwp <path>
Dmitry Venikov119cf662019-01-21 10:00:57 +0000166
James Henderson512c5252019-06-26 11:42:03 +0000167 Use the specified DWP file at ``<path>`` for any CUs that have split DWARF
168 debug data.
169
170.. option:: --fallback-debug-path <path>
171
172 When a separate file contains debug data, and is referenced by a GNU debug
173 link section, use the specified path as a basis for locating the debug data if
174 it cannot be found relative to the object.
175
176.. _llvm-symbolizer-opt-f:
177
178.. option:: --functions [<none|short|linkage>], -f
179
180 Specify the way function names are printed (omit function name, print short
181 function name, or print full linkage name, respectively). Defaults to
182 ``linkage``.
183
184.. option:: --help, -h
185
186 Show help and usage for this command.
187
188.. option:: --help-list
189
190 Show help and usage for this command without grouping the options into categories.
Dmitry Venikov119cf662019-01-21 10:00:57 +0000191
Igor Kudrin99f641c2019-04-19 10:17:52 +0000192.. _llvm-symbolizer-opt-i:
193
James Henderson512c5252019-06-26 11:42:03 +0000194.. option:: --inlining, --inlines, -i
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000195
James Henderson512c5252019-06-26 11:42:03 +0000196 If a source code location is in an inlined function, prints all the inlined
197 frames. Defaults to true.
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000198
James Henderson512c5252019-06-26 11:42:03 +0000199.. option:: --no-demangle
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000200
James Henderson512c5252019-06-26 11:42:03 +0000201 Don't print demangled function names.
Alexey Samsonov2ca65362013-06-28 08:15:40 +0000202
James Henderson512c5252019-06-26 11:42:03 +0000203.. option:: --obj <path>, --exe, -e
Alexander Potapenko7aaf5142014-10-17 00:50:19 +0000204
James Henderson512c5252019-06-26 11:42:03 +0000205 Path to object file to be symbolized. If ``-`` is specified, read the object
206 directly from the standard input stream.
James Henderson759d5e62019-01-25 11:49:21 +0000207
Igor Kudrin99f641c2019-04-19 10:17:52 +0000208.. _llvm-symbolizer-opt-output-style:
209
James Henderson512c5252019-06-26 11:42:03 +0000210.. option:: --output-style <LLVM|GNU>
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000211
212 Specify the preferred output style. Defaults to ``LLVM``. When the output
213 style is set to ``GNU``, the tool follows the style of GNU's **addr2line**.
214 The differences from the ``LLVM`` style are:
215
216 * Does not print column of a source code location.
217
218 * Does not add an empty line after the report for an address.
219
220 * Does not replace the name of an inlined function with the name of the
James Henderson512c5252019-06-26 11:42:03 +0000221 topmost caller when inlined frames are not shown and :option:`--use-symbol-table`
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000222 is on.
223
224 .. code-block:: console
225
James Henderson512c5252019-06-26 11:42:03 +0000226 $ llvm-symbolizer --obj=inlined.elf 0x4004be 0x400486 -p
227 baz() at /tmp/test.cpp:11:18
228 (inlined by) main at /tmp/test.cpp:15:0
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000229
James Henderson512c5252019-06-26 11:42:03 +0000230 foo() at /tmp/test.cpp:6:3
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000231
James Henderson512c5252019-06-26 11:42:03 +0000232 $ llvm-symbolizer --output-style=LLVM --obj=inlined.elf 0x4004be 0x400486 -p -i=0
233 main at /tmp/test.cpp:11:18
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000234
James Henderson512c5252019-06-26 11:42:03 +0000235 foo() at /tmp/test.cpp:6:3
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000236
James Henderson512c5252019-06-26 11:42:03 +0000237 $ llvm-symbolizer --output-style=GNU --obj=inlined.elf 0x4004be 0x400486 -p -i=0
238 baz() at /tmp/test.cpp:11
239 foo() at /tmp/test.cpp:6
240
241.. option:: --pretty-print, -p
242
243 Print human readable output. If :option:`--inlining` is specified, the
244 enclosing scope is prefixed by (inlined by).
245
246.. code-block:: console
247
248 $ llvm-symbolizer --obj=inlined.elf 0x4004be --inlining --pretty-print
249 baz() at /tmp/test.cpp:11:18
250 (inlined by) main at /tmp/test.cpp:15:0
251
252.. option:: --print-address, --addresses, -a
253
254 Print address before the source code location. Defaults to false.
255
256.. code-block:: console
257
258 $ llvm-symbolizer --obj=inlined.elf --print-address 0x4004be
259 0x4004be
260 baz()
261 /tmp/test.cpp:11:18
262 main
263 /tmp/test.cpp:15:0
264
265 $ llvm-symbolizer --obj=inlined.elf 0x4004be --pretty-print --print-address
266 0x4004be: baz() at /tmp/test.cpp:11:18
267 (inlined by) main at /tmp/test.cpp:15:0
268
269.. option:: --print-source-context-lines <N>
270
271 Print ``N`` lines of source context for each symbolized address.
272
273.. code-block:: console
274
275 $ llvm-symbolizer --obj=test.elf 0x400490 --print-source-context-lines=2
276 baz()
277 /tmp/test.cpp:11:0
278 10 : volatile int k = 42;
279 11 >: return foz() + k;
280 12 : }
281
282.. _llvm-symbolizer-opt-use-symbol-table:
283
284.. option:: --use-symbol-table
285
286 Prefer function names stored in symbol table to function names in debug info
287 sections. Defaults to true.
288
289.. option:: --verbose
290
291 Print verbose line and column information.
292
293.. code-block:: console
294
295 $ llvm-symbolizer --obj=inlined.elf --verbose 0x4004be
296 baz()
297 Filename: /tmp/test.cpp
298 Function start line: 9
299 Line: 11
300 Column: 18
301 main
302 Filename: /tmp/test.cpp
303 Function start line: 14
304 Line: 15
305 Column: 0
306
307.. option:: --version
308
309 Print version information for the tool.
Igor Kudrin1b71b7f2019-04-19 10:14:18 +0000310
James Henderson9485b262019-06-21 11:49:20 +0000311.. option:: @<FILE>
312
James Henderson512c5252019-06-26 11:42:03 +0000313 Read command-line options from response file `<FILE>`.
314
315MACH-O SPECIFIC OPTIONS
316-----------------------
317
318.. option:: --default-arch <arch>
319
320 If a binary contains object files for multiple architectures (e.g. it is a
321 Mach-O universal binary), symbolize the object file for a given architecture.
322 You can also specify the architecture by writing ``binary_name:arch_name`` in
323 the input (see example below). If the architecture is not specified in either
324 way, the address will not be symbolized. Defaults to empty string.
325
326.. code-block:: console
327
328 $ cat addr.txt
329 /tmp/mach_universal_binary:i386 0x1f84
330 /tmp/mach_universal_binary:x86_64 0x100000f24
331
332 $ llvm-symbolizer < addr.txt
333 _main
334 /tmp/source_i386.cc:8
335
336 _main
337 /tmp/source_x86_64.cc:8
338
339.. option:: --dsym-hint <path/to/file.dSYM>
340
341 If the debug info for a binary isn't present in the default location, look for
342 the debug info at the .dSYM path provided via this option. This flag can be
343 used multiple times.
James Henderson9485b262019-06-21 11:49:20 +0000344
Alexey Samsonov2bc10122013-03-01 07:58:27 +0000345EXIT STATUS
346-----------
347
James Henderson31908662019-06-12 11:41:43 +0000348:program:`llvm-symbolizer` returns 0. Other exit codes imply an internal program
349error.
James Henderson512c5252019-06-26 11:42:03 +0000350
351SEE ALSO
352--------
353
354:manpage:`llvm-addr2line(1)`