StringRef Command) = 0;
virtual bool printError(const Request &Request,
- const ErrorInfoBase &ErrorInfo) = 0;
+ const ErrorInfoBase &ErrorInfo,
+ StringRef ErrorBanner) = 0;
virtual void listBegin() = 0;
virtual void listEnd() = 0;
int SourceContextLines;
};
-using ErrorHandler = function_ref<void(const ErrorInfoBase &, StringRef)>;
-
class PlainPrinterBase : public DIPrinter {
protected:
raw_ostream &OS;
- ErrorHandler ErrHandler;
+ raw_ostream &ES;
PrinterConfig Config;
void print(const DILineInfo &Info, bool Inlined);
void printHeader(uint64_t Address);
public:
- PlainPrinterBase(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
- : OS(OS), ErrHandler(EH), Config(Config) {}
+ PlainPrinterBase(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
+ : OS(OS), ES(ES), Config(Config) {}
void print(const Request &Request, const DILineInfo &Info) override;
void print(const Request &Request, const DIInliningInfo &Info) override;
void printInvalidCommand(const Request &Request, StringRef Command) override;
- bool printError(const Request &Request,
- const ErrorInfoBase &ErrorInfo) override;
+ bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo,
+ StringRef ErrorBanner) override;
void listBegin() override {}
void listEnd() override {}
void printFooter() override;
public:
- LLVMPrinter(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
- : PlainPrinterBase(OS, EH, Config) {}
+ LLVMPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
+ : PlainPrinterBase(OS, ES, Config) {}
};
class GNUPrinter : public PlainPrinterBase {
void printSimpleLocation(StringRef Filename, const DILineInfo &Info) override;
public:
- GNUPrinter(raw_ostream &OS, ErrorHandler EH, PrinterConfig &Config)
- : PlainPrinterBase(OS, EH, Config) {}
-
+ GNUPrinter(raw_ostream &OS, raw_ostream &ES, PrinterConfig &Config)
+ : PlainPrinterBase(OS, ES, Config) {}
};
class JSONPrinter : public DIPrinter {
void printInvalidCommand(const Request &Request, StringRef Command) override;
- bool printError(const Request &Request,
- const ErrorInfoBase &ErrorInfo) override;
+ bool printError(const Request &Request, const ErrorInfoBase &ErrorInfo,
+ StringRef ErrorBanner) override;
void listBegin() override;
void listEnd() override;
}
bool PlainPrinterBase::printError(const Request &Request,
- const ErrorInfoBase &ErrorInfo) {
- ErrHandler(ErrorInfo, Request.ModuleName);
+ const ErrorInfoBase &ErrorInfo,
+ StringRef ErrorBanner) {
+ ES << ErrorBanner;
+ ErrorInfo.log(ES);
+ ES << '\n';
// Print an empty struct too.
return true;
}
StringRef Command) {
printError(Request,
StringError("unable to parse arguments: " + Command,
- std::make_error_code(std::errc::invalid_argument)));
+ std::make_error_code(std::errc::invalid_argument)),
+ "");
}
bool JSONPrinter::printError(const Request &Request,
- const ErrorInfoBase &ErrorInfo) {
+ const ErrorInfoBase &ErrorInfo,
+ StringRef ErrorBanner) {
json::Object Json = toJSON(Request, ErrorInfo.message());
if (ObjectList)
ObjectList->push_back(std::move(Json));
std::string Path;
if (!getOrFindDebugBinary(BuildID, Path)) {
return createStringError(errc::no_such_file_or_directory,
- "could not find build ID");
+ Twine("could not find build ID '") +
+ toHex(BuildID) + "'");
}
return getOrCreateModuleInfo(Path);
}
# RUN: yaml2obj --docnum=2 %s -o %t2
# RUN: llvm-symbolizer --obj=%t2 0 0 2>&1 | FileCheck %s --check-prefix=CHECK2
-# CHECK2: llvm-symbolizer{{.*}}: error: '{{.*}}symtab-file2.yaml.tmp2': st_name (0xffff) is past the end of the string table of size
+# CHECK2: error reading file: st_name (0xffff) is past the end of the string table of size
# CHECK2-NEXT: ??
# CHECK2-NEXT: ??:0:0
# CHECK2-EMPTY:
RUN: llvm-symbolizer --obj=unexisting-file 0x1234 2>&1 | FileCheck -DMSG=%errc_ENOENT %s
-CHECK: llvm-symbolizer{{.*}}: error: 'unexisting-file': [[MSG]]
+CHECK: LLVMSymbolizer: error reading file: [[MSG]]
STDOUT: ??
STDOUT: ??:0:0
-STDERR-COUNT-2: llvm-symbolizer{{.*}}: error: 'ABAD': could not find build ID
+STDERR-COUNT-2: LLVMSymbolizer: error reading file: could not find build ID 'ABAD'
RUN: llvm-symbolizer --output-style=LLVM --obj=%p/Inputs/not.exist 0x1 0x2 --no-inlines 2>&1 \
RUN: | FileCheck %s --check-prefix=NOT-EXIST-LLVM -DMSG=%errc_ENOENT
-# NOT-EXIST-GNU: llvm-symbolizer{{.*}}: error: '{{.*}}Inputs/not.exist': [[MSG]]
+# NOT-EXIST-GNU: LLVMSymbolizer: error reading file: [[MSG]]
# NOT-EXIST-GNU-NEXT: ??
# NOT-EXIST-GNU-NEXT: ??:0
# NOT-EXIST-GNU-NEXT: ??
# NOT-EXIST-GNU-NEXT: ??:0
-# NOT-EXIST-LLVM: llvm-symbolizer{{.*}}: error: '{{.*}}Inputs/not.exist': [[MSG]]
+# NOT-EXIST-LLVM: LLVMSymbolizer: error reading file: [[MSG]]
# NOT-EXIST-LLVM-NEXT: ??
# NOT-EXIST-LLVM-NEXT: ??:0:0
# NOT-EXIST-LLVM-EMPTY:
llvm-symbolizer should print one error and two unknown line info records.
-ERROR: llvm-symbolizer{{.*}}: error: '{{.*}}missing_pdb.pdb': [[MSG]]
+ERROR: LLVMSymbolizer: error reading file: {{.*}}: [[MSG]]
ERROR-NOT: error reading file
CHECK: ??
#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>
};
} // 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) {
bool PrintEmpty = true;
handleAllErrors(std::move(ResOrErr.takeError()),
[&](const ErrorInfoBase &EI) {
- PrintEmpty = Printer.printError(Request, EI);
+ PrintEmpty = Printer.printError(
+ Request, EI, "LLVMSymbolizer: error reading file: ");
});
if (PrintEmpty)
InitLLVM X(argc, argv);
sys::InitializeCOMRAII COM(sys::COMThreadingMode::MultiThreaded);
- ToolName = argv[0];
- bool IsAddr2Line = sys::path::stem(ToolName).contains("addr2line");
+ bool IsAddr2Line = sys::path::stem(argv[0]).contains("addr2line");
BumpPtrAllocator A;
StringSaver Saver(A);
SymbolizerOptTable Tbl;
std::unique_ptr<DIPrinter> Printer;
if (Style == OutputStyle::GNU)
- Printer = std::make_unique<GNUPrinter>(outs(), printError, Config);
+ Printer = std::make_unique<GNUPrinter>(outs(), errs(), Config);
else if (Style == OutputStyle::JSON)
Printer = std::make_unique<JSONPrinter>(outs(), Config);
else
- Printer = std::make_unique<LLVMPrinter>(outs(), printError, Config);
+ Printer = std::make_unique<LLVMPrinter>(outs(), errs(), Config);
std::vector<std::string> InputAddresses = Args.getAllArgValues(OPT_INPUT);
if (InputAddresses.empty()) {