[llvm] r357965 - [llvm-objdump] Migrate some functions from std::error_code to Error
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 22:41:25 PDT 2019
Author: maskray
Date: Mon Apr 8 22:41:24 2019
New Revision: 357965
URL: http://llvm.org/viewvc/llvm-project?rev=357965&view=rev
Log:
[llvm-objdump] Migrate some functions from std::error_code to Error
Modified:
llvm/trunk/tools/llvm-objdump/COFFDump.cpp
llvm/trunk/tools/llvm-objdump/MachODump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
llvm/trunk/tools/llvm-objdump/llvm-objdump.h
Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=357965&r1=357964&r2=357965&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Mon Apr 8 22:41:24 2019
@@ -155,67 +155,67 @@ static void printAllUnwindCodes(ArrayRef
}
// Given a symbol sym this functions returns the address and section of it.
-static std::error_code
-resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
- const coff_section *&ResolvedSection,
- uint64_t &ResolvedAddr) {
+static Error resolveSectionAndAddress(const COFFObjectFile *Obj,
+ const SymbolRef &Sym,
+ const coff_section *&ResolvedSection,
+ uint64_t &ResolvedAddr) {
Expected<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
if (!ResolvedAddrOrErr)
- return errorToErrorCode(ResolvedAddrOrErr.takeError());
+ return ResolvedAddrOrErr.takeError();
ResolvedAddr = *ResolvedAddrOrErr;
Expected<section_iterator> Iter = Sym.getSection();
if (!Iter)
- return errorToErrorCode(Iter.takeError());
+ return Iter.takeError();
ResolvedSection = Obj->getCOFFSection(**Iter);
- return std::error_code();
+ return Error::success();
}
// Given a vector of relocations for a section and an offset into this section
// the function returns the symbol used for the relocation at the offset.
-static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
+static Error resolveSymbol(const std::vector<RelocationRef> &Rels,
uint64_t Offset, SymbolRef &Sym) {
for (auto &R : Rels) {
uint64_t Ofs = R.getOffset();
if (Ofs == Offset) {
Sym = *R.getSymbol();
- return std::error_code();
+ return Error::success();
}
}
- return object_error::parse_failed;
+ return make_error<BinaryError>();
}
// Given a vector of relocations for a section and an offset into this section
// the function resolves the symbol used for the relocation at the offset and
// returns the section content and the address inside the content pointed to
// by the symbol.
-static std::error_code
+static Error
getSectionContents(const COFFObjectFile *Obj,
const std::vector<RelocationRef> &Rels, uint64_t Offset,
ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
SymbolRef Sym;
- if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
- return EC;
+ if (Error E = resolveSymbol(Rels, Offset, Sym))
+ return E;
const coff_section *Section;
- if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
- return EC;
+ if (Error E = resolveSectionAndAddress(Obj, Sym, Section, Addr))
+ return E;
if (std::error_code EC = Obj->getSectionContents(Section, Contents))
- return EC;
- return std::error_code();
+ return errorCodeToError(EC);
+ return Error::success();
}
// Given a vector of relocations for a section and an offset into this section
// the function returns the name of the symbol used for the relocation at the
// offset.
-static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
- uint64_t Offset, StringRef &Name) {
+static Error resolveSymbolName(const std::vector<RelocationRef> &Rels,
+ uint64_t Offset, StringRef &Name) {
SymbolRef Sym;
- if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
+ if (Error EC = resolveSymbol(Rels, Offset, Sym))
return EC;
Expected<StringRef> NameOrErr = Sym.getName();
if (!NameOrErr)
- return errorToErrorCode(NameOrErr.takeError());
+ return NameOrErr.takeError();
Name = *NameOrErr;
- return std::error_code();
+ return Error::success();
}
static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
@@ -653,7 +653,7 @@ void llvm::printCOFFSymbolTable(const CO
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
StringRef Name;
- error(errorToErrorCode(Symbol.takeError()));
+ error(Symbol.takeError());
error(coff->getSymbolName(*Symbol, Name));
outs() << "[" << format("%2d", SI) << "]"
Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=357965&r1=357964&r2=357965&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Mon Apr 8 22:41:24 2019
@@ -362,14 +362,12 @@ static void printRelocationTargetName(co
// If we couldn't find a symbol that this relocation refers to, try
// to find a section beginning instead.
for (const SectionRef &Section : ToolSectionFilter(*O)) {
- std::error_code ec;
-
StringRef Name;
uint64_t Addr = Section.getAddress();
if (Addr != Val)
continue;
- if ((ec = Section.getName(Name)))
- report_error(O->getFileName(), ec);
+ if (std::error_code EC = Section.getName(Name))
+ report_error(errorCodeToError(EC), O->getFileName());
Fmt << Name;
return;
}
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=357965&r1=357964&r2=357965&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Mon Apr 8 22:41:24 2019
@@ -355,14 +355,6 @@ LLVM_ATTRIBUTE_NORETURN void llvm::repor
exit(1);
}
-LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
- std::error_code EC) {
- assert(EC);
- WithColor::error(errs(), ToolName)
- << "'" << File << "': " << EC.message() << ".\n";
- exit(1);
-}
-
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef File) {
assert(E);
std::string Buf;
@@ -2013,7 +2005,8 @@ static void dumpArchive(const Archive *A
else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
dumpObject(I, A, &C);
else
- report_error(A->getFileName(), object_error::invalid_file_type);
+ report_error(errorCodeToError(object_error::invalid_file_type),
+ A->getFileName());
}
if (Err)
report_error(std::move(Err), A->getFileName());
@@ -2040,7 +2033,7 @@ static void dumpInput(StringRef file) {
else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Binary))
parseInputMachO(UB);
else
- report_error(file, object_error::invalid_file_type);
+ report_error(errorCodeToError(object_error::invalid_file_type), file);
}
int main(int argc, char **argv) {
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.h?rev=357965&r1=357964&r2=357965&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Mon Apr 8 22:41:24 2019
@@ -172,7 +172,6 @@ void printSymbolTable(const object::Obje
void warn(StringRef Message);
LLVM_ATTRIBUTE_NORETURN void error(Twine Message);
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message);
-LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, std::error_code EC);
LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef File);
LLVM_ATTRIBUTE_NORETURN void
report_error(Error E, StringRef FileName, StringRef ArchiveName,
More information about the llvm-commits
mailing list