Skip to content

Commit 3f20968

Browse files
committed
[llvm-objdump] Migrate some functions from std::error_code to Error
llvm-svn: 357965
1 parent 206b992 commit 3f20968

File tree

4 files changed

+28
-38
lines changed

4 files changed

+28
-38
lines changed

llvm/tools/llvm-objdump/COFFDump.cpp

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -155,67 +155,67 @@ static void printAllUnwindCodes(ArrayRef<UnwindCode> UCs) {
155155
}
156156

157157
// Given a symbol sym this functions returns the address and section of it.
158-
static std::error_code
159-
resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
160-
const coff_section *&ResolvedSection,
161-
uint64_t &ResolvedAddr) {
158+
static Error resolveSectionAndAddress(const COFFObjectFile *Obj,
159+
const SymbolRef &Sym,
160+
const coff_section *&ResolvedSection,
161+
uint64_t &ResolvedAddr) {
162162
Expected<uint64_t> ResolvedAddrOrErr = Sym.getAddress();
163163
if (!ResolvedAddrOrErr)
164-
return errorToErrorCode(ResolvedAddrOrErr.takeError());
164+
return ResolvedAddrOrErr.takeError();
165165
ResolvedAddr = *ResolvedAddrOrErr;
166166
Expected<section_iterator> Iter = Sym.getSection();
167167
if (!Iter)
168-
return errorToErrorCode(Iter.takeError());
168+
return Iter.takeError();
169169
ResolvedSection = Obj->getCOFFSection(**Iter);
170-
return std::error_code();
170+
return Error::success();
171171
}
172172

173173
// Given a vector of relocations for a section and an offset into this section
174174
// the function returns the symbol used for the relocation at the offset.
175-
static std::error_code resolveSymbol(const std::vector<RelocationRef> &Rels,
175+
static Error resolveSymbol(const std::vector<RelocationRef> &Rels,
176176
uint64_t Offset, SymbolRef &Sym) {
177177
for (auto &R : Rels) {
178178
uint64_t Ofs = R.getOffset();
179179
if (Ofs == Offset) {
180180
Sym = *R.getSymbol();
181-
return std::error_code();
181+
return Error::success();
182182
}
183183
}
184-
return object_error::parse_failed;
184+
return make_error<BinaryError>();
185185
}
186186

187187
// Given a vector of relocations for a section and an offset into this section
188188
// the function resolves the symbol used for the relocation at the offset and
189189
// returns the section content and the address inside the content pointed to
190190
// by the symbol.
191-
static std::error_code
191+
static Error
192192
getSectionContents(const COFFObjectFile *Obj,
193193
const std::vector<RelocationRef> &Rels, uint64_t Offset,
194194
ArrayRef<uint8_t> &Contents, uint64_t &Addr) {
195195
SymbolRef Sym;
196-
if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
197-
return EC;
196+
if (Error E = resolveSymbol(Rels, Offset, Sym))
197+
return E;
198198
const coff_section *Section;
199-
if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
200-
return EC;
199+
if (Error E = resolveSectionAndAddress(Obj, Sym, Section, Addr))
200+
return E;
201201
if (std::error_code EC = Obj->getSectionContents(Section, Contents))
202-
return EC;
203-
return std::error_code();
202+
return errorCodeToError(EC);
203+
return Error::success();
204204
}
205205

206206
// Given a vector of relocations for a section and an offset into this section
207207
// the function returns the name of the symbol used for the relocation at the
208208
// offset.
209-
static std::error_code resolveSymbolName(const std::vector<RelocationRef> &Rels,
210-
uint64_t Offset, StringRef &Name) {
209+
static Error resolveSymbolName(const std::vector<RelocationRef> &Rels,
210+
uint64_t Offset, StringRef &Name) {
211211
SymbolRef Sym;
212-
if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
212+
if (Error EC = resolveSymbol(Rels, Offset, Sym))
213213
return EC;
214214
Expected<StringRef> NameOrErr = Sym.getName();
215215
if (!NameOrErr)
216-
return errorToErrorCode(NameOrErr.takeError());
216+
return NameOrErr.takeError();
217217
Name = *NameOrErr;
218-
return std::error_code();
218+
return Error::success();
219219
}
220220

221221
static void printCOFFSymbolAddress(llvm::raw_ostream &Out,
@@ -653,7 +653,7 @@ void llvm::printCOFFSymbolTable(const COFFObjectFile *coff) {
653653
for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
654654
Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
655655
StringRef Name;
656-
error(errorToErrorCode(Symbol.takeError()));
656+
error(Symbol.takeError());
657657
error(coff->getSymbolName(*Symbol, Name));
658658

659659
outs() << "[" << format("%2d", SI) << "]"

llvm/tools/llvm-objdump/MachODump.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,12 @@ static void printRelocationTargetName(const MachOObjectFile *O,
362362
// If we couldn't find a symbol that this relocation refers to, try
363363
// to find a section beginning instead.
364364
for (const SectionRef &Section : ToolSectionFilter(*O)) {
365-
std::error_code ec;
366-
367365
StringRef Name;
368366
uint64_t Addr = Section.getAddress();
369367
if (Addr != Val)
370368
continue;
371-
if ((ec = Section.getName(Name)))
372-
report_error(O->getFileName(), ec);
369+
if (std::error_code EC = Section.getName(Name))
370+
report_error(errorCodeToError(EC), O->getFileName());
373371
Fmt << Name;
374372
return;
375373
}

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,6 @@ LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
355355
exit(1);
356356
}
357357

358-
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(StringRef File,
359-
std::error_code EC) {
360-
assert(EC);
361-
WithColor::error(errs(), ToolName)
362-
<< "'" << File << "': " << EC.message() << ".\n";
363-
exit(1);
364-
}
365-
366358
LLVM_ATTRIBUTE_NORETURN void llvm::report_error(Error E, StringRef File) {
367359
assert(E);
368360
std::string Buf;
@@ -2013,7 +2005,8 @@ static void dumpArchive(const Archive *A) {
20132005
else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
20142006
dumpObject(I, A, &C);
20152007
else
2016-
report_error(A->getFileName(), object_error::invalid_file_type);
2008+
report_error(errorCodeToError(object_error::invalid_file_type),
2009+
A->getFileName());
20172010
}
20182011
if (Err)
20192012
report_error(std::move(Err), A->getFileName());
@@ -2040,7 +2033,7 @@ static void dumpInput(StringRef file) {
20402033
else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Binary))
20412034
parseInputMachO(UB);
20422035
else
2043-
report_error(file, object_error::invalid_file_type);
2036+
report_error(errorCodeToError(object_error::invalid_file_type), file);
20442037
}
20452038

20462039
int main(int argc, char **argv) {

llvm/tools/llvm-objdump/llvm-objdump.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
172172
void warn(StringRef Message);
173173
LLVM_ATTRIBUTE_NORETURN void error(Twine Message);
174174
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message);
175-
LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, std::error_code EC);
176175
LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef File);
177176
LLVM_ATTRIBUTE_NORETURN void
178177
report_error(Error E, StringRef FileName, StringRef ArchiveName,

0 commit comments

Comments
 (0)