Skip to content

Commit

Permalink
[llvm-objdump] - Remove one overload of reportError. NFCI.
Browse files Browse the repository at this point in the history
There is a problem with reportError we have.
Declaration says we have ArchiveName
that follows the FileName:

reportError(Error E, StringRef FileName, StringRef ArchiveName,...

Though implementation have them reversed. I cleaned it up and
removed an excessive reportError(Error E, StringRef File) version.

Rebased on top of D66418.

Differential revision: https://reviews.llvm.org/D66517

llvm-svn: 370034
  • Loading branch information
George Rimar committed Aug 27, 2019
1 parent 999e4c4 commit dd591bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 47 deletions.
46 changes: 22 additions & 24 deletions llvm/tools/llvm-objdump/MachODump.cpp
Expand Up @@ -1945,7 +1945,7 @@ static void ProcessMachO(StringRef Name, MachOObjectFile *MachOOF,
// the error message.
if (Disassemble || IndirectSymbols || !FilterSections.empty() || UnwindInfo)
if (Error Err = MachOOF->checkSymbolTable())
reportError(std::move(Err), ArchiveName, FileName, ArchitectureName);
reportError(std::move(Err), FileName, ArchiveName, ArchitectureName);

if (DisassembleAll) {
for (const SectionRef &Section : MachOOF->sections()) {
Expand Down Expand Up @@ -2219,9 +2219,8 @@ static void printArchiveChild(StringRef Filename, const Archive::Child &C,
if (print_offset)
outs() << C.getChildOffset() << "\t";
sys::fs::perms Mode =
unwrapOrError(C.getAccessMode(), Filename,
getFileNameForError(C, ChildIndex),
ArchitectureName);
unwrapOrError(C.getAccessMode(), getFileNameForError(C, ChildIndex),
Filename, ArchitectureName);
if (verbose) {
// FIXME: this first dash, "-", is for (Mode & S_IFMT) == S_IFREG.
// But there is nothing in sys::fs::perms for S_IFMT or S_IFREG.
Expand All @@ -2239,14 +2238,14 @@ static void printArchiveChild(StringRef Filename, const Archive::Child &C,
outs() << format("0%o ", Mode);
}

outs() << format(
"%3d/%-3d %5" PRId64 " ",
unwrapOrError(C.getUID(), Filename, getFileNameForError(C, ChildIndex),
ArchitectureName),
unwrapOrError(C.getGID(), Filename, getFileNameForError(C, ChildIndex),
ArchitectureName),
unwrapOrError(C.getRawSize(), Filename,
getFileNameForError(C, ChildIndex), ArchitectureName));
outs() << format("%3d/%-3d %5" PRId64 " ",
unwrapOrError(C.getUID(), getFileNameForError(C, ChildIndex),
Filename, ArchitectureName),
unwrapOrError(C.getGID(), getFileNameForError(C, ChildIndex),
Filename, ArchitectureName),
unwrapOrError(C.getRawSize(),
getFileNameForError(C, ChildIndex), Filename,
ArchitectureName));

StringRef RawLastModified = C.getRawLastModified();
if (verbose) {
Expand All @@ -2269,18 +2268,17 @@ static void printArchiveChild(StringRef Filename, const Archive::Child &C,
Expected<StringRef> NameOrErr = C.getName();
if (!NameOrErr) {
consumeError(NameOrErr.takeError());
outs() << unwrapOrError(C.getRawName(), Filename,
getFileNameForError(C, ChildIndex),
outs() << unwrapOrError(C.getRawName(),
getFileNameForError(C, ChildIndex), Filename,
ArchitectureName)
<< "\n";
} else {
StringRef Name = NameOrErr.get();
outs() << Name << "\n";
}
} else {
outs() << unwrapOrError(C.getRawName(), Filename,
getFileNameForError(C, ChildIndex),
ArchitectureName)
outs() << unwrapOrError(C.getRawName(), getFileNameForError(C, ChildIndex),
Filename, ArchitectureName)
<< "\n";
}
}
Expand All @@ -2295,7 +2293,7 @@ static void printArchiveHeaders(StringRef Filename, Archive *A, bool verbose,
ArchitectureName);

if (Err)
reportError(std::move(Err), StringRef(), Filename, ArchitectureName);
reportError(std::move(Err), Filename, "", ArchitectureName);
}

static bool ValidateArchFlags() {
Expand Down Expand Up @@ -2346,7 +2344,7 @@ void parseInputMachO(StringRef Filename) {
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
reportError(std::move(E), Filename, getFileNameForError(C, I));
reportError(std::move(E), getFileNameForError(C, I), Filename);
continue;
}
if (MachOObjectFile *O = dyn_cast<MachOObjectFile>(&*ChildOrErr.get())) {
Expand Down Expand Up @@ -2408,7 +2406,7 @@ void parseInputMachO(MachOUniversalBinary *UB) {
ProcessMachO(Filename, MachOOF, "", ArchitectureName);
} else if (Error E = isNotObjectErrorInvalidFileType(
ObjOrErr.takeError())) {
reportError(std::move(E), Filename, StringRef(), ArchitectureName);
reportError(std::move(E), "", Filename, ArchitectureName);
continue;
} else if (Expected<std::unique_ptr<Archive>> AOrErr =
I->getAsArchive()) {
Expand All @@ -2428,7 +2426,7 @@ void parseInputMachO(MachOUniversalBinary *UB) {
if (!ChildOrErr) {
if (Error E =
isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
reportError(std::move(E), Filename, getFileNameForError(C, I),
reportError(std::move(E), getFileNameForError(C, I), Filename,
ArchitectureName);
continue;
}
Expand Down Expand Up @@ -2489,7 +2487,7 @@ void parseInputMachO(MachOUniversalBinary *UB) {
if (!ChildOrErr) {
if (Error E =
isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
reportError(std::move(E), Filename, getFileNameForError(C, I));
reportError(std::move(E), getFileNameForError(C, I), Filename);
continue;
}
if (MachOObjectFile *O =
Expand Down Expand Up @@ -2524,7 +2522,7 @@ void parseInputMachO(MachOUniversalBinary *UB) {
ProcessMachO(Filename, MachOOF, "", ArchitectureName);
} else if (Error E =
isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
reportError(std::move(E), StringRef(), Filename, ArchitectureName);
reportError(std::move(E), Filename, "", ArchitectureName);
} else if (Expected<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) {
std::unique_ptr<Archive> &A = *AOrErr;
outs() << "Archive : " << Filename;
Expand All @@ -2541,7 +2539,7 @@ void parseInputMachO(MachOUniversalBinary *UB) {
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
reportError(std::move(E), Filename, getFileNameForError(C, I),
reportError(std::move(E), getFileNameForError(C, I), Filename,
ArchitectureName);
continue;
}
Expand Down
28 changes: 9 additions & 19 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Expand Up @@ -389,18 +389,8 @@ LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message) {
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef File) {
assert(E);
std::string Buf;
raw_string_ostream OS(Buf);
logAllUnhandledErrors(std::move(E), OS);
OS.flush();
WithColor::error(errs(), ToolName) << "'" << File << "': " << Buf;
exit(1);
}

LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef ArchiveName,
StringRef FileName,
LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef FileName,
StringRef ArchiveName,
StringRef ArchitectureName) {
assert(E);
WithColor::error(errs(), ToolName);
Expand Down Expand Up @@ -1752,15 +1742,15 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
const StringRef FileName = O->getFileName();
for (auto I = O->symbol_begin(), E = O->symbol_end(); I != E; ++I) {
const SymbolRef &Symbol = *I;
uint64_t Address = unwrapOrError(Symbol.getAddress(), ArchiveName, FileName,
uint64_t Address = unwrapOrError(Symbol.getAddress(), FileName, ArchiveName,
ArchitectureName);
if ((Address < StartAddress) || (Address > StopAddress))
continue;
SymbolRef::Type Type = unwrapOrError(Symbol.getType(), ArchiveName,
FileName, ArchitectureName);
SymbolRef::Type Type = unwrapOrError(Symbol.getType(), FileName,
ArchiveName, ArchitectureName);
uint32_t Flags = Symbol.getFlags();
section_iterator Section = unwrapOrError(Symbol.getSection(), ArchiveName,
FileName, ArchitectureName);
section_iterator Section = unwrapOrError(Symbol.getSection(), FileName,
ArchiveName, ArchitectureName);
StringRef Name;
if (Type == SymbolRef::ST_Debug && Section != O->section_end()) {
if (Expected<StringRef> NameOrErr = Section->getName())
Expand All @@ -1769,7 +1759,7 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,
consumeError(NameOrErr.takeError());

} else {
Name = unwrapOrError(Symbol.getName(), ArchiveName, FileName,
Name = unwrapOrError(Symbol.getName(), FileName, ArchiveName,
ArchitectureName);
}

Expand Down Expand Up @@ -2156,7 +2146,7 @@ static void dumpArchive(const Archive *A) {
Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
if (!ChildOrErr) {
if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
reportError(std::move(E), A->getFileName(), getFileNameForError(C, I));
reportError(std::move(E), getFileNameForError(C, I), A->getFileName());
continue;
}
if (ObjectFile *O = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
Expand Down
7 changes: 3 additions & 4 deletions llvm/tools/llvm-objdump/llvm-objdump.h
Expand Up @@ -128,10 +128,9 @@ void printSectionContents(const object::ObjectFile *O);
void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
StringRef ArchitectureName = StringRef());
LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message);
LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef File);
LLVM_ATTRIBUTE_NORETURN void
reportError(Error E, StringRef FileName, StringRef ArchiveName,
StringRef ArchitectureName = StringRef());
LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef FileName,
StringRef ArchiveName = "",
StringRef ArchitectureName = "");
void reportWarning(Twine Message, StringRef File);

template <typename T, typename... Ts>
Expand Down

0 comments on commit dd591bd

Please sign in to comment.