diff --git a/llvm/test/tools/llvm-symbolizer/relativenames.s b/llvm/test/tools/llvm-symbolizer/relativenames.s new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-symbolizer/relativenames.s @@ -0,0 +1,10 @@ +# 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 | FileCheck %s -DDIR=%p +# RUN: llvm-symbolizer 0 -r --obj=%t.o | FileCheck %s -DDIR=%p + +# CHECK: [[DIR]]{{\\|/}}relativenames.s:4 diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -77,6 +77,12 @@ static cl::alias ClBasenamesShort("s", cl::desc("Alias for -basenames"), cl::NotHidden, cl::aliasopt(ClBasenames)); +// -relativenames, -r +static cl::opt ClRelativenames("relativenames", cl::init(false), + cl::desc("Strip the compilation directory from paths")); +static cl::alias ClRelativenamesShort("r", cl::desc("Alias for -relativenames"), + cl::NotHidden, cl::aliasopt(ClRelativenames)); + // -demangle, -C, -no-demangle static cl::opt ClDemangle("demangle", cl::init(true), cl::desc("Demangle function names")); @@ -310,8 +316,11 @@ 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") {