summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJames Henderson <jh7370@my.bristol.ac.uk>2019-01-22 10:24:32 +0000
committerJames Henderson <jh7370@my.bristol.ac.uk>2019-01-22 10:24:32 +0000
commit33c16a3f16fa56ad945e086af669760e0b80d8c7 (patch)
treeb820794d444c44cfa8cbbab75a51231834b22d40 /llvm
parentca45087826f66d4e9848a3c10925ff02c924de2c (diff)
downloadbcm5719-llvm-33c16a3f16fa56ad945e086af669760e0b80d8c7.tar.gz
bcm5719-llvm-33c16a3f16fa56ad945e086af669760e0b80d8c7.zip
[llvm-symbolizer] Add support for --basenames/-s
This fixes https://bugs.llvm.org/show_bug.cgi?id=40068. --basenames is a GNU addr2line switch which strips the directory names from the file path in the output. Reviewed by: ruiu Differential Revision: https://reviews.llvm.org/D56919 llvm-svn: 351795
Diffstat (limited to 'llvm')
-rw-r--r--llvm/docs/CommandGuide/llvm-symbolizer.rst4
-rw-r--r--llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h5
-rw-r--r--llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp3
-rw-r--r--llvm/test/tools/llvm-symbolizer/basenames.s12
-rw-r--r--llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp9
5 files changed, 30 insertions, 3 deletions
diff --git a/llvm/docs/CommandGuide/llvm-symbolizer.rst b/llvm/docs/CommandGuide/llvm-symbolizer.rst
index 56999207e20..bfe8f3ee6bb 100644
--- a/llvm/docs/CommandGuide/llvm-symbolizer.rst
+++ b/llvm/docs/CommandGuide/llvm-symbolizer.rst
@@ -119,6 +119,10 @@ OPTIONS
Print human readable output. If ``-inlining`` is specified, enclosing scope is
prefixed by (inlined by). Refer to listed examples.
+.. option:: -basenames, -s
+
+ Strip directories when printing the file path.
+
EXIT STATUS
-----------
diff --git a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
index 1a9b84fccb1..71663f30a59 100644
--- a/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
+++ b/llvm/include/llvm/DebugInfo/Symbolize/DIPrinter.h
@@ -29,6 +29,7 @@ class DIPrinter {
bool PrintPretty;
int PrintSourceContext;
bool Verbose;
+ bool Basenames;
void print(const DILineInfo &Info, bool Inlined);
void printContext(const std::string &FileName, int64_t Line);
@@ -36,10 +37,10 @@ class DIPrinter {
public:
DIPrinter(raw_ostream &OS, bool PrintFunctionNames = true,
bool PrintPretty = false, int PrintSourceContext = 0,
- bool Verbose = false)
+ bool Verbose = false, bool Basenames = false)
: OS(OS), PrintFunctionNames(PrintFunctionNames),
PrintPretty(PrintPretty), PrintSourceContext(PrintSourceContext),
- Verbose(Verbose) {}
+ Verbose(Verbose), Basenames(Basenames) {}
DIPrinter &operator<<(const DILineInfo &Info);
DIPrinter &operator<<(const DIInliningInfo &Info);
diff --git a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
index 89a537c7f38..18fe9bc610b 100644
--- a/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
+++ b/llvm/lib/DebugInfo/Symbolize/DIPrinter.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/Format.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cmath>
@@ -77,6 +78,8 @@ void DIPrinter::print(const DILineInfo &Info, bool Inlined) {
std::string Filename = Info.FileName;
if (Filename == kDILineInfoBadString)
Filename = kBadString;
+ else if (Basenames)
+ Filename = llvm::sys::path::filename(Filename);
if (!Verbose) {
OS << Filename << ":" << Info.Line << ":" << Info.Column << "\n";
printContext(Filename, Info.Line);
diff --git a/llvm/test/tools/llvm-symbolizer/basenames.s b/llvm/test/tools/llvm-symbolizer/basenames.s
new file mode 100644
index 00000000000..b95817c6522
--- /dev/null
+++ b/llvm/test/tools/llvm-symbolizer/basenames.s
@@ -0,0 +1,12 @@
+# 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 --basenames --obj=%t.o | FileCheck %s
+# RUN: llvm-symbolizer 0 -s --obj=%t.o | FileCheck %s
+# RUN: llvm-symbolizer 0 --obj=%t.o | FileCheck %s -DDIR=%p --check-prefix=DEFAULT
+
+# CHECK: {{^}}basenames.s:4
+# DEFAULT: [[DIR]]{{\\|/}}basenames.s:4
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
index 5986e5bbdcf..7414a9db284 100644
--- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
+++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp
@@ -54,6 +54,12 @@ static cl::opt<bool>
ClPrintInlining("inlining", cl::init(true),
cl::desc("Print all inlined frames for a given address"));
+// -basenames, -s
+static cl::opt<bool> ClBasenames("basenames", cl::init(false),
+ cl::desc("Strip directory names from paths"));
+static cl::alias ClBasenamesShort("s", cl::desc("Alias for -basenames"),
+ cl::NotHidden, cl::aliasopt(ClBasenames));
+
// -demangle, -C, -no-demangle
static cl::opt<bool>
ClDemangle("demangle", cl::init(true), cl::desc("Demangle function names"));
@@ -223,7 +229,8 @@ int main(int argc, char **argv) {
LLVMSymbolizer Symbolizer(Opts);
DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None,
- ClPrettyPrint, ClPrintSourceContextLines, ClVerbose);
+ ClPrettyPrint, ClPrintSourceContextLines, ClVerbose,
+ ClBasenames);
if (ClInputAddresses.empty()) {
const int kMaxInputStringLength = 1024;
OpenPOWER on IntegriCloud