diff options
author | Kevin Enderby <enderby@apple.com> | 2016-05-02 20:28:12 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2016-05-02 20:28:12 +0000 |
commit | 7bd8d994978d6404a79b28e04a802d070c45ba16 (patch) | |
tree | b827e6424c503f1ec157ad5dd700b9a0fee9bc06 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 34c549ea02081e48946750adbc928ae57ff67bd9 (diff) | |
download | bcm5719-llvm-7bd8d994978d6404a79b28e04a802d070c45ba16.tar.gz bcm5719-llvm-7bd8d994978d6404a79b28e04a802d070c45ba16.zip |
Thread Expected<...> up from libObject’s getType() for symbols to allow llvm-objdump to produce a good error message.
Produce another specific error message for a malformed Mach-O file when a symbol’s
section index is more than the number of sections. The existing test case in test/Object/macho-invalid.test
for macho-invalid-section-index-getSectionRawName now reports the error with the message indicating
that a symbol at a specific index has a bad section index and that bad section 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.
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.
llvm-svn: 268298
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 2fcd59fe2b2..1eb9f61c6ac 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -490,9 +490,9 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj, const Elf_Sym *symb = Obj->getSymbol(SI->getRawDataRefImpl()); StringRef Target; if (symb->getType() == ELF::STT_SECTION) { - ErrorOr<section_iterator> SymSI = SI->getSection(); - if (std::error_code EC = SymSI.getError()) - return EC; + Expected<section_iterator> SymSI = SI->getSection(); + if (!SymSI) + return errorToErrorCode(SymSI.takeError()); const Elf_Shdr *SymSec = Obj->getSection((*SymSI)->getRawDataRefImpl()); ErrorOr<StringRef> SecName = EF.getSectionName(SymSec); if (std::error_code EC = SecName.getError()) @@ -967,8 +967,8 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (Name->empty()) continue; - ErrorOr<section_iterator> SectionOrErr = Symbol.getSection(); - error(SectionOrErr.getError()); + Expected<section_iterator> SectionOrErr = Symbol.getSection(); + error(errorToErrorCode(SectionOrErr.takeError())); section_iterator SecI = *SectionOrErr; if (SecI == Obj->section_end()) continue; @@ -1357,12 +1357,13 @@ void llvm::PrintSymbolTable(const ObjectFile *o) { ErrorOr<uint64_t> AddressOrError = Symbol.getAddress(); error(AddressOrError.getError()); uint64_t Address = *AddressOrError; - ErrorOr<SymbolRef::Type> TypeOrError = Symbol.getType(); - error(TypeOrError.getError()); + Expected<SymbolRef::Type> TypeOrError = Symbol.getType(); + if (!TypeOrError) + report_error(o->getFileName(), TypeOrError.takeError()); SymbolRef::Type Type = *TypeOrError; uint32_t Flags = Symbol.getFlags(); - ErrorOr<section_iterator> SectionOrErr = Symbol.getSection(); - error(SectionOrErr.getError()); + Expected<section_iterator> SectionOrErr = Symbol.getSection(); + error(errorToErrorCode(SectionOrErr.takeError())); section_iterator Section = *SectionOrErr; StringRef Name; if (Type == SymbolRef::ST_Debug && Section != o->section_end()) { |