From db0d98345ba3ed6e3ea52184b08672b3b20b784a Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 27 Aug 2019 10:03:45 +0000 Subject: [PATCH] [llvm-objdump] - Remove one overload of reportError. NFCI. 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370034 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-objdump/MachODump.cpp | 46 ++++++++++++++++++------------------- tools/llvm-objdump/llvm-objdump.cpp | 28 ++++++++-------------- tools/llvm-objdump/llvm-objdump.h | 7 +++--- 3 files changed, 34 insertions(+), 47 deletions(-) diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index e6845400a92..5f4ff0c636c 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -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()) { @@ -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. @@ -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) { @@ -2269,8 +2268,8 @@ static void printArchiveChild(StringRef Filename, const Archive::Child &C, Expected 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 { @@ -2278,9 +2277,8 @@ static void printArchiveChild(StringRef Filename, const Archive::Child &C, outs() << Name << "\n"; } } else { - outs() << unwrapOrError(C.getRawName(), Filename, - getFileNameForError(C, ChildIndex), - ArchitectureName) + outs() << unwrapOrError(C.getRawName(), getFileNameForError(C, ChildIndex), + Filename, ArchitectureName) << "\n"; } } @@ -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() { @@ -2346,7 +2344,7 @@ void parseInputMachO(StringRef Filename) { Expected> 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(&*ChildOrErr.get())) { @@ -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> AOrErr = I->getAsArchive()) { @@ -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; } @@ -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 = @@ -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> AOrErr = I->getAsArchive()) { std::unique_ptr &A = *AOrErr; outs() << "Archive : " << Filename; @@ -2541,7 +2539,7 @@ void parseInputMachO(MachOUniversalBinary *UB) { Expected> 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; } diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 0b699673972..e066365cb1b 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -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); @@ -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 NameOrErr = Section->getName()) @@ -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); } @@ -2156,7 +2146,7 @@ static void dumpArchive(const Archive *A) { Expected> 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(&*ChildOrErr.get())) diff --git a/tools/llvm-objdump/llvm-objdump.h b/tools/llvm-objdump/llvm-objdump.h index 771e94a23f4..d36c4fdc00e 100644 --- a/tools/llvm-objdump/llvm-objdump.h +++ b/tools/llvm-objdump/llvm-objdump.h @@ -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 -- 2.11.4.GIT