From e95f9a23fad52ffa3a5b6466c7dcdf910d099956 Mon Sep 17 00:00:00 2001 From: Vinicius Tinti Date: Fri, 16 Oct 2020 15:35:19 +0100 Subject: [llvm-objdump] Implement --prefix option The prefix given to --prefix will be added to GNU absolute paths when used with --source option (source interleaved with the disassembly). This matches GNU's objdump behavior. GNU and C++17 rules for absolute paths are different. Differential Revision: https://reviews.llvm.org/D85024 Fixes PR46368. Differential Revision: https://reviews.llvm.org/D85024 --- llvm/tools/llvm-objdump/llvm-objdump.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp') diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index d57ea8e..bc13b26 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -353,6 +353,10 @@ static cl::opt cl::cat(ObjdumpCat)); static cl::alias WideShort("w", cl::Grouping, cl::aliasopt(Wide)); +cl::opt objdump::Prefix("prefix", + cl::desc("Add prefix to absolute paths"), + cl::cat(ObjdumpCat)); + enum DebugVarsFormat { DVDisabled, DVUnicode, @@ -1031,6 +1035,13 @@ void SourcePrinter::printSourceLine(formatted_raw_ostream &OS, } } + if (!Prefix.empty() && sys::path::is_absolute_gnu(LineInfo.FileName)) { + SmallString<128> FilePath; + sys::path::append(FilePath, Prefix, LineInfo.FileName); + + LineInfo.FileName = std::string(FilePath); + } + if (PrintLines) printLines(OS, LineInfo, Delimiter, LVP); if (PrintSource) @@ -2961,6 +2972,10 @@ int main(int argc, char **argv) { if (InputFilenames.empty()) InputFilenames.push_back("a.out"); + // Removes trailing separators from prefix. + while (!Prefix.empty() && sys::path::is_separator(Prefix.back())) + Prefix.pop_back(); + if (AllHeaders) ArchiveHeaders = FileHeaders = PrivateHeaders = Relocations = SectionHeaders = SymbolTable = true; -- cgit v1.1