llvm.org GIT mirror llvm / dac6480
[llvm-symbolizer] Add llvm-addr2line This adds an alias for llvm-symbolizer with different defaults so that it can be used as a drop-in replacement for GNU's addr2line. If a substring "addr2line" is found in the tool's name: * it defaults "-i", "-f" and "-C" to OFF; * it uses "--output-style=GNU" by default. Differential Revision: https://reviews.llvm.org/D60067 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358749 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Kudrin 1 year, 6 months ago
12 changed file(s) with 128 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
3030 llvm-profdata
3131 llvm-stress
3232 llvm-symbolizer
33 llvm-addr2line
3334 llvm-dwarfdump
3435 dsymutil
3536 llvm-mca
0 # llvm-addr2line - a drop-in replacement for addr2line
1
2 ## SYNOPSIS
3
4 **llvm-addr2line** [*options*]
5
6 ## DESCRIPTION
7
8 **llvm-addr2line** is an alias for the [llvm-symbolizer](llvm-symbolizer) tool
9 with different defaults. The goal is to make it a drop-in replacement for
10 GNU's **addr2line**.
11
12 Here are some of those differences:
13
14 * Defaults not to print function names. Use [-f](llvm-symbolizer-opt-f)
15 to enable that.
16
17 * Defaults not to demangle function names. Use [-C](llvm-symbolizer-opt-C)
18 to switch the demangling on.
19
20 * Defaults not to print inlined frames. Use [-i](llvm-symbolizer-opt-i)
21 to show inlined frames for a source code location in an inlined function.
22
23 * Uses [--output-style=GNU](llvm-symbolizer-opt-output-style) by default.
24
25 ## SEE ALSO
26
27 Refer to [llvm-symbolizer](llvm-symbolizer) for additional information.
7171
7272 Path to object file to be symbolized.
7373
74 .. _llvm-symbolizer-opt-f:
75
7476 .. option:: -functions[=], -f
7577
7678 Specify the way function names are printed (omit function name,
7779 print short function name, or print full linkage name, respectively).
7880 Defaults to ``linkage``.
7981
82 .. _llvm-symbolizer-opt-use-symbol-table:
83
8084 .. option:: -use-symbol-table
8185
8286 Prefer function names stored in symbol table to function names
8387 in debug info sections. Defaults to true.
88
89 .. _llvm-symbolizer-opt-C:
8490
8591 .. option:: -demangle, -C
8692
8995 .. option:: -no-demangle
9096
9197 Don't print demangled function names.
98
99 .. _llvm-symbolizer-opt-i:
92100
93101 .. option:: -inlining, -inlines, -i
94102
127135 Add the specified offset to object file addresses when performing lookups. This
128136 can be used to perform lookups as if the object were relocated by the offset.
129137
138 .. _llvm-symbolizer-opt-output-style:
139
130140 .. option:: -output-style=
131141
132142 Specify the preferred output style. Defaults to ``LLVM``. When the output
4444 llc
4545 lli
4646 lli-child-target
47 llvm-addr2line
4748 llvm-ar
4849 llvm-as
4950 llvm-bcanalyzer
2424 # RUN: llvm-symbolizer --no-demangle -C --obj %t.o 0 \
2525 # RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME
2626
27 # Check that for llvm-addr2line the default is not to demangle.
28 # RUN: llvm-addr2line -fe %t.o 0 \
29 # RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME
30 # RUN: llvm-addr2line -fCe %t.o 0 \
31 # RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME
32
2733 # MANGLED_FUNCTION_NAME: _Z1cv
2834 # DEMANGLED_FUNCTION_NAME: c()
0 RUN: llvm-symbolizer -help | FileCheck %s --check-prefix=SYMBOLIZER
1 RUN: llvm-addr2line -help | FileCheck %s --check-prefix=ADDR2LINE
2
3 SYMBOLIZER: OVERVIEW: llvm-symbolizer
4 SYMBOLIZER: USAGE: llvm-symbolizer{{(.exe)?}} [options] ...
5
6 ADDR2LINE: OVERVIEW: llvm-addr2line
7 ADDR2LINE: USAGE: llvm-addr2line{{(.exe)?}} [options] ...
66 RUN: llvm-symbolizer --output-style=LLVM -e %p/Inputs/addr.exe 0x40054d \
77 RUN: | FileCheck %s --check-prefix=LLVM
88
9 RUN: llvm-addr2line -e %p/Inputs/addr.exe 0x40054d \
10 RUN: | FileCheck %s --check-prefix=GNU
11
12 RUN: llvm-addr2line --output-style=GNU -e %p/Inputs/addr.exe 0x40054d \
13 RUN: | FileCheck %s --check-prefix=GNU
14
15 RUN: llvm-addr2line --output-style=LLVM -e %p/Inputs/addr.exe 0x40054d \
16 RUN: | FileCheck %s --check-prefix=LLVM
17
918 LLVM: {{^}}/tmp{{\\|/}}x.c:3:3{{$}}
1019 GNU: {{^}}/tmp{{\\|/}}x.c:3{{$}}
1010 RUN: llvm-symbolizer --output-style=GNU -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
1111 RUN: | FileCheck %s --check-prefix=GNU
1212
13 RUN: llvm-addr2line -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
14 RUN: | FileCheck %s --check-prefix=GNU
15
16 RUN: llvm-addr2line --output-style=GNU -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
17 RUN: | FileCheck %s --check-prefix=GNU
18
19 RUN: llvm-addr2line --output-style=LLVM -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
20 RUN: | FileCheck %s --check-prefix=LLVM
21
1322 LLVM: x.c:14:0
1423 LLVM-EMPTY:
1524 LLVM-NEXT: some text2
1212 RUN: llvm-symbolizer --output-style=GNU -i=0 -e %p/Inputs/addr.exe 0x40054d \
1313 RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
1414
15 RUN: llvm-addr2line -f -e %p/Inputs/addr.exe 0x40054d \
16 RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
17
18 RUN: llvm-addr2line --output-style=GNU -f -e %p/Inputs/addr.exe 0x40054d \
19 RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
20
21 RUN: llvm-addr2line --output-style=LLVM -f -e %p/Inputs/addr.exe 0x40054d \
22 RUN: | FileCheck %s --check-prefix=LLVM --implicit-check-not=inctwo
23
1524 LLVM: main
1625 GNU: inctwo
2828 RUN: echo "0x1" > %t.input
2929 RUN: llvm-symbolizer -obj=%p/Inputs/zero < %t.input | FileCheck -check-prefix="ZERO" %s
3030
31 RUN: llvm-addr2line -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefix=A2L %s
32 RUN: llvm-addr2line -a -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_A %s
33 RUN: llvm-addr2line -f -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_F %s
34 RUN: llvm-addr2line -i -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_I %s
35 RUN: llvm-addr2line -fi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_F,A2L_I,A2L_FI %s
36
37 RUN: llvm-addr2line -pa -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_A %s
38 RUN: llvm-addr2line -pf -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_F %s
39 RUN: llvm-addr2line -paf -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_AF %s
40 RUN: llvm-addr2line -pai -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_A,A2LP_I %s
41 RUN: llvm-addr2line -pfi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_F,A2LP_FI %s
42 RUN: llvm-addr2line -pafi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_AF,A2LP_FI %s
43
3144 #CHECK: some text
3245 #CHECK: 0x40054d
3346 #CHECK: main
4255 #
4356 #ZERO: ??
4457 #ZERO: ??:0:0
58 #
59 #A2L: some text
60 #A2L_A-NEXT: 0x40054d
61 #A2L_F-NEXT: inctwo
62 #A2L-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
63 #A2L_FI-NEXT: inc{{$}}
64 #A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
65 #A2L_FI-NEXT: main
66 #A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
67 #A2L-NEXT: some text2
68
69 #A2LP: some text
70 #A2LP_A-NEXT: 0x40054d: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
71 #A2LP_F-NEXT: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
72 #A2LP_AF-NEXT: 0x40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
73 #A2LP_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
74 #A2LP_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
75 #A2LP_FI-NEXT: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
76 #A2LP_FI-NEXT: (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
77 #A2LP-NEXT: some text2
1515 llvm-symbolizer.cpp
1616 )
1717
18 add_llvm_tool_symlink(llvm-addr2line llvm-symbolizer)
19
1820 if(LLVM_INSTALL_BINUTILS_SYMLINKS)
1921 add_llvm_tool_symlink(addr2line llvm-symbolizer)
2022 endif()
4242 clEnumValN(FunctionNameKind::ShortName, "short",
4343 "print short function name"),
4444 clEnumValN(FunctionNameKind::LinkageName, "linkage",
45 "print function linkage name (default)"),
45 "print function linkage name"),
4646 // Sentinel value for unspecified value.
4747 clEnumValN(FunctionNameKind::LinkageName, "", "")));
4848 static cl::alias ClPrintFunctionsShort("f", cl::desc("Alias for -functions"),
251251 int main(int argc, char **argv) {
252252 InitLLVM X(argc, argv);
253253
254 bool IsAddr2Line = sys::path::stem(argv[0]).contains("addr2line");
255
256 if (IsAddr2Line) {
257 ClDemangle.setInitialValue(false);
258 ClPrintFunctions.setInitialValue(FunctionNameKind::None);
259 ClPrintInlining.setInitialValue(false);
260 ClOutputStyle.setInitialValue(DIPrinter::OutputStyle::GNU);
261 }
262
254263 llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
255 cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n");
264 cl::ParseCommandLineOptions(argc, argv, IsAddr2Line ? "llvm-addr2line\n"
265 : "llvm-symbolizer\n");
256266
257267 // If both --demangle and --no-demangle are specified then pick the last one.
258268 if (ClNoDemangle.getPosition() > ClDemangle.getPosition())