From 81e8b7d9496688476c6bb601cce2575c3f2811ed Mon Sep 17 00:00:00 2001 From: Kevin Enderby Date: Wed, 20 Apr 2016 21:24:34 +0000 Subject: Thread Expected<...> up from libObject’s getName() for symbols to allow llvm-objdump to produce a good error message. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Produce another specific error message for a malformed Mach-O file when a symbol’s string index is past the end of the string table. The existing test case in test/Object/macho-invalid.test for macho-invalid-symbol-name-past-eof now reports the error with the message indicating that a symbol at a specific index has a bad sting index and that bad string index value. Again converting interfaces to Expected<> from ErrorOr<> does involve touching a number of places. Where the existing code reported the error with a string message or an error code it was converted to do the same. There is some code for this that could be factored into a routine but I would like to leave that for the code owners post-commit to do as they want for handling an llvm::Error. An example of how this could be done is shown in the diff in lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h which had a Check() routine already for std::error_code so I added one like it for llvm::Error . Also there some were bugs in the existing code that did not deal with the old ErrorOr<> return values.  So now with Expected<> since they must be checked and the error handled, I added a TODO and a comment: “// TODO: Actually report errors helpfully” and a call something like consumeError(NameOrErr.takeError()) so the buggy code will not crash since needed to deal with the Error. Note there fixes needed to lld that goes along with this that I will commit right after this. So expect lld not to built after this commit and before the next one. llvm-svn: 266919 --- llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp | 44 +++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp') diff --git a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp index 0f74a998707..8d00c90b3c1 100644 --- a/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp +++ b/llvm/tools/llvm-readobj/ARMWinEHPrinter.cpp @@ -570,9 +570,14 @@ bool Decoder::dumpXDataRecord(const COFFObjectFile &COFF, if (!Symbol) Symbol = getSymbol(COFF, Address, /*FunctionOnly=*/true); - ErrorOr Name = Symbol->getName(); - if (std::error_code EC = Name.getError()) - report_fatal_error(EC.message()); + Expected Name = Symbol->getName(); + if (!Name) { + std::string Buf; + llvm::raw_string_ostream OS(Buf); + logAllUnhandledErrors(Name.takeError(), OS, ""); + OS.flush(); + report_fatal_error(Buf); + } ListScope EHS(SW, "ExceptionHandler"); SW.printString("Routine", formatSymbol(*Name, Address)); @@ -604,9 +609,14 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF, StringRef FunctionName; uint64_t FunctionAddress; if (Function) { - ErrorOr FunctionNameOrErr = Function->getName(); - if (std::error_code EC = FunctionNameOrErr.getError()) - report_fatal_error(EC.message()); + Expected FunctionNameOrErr = Function->getName(); + if (!FunctionNameOrErr) { + std::string Buf; + llvm::raw_string_ostream OS(Buf); + logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, ""); + OS.flush(); + report_fatal_error(Buf); + } FunctionName = *FunctionNameOrErr; ErrorOr FunctionAddressOrErr = Function->getAddress(); if (std::error_code EC = FunctionAddressOrErr.getError()) @@ -622,9 +632,14 @@ bool Decoder::dumpUnpackedEntry(const COFFObjectFile &COFF, SW.printString("Function", formatSymbol(FunctionName, FunctionAddress)); if (XDataRecord) { - ErrorOr Name = XDataRecord->getName(); - if (std::error_code EC = Name.getError()) - report_fatal_error(EC.message()); + Expected Name = XDataRecord->getName(); + if (!Name) { + std::string Buf; + llvm::raw_string_ostream OS(Buf); + logAllUnhandledErrors(Name.takeError(), OS, ""); + OS.flush(); + report_fatal_error(Buf); + } ErrorOr AddressOrErr = XDataRecord->getAddress(); if (std::error_code EC = AddressOrErr.getError()) @@ -671,9 +686,14 @@ bool Decoder::dumpPackedEntry(const object::COFFObjectFile &COFF, StringRef FunctionName; uint64_t FunctionAddress; if (Function) { - ErrorOr FunctionNameOrErr = Function->getName(); - if (std::error_code EC = FunctionNameOrErr.getError()) - report_fatal_error(EC.message()); + Expected FunctionNameOrErr = Function->getName(); + if (!FunctionNameOrErr) { + std::string Buf; + llvm::raw_string_ostream OS(Buf); + logAllUnhandledErrors(FunctionNameOrErr.takeError(), OS, ""); + OS.flush(); + report_fatal_error(Buf); + } FunctionName = *FunctionNameOrErr; ErrorOr FunctionAddressOrErr = Function->getAddress(); FunctionAddress = *FunctionAddressOrErr; -- cgit v1.2.3