[llvm] r351795 - [llvm-symbolizer] Add support for --basenames/-s

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 22 02:24:32 PST 2019


Author: jhenderson
Date: Tue Jan 22 02:24:32 2019
New Revision: 351795

URL: http://llvm.org/viewvc/llvm-project?rev=351795&view=rev
Log:
[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

Added:
    llvm/trunk/test/tools/llvm-symbolizer/basenames.s
Modified:
    llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst
    llvm/trunk/include/llvm/DebugInfo/Symbolize/DIPrinter.h
    llvm/trunk/lib/DebugInfo/Symbolize/DIPrinter.cpp
    llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp

Modified: llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst?rev=351795&r1=351794&r2=351795&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-symbolizer.rst Tue Jan 22 02:24:32 2019
@@ -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
 -----------
 

Modified: llvm/trunk/include/llvm/DebugInfo/Symbolize/DIPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/Symbolize/DIPrinter.h?rev=351795&r1=351794&r2=351795&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/Symbolize/DIPrinter.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/Symbolize/DIPrinter.h Tue Jan 22 02:24:32 2019
@@ -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);

Modified: llvm/trunk/lib/DebugInfo/Symbolize/DIPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/Symbolize/DIPrinter.cpp?rev=351795&r1=351794&r2=351795&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/Symbolize/DIPrinter.cpp (original)
+++ llvm/trunk/lib/DebugInfo/Symbolize/DIPrinter.cpp Tue Jan 22 02:24:32 2019
@@ -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 &
   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);

Added: llvm/trunk/test/tools/llvm-symbolizer/basenames.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-symbolizer/basenames.s?rev=351795&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-symbolizer/basenames.s (added)
+++ llvm/trunk/test/tools/llvm-symbolizer/basenames.s Tue Jan 22 02:24:32 2019
@@ -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

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=351795&r1=351794&r2=351795&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp Tue Jan 22 02:24:32 2019
@@ -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;




More information about the llvm-commits mailing list