diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2023-04-14 13:03:28 +0700 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2023-04-14 13:03:28 +0700 |
commit | 75f1f158812dabc03e70697b6b9c272230bce63d (patch) | |
tree | 2a364202b140f088af71af5573997717adfd70b3 /llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp | |
parent | a39b807d41f1f8ebe54b02769d3848e6d0d6e5a5 (diff) | |
download | llvm-75f1f158812dabc03e70697b6b9c272230bce63d.zip llvm-75f1f158812dabc03e70697b6b9c272230bce63d.tar.gz llvm-75f1f158812dabc03e70697b6b9c272230bce63d.tar.bz2 |
[symbolizer] Change error message if module not found
If llvm-symbolize did not find module, the error looked like:
LLVMSymbolizer: error reading file: No such file or directory
This message does not follow common practice: LLVMSymbolizer is not an
utility name. Also the message did not not contain the name of missed file.
With this change the error message looks differently:
llvm-symbolizer: error: 'abc': No such file or directory
This format is closer to messages produced by other utilities and allow
proper coloring.
Differential Revision: https://reviews.llvm.org/D148032
Diffstat (limited to 'llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp')
-rw-r--r-- | llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp index 419f998..bcbf284 100644 --- a/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp +++ b/llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp @@ -36,6 +36,7 @@ #include "llvm/Support/InitLLVM.h" #include "llvm/Support/Path.h" #include "llvm/Support/StringSaver.h" +#include "llvm/Support/WithColor.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> #include <cstdio> @@ -83,6 +84,16 @@ public: }; } // namespace +static std::string ToolName; + +static void printError(const ErrorInfoBase &EI, StringRef Path) { + WithColor::error(errs(), ToolName); + if (!EI.isA<FileError>()) + errs() << "'" << Path << "': "; + EI.log(errs()); + errs() << '\n'; +} + template <typename T> static void print(const Request &Request, Expected<T> &ResOrErr, DIPrinter &Printer) { @@ -96,8 +107,7 @@ static void print(const Request &Request, Expected<T> &ResOrErr, bool PrintEmpty = true; handleAllErrors(std::move(ResOrErr.takeError()), [&](const ErrorInfoBase &EI) { - PrintEmpty = Printer.printError( - Request, EI, "LLVMSymbolizer: error reading file: "); + PrintEmpty = Printer.printError(Request, EI); }); if (PrintEmpty) @@ -378,7 +388,8 @@ int main(int argc, char **argv) { InitLLVM X(argc, argv); sys::InitializeCOMRAII COM(sys::COMThreadingMode::MultiThreaded); - bool IsAddr2Line = sys::path::stem(argv[0]).contains("addr2line"); + ToolName = argv[0]; + bool IsAddr2Line = sys::path::stem(ToolName).contains("addr2line"); BumpPtrAllocator A; StringSaver Saver(A); SymbolizerOptTable Tbl; @@ -461,11 +472,11 @@ int main(int argc, char **argv) { std::unique_ptr<DIPrinter> Printer; if (Style == OutputStyle::GNU) - Printer = std::make_unique<GNUPrinter>(outs(), errs(), Config); + Printer = std::make_unique<GNUPrinter>(outs(), printError, Config); else if (Style == OutputStyle::JSON) Printer = std::make_unique<JSONPrinter>(outs(), Config); else - Printer = std::make_unique<LLVMPrinter>(outs(), errs(), Config); + Printer = std::make_unique<LLVMPrinter>(outs(), printError, Config); std::vector<std::string> InputAddresses = Args.getAllArgValues(OPT_INPUT); if (InputAddresses.empty()) { |