[llvm] r369515 - [llvm-objdump] - Cleanup the error reporting.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 21 04:07:31 PDT 2019


Author: grimar
Date: Wed Aug 21 04:07:31 2019
New Revision: 369515

URL: http://llvm.org/viewvc/llvm-project?rev=369515&view=rev
Log:
[llvm-objdump] - Cleanup the error reporting.

The error reporting function are not consistent.

Before this change:

* They had inconsistent naming (e.g. 'error' vs 'report_error').
* Some of them reported the object name, others - dont.
* Some of them accepted the case when there was no error. (i.e. error code or Error had a success value).

This patch tries to cleanup it a bit.

It also renames report_error -> reportError, report_warning -> reportWarning
and removes a full stop from messages.

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

Modified:
    llvm/trunk/test/Object/macho-invalid.test
    llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test
    llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test
    llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-missing-source.test
    llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test
    llvm/trunk/test/tools/llvm-objdump/X86/start-stop-address.test
    llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test
    llvm/trunk/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test
    llvm/trunk/tools/llvm-objdump/COFFDump.cpp
    llvm/trunk/tools/llvm-objdump/ELFDump.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/test/Object/macho-invalid.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Object/macho-invalid.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/Object/macho-invalid.test (original)
+++ llvm/trunk/test/Object/macho-invalid.test Wed Aug 21 04:07:31 2019
@@ -102,7 +102,7 @@ RUN: not llvm-objdump --macho --universa
 INVALID-FAT: truncated or malformed fat file (fat_arch_64 structs would extend past the end of the file)
 
 RUN: not llvm-objdump --macho --private-headers -arch all %p/Inputs/macho-invalid-fat.obj.elf-x86_64 2>&1 | FileCheck -check-prefix INVALID-FAT-ELF %s
-INVALID-FAT-ELF: Mach-O universal file: {{.*}}/macho-invalid-fat.obj.elf-x86_64 for architecture x86_64 is not a Mach-O file or an archive file
+INVALID-FAT-ELF: error: '{{.*}}/macho-invalid-fat.obj.elf-x86_64': Mach-O universal file for architecture x86_64 is not a Mach-O file or an archive file
 
 RUN: not llvm-objdump --macho --private-headers %p/Inputs/macho-invalid-segment-fileoff 2>&1 | FileCheck -check-prefix INVALID-SEGMENT-FILEOFF %s
 INVALID-SEGMENT-FILEOFF: macho-invalid-segment-fileoff': truncated or malformed object (load command 0 fileoff field in LC_SEGMENT extends past the end of the file)

Modified: llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/disassemble-functions-mangling.test Wed Aug 21 04:07:31 2019
@@ -20,10 +20,10 @@
 # RUN:   | FileCheck %s --check-prefix=DEMANGLED-MULTI
 
 # MANGLED: _Z3foov:
-# MANGLED-MISS: warning: failed to disassemble missing function foo
+# MANGLED-MISS: warning: '{{.*}}': failed to disassemble missing function foo
 
 # DEMANGLED: foo():
-# DEMANGLED-MISS: warning: failed to disassemble missing function _Z3foov
+# DEMANGLED-MISS: warning: '{{.*}}': failed to disassemble missing function _Z3foov
 
 # NOMANGLE: i:
 # NOMANGLE: f:

Modified: llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-invalid-source.test Wed Aug 21 04:07:31 2019
@@ -13,6 +13,6 @@
 
 # CHECK:      main:
 # CHECK-NEXT: ; int main() {
-# WARN:       warning: debug info line number 9999 exceeds the number of lines in {{.*}}source-interleave-x86_64.c
+# WARN:       warning: '{{.*}}': debug info line number 9999 exceeds the number of lines in {{.*}}source-interleave-x86_64.c
 # GOOD:       ;   int *b = &a;
 # CHECK:      ;   return *b + foo();

Modified: llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-missing-source.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-missing-source.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-missing-source.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-missing-source.test Wed Aug 21 04:07:31 2019
@@ -11,7 +11,7 @@
 # RUN: llvm-objdump --source %t2.o | FileCheck %s --check-prefixes=CHECK,SOURCE
 # RUN: FileCheck %s --input-file %t.e --check-prefixes=WARN
 
-# WARN:        warning: failed to find source {{.*}}source-interleave-x86_64.c
+# WARN:        warning: '{{.*}}': failed to find source {{.*}}source-interleave-x86_64.c
 # CHECK:       0000000000000010 main:
 # SOURCE-NEXT: ; int main() {
 # CHECK-NEXT:   10:   55                      pushq   %rbp

Modified: llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/source-interleave-no-debug-info.test Wed Aug 21 04:07:31 2019
@@ -9,7 +9,7 @@
 # RUN: llvm-objdump --source %t2.o 2> %t2.e | FileCheck %s --check-prefixes=CHECK --implicit-check-not='main()'
 # RUN: FileCheck %s --input-file %t2.e --check-prefixes=WARN
 
-# WARN:        warning: failed to parse debug information for {{.*}}2.o
+# WARN:        warning: '{{.*}}2.o': failed to parse debug information
 # CHECK:       0000000000000010 main:
 # SOURCE-NEXT: ; int main() {
 # CHECK-NEXT:   10:   55                      pushq   %rbp

Modified: llvm/trunk/test/tools/llvm-objdump/X86/start-stop-address.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/start-stop-address.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/start-stop-address.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/start-stop-address.test Wed Aug 21 04:07:31 2019
@@ -69,4 +69,4 @@
 
 // RUN: not llvm-objdump %t.out --start-address=0x40 --stop-address=0x3f 2>&1 | FileCheck %s --check-prefix ERRMSG
 // RUN: not llvm-objdump %t.out --start-address=0x40 --stop-address=0x40 2>&1 | FileCheck %s --check-prefix ERRMSG
-// ERRMSG: start address should be less than stop address.
+// ERRMSG: start address should be less than stop address

Modified: llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/X86/warn-missing-disasm-func.test Wed Aug 21 04:07:31 2019
@@ -13,9 +13,9 @@ FileHeader:
   Type:    ET_REL
   Machine: EM_X86_64
 
-# CHECK: warning: failed to disassemble missing function foo
+# CHECK: warning: {{.*}}: failed to disassemble missing function foo
 
 # MULTI: file format ELF64-x86-64
-# MULTI: warning: failed to disassemble missing function foo
+# MULTI: warning: {{.*}}: failed to disassemble missing function foo
 # MULTI: file format ELF64-x86-64
-# MULTI: warning: failed to disassemble missing function foo
+# MULTI: warning: {{.*}}: failed to disassemble missing function foo

Modified: llvm/trunk/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/warn-on-out-of-range-start-stop-address.test Wed Aug 21 04:07:31 2019
@@ -120,12 +120,12 @@
 ## No warning if neither --start-address nor --stop-address are specified.
 # RUN: llvm-objdump --file-headers %t 2>&1 | FileCheck %s --implicit-check-not=warning:
 
-# WARN: warning: no section overlaps the range {{.*}} specified by --start-address/--stop-address
-# WARN-STOP-ONLY: warning: no section has address less than 0x1000 specified by --stop-address
-# WARN-START-ONLY: warning: no section has address greater than or equal to 0x1500 specified by --start-address
+# WARN: warning: {{.*}}: no section overlaps the range {{.*}} specified by --start-address/--stop-address
+# WARN-STOP-ONLY: warning: {{.*}}: no section has address less than 0x1000 specified by --stop-address
+# WARN-START-ONLY: warning: {{.*}}: no section has address greater than or equal to 0x1500 specified by --start-address
 
 # MULTI-INPUT: file format
-# MULTI-INPUT: warning: no section overlaps the range [0x2001,0x2005) specified by --start-address/--stop-address
+# MULTI-INPUT: warning: {{.*}}: no section overlaps the range [0x2001,0x2005) specified by --start-address/--stop-address
 # MULTI-INPUT: file format
 # MULTI-INPUT-NOT: warning:
 

Modified: llvm/trunk/tools/llvm-objdump/COFFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/COFFDump.cpp?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/COFFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/COFFDump.cpp Wed Aug 21 04:07:31 2019
@@ -234,13 +234,14 @@ printSEHTable(const COFFObjectFile *Obj,
   if (Count == 0)
     return;
 
-  uint32_t ImageBase = Obj->getPE32Header()->ImageBase;
   uintptr_t IntPtr = 0;
-  error(Obj->getVaPtr(TableVA, IntPtr));
+  if (std::error_code EC = Obj->getVaPtr(TableVA, IntPtr))
+    reportError(errorCodeToError(EC), Obj->getFileName());
+
   const support::ulittle32_t *P = (const support::ulittle32_t *)IntPtr;
   outs() << "SEH Table:";
   for (int I = 0; I < Count; ++I)
-    outs() << format(" 0x%x", P[I] + ImageBase);
+    outs() << format(" 0x%x", P[I] + Obj->getPE32Header()->ImageBase);
   outs() << "\n\n";
 }
 
@@ -274,11 +275,16 @@ static void printTLSDirectory(const COFF
     return;
 
   const data_directory *DataDir;
-  error(Obj->getDataDirectory(COFF::TLS_TABLE, DataDir));
-  uintptr_t IntPtr = 0;
+  if (std::error_code EC = Obj->getDataDirectory(COFF::TLS_TABLE, DataDir))
+    reportError(errorCodeToError(EC), Obj->getFileName());
+
   if (DataDir->RelativeVirtualAddress == 0)
     return;
-  error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+  uintptr_t IntPtr = 0;
+  if (std::error_code EC =
+          Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+    reportError(errorCodeToError(EC), Obj->getFileName());
 
   if (PE32Header) {
     auto *TLSDir = reinterpret_cast<const coff_tls_directory32 *>(IntPtr);
@@ -301,11 +307,18 @@ static void printLoadConfiguration(const
     return;
 
   const data_directory *DataDir;
-  error(Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir));
+
+  if (std::error_code EC =
+          Obj->getDataDirectory(COFF::LOAD_CONFIG_TABLE, DataDir))
+    reportError(errorCodeToError(EC), Obj->getFileName());
+
   uintptr_t IntPtr = 0;
   if (DataDir->RelativeVirtualAddress == 0)
     return;
-  error(Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr));
+
+  if (std::error_code EC =
+          Obj->getRvaPtr(DataDir->RelativeVirtualAddress, IntPtr))
+    reportError(errorCodeToError(EC), Obj->getFileName());
 
   auto *LoadConf = reinterpret_cast<const coff_load_configuration32 *>(IntPtr);
   outs() << "Load configuration:"
@@ -447,7 +460,9 @@ static bool getPDataSection(const COFFOb
     llvm::sort(Rels, isRelocAddressLess);
 
     ArrayRef<uint8_t> Contents;
-    error(Obj->getSectionContents(Pdata, Contents));
+    if (Error E = Obj->getSectionContents(Pdata, Contents))
+      reportError(std::move(E), Obj->getFileName());
+
     if (Contents.empty())
       continue;
 
@@ -563,10 +578,12 @@ static void printRuntimeFunctionRels(con
 
   ArrayRef<uint8_t> XContents;
   uint64_t UnwindInfoOffset = 0;
-  error(getSectionContents(
-          Obj, Rels, SectionOffset +
-                         /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
-          XContents, UnwindInfoOffset));
+  if (Error E = getSectionContents(
+          Obj, Rels,
+          SectionOffset +
+              /*offsetof(RuntimeFunction, UnwindInfoOffset)*/ 8,
+          XContents, UnwindInfoOffset))
+    reportError(std::move(E), Obj->getFileName());
   if (XContents.empty())
     return;
 
@@ -642,9 +659,12 @@ void printCOFFSymbolTable(const object::
 void printCOFFSymbolTable(const COFFObjectFile *coff) {
   for (unsigned SI = 0, SE = coff->getNumberOfSymbols(); SI != SE; ++SI) {
     Expected<COFFSymbolRef> Symbol = coff->getSymbol(SI);
+    if (!Symbol)
+      reportError(Symbol.takeError(), coff->getFileName());
+
     StringRef Name;
-    error(Symbol.takeError());
-    error(coff->getSymbolName(*Symbol, Name));
+    if (std::error_code EC = coff->getSymbolName(*Symbol, Name))
+      reportError(errorCodeToError(EC), coff->getFileName());
 
     outs() << "[" << format("%2d", SI) << "]"
            << "(sec " << format("%2d", int(Symbol->getSectionNumber())) << ")"
@@ -674,7 +694,9 @@ void printCOFFSymbolTable(const COFFObje
     for (unsigned AI = 0, AE = Symbol->getNumberOfAuxSymbols(); AI < AE; ++AI, ++SI) {
       if (Symbol->isSectionDefinition()) {
         const coff_aux_section_definition *asd;
-        error(coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd));
+        if (std::error_code EC =
+                coff->getAuxSymbol<coff_aux_section_definition>(SI + 1, asd))
+          reportError(errorCodeToError(EC), coff->getFileName());
 
         int32_t AuxNumber = asd->getNumber(Symbol->isBigObj());
 
@@ -689,7 +711,8 @@ void printCOFFSymbolTable(const COFFObje
                          , unsigned(asd->Selection));
       } else if (Symbol->isFileRecord()) {
         const char *FileName;
-        error(coff->getAuxSymbol<char>(SI + 1, FileName));
+        if (std::error_code EC = coff->getAuxSymbol<char>(SI + 1, FileName))
+          reportError(errorCodeToError(EC), coff->getFileName());
 
         StringRef Name(FileName, Symbol->getNumberOfAuxSymbols() *
                                      coff->getSymbolTableEntrySize());
@@ -699,7 +722,9 @@ void printCOFFSymbolTable(const COFFObje
         break;
       } else if (Symbol->isWeakExternal()) {
         const coff_aux_weak_external *awe;
-        error(coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe));
+        if (std::error_code EC =
+                coff->getAuxSymbol<coff_aux_weak_external>(SI + 1, awe))
+          reportError(errorCodeToError(EC), coff->getFileName());
 
         outs() << "AUX " << format("indx %d srch %d\n",
                                    static_cast<uint32_t>(awe->TagIndex),

Modified: llvm/trunk/tools/llvm-objdump/ELFDump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/ELFDump.cpp?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/ELFDump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/ELFDump.cpp Wed Aug 21 04:07:31 2019
@@ -178,7 +178,7 @@ void printDynamicSection(const ELFFile<E
         outs() << (Data + Dyn.d_un.d_val) << "\n";
         continue;
       }
-      warn(toString(StrTabOrErr.takeError()));
+      reportWarning(toString(StrTabOrErr.takeError()), Filename);
       consumeError(StrTabOrErr.takeError());
     }
     outs() << format(Fmt, (uint64_t)Dyn.d_un.d_val);

Modified: llvm/trunk/tools/llvm-objdump/MachODump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/MachODump.cpp?rev=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/MachODump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/MachODump.cpp Wed Aug 21 04:07:31 2019
@@ -236,11 +236,11 @@ struct SymbolSorter {
   bool operator()(const SymbolRef &A, const SymbolRef &B) {
     Expected<SymbolRef::Type> ATypeOrErr = A.getType();
     if (!ATypeOrErr)
-      report_error(ATypeOrErr.takeError(), A.getObject()->getFileName());
+      reportError(ATypeOrErr.takeError(), A.getObject()->getFileName());
     SymbolRef::Type AType = *ATypeOrErr;
     Expected<SymbolRef::Type> BTypeOrErr = B.getType();
     if (!BTypeOrErr)
-      report_error(BTypeOrErr.takeError(), B.getObject()->getFileName());
+      reportError(BTypeOrErr.takeError(), B.getObject()->getFileName());
     SymbolRef::Type BType = *BTypeOrErr;
     uint64_t AAddr = (AType != SymbolRef::ST_Function) ? 0 : A.getValue();
     uint64_t BAddr = (BType != SymbolRef::ST_Function) ? 0 : B.getValue();
@@ -533,8 +533,8 @@ Error getMachORelocationValueString(cons
       // NOTE: Scattered relocations don't exist on x86_64.
       unsigned RType = Obj->getAnyRelocationType(RENext);
       if (RType != MachO::X86_64_RELOC_UNSIGNED)
-        report_error(Obj->getFileName(), "Expected X86_64_RELOC_UNSIGNED after "
-                                         "X86_64_RELOC_SUBTRACTOR.");
+        reportError(Obj->getFileName(), "Expected X86_64_RELOC_UNSIGNED after "
+                                        "X86_64_RELOC_SUBTRACTOR.");
 
       // The X86_64_RELOC_UNSIGNED contains the minuend symbol;
       // X86_64_RELOC_SUBTRACTOR contains the subtrahend.
@@ -582,8 +582,8 @@ Error getMachORelocationValueString(cons
       unsigned RType = Obj->getAnyRelocationType(RENext);
 
       if (RType != MachO::GENERIC_RELOC_PAIR)
-        report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
-                                         "GENERIC_RELOC_SECTDIFF.");
+        reportError(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
+                                        "GENERIC_RELOC_SECTDIFF.");
 
       printRelocationTargetName(Obj, RE, Fmt);
       Fmt << "-";
@@ -603,8 +603,8 @@ Error getMachORelocationValueString(cons
         // GENERIC_RELOC_PAIR.
         unsigned RType = Obj->getAnyRelocationType(RENext);
         if (RType != MachO::GENERIC_RELOC_PAIR)
-          report_error(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
-                                           "GENERIC_RELOC_LOCAL_SECTDIFF.");
+          reportError(Obj->getFileName(), "Expected GENERIC_RELOC_PAIR after "
+                                          "GENERIC_RELOC_LOCAL_SECTDIFF.");
 
         printRelocationTargetName(Obj, RE, Fmt);
         Fmt << "-";
@@ -643,8 +643,8 @@ Error getMachORelocationValueString(cons
         // ARM_RELOC_PAIR.
         unsigned RType = Obj->getAnyRelocationType(RENext);
         if (RType != MachO::ARM_RELOC_PAIR)
-          report_error(Obj->getFileName(), "Expected ARM_RELOC_PAIR after "
-                                           "ARM_RELOC_HALF");
+          reportError(Obj->getFileName(), "Expected ARM_RELOC_PAIR after "
+                                          "ARM_RELOC_HALF");
 
         // NOTE: The half of the target virtual address is stashed in the
         // address field of the secondary relocation, but we can't reverse
@@ -1945,7 +1945,7 @@ static void ProcessMachO(StringRef Name,
   // the error message.
   if (Disassemble || IndirectSymbols || !FilterSections.empty() || UnwindInfo)
     if (Error Err = MachOOF->checkSymbolTable())
-      report_error(std::move(Err), ArchiveName, FileName, ArchitectureName);
+      reportError(std::move(Err), ArchiveName, FileName, ArchitectureName);
 
   if (DisassembleAll) {
     for (const SectionRef &Section : MachOOF->sections()) {
@@ -2295,7 +2295,7 @@ static void printArchiveHeaders(StringRe
                       ArchitectureName);
 
   if (Err)
-    report_error(std::move(Err), StringRef(), Filename, ArchitectureName);
+    reportError(std::move(Err), StringRef(), Filename, ArchitectureName);
 }
 
 static bool ValidateArchFlags() {
@@ -2327,7 +2327,7 @@ void parseInputMachO(StringRef Filename)
   Expected<OwningBinary<Binary>> BinaryOrErr = createBinary(Filename);
   if (!BinaryOrErr) {
     if (Error E = isNotObjectErrorInvalidFileType(BinaryOrErr.takeError()))
-      report_error(std::move(E), Filename);
+      reportError(std::move(E), Filename);
     else
       outs() << Filename << ": is not an object file\n";
     return;
@@ -2346,7 +2346,7 @@ void parseInputMachO(StringRef Filename)
       Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
       if (!ChildOrErr) {
         if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
-          report_error(std::move(E), Filename, getFileNameForError(C, I));
+          reportError(std::move(E), Filename, getFileNameForError(C, I));
         continue;
       }
       if (MachOObjectFile *O = dyn_cast<MachOObjectFile>(&*ChildOrErr.get())) {
@@ -2356,7 +2356,7 @@ void parseInputMachO(StringRef Filename)
       }
     }
     if (Err)
-      report_error(std::move(Err), Filename);
+      reportError(std::move(Err), Filename);
     return;
   }
   if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Bin)) {
@@ -2408,7 +2408,7 @@ void parseInputMachO(MachOUniversalBinar
               ProcessMachO(Filename, MachOOF, "", ArchitectureName);
           } else if (Error E = isNotObjectErrorInvalidFileType(
                          ObjOrErr.takeError())) {
-            report_error(std::move(E), Filename, StringRef(), ArchitectureName);
+            reportError(std::move(E), Filename, StringRef(), ArchitectureName);
             continue;
           } else if (Expected<std::unique_ptr<Archive>> AOrErr =
                          I->getAsArchive()) {
@@ -2428,8 +2428,8 @@ void parseInputMachO(MachOUniversalBinar
               if (!ChildOrErr) {
                 if (Error E =
                         isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
-                  report_error(std::move(E), Filename, getFileNameForError(C, I),
-                               ArchitectureName);
+                  reportError(std::move(E), Filename, getFileNameForError(C, I),
+                              ArchitectureName);
                 continue;
               }
               if (MachOObjectFile *O =
@@ -2437,12 +2437,13 @@ void parseInputMachO(MachOUniversalBinar
                 ProcessMachO(Filename, O, O->getFileName(), ArchitectureName);
             }
             if (Err)
-              report_error(std::move(Err), Filename);
+              reportError(std::move(Err), Filename);
           } else {
             consumeError(AOrErr.takeError());
-            error("Mach-O universal file: " + Filename + " for " +
-                  "architecture " + StringRef(I->getArchFlagName()) +
-                  " is not a Mach-O file or an archive file");
+            reportError(Filename,
+                        "Mach-O universal file for architecture " +
+                            StringRef(I->getArchFlagName()) +
+                            " is not a Mach-O file or an archive file");
           }
         }
       }
@@ -2472,7 +2473,7 @@ void parseInputMachO(MachOUniversalBinar
             ProcessMachO(Filename, MachOOF);
         } else if (Error E =
                        isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
-          report_error(std::move(E), Filename);
+          reportError(std::move(E), Filename);
         } else if (Expected<std::unique_ptr<Archive>> AOrErr =
                        I->getAsArchive()) {
           std::unique_ptr<Archive> &A = *AOrErr;
@@ -2488,7 +2489,7 @@ void parseInputMachO(MachOUniversalBinar
             if (!ChildOrErr) {
               if (Error E =
                       isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
-                report_error(std::move(E), Filename, getFileNameForError(C, I));
+                reportError(std::move(E), Filename, getFileNameForError(C, I));
               continue;
             }
             if (MachOObjectFile *O =
@@ -2496,12 +2497,12 @@ void parseInputMachO(MachOUniversalBinar
               ProcessMachO(Filename, O, O->getFileName());
           }
           if (Err)
-            report_error(std::move(Err), Filename);
+            reportError(std::move(Err), Filename);
         } else {
           consumeError(AOrErr.takeError());
-          error("Mach-O universal file: " + Filename + " for architecture " +
-                StringRef(I->getArchFlagName()) +
-                " is not a Mach-O file or an archive file");
+          reportError(Filename, "Mach-O universal file for architecture " +
+                                    StringRef(I->getArchFlagName()) +
+                                    " is not a Mach-O file or an archive file");
         }
         return;
       }
@@ -2523,7 +2524,7 @@ void parseInputMachO(MachOUniversalBinar
         ProcessMachO(Filename, MachOOF, "", ArchitectureName);
     } else if (Error E =
                    isNotObjectErrorInvalidFileType(ObjOrErr.takeError())) {
-      report_error(std::move(E), StringRef(), Filename, ArchitectureName);
+      reportError(std::move(E), StringRef(), Filename, ArchitectureName);
     } else if (Expected<std::unique_ptr<Archive>> AOrErr = I->getAsArchive()) {
       std::unique_ptr<Archive> &A = *AOrErr;
       outs() << "Archive : " << Filename;
@@ -2540,8 +2541,8 @@ void parseInputMachO(MachOUniversalBinar
         Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
         if (!ChildOrErr) {
           if (Error E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
-            report_error(std::move(E), Filename, getFileNameForError(C, I),
-                         ArchitectureName);
+            reportError(std::move(E), Filename, getFileNameForError(C, I),
+                        ArchitectureName);
           continue;
         }
         if (MachOObjectFile *O =
@@ -2552,12 +2553,12 @@ void parseInputMachO(MachOUniversalBinar
         }
       }
       if (Err)
-        report_error(std::move(Err), Filename);
+        reportError(std::move(Err), Filename);
     } else {
       consumeError(AOrErr.takeError());
-      error("Mach-O universal file: " + Filename + " for architecture " +
-            StringRef(I->getArchFlagName()) +
-            " is not a Mach-O file or an archive file");
+      reportError(Filename, "Mach-O universal file for architecture " +
+                                StringRef(I->getArchFlagName()) +
+                                " is not a Mach-O file or an archive file");
     }
   }
 }
@@ -7344,7 +7345,7 @@ static void DisassembleMachO(StringRef F
       ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
           MemoryBuffer::getFileOrSTDIN(DSYMFile);
       if (std::error_code EC = BufOrErr.getError()) {
-        report_error(errorCodeToError(EC), DSYMFile);
+        reportError(errorCodeToError(EC), DSYMFile);
         return;
       }
 
@@ -7354,7 +7355,7 @@ static void DisassembleMachO(StringRef F
       Expected<std::unique_ptr<Binary>> BinaryOrErr =
       createBinary(DSYMBuf.get()->getMemBufferRef());
       if (!BinaryOrErr) {
-        report_error(BinaryOrErr.takeError(), DSYMFile);
+        reportError(BinaryOrErr.takeError(), DSYMFile);
         return;
       }
 
@@ -7390,7 +7391,7 @@ static void DisassembleMachO(StringRef F
         Expected<std::unique_ptr<MachOObjectFile>> MachDSYM =
             UB->getObjectForArch(ArchFlag);
         if (!MachDSYM) {
-          report_error(MachDSYM.takeError(), DSYMFile);
+          reportError(MachDSYM.takeError(), DSYMFile);
           return;
         }
     
@@ -10294,7 +10295,7 @@ void printMachOExportsTrie(const object:
     outs() << "\n";
   }
   if (Err)
-    report_error(std::move(Err), Obj->getFileName());
+    reportError(std::move(Err), Obj->getFileName());
 }
 
 //===----------------------------------------------------------------------===//
@@ -10315,7 +10316,7 @@ void printMachORebaseTable(object::MachO
                      Address, Entry.typeName().str().c_str());
   }
   if (Err)
-    report_error(std::move(Err), Obj->getFileName());
+    reportError(std::move(Err), Obj->getFileName());
 }
 
 static StringRef ordinalName(const object::MachOObjectFile *Obj, int Ordinal) {
@@ -10367,7 +10368,7 @@ void printMachOBindTable(object::MachOOb
            << Entry.symbolName() << Attr << "\n";
   }
   if (Err)
-    report_error(std::move(Err), Obj->getFileName());
+    reportError(std::move(Err), Obj->getFileName());
 }
 
 //===----------------------------------------------------------------------===//
@@ -10392,7 +10393,7 @@ void printMachOLazyBindTable(object::Mac
            << Entry.symbolName() << "\n";
   }
   if (Err)
-    report_error(std::move(Err), Obj->getFileName());
+    reportError(std::move(Err), Obj->getFileName());
 }
 
 //===----------------------------------------------------------------------===//
@@ -10424,7 +10425,7 @@ void printMachOWeakBindTable(object::Mac
            << "\n";
   }
   if (Err)
-    report_error(std::move(Err), Obj->getFileName());
+    reportError(std::move(Err), Obj->getFileName());
 }
 
 // get_dyld_bind_info_symbolname() is used for disassembly and passed an
@@ -10443,7 +10444,7 @@ static const char *get_dyld_bind_info_sy
         (*info->bindtable)[Address] = name;
     }
     if (Err)
-      report_error(std::move(Err), info->O->getFileName());
+      reportError(std::move(Err), info->O->getFileName());
   }
   auto name = info->bindtable->lookup(ReferenceValue);
   return !name.empty() ? name.data() : nullptr;

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=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Wed Aug 21 04:07:31 2019
@@ -375,43 +375,21 @@ std::string getFileNameForError(const ob
   return "<file index: " + std::to_string(Index) + ">";
 }
 
-void error(std::error_code EC) {
-  if (!EC)
-    return;
-  WithColor::error(errs(), ToolName)
-      << "reading file: " << EC.message() << ".\n";
-  errs().flush();
-  exit(1);
-}
-
-void error(Error E) {
-  if (!E)
-    return;
-  WithColor::error(errs(), ToolName) << toString(std::move(E));
-  exit(1);
-}
-
-LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
-  WithColor::error(errs(), ToolName) << Message << ".\n";
-  errs().flush();
-  exit(1);
-}
-
-void warn(Twine Message) {
+void reportWarning(Twine Message, StringRef File) {
   // Output order between errs() and outs() matters especially for archive
   // files where the output is per member object.
   outs().flush();
-  WithColor::warning(errs(), ToolName) << Message << "\n";
+  WithColor::warning(errs(), ToolName)
+      << "'" << File << "': " << Message << "\n";
   errs().flush();
 }
 
-LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message) {
-  WithColor::error(errs(), ToolName)
-      << "'" << File << "': " << Message << ".\n";
+LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message) {
+  WithColor::error(errs(), ToolName) << "'" << File << "': " << Message << "\n";
   exit(1);
 }
 
-LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef File) {
+LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef File) {
   assert(E);
   std::string Buf;
   raw_string_ostream OS(Buf);
@@ -421,9 +399,9 @@ LLVM_ATTRIBUTE_NORETURN void report_erro
   exit(1);
 }
 
-LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef ArchiveName,
-                                          StringRef FileName,
-                                          StringRef ArchitectureName) {
+LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef ArchiveName,
+                                         StringRef FileName,
+                                         StringRef ArchitectureName) {
   assert(E);
   WithColor::error(errs(), ToolName);
   if (ArchiveName != "")
@@ -440,6 +418,15 @@ LLVM_ATTRIBUTE_NORETURN void report_erro
   exit(1);
 }
 
+static void reportCmdLineWarning(Twine Message) {
+  WithColor::warning(errs(), ToolName) << Message << "\n";
+}
+
+LLVM_ATTRIBUTE_NORETURN static void reportCmdLineError(Twine Message) {
+  WithColor::error(errs(), ToolName) << Message << "\n";
+  exit(1);
+}
+
 static void warnOnNoMatchForSections() {
   SetVector<StringRef> MissingSections;
   for (StringRef S : FilterSections) {
@@ -452,37 +439,29 @@ static void warnOnNoMatchForSections() {
 
   // Warn only if no section in FilterSections is matched.
   for (StringRef S : MissingSections)
-    warn("section '" + S + "' mentioned in a -j/--section option, but not "
-         "found in any input file");
+    reportCmdLineWarning("section '" + S +
+                         "' mentioned in a -j/--section option, but not "
+                         "found in any input file");
 }
 
-static const Target *getTarget(const ObjectFile *Obj = nullptr) {
+static const Target *getTarget(const ObjectFile *Obj) {
   // Figure out the target triple.
   Triple TheTriple("unknown-unknown-unknown");
   if (TripleName.empty()) {
-    if (Obj)
-      TheTriple = Obj->makeTriple();
+    TheTriple = Obj->makeTriple();
   } else {
     TheTriple.setTriple(Triple::normalize(TripleName));
-
-    // Use the triple, but also try to combine with ARM build attributes.
-    if (Obj) {
-      auto Arch = Obj->getArch();
-      if (Arch == Triple::arm || Arch == Triple::armeb)
-        Obj->setARMSubArch(TheTriple);
-    }
+    auto Arch = Obj->getArch();
+    if (Arch == Triple::arm || Arch == Triple::armeb)
+      Obj->setARMSubArch(TheTriple);
   }
 
   // Get the target specific parser.
   std::string Error;
   const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
                                                          Error);
-  if (!TheTarget) {
-    if (Obj)
-      report_error(Obj->getFileName(), "can't find target: " + Error);
-    else
-      error("can't find target: " + Error);
-  }
+  if (!TheTarget)
+    reportError(Obj->getFileName(), "can't find target: " + Error);
 
   // Update the triple name and return the found target.
   TripleName = TheTriple.getTriple();
@@ -582,8 +561,8 @@ bool SourcePrinter::cacheSource(const DI
     auto BufferOrError = MemoryBuffer::getFile(LineInfo.FileName);
     if (!BufferOrError) {
       if (MissingSources.insert(LineInfo.FileName).second)
-        warn("failed to find source " + LineInfo.FileName);
-
+        reportWarning("failed to find source " + LineInfo.FileName,
+                      Obj->getFileName());
       return false;
     }
     Buffer = std::move(*BufferOrError);
@@ -625,7 +604,7 @@ void SourcePrinter::printSourceLine(raw_
           "failed to parse debug information for " + ObjectFilename.str();
       if (!ErrorMessage.empty())
         Warning += ": " + ErrorMessage;
-      warn(Warning);
+      reportWarning(Warning, ObjectFilename);
       WarnedNoDebugInfo = true;
     }
     return;
@@ -644,9 +623,11 @@ void SourcePrinter::printSourceLine(raw_
     auto LineBuffer = LineCache.find(LineInfo.FileName);
     if (LineBuffer != LineCache.end()) {
       if (LineInfo.Line > LineBuffer->second.size()) {
-        warn(formatv(
-            "debug info line number {0} exceeds the number of lines in {1}",
-            LineInfo.Line, LineInfo.FileName));
+        reportWarning(
+            formatv(
+                "debug info line number {0} exceeds the number of lines in {1}",
+                LineInfo.Line, LineInfo.FileName),
+            ObjectFilename);
         return;
       }
       // Vector begins at 0, line numbers are non-zero
@@ -670,13 +651,14 @@ static bool hasMappingSymbols(const Obje
   return isArmElf(Obj) || isAArch64Elf(Obj);
 }
 
-static void printRelocation(const RelocationRef &Rel, uint64_t Address,
-                            bool Is64Bits) {
+static void printRelocation(StringRef FileName, const RelocationRef &Rel,
+                            uint64_t Address, bool Is64Bits) {
   StringRef Fmt = Is64Bits ? "\t\t%016" PRIx64 ":  " : "\t\t\t%08" PRIx64 ":  ";
   SmallString<16> Name;
   SmallString<32> Val;
   Rel.getTypeName(Name);
-  error(getRelocationValueString(Rel, Val));
+  if (Error E = getRelocationValueString(Rel, Val))
+    reportError(std::move(E), FileName);
   outs() << format(Fmt.data(), Address) << Name << "\t" << Val << "\n";
 }
 
@@ -760,7 +742,7 @@ public:
     auto PrintReloc = [&]() -> void {
       while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address.Address)) {
         if (RelCur->getOffset() == Address.Address) {
-          printRelocation(*RelCur, Address.Address, false);
+          printRelocation(ObjectFilename, *RelCur, Address.Address, false);
           return;
         }
         ++RelCur;
@@ -1162,11 +1144,14 @@ static void disassembleObject(const Targ
   if (const auto *COFFObj = dyn_cast<COFFObjectFile>(Obj)) {
     for (const auto &ExportEntry : COFFObj->export_directories()) {
       StringRef Name;
-      error(ExportEntry.getSymbolName(Name));
+      if (std::error_code EC = ExportEntry.getSymbolName(Name))
+        reportError(errorCodeToError(EC), Obj->getFileName());
       if (Name.empty())
         continue;
+
       uint32_t RVA;
-      error(ExportEntry.getExportRVA(RVA));
+      if (std::error_code EC = ExportEntry.getExportRVA(RVA))
+        reportError(errorCodeToError(EC), Obj->getFileName());
 
       uint64_t VA = COFFObj->getImageBase() + RVA;
       auto Sec = partition_point(
@@ -1494,7 +1479,8 @@ static void disassembleObject(const Targ
                 Offset += AdjustVMA;
             }
 
-            printRelocation(*RelCur, SectionAddr + Offset, Is64Bits);
+            printRelocation(Obj->getFileName(), *RelCur, SectionAddr + Offset,
+                            Is64Bits);
             ++RelCur;
           }
         }
@@ -1506,7 +1492,8 @@ static void disassembleObject(const Targ
   StringSet<> MissingDisasmFuncsSet =
       set_difference(DisasmFuncsSet, FoundDisasmFuncsSet);
   for (StringRef MissingDisasmFunc : MissingDisasmFuncsSet.keys())
-    warn("failed to disassemble missing function " + MissingDisasmFunc);
+    reportWarning("failed to disassemble missing function " + MissingDisasmFunc,
+                  FileName);
 }
 
 static void disassembleObject(const ObjectFile *Obj, bool InlineRelocs) {
@@ -1521,24 +1508,24 @@ static void disassembleObject(const Obje
   std::unique_ptr<const MCRegisterInfo> MRI(
       TheTarget->createMCRegInfo(TripleName));
   if (!MRI)
-    report_error(Obj->getFileName(),
-                 "no register info for target " + TripleName);
+    reportError(Obj->getFileName(),
+                "no register info for target " + TripleName);
 
   // Set up disassembler.
   std::unique_ptr<const MCAsmInfo> AsmInfo(
       TheTarget->createMCAsmInfo(*MRI, TripleName));
   if (!AsmInfo)
-    report_error(Obj->getFileName(),
-                 "no assembly info for target " + TripleName);
+    reportError(Obj->getFileName(),
+                "no assembly info for target " + TripleName);
   std::unique_ptr<const MCSubtargetInfo> STI(
       TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
   if (!STI)
-    report_error(Obj->getFileName(),
-                 "no subtarget info for target " + TripleName);
+    reportError(Obj->getFileName(),
+                "no subtarget info for target " + TripleName);
   std::unique_ptr<const MCInstrInfo> MII(TheTarget->createMCInstrInfo());
   if (!MII)
-    report_error(Obj->getFileName(),
-                 "no instruction info for target " + TripleName);
+    reportError(Obj->getFileName(),
+                "no instruction info for target " + TripleName);
   MCObjectFileInfo MOFI;
   MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
   // FIXME: for now initialize MCObjectFileInfo with default values
@@ -1547,8 +1534,7 @@ static void disassembleObject(const Obje
   std::unique_ptr<MCDisassembler> DisAsm(
       TheTarget->createMCDisassembler(*STI, Ctx));
   if (!DisAsm)
-    report_error(Obj->getFileName(),
-                 "no disassembler for target " + TripleName);
+    reportError(Obj->getFileName(), "no disassembler for target " + TripleName);
 
   // If we have an ARM object file, we need a second disassembler, because
   // ARM CPUs have two different instruction sets: ARM mode, and Thumb mode.
@@ -1573,8 +1559,8 @@ static void disassembleObject(const Obje
   std::unique_ptr<MCInstPrinter> IP(TheTarget->createMCInstPrinter(
       Triple(TripleName), AsmPrinterVariant, *AsmInfo, *MII, *MRI));
   if (!IP)
-    report_error(Obj->getFileName(),
-                 "no instruction printer for target " + TripleName);
+    reportError(Obj->getFileName(),
+                "no instruction printer for target " + TripleName);
   IP->setPrintImmHex(PrintImmHex);
 
   PrettyPrinter &PIP = selectPrettyPrinter(Triple(TripleName));
@@ -1582,7 +1568,8 @@ static void disassembleObject(const Obje
 
   for (StringRef Opt : DisassemblerOptions)
     if (!IP->applyTargetSpecificCLOption(Opt))
-      error("Unrecognized disassembler option: " + Opt);
+      reportError(Obj->getFileName(),
+                  "Unrecognized disassembler option: " + Opt);
 
   disassembleObject(TheTarget, Obj, Ctx, DisAsm.get(), SecondaryDisAsm.get(),
                     MIA.get(), IP.get(), STI.get(), SecondarySTI.get(), PIP,
@@ -1620,7 +1607,9 @@ void printRelocations(const ObjectFile *
         if (Address < StartAddress || Address > StopAddress || getHidden(Reloc))
           continue;
         Reloc.getTypeName(RelocName);
-        error(getRelocationValueString(Reloc, ValueStr));
+        if (Error E = getRelocationValueString(Reloc, ValueStr))
+          reportError(std::move(E), Obj->getFileName());
+
         outs() << format(Fmt.data(), Address) << " " << RelocName << " "
                << ValueStr << "\n";
       }
@@ -1636,7 +1625,7 @@ void printDynamicRelocations(const Objec
 
   const auto *Elf = dyn_cast<ELFObjectFileBase>(Obj);
   if (!Elf || Elf->getEType() != ELF::ET_DYN) {
-    error("not a dynamic object");
+    reportError(Obj->getFileName(), "not a dynamic object");
     return;
   }
 
@@ -1652,7 +1641,8 @@ void printDynamicRelocations(const Objec
       SmallString<32> RelocName;
       SmallString<32> ValueStr;
       Reloc.getTypeName(RelocName);
-      error(getRelocationValueString(Reloc, ValueStr));
+      if (Error E = getRelocationValueString(Reloc, ValueStr))
+        reportError(std::move(E), Obj->getFileName());
       outs() << format(Fmt.data(), Address) << " " << RelocName << " "
              << ValueStr << "\n";
     }
@@ -1980,12 +1970,12 @@ static void printPrivateFileHeaders(cons
       printMachOLoadCommands(O);
     return;
   }
-  report_error(O->getFileName(), "Invalid/Unsupported object file format");
+  reportError(O->getFileName(), "Invalid/Unsupported object file format");
 }
 
 static void printFileHeaders(const ObjectFile *O) {
   if (!O->isELF() && !O->isCOFF())
-    report_error(O->getFileName(), "Invalid/Unsupported object file format");
+    reportError(O->getFileName(), "Invalid/Unsupported object file format");
 
   Triple::ArchType AT = O->getArch();
   outs() << "architecture: " << Triple::getArchTypeName(AT) << "\n";
@@ -2067,15 +2057,18 @@ static void checkForInvalidStartStopAddr
     }
 
   if (StartAddress.getNumOccurrences() == 0)
-    warn("no section has address less than 0x" +
-         Twine::utohexstr(Stop) + " specified by --stop-address");
+    reportWarning("no section has address less than 0x" +
+                      Twine::utohexstr(Stop) + " specified by --stop-address",
+                  Obj->getFileName());
   else if (StopAddress.getNumOccurrences() == 0)
-    warn("no section has address greater than or equal to 0x" +
-         Twine::utohexstr(Start) + " specified by --start-address");
+    reportWarning("no section has address greater than or equal to 0x" +
+                      Twine::utohexstr(Start) + " specified by --start-address",
+                  Obj->getFileName());
   else
-    warn("no section overlaps the range [0x" +
-         Twine::utohexstr(Start) + ",0x" + Twine::utohexstr(Stop) +
-         ") specified by --start-address/--stop-address");
+    reportWarning("no section overlaps the range [0x" +
+                      Twine::utohexstr(Start) + ",0x" + Twine::utohexstr(Stop) +
+                      ") specified by --start-address/--stop-address",
+                  Obj->getFileName());
 }
 
 static void dumpObject(ObjectFile *O, const Archive *A = nullptr,
@@ -2163,7 +2156,7 @@ static void dumpArchive(const Archive *A
     Expected<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
     if (!ChildOrErr) {
       if (auto E = isNotObjectErrorInvalidFileType(ChildOrErr.takeError()))
-        report_error(std::move(E), A->getFileName(), getFileNameForError(C, I));
+        reportError(std::move(E), A->getFileName(), getFileNameForError(C, I));
       continue;
     }
     if (ObjectFile *O = dyn_cast<ObjectFile>(&*ChildOrErr.get()))
@@ -2171,11 +2164,11 @@ static void dumpArchive(const Archive *A
     else if (COFFImportFile *I = dyn_cast<COFFImportFile>(&*ChildOrErr.get()))
       dumpObject(I, A, &C);
     else
-      report_error(errorCodeToError(object_error::invalid_file_type),
-                   A->getFileName());
+      reportError(errorCodeToError(object_error::invalid_file_type),
+                  A->getFileName());
   }
   if (Err)
-    report_error(std::move(Err), A->getFileName());
+    reportError(std::move(Err), A->getFileName());
 }
 
 /// Open file and figure out how to dump it.
@@ -2199,7 +2192,7 @@ static void dumpInput(StringRef file) {
   else if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(&Binary))
     parseInputMachO(UB);
   else
-    report_error(errorCodeToError(object_error::invalid_file_type), file);
+    reportError(errorCodeToError(object_error::invalid_file_type), file);
 }
 } // namespace llvm
 
@@ -2220,7 +2213,7 @@ int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv, "llvm object file dumper\n");
 
   if (StartAddress >= StopAddress)
-    error("start address should be less than stop address");
+    reportCmdLineError("start address should be less than stop address");
 
   ToolName = argv[0];
 

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=369515&r1=369514&r2=369515&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.h (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.h Wed Aug 21 04:07:31 2019
@@ -96,8 +96,6 @@ Error getMachORelocationValueString(cons
 
 uint64_t getELFSectionLMA(const object::ELFSectionRef& Sec);
 
-void error(std::error_code ec);
-void error(Error E);
 bool isRelocAddressLess(object::RelocationRef A, object::RelocationRef B);
 void parseInputMachO(StringRef Filename);
 void parseInputMachO(object::MachOUniversalBinary *UB);
@@ -129,19 +127,18 @@ void printSectionHeaders(const object::O
 void printSectionContents(const object::ObjectFile *O);
 void printSymbolTable(const object::ObjectFile *O, StringRef ArchiveName,
                       StringRef ArchitectureName = StringRef());
-void warn(Twine Message);
-LLVM_ATTRIBUTE_NORETURN void error(Twine Message);
-LLVM_ATTRIBUTE_NORETURN void report_error(StringRef File, Twine Message);
-LLVM_ATTRIBUTE_NORETURN void report_error(Error E, StringRef File);
+LLVM_ATTRIBUTE_NORETURN void reportError(StringRef File, Twine Message);
+LLVM_ATTRIBUTE_NORETURN void reportError(Error E, StringRef File);
 LLVM_ATTRIBUTE_NORETURN void
-report_error(Error E, StringRef FileName, StringRef ArchiveName,
-             StringRef ArchitectureName = StringRef());
+reportError(Error E, StringRef FileName, StringRef ArchiveName,
+            StringRef ArchitectureName = StringRef());
+void reportWarning(Twine Message, StringRef File);
 
 template <typename T, typename... Ts>
 T unwrapOrError(Expected<T> EO, Ts &&... Args) {
   if (EO)
     return std::move(*EO);
-  report_error(EO.takeError(), std::forward<Ts>(Args)...);
+  reportError(EO.takeError(), std::forward<Ts>(Args)...);
 }
 
 std::string getFileNameForError(const object::Archive::Child &C,




More information about the llvm-commits mailing list