Index: docs/CommandGuide/llvm-symbolizer.rst =================================================================== --- docs/CommandGuide/llvm-symbolizer.rst +++ docs/CommandGuide/llvm-symbolizer.rst @@ -115,6 +115,10 @@ 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 ----------- Index: include/llvm/DebugInfo/Symbolize/DIPrinter.h =================================================================== --- include/llvm/DebugInfo/Symbolize/DIPrinter.h +++ include/llvm/DebugInfo/Symbolize/DIPrinter.h @@ -30,6 +30,7 @@ bool PrintPretty; int PrintSourceContext; bool Verbose; + bool Basenames; void print(const DILineInfo &Info, bool Inlined); void printContext(const std::string &FileName, int64_t Line); @@ -37,10 +38,10 @@ 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); Index: lib/DebugInfo/Symbolize/DIPrinter.cpp =================================================================== --- lib/DebugInfo/Symbolize/DIPrinter.cpp +++ lib/DebugInfo/Symbolize/DIPrinter.cpp @@ -19,6 +19,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 #include @@ -78,6 +79,8 @@ 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); Index: test/tools/llvm-symbolizer/basenames.s =================================================================== --- test/tools/llvm-symbolizer/basenames.s +++ 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 Index: tools/llvm-symbolizer/llvm-symbolizer.cpp =================================================================== --- tools/llvm-symbolizer/llvm-symbolizer.cpp +++ tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -55,6 +55,12 @@ ClPrintInlining("inlining", cl::init(true), cl::desc("Print all inlined frames for a given address")); +// -basenames, -s +static cl::opt 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 static cl::opt ClDemangle("demangle", cl::init(true), cl::desc("Demangle function names")); @@ -217,7 +223,8 @@ LLVMSymbolizer Symbolizer(Opts); DIPrinter Printer(outs(), ClPrintFunctions != FunctionNameKind::None, - ClPrettyPrint, ClPrintSourceContextLines, ClVerbose); + ClPrettyPrint, ClPrintSourceContextLines, ClVerbose, + ClBasenames); if (ClInputAddresses.empty()) { const int kMaxInputStringLength = 1024;