[llvm] r358749 - [llvm-symbolizer] Add llvm-addr2line
Igor Kudrin via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 19 03:17:52 PDT 2019
Author: ikudrin
Date: Fri Apr 19 03:17:52 2019
New Revision: 358749
URL: http://llvm.org/viewvc/llvm-project?rev=358749&view=rev
Log:
[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
Added:
llvm/trunk/docs/CommandGuide/llvm-addr2line.md
llvm/trunk/test/tools/llvm-symbolizer/help.test
Modified:
llvm/trunk/docs/CommandGuide/index.rst
llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst
llvm/trunk/test/CMakeLists.txt
llvm/trunk/test/tools/llvm-symbolizer/demangle.s
llvm/trunk/test/tools/llvm-symbolizer/output-style-column.test
llvm/trunk/test/tools/llvm-symbolizer/output-style-empty-line.test
llvm/trunk/test/tools/llvm-symbolizer/output-style-inlined.test
llvm/trunk/test/tools/llvm-symbolizer/sym.test
llvm/trunk/tools/llvm-symbolizer/CMakeLists.txt
llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
Modified: llvm/trunk/docs/CommandGuide/index.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/index.rst?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/index.rst (original)
+++ llvm/trunk/docs/CommandGuide/index.rst Fri Apr 19 03:17:52 2019
@@ -31,6 +31,7 @@ Basic Commands
llvm-profdata
llvm-stress
llvm-symbolizer
+ llvm-addr2line
llvm-dwarfdump
dsymutil
llvm-mca
Added: llvm/trunk/docs/CommandGuide/llvm-addr2line.md
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-addr2line.md?rev=358749&view=auto
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-addr2line.md (added)
+++ llvm/trunk/docs/CommandGuide/llvm-addr2line.md Fri Apr 19 03:17:52 2019
@@ -0,0 +1,28 @@
+# llvm-addr2line - a drop-in replacement for addr2line
+
+## SYNOPSIS
+
+**llvm-addr2line** [*options*]
+
+## DESCRIPTION
+
+**llvm-addr2line** is an alias for the [llvm-symbolizer](llvm-symbolizer) tool
+with different defaults. The goal is to make it a drop-in replacement for
+GNU's **addr2line**.
+
+Here are some of those differences:
+
+* Defaults not to print function names. Use [-f](llvm-symbolizer-opt-f)
+ to enable that.
+
+* Defaults not to demangle function names. Use [-C](llvm-symbolizer-opt-C)
+ to switch the demangling on.
+
+* Defaults not to print inlined frames. Use [-i](llvm-symbolizer-opt-i)
+ to show inlined frames for a source code location in an inlined function.
+
+* Uses [--output-style=GNU](llvm-symbolizer-opt-output-style) by default.
+
+## SEE ALSO
+
+Refer to [llvm-symbolizer](llvm-symbolizer) for additional information.
Modified: llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst Fri Apr 19 03:17:52 2019
@@ -72,17 +72,23 @@ OPTIONS
Path to object file to be symbolized.
+.. _llvm-symbolizer-opt-f:
+
.. option:: -functions[=<none|short|linkage>], -f
Specify the way function names are printed (omit function name,
print short function name, or print full linkage name, respectively).
Defaults to ``linkage``.
+.. _llvm-symbolizer-opt-use-symbol-table:
+
.. option:: -use-symbol-table
Prefer function names stored in symbol table to function names
in debug info sections. Defaults to true.
+.. _llvm-symbolizer-opt-C:
+
.. option:: -demangle, -C
Print demangled function names. Defaults to true.
@@ -91,6 +97,8 @@ OPTIONS
Don't print demangled function names.
+.. _llvm-symbolizer-opt-i:
+
.. option:: -inlining, -inlines, -i
If a source code location is in an inlined function, prints all the
@@ -128,6 +136,8 @@ OPTIONS
Add the specified offset to object file addresses when performing lookups. This
can be used to perform lookups as if the object were relocated by the offset.
+.. _llvm-symbolizer-opt-output-style:
+
.. option:: -output-style=<LLVM|GNU>
Specify the preferred output style. Defaults to ``LLVM``. When the output
Modified: llvm/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CMakeLists.txt?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/CMakeLists.txt (original)
+++ llvm/trunk/test/CMakeLists.txt Fri Apr 19 03:17:52 2019
@@ -45,6 +45,7 @@ set(LLVM_TEST_DEPENDS
llc
lli
lli-child-target
+ llvm-addr2line
llvm-ar
llvm-as
llvm-bcanalyzer
Modified: llvm/trunk/test/tools/llvm-symbolizer/demangle.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/demangle.s?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/demangle.s (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/demangle.s Fri Apr 19 03:17:52 2019
@@ -25,5 +25,11 @@ _Z1cv:
# RUN: llvm-symbolizer --no-demangle -C --obj %t.o 0 \
# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME
+# Check that for llvm-addr2line the default is not to demangle.
+# RUN: llvm-addr2line -fe %t.o 0 \
+# RUN: | FileCheck %s --check-prefix=MANGLED_FUNCTION_NAME
+# RUN: llvm-addr2line -fCe %t.o 0 \
+# RUN: | FileCheck %s --check-prefix=DEMANGLED_FUNCTION_NAME
+
# MANGLED_FUNCTION_NAME: _Z1cv
# DEMANGLED_FUNCTION_NAME: c()
Added: llvm/trunk/test/tools/llvm-symbolizer/help.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/help.test?rev=358749&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/help.test (added)
+++ llvm/trunk/test/tools/llvm-symbolizer/help.test Fri Apr 19 03:17:52 2019
@@ -0,0 +1,8 @@
+RUN: llvm-symbolizer -help | FileCheck %s --check-prefix=SYMBOLIZER
+RUN: llvm-addr2line -help | FileCheck %s --check-prefix=ADDR2LINE
+
+SYMBOLIZER: OVERVIEW: llvm-symbolizer
+SYMBOLIZER: USAGE: llvm-symbolizer{{(.exe)?}} [options] <input addresses>...
+
+ADDR2LINE: OVERVIEW: llvm-addr2line
+ADDR2LINE: USAGE: llvm-addr2line{{(.exe)?}} [options] <input addresses>...
Modified: llvm/trunk/test/tools/llvm-symbolizer/output-style-column.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/output-style-column.test?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/output-style-column.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/output-style-column.test Fri Apr 19 03:17:52 2019
@@ -7,5 +7,14 @@ RUN: | FileCheck %s --check-prefix=GNU
RUN: llvm-symbolizer --output-style=LLVM -e %p/Inputs/addr.exe 0x40054d \
RUN: | FileCheck %s --check-prefix=LLVM
+RUN: llvm-addr2line -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=GNU
+
+RUN: llvm-addr2line --output-style=GNU -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=GNU
+
+RUN: llvm-addr2line --output-style=LLVM -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=LLVM
+
LLVM: {{^}}/tmp{{\\|/}}x.c:3:3{{$}}
GNU: {{^}}/tmp{{\\|/}}x.c:3{{$}}
Modified: llvm/trunk/test/tools/llvm-symbolizer/output-style-empty-line.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/output-style-empty-line.test?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/output-style-empty-line.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/output-style-empty-line.test Fri Apr 19 03:17:52 2019
@@ -11,6 +11,15 @@ RUN: | FileCheck %s --check-prefix=LLV
RUN: llvm-symbolizer --output-style=GNU -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
RUN: | FileCheck %s --check-prefix=GNU
+RUN: llvm-addr2line -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
+RUN: | FileCheck %s --check-prefix=GNU
+
+RUN: llvm-addr2line --output-style=GNU -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
+RUN: | FileCheck %s --check-prefix=GNU
+
+RUN: llvm-addr2line --output-style=LLVM -i -e %p/Inputs/addr.exe < %p/Inputs/addr.inp \
+RUN: | FileCheck %s --check-prefix=LLVM
+
LLVM: x.c:14:0
LLVM-EMPTY:
LLVM-NEXT: some text2
Modified: llvm/trunk/test/tools/llvm-symbolizer/output-style-inlined.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/output-style-inlined.test?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/output-style-inlined.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/output-style-inlined.test Fri Apr 19 03:17:52 2019
@@ -13,5 +13,14 @@ RUN: | FileCheck %s --check-prefix=LLV
RUN: llvm-symbolizer --output-style=GNU -i=0 -e %p/Inputs/addr.exe 0x40054d \
RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
+RUN: llvm-addr2line -f -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
+
+RUN: llvm-addr2line --output-style=GNU -f -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=GNU --implicit-check-not=main
+
+RUN: llvm-addr2line --output-style=LLVM -f -e %p/Inputs/addr.exe 0x40054d \
+RUN: | FileCheck %s --check-prefix=LLVM --implicit-check-not=inctwo
+
LLVM: main
GNU: inctwo
Modified: llvm/trunk/test/tools/llvm-symbolizer/sym.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/sym.test?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/sym.test (original)
+++ llvm/trunk/test/tools/llvm-symbolizer/sym.test Fri Apr 19 03:17:52 2019
@@ -29,6 +29,19 @@ RUN: llvm-symbolizer -i -print-address -
RUN: echo "0x1" > %t.input
RUN: llvm-symbolizer -obj=%p/Inputs/zero < %t.input | FileCheck -check-prefix="ZERO" %s
+RUN: llvm-addr2line -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefix=A2L %s
+RUN: llvm-addr2line -a -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_A %s
+RUN: llvm-addr2line -f -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_F %s
+RUN: llvm-addr2line -i -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_I %s
+RUN: llvm-addr2line -fi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2L,A2L_F,A2L_I,A2L_FI %s
+
+RUN: llvm-addr2line -pa -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_A %s
+RUN: llvm-addr2line -pf -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_F %s
+RUN: llvm-addr2line -paf -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_AF %s
+RUN: llvm-addr2line -pai -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_A,A2LP_I %s
+RUN: llvm-addr2line -pfi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_F,A2LP_FI %s
+RUN: llvm-addr2line -pafi -obj=%p/Inputs/addr.exe < %p/Inputs/addr.inp | FileCheck -check-prefixes=A2LP,A2LP_AF,A2LP_FI %s
+
#CHECK: some text
#CHECK: 0x40054d
#CHECK: main
@@ -43,3 +56,23 @@ RUN: llvm-symbolizer -obj=%p/Inputs/zero
#
#ZERO: ??
#ZERO: ??:0:0
+#
+#A2L: some text
+#A2L_A-NEXT: 0x40054d
+#A2L_F-NEXT: inctwo
+#A2L-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
+#A2L_FI-NEXT: inc{{$}}
+#A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
+#A2L_FI-NEXT: main
+#A2L_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
+#A2L-NEXT: some text2
+
+#A2LP: some text
+#A2LP_A-NEXT: 0x40054d: {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
+#A2LP_F-NEXT: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
+#A2LP_AF-NEXT: 0x40054d: inctwo at {{[/\]+}}tmp{{[/\]+}}x.c:3{{$}}
+#A2LP_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
+#A2LP_I-NEXT: {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
+#A2LP_FI-NEXT: (inlined by) inc at {{[/\]+}}tmp{{[/\]+}}x.c:7{{$}}
+#A2LP_FI-NEXT: (inlined by) main at {{[/\]+}}tmp{{[/\]+}}x.c:14{{$}}
+#A2LP-NEXT: some text2
Modified: llvm/trunk/tools/llvm-symbolizer/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/CMakeLists.txt?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-symbolizer/CMakeLists.txt Fri Apr 19 03:17:52 2019
@@ -16,6 +16,8 @@ add_llvm_tool(llvm-symbolizer
llvm-symbolizer.cpp
)
+add_llvm_tool_symlink(llvm-addr2line llvm-symbolizer)
+
if(LLVM_INSTALL_BINUTILS_SYMLINKS)
add_llvm_tool_symlink(addr2line llvm-symbolizer)
endif()
Modified: llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp?rev=358749&r1=358748&r2=358749&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp Fri Apr 19 03:17:52 2019
@@ -43,7 +43,7 @@ static cl::opt<FunctionNameKind> ClPrint
clEnumValN(FunctionNameKind::ShortName, "short",
"print short function name"),
clEnumValN(FunctionNameKind::LinkageName, "linkage",
- "print function linkage name (default)"),
+ "print function linkage name"),
// Sentinel value for unspecified value.
clEnumValN(FunctionNameKind::LinkageName, "", "")));
static cl::alias ClPrintFunctionsShort("f", cl::desc("Alias for -functions"),
@@ -252,8 +252,18 @@ static void symbolizeInput(StringRef Inp
int main(int argc, char **argv) {
InitLLVM X(argc, argv);
+ bool IsAddr2Line = sys::path::stem(argv[0]).contains("addr2line");
+
+ if (IsAddr2Line) {
+ ClDemangle.setInitialValue(false);
+ ClPrintFunctions.setInitialValue(FunctionNameKind::None);
+ ClPrintInlining.setInitialValue(false);
+ ClOutputStyle.setInitialValue(DIPrinter::OutputStyle::GNU);
+ }
+
llvm::sys::InitializeCOMRAII COM(llvm::sys::COMThreadingMode::MultiThreaded);
- cl::ParseCommandLineOptions(argc, argv, "llvm-symbolizer\n");
+ cl::ParseCommandLineOptions(argc, argv, IsAddr2Line ? "llvm-addr2line\n"
+ : "llvm-symbolizer\n");
// If both --demangle and --no-demangle are specified then pick the last one.
if (ClNoDemangle.getPosition() > ClDemangle.getPosition())
More information about the llvm-commits
mailing list