mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-12-14 07:09:08 +00:00
[llvm-objdump] Migrate some functions from std::error_code to Error
llvm-svn: 357965
This commit is contained in:
parent
e9e7b01ac5
commit
18d95a3fc3
@ -155,67 +155,67 @@ static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) {
|
||||
}
|
||||
|
||||
// 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 COFFObjectFile *coff) {
|
||||
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) << "]"
|
||||
|
@ -362,14 +362,12 @@ static void printRelocationTargetName(const MachOObjectFile *O,
|
||||
// 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;
|
||||
}
|
||||
|
@ -355,14 +355,6 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
|
||||
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) {
|
||||
|
@ -172,7 +172,6 @@ void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user