[llvm] c64b566 - Print discriminators when printing .debug_line in GNU style.
Sterling Augustine via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 29 12:22:33 PST 2020
Author: Sterling Augustine
Date: 2020-01-29T12:22:12-08:00
New Revision: c64b56617da293685d6467bd38ad000f8c4fd75e
URL: https://github.com/llvm/llvm-project/commit/c64b56617da293685d6467bd38ad000f8c4fd75e
DIFF: https://github.com/llvm/llvm-project/commit/c64b56617da293685d6467bd38ad000f8c4fd75e.diff
LOG: Print discriminators when printing .debug_line in GNU style.
Summary:
gnu addr2line prints DWARF line table discriminators like so:
<file>:<line> (discriminator <Number>)
This matches that behavior.
Document how and when --output-style=GNU prints discriminators
Add test for new GNU-style discriminator printing.
Reviewers: rupprecht, labath, jhenderson
Subscribers: aprantl, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73318
Added:
llvm/test/tools/llvm-symbolizer/discriminator.test
Modified:
llvm/docs/CommandGuide/llvm-symbolizer.rst
llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index bb60246c8352..10f72a002e4e 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -227,6 +227,9 @@ OPTIONS
topmost caller when inlined frames are not shown and :option:`--use-symbol-table`
is on.
+ * Prints an address's debug-data discriminator when it is non-zero. One way to
+ produce discriminators is to compile with clang's -fdebug-info-for-profiling.
+
.. code-block:: console
$ llvm-symbolizer --obj=inlined.elf 0x4004be 0x400486 -p
@@ -244,6 +247,10 @@ OPTIONS
baz() at /tmp/test.cpp:11
foo() at /tmp/test.cpp:6
+ $ clang -g -fdebug-info-for-profiling test.cpp -o profiling.elf
+ $ llvm-symbolizer --output-style=GNU --obj=profiling.elf 0x401167 -p -i=0
+ main at /tmp/test.cpp:15 (discriminator 2)
+
.. option:: --pretty-print, -p
Print human readable output. If :option:`--inlining` is specified, the
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index c5b71ba06456..223b6630d69d 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -79,6 +79,8 @@ void DIPrinter::print(const DILineInfo &Info, bool Inlined) {
OS << Filename << ":" << Info.Line;
if (Style == OutputStyle::LLVM)
OS << ":" << Info.Column;
+ else if (Style == OutputStyle::GNU && Info.Discriminator != 0)
+ OS << " (discriminator " << Info.Discriminator << ")";
OS << "\n";
printContext(Filename, Info.Line);
return;
diff --git a/llvm/test/tools/llvm-symbolizer/discriminator.test b/llvm/test/tools/llvm-symbolizer/discriminator.test
new file mode 100644
index 000000000000..1cc398732dd2
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/discriminator.test
@@ -0,0 +1,20 @@
+# Check that llvm-symbolizer prints line-table discriminators properly.
+
+RUN: llvm-symbolizer --output-style=GNU -f --obj=%p/Inputs/discrim 0x400590 0x400575 \
+RUN: | FileCheck %s --check-prefix=GNU --match-full-lines
+RUN: llvm-symbolizer --output-style=LLVM -f --obj=%p/Inputs/discrim 0x400590 0x400575 \
+RUN: | FileCheck %s --check-prefix=LLVM --match-full-lines
+
+GNU: foo
+GNU: /tmp{{[\\/]}}discrim.c:5
+GNU: main
+GNU: /tmp{{[\\/]}}discrim.c:10
+GNU: foo
+GNU: /tmp{{[\\/]}}discrim.c:5 (discriminator 2)
+
+LLVM: foo
+LLVM: /tmp{{[\\/]}}discrim.c:5:7
+LLVM: main
+LLVM: /tmp{{[\\/]}}discrim.c:10:0
+LLVM: foo
+LLVM: /tmp{{[\\/]}}discrim.c:5:17
More information about the llvm-commits
mailing list