[llvm] 21d9d08 - New symbolizer option to print files relative to the compilation directory.
Sterling Augustine via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 31 09:29:51 PDT 2020
Author: Sterling Augustine
Date: 2020-03-31T09:29:24-07:00
New Revision: 21d9d0855be17220e869ef5bbec2d839fe841840
URL: https://github.com/llvm/llvm-project/commit/21d9d0855be17220e869ef5bbec2d839fe841840
DIFF: https://github.com/llvm/llvm-project/commit/21d9d0855be17220e869ef5bbec2d839fe841840.diff
LOG: New symbolizer option to print files relative to the compilation directory.
Summary: New "--relative" option to allow printing files relative to the compilation directory.
Reviewers: jhenderson
Subscribers: MaskRay, rupprecht, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D76733
Added:
llvm/test/tools/llvm-symbolizer/relativenames.s
Modified:
llvm/docs/CommandGuide/llvm-symbolizer.rst
llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index dd93efd03cfc..820b15061715 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -147,6 +147,27 @@ Example 4 - CODE and DATA prefixes:
bar
6295592 4
+Example 5 - path-style options:
+
+This example uses the same source file as above, but the source file's
+full path is /tmp/foo/test.cpp and is compiled as follows. The first case
+shows the default absolute path, the second --basenames, and the third
+shows --relativenames.
+
+.. code-block:: console
+ $ pwd
+ /tmp
+ $ clang -g foo/test.cpp -o test.elf
+ $ llvm-symbolizer --obj=test.elf 0x4004a0
+ main
+ /tmp/foo/test.cpp:15:0
+ $ llvm-symbolizer --obj=test.elf 0x4004a0 --basenames
+ main
+ test.cpp:15:0
+ $ llvm-symbolizer --obj=test.elf 0x4004a0 --relativenames
+ main
+ foo/test.cpp:15:0
+
OPTIONS
-------
@@ -158,8 +179,15 @@ OPTIONS
.. option:: --basenames, -s
- Strip directories when printing the file path.
+ Print just the file's name without any directories, instead of the
+ absolute path.
+.. option:: --relativenames
+
+ Print the file's path relative to the compilation directory, instead
+ of the absolute path. If the command-line to the compiler included
+ the full path, this will be the same as the default.
+
.. _llvm-symbolizer-opt-C:
.. option:: --demangle, -C
diff --git a/llvm/test/tools/llvm-symbolizer/relativenames.s b/llvm/test/tools/llvm-symbolizer/relativenames.s
new file mode 100644
index 000000000000..96b89cb004bf
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/relativenames.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86-registered-target
+
+foo:
+ nop
+
+# RUN: llvm-mc --filetype=obj --triple=x86_64-pc-linux %s -o %t.o -g
+
+# RUN: llvm-symbolizer 0 --relativenames --obj=%t.o \
+# RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
+
+## Ensure last option wins.
+# RUN: llvm-symbolizer 0 --basenames --relativenames --obj=%t.o \
+# RUN: | FileCheck %s -DDIR=%p --check-prefix=RELATIVENAMES
+# RUN: llvm-symbolizer 0 --relativenames --basenames --obj=%t.o \
+# RUN: | FileCheck %s --check-prefix=BASENAMES
+
+# RELATIVENAMES: [[DIR]]{{\\|/}}relativenames.s:4
+# BASENAMES: {{^}}relativenames.s:4
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 8f4a93fcc25d..55d9c65d9941 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -77,6 +77,11 @@ static cl::opt<bool> ClBasenames("basenames", cl::init(false),
static cl::alias ClBasenamesShort("s", cl::desc("Alias for -basenames"),
cl::NotHidden, cl::aliasopt(ClBasenames));
+// -relativenames
+static cl::opt<bool>
+ ClRelativenames("relativenames", cl::init(false),
+ cl::desc("Strip the compilation directory from paths"));
+
// -demangle, -C, -no-demangle
static cl::opt<bool>
ClDemangle("demangle", cl::init(true), cl::desc("Demangle function names"));
@@ -310,8 +315,12 @@ int main(int argc, char **argv) {
Opts.DWPName = ClDwpName;
Opts.DebugFileDirectory = ClDebugFileDirectory;
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath;
- if (ClBasenames)
+ // If both --basenames and --relativenames are specified then pick the last
+ // one.
+ if (ClBasenames.getPosition() > ClRelativenames.getPosition())
Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::BaseNameOnly;
+ else if (ClRelativenames)
+ Opts.PathStyle = DILineInfoSpecifier::FileLineInfoKind::RelativeFilePath;
for (const auto &hint : ClDsymHint) {
if (sys::path::extension(hint) == ".dSYM") {
More information about the llvm-commits
mailing list