[llvm-objdump/MachO] Don't cut'n'paste the same code over and over.
authorDavide Italiano <davide@freebsd.org>
Tue, 8 Dec 2015 02:45:59 +0000 (02:45 +0000)
committerDavide Italiano <davide@freebsd.org>
Tue, 8 Dec 2015 02:45:59 +0000 (02:45 +0000)
Use the appropriate helper instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254990 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-objdump/MachODump.cpp
tools/llvm-objdump/llvm-objdump.cpp
tools/llvm-objdump/llvm-objdump.h

index b270057..6156743 100644 (file)
@@ -1495,11 +1495,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
       printArchiveHeaders(A, !NonVerbose, ArchiveMemberOffsets);
     for (Archive::child_iterator I = A->child_begin(), E = A->child_end();
          I != E; ++I) {
-      if (std::error_code EC = I->getError()) {
-        errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
-               << ".\n";
-        exit(1);
-      }
+      if (std::error_code EC = I->getError())
+        report_error(Filename, EC);
       auto &C = I->get();
       ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
       if (ChildOrErr.getError())
@@ -1549,11 +1546,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
               for (Archive::child_iterator AI = A->child_begin(),
                                            AE = A->child_end();
                    AI != AE; ++AI) {
-                if (std::error_code EC = AI->getError()) {
-                  errs() << "llvm-objdump: '" << Filename
-                         << "': " << EC.message() << ".\n";
-                  exit(1);
-                }
+                if (std::error_code EC = AI->getError())
+                  report_error(Filename, EC);
                 auto &C = AI->get();
                 ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
                 if (ChildOrErr.getError())
@@ -1597,11 +1591,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
             for (Archive::child_iterator AI = A->child_begin(),
                                          AE = A->child_end();
                  AI != AE; ++AI) {
-              if (std::error_code EC = AI->getError()) {
-                errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
-                       << ".\n";
-                exit(1);
-              }
+              if (std::error_code EC = AI->getError())
+                report_error(Filename, EC);
               auto &C = AI->get();
               ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
               if (ChildOrErr.getError())
@@ -1639,11 +1630,8 @@ void llvm::ParseInputMachO(StringRef Filename) {
           printArchiveHeaders(A.get(), !NonVerbose, ArchiveMemberOffsets);
         for (Archive::child_iterator AI = A->child_begin(), AE = A->child_end();
              AI != AE; ++AI) {
-          if (std::error_code EC = AI->getError()) {
-            errs() << "llvm-objdump: '" << Filename << "': " << EC.message()
-                   << ".\n";
-            exit(1);
-          }
+          if (std::error_code EC = AI->getError())
+            report_error(Filename, EC);
           auto &C = AI->get();
           ErrorOr<std::unique_ptr<Binary>> ChildOrErr = C.getAsBinary();
           if (ChildOrErr.getError())
index 0694254..a2c43e1 100644 (file)
@@ -252,7 +252,7 @@ void llvm::error(std::error_code EC) {
   exit(1);
 }
 
-static void report_error(StringRef File, std::error_code EC) {
+void llvm::report_error(StringRef File, std::error_code EC) {
   assert(EC);
   errs() << ToolName << ": '" << File << "': " << EC.message() << ".\n";
   exit(1);
index 3c5e7b3..f74ed01 100644 (file)
@@ -78,6 +78,7 @@ void PrintRelocations(const object::ObjectFile *o);
 void PrintSectionHeaders(const object::ObjectFile *o);
 void PrintSectionContents(const object::ObjectFile *o);
 void PrintSymbolTable(const object::ObjectFile *o);
+void report_error(StringRef File, std::error_code EC);
 
 } // end namespace llvm